Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Note Hold Covers #2

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Binary file added images/game/splashes/hold/holdCoverBlue.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
16 changes: 16 additions & 0 deletions images/game/splashes/hold/holdCoverBlue.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
<?xml version="1.0" encoding="UTF-8"?>
<TextureAtlas imagePath="holdCoverBlue.png" width="599" height="591">
<SubTexture name="holdCoverStartBlue0001" x="413" y="96" width="93" height="93" frameX="-111" frameY="-107" frameWidth="300" frameHeight="400" />
<SubTexture name="holdCoverBlue0001" x="407" y="242" width="108" height="138" rotated="true" frameX="-94" frameY="-94" frameWidth="300" frameHeight="400" />
<SubTexture name="holdCoverBlue0002" x="413" y="0" width="120" height="96" frameX="-100" frameY="-104" frameWidth="300" frameHeight="400" />
<SubTexture name="holdCoverBlue0003" x="506" y="96" width="93" height="80" frameX="-115" frameY="-107" frameWidth="300" frameHeight="400" />
<SubTexture name="holdCoverBlue0004" x="146" y="423" width="36" height="78" rotated="true" frameX="-122" frameY="-133" frameWidth="300" frameHeight="400" />
<SubTexture name="holdCoverEndBlue0001" x="146" y="423" width="36" height="78" rotated="true" frameX="-122" frameY="-133" frameWidth="300" frameHeight="400" />
<SubTexture name="holdCoverEndBlue0002" x="0" y="423" width="146" height="168" rotated="true" frameX="-72" frameY="-59" frameWidth="300" frameHeight="400" />
<SubTexture name="holdCoverEndBlue0003" x="192" y="242" width="215" height="185" frameX="-47" frameY="-55" frameWidth="300" frameHeight="400" />
<SubTexture name="holdCoverEndBlue0004" x="192" y="242" width="215" height="185" frameX="-47" frameY="-55" frameWidth="300" frameHeight="400" />
<SubTexture name="holdCoverEndBlue0005" x="0" y="193" width="192" height="230" rotated="true" frameX="-44" frameY="-62" frameWidth="300" frameHeight="400" />
<SubTexture name="holdCoverEndBlue0006" x="0" y="0" width="246" height="193" frameX="-43" frameY="-78" frameWidth="300" frameHeight="400" />
<SubTexture name="holdCoverEndBlue0007" x="246" y="0" width="167" height="242" rotated="true" frameX="-53" frameY="-113" frameWidth="300" frameHeight="400" />
<SubTexture name="holdCoverEndBlue0008" x="246" y="0" width="167" height="242" rotated="true" frameX="-53" frameY="-113" frameWidth="300" frameHeight="400" />
</TextureAtlas>
Binary file added images/game/splashes/hold/holdCoverGreen.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
16 changes: 16 additions & 0 deletions images/game/splashes/hold/holdCoverGreen.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
<?xml version="1.0" encoding="UTF-8"?>
<TextureAtlas imagePath="holdCoverGreen.png" width="599" height="591">
<SubTexture name="holdCoverStartGreen0001" x="413" y="96" width="93" height="93" frameX="-111" frameY="-107" frameWidth="300" frameHeight="400" />
<SubTexture name="holdCoverGreen0001" x="407" y="243" width="108" height="139" rotated="true" frameX="-93" frameY="-94" frameWidth="300" frameHeight="400" />
<SubTexture name="holdCoverGreen0002" x="413" y="0" width="120" height="96" frameX="-100" frameY="-104" frameWidth="300" frameHeight="400" />
<SubTexture name="holdCoverGreen0003" x="506" y="96" width="93" height="80" frameX="-115" frameY="-107" frameWidth="300" frameHeight="400" />
<SubTexture name="holdCoverGreen0004" x="146" y="423" width="36" height="78" rotated="true" frameX="-122" frameY="-133" frameWidth="300" frameHeight="400" />
<SubTexture name="holdCoverEndGreen0001" x="146" y="423" width="36" height="78" rotated="true" frameX="-122" frameY="-133" frameWidth="300" frameHeight="400" />
<SubTexture name="holdCoverEndGreen0002" x="0" y="423" width="146" height="168" rotated="true" frameX="-72" frameY="-59" frameWidth="300" frameHeight="400" />
<SubTexture name="holdCoverEndGreen0003" x="192" y="243" width="215" height="185" frameX="-47" frameY="-55" frameWidth="300" frameHeight="400" />
<SubTexture name="holdCoverEndGreen0004" x="192" y="243" width="215" height="185" frameX="-47" frameY="-55" frameWidth="300" frameHeight="400" />
<SubTexture name="holdCoverEndGreen0005" x="0" y="193" width="192" height="230" rotated="true" frameX="-44" frameY="-62" frameWidth="300" frameHeight="400" />
<SubTexture name="holdCoverEndGreen0006" x="0" y="0" width="246" height="193" frameX="-43" frameY="-78" frameWidth="300" frameHeight="400" />
<SubTexture name="holdCoverEndGreen0007" x="246" y="0" width="167" height="243" rotated="true" frameX="-52" frameY="-113" frameWidth="300" frameHeight="400" />
<SubTexture name="holdCoverEndGreen0008" x="246" y="0" width="167" height="243" rotated="true" frameX="-52" frameY="-113" frameWidth="300" frameHeight="400" />
</TextureAtlas>
Binary file added images/game/splashes/hold/holdCoverPurple.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
16 changes: 16 additions & 0 deletions images/game/splashes/hold/holdCoverPurple.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
<?xml version="1.0" encoding="UTF-8"?>
<TextureAtlas imagePath="holdCoverPurple.png" width="599" height="591">
<SubTexture name="holdCoverStartPurple0001" x="413" y="96" width="93" height="93" frameX="-111" frameY="-107" frameWidth="300" frameHeight="400" />
<SubTexture name="holdCoverPurple0001" x="407" y="243" width="108" height="139" rotated="true" frameX="-93" frameY="-94" frameWidth="300" frameHeight="400" />
<SubTexture name="holdCoverPurple0002" x="413" y="0" width="120" height="96" frameX="-100" frameY="-104" frameWidth="300" frameHeight="400" />
<SubTexture name="holdCoverPurple0003" x="506" y="96" width="93" height="80" frameX="-115" frameY="-107" frameWidth="300" frameHeight="400" />
<SubTexture name="holdCoverPurple0004" x="146" y="423" width="36" height="78" rotated="true" frameX="-122" frameY="-133" frameWidth="300" frameHeight="400" />
<SubTexture name="holdCoverEndPurple0001" x="146" y="423" width="36" height="78" rotated="true" frameX="-122" frameY="-133" frameWidth="300" frameHeight="400" />
<SubTexture name="holdCoverEndPurple0002" x="0" y="423" width="146" height="168" rotated="true" frameX="-72" frameY="-59" frameWidth="300" frameHeight="400" />
<SubTexture name="holdCoverEndPurple0003" x="192" y="243" width="215" height="185" frameX="-47" frameY="-55" frameWidth="300" frameHeight="400" />
<SubTexture name="holdCoverEndPurple0004" x="192" y="243" width="215" height="185" frameX="-47" frameY="-55" frameWidth="300" frameHeight="400" />
<SubTexture name="holdCoverEndPurple0005" x="0" y="193" width="192" height="230" rotated="true" frameX="-44" frameY="-62" frameWidth="300" frameHeight="400" />
<SubTexture name="holdCoverEndPurple0006" x="0" y="0" width="246" height="193" frameX="-43" frameY="-78" frameWidth="300" frameHeight="400" />
<SubTexture name="holdCoverEndPurple0007" x="246" y="0" width="167" height="243" rotated="true" frameX="-52" frameY="-113" frameWidth="300" frameHeight="400" />
<SubTexture name="holdCoverEndPurple0008" x="246" y="0" width="167" height="243" rotated="true" frameX="-52" frameY="-113" frameWidth="300" frameHeight="400" />
</TextureAtlas>
Binary file added images/game/splashes/hold/holdCoverRed.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
16 changes: 16 additions & 0 deletions images/game/splashes/hold/holdCoverRed.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
<?xml version="1.0" encoding="UTF-8"?>
<TextureAtlas imagePath="holdCoverRed.png" width="599" height="591">
<SubTexture name="holdCoverStartRed0001" x="413" y="96" width="93" height="93" frameX="-111" frameY="-107" frameWidth="300" frameHeight="400" />
<SubTexture name="holdCoverRed0001" x="407" y="243" width="108" height="139" rotated="true" frameX="-93" frameY="-94" frameWidth="300" frameHeight="400" />
<SubTexture name="holdCoverRed0002" x="413" y="0" width="120" height="96" frameX="-100" frameY="-104" frameWidth="300" frameHeight="400" />
<SubTexture name="holdCoverRed0003" x="506" y="96" width="93" height="80" frameX="-115" frameY="-107" frameWidth="300" frameHeight="400" />
<SubTexture name="holdCoverRed0004" x="146" y="423" width="36" height="78" rotated="true" frameX="-122" frameY="-133" frameWidth="300" frameHeight="400" />
<SubTexture name="holdCoverEndRed0001" x="146" y="423" width="36" height="78" rotated="true" frameX="-122" frameY="-133" frameWidth="300" frameHeight="400" />
<SubTexture name="holdCoverEndRed0002" x="0" y="423" width="146" height="168" rotated="true" frameX="-72" frameY="-59" frameWidth="300" frameHeight="400" />
<SubTexture name="holdCoverEndRed0003" x="192" y="243" width="215" height="185" frameX="-47" frameY="-55" frameWidth="300" frameHeight="400" />
<SubTexture name="holdCoverEndRed0004" x="192" y="243" width="215" height="185" frameX="-47" frameY="-55" frameWidth="300" frameHeight="400" />
<SubTexture name="holdCoverEndRed0005" x="0" y="193" width="192" height="230" rotated="true" frameX="-44" frameY="-62" frameWidth="300" frameHeight="400" />
<SubTexture name="holdCoverEndRed0006" x="0" y="0" width="246" height="193" frameX="-43" frameY="-78" frameWidth="300" frameHeight="400" />
<SubTexture name="holdCoverEndRed0007" x="246" y="0" width="167" height="243" rotated="true" frameX="-52" frameY="-113" frameWidth="300" frameHeight="400" />
<SubTexture name="holdCoverEndRed0008" x="246" y="0" width="167" height="243" rotated="true" frameX="-52" frameY="-113" frameWidth="300" frameHeight="400" />
</TextureAtlas>
29 changes: 29 additions & 0 deletions songs/vslice_uiShits.hx
Original file line number Diff line number Diff line change
@@ -1,6 +1,24 @@
//
import game.NoteCoverHandler;

/*
* Whether to init the note hold covers if set to true (to set before onStrumCreation).
*/
public var initHoldCovers:Bool = true;
public var noteCoversHandler:NoteCoverHandler;

public var ratingScaleDiff:Float = 0.1;

function onPostStrumCreation(e)
{
if (!hideHoldCovers) return;

if (noteCoversHandler == null)
add(noteCoversHandler = new NoteCoverHandler());

noteCoversHandler.cacheStuff(e.strumID);
}

function create() {
comboGroup.x = 560;
comboGroup.y = 290;
Expand All @@ -22,7 +40,18 @@ function onPostCountdown(event) {
function onNoteHit(event) {
event.numScale -= ratingScaleDiff;
event.ratingScale -= ratingScaleDiff;

if (!e.cancelled && e.note.isSustainNote && e.note.__strum != null && noteCoversHandler != null) {
noteCoversHandler.showCover();

if (e.note.animation.name == "holdend")
noteCoversHandler.coverSpark(e.note.__strum, e.note.height / 3.5, e.player);
}
}

function onPlayerMiss(e)
if (noteCoversHandler.cacheStuff(e.note.__strum.ID).cover.visible)
noteCoversHandler.coverSpark(e.note.__strum, null);

function update()
comboGroup.forEachAlive(function(spr) if (spr.camera != camHUD) spr.camera = camHUD);
113 changes: 113 additions & 0 deletions source/game/NoteCoverHandler.hx
Original file line number Diff line number Diff line change
@@ -0,0 +1,113 @@
import flixel.group.FlxTypedSpriteGroup;

import funkin.game.Strum;
import notes.NoteHoldCover;
import notes.NoteHoldSplash;

class NoteCoverHandler extends FlxTypedGroup<FunkinSprite>
{
/*
* Array of the color directions for the strumlines.
*/
public static var directions:Array<String> = ['Purple', 'Blue', 'Green', 'Red'];

public static function getDirectionName(direction:Int)
return NoteCoverHandler.directions[direction % NoteCoverHandler.directions.length];

/**
* Array containing all of the covers group (index = direction).
*/
public var datas:Array<CoverData> = [];

public function new() {
super();
}

/**
* Caches Hold Covers/Splashes.
*/
public function cacheStuff(direction:Int):CoverData {
if (datas[i] == null) datas[i] = CoverData.initNcache(direction);
return datas[i];
}

public override function destroy() {
super.destroy();
for(data in datas)
data.destroy();
datas = null;
}

var _firstDraw:Bool = true;
public override function draw() {
super.draw();
if (_firstDraw != (_firstDraw = false))
for(sprs in datas)
sprs.draw();
}

public function showCover(strum:Strum) {
var __spr = cacheStuff(strum.ID).cover;
__spr.cameras = strum.lastDrawCameras;

__spr.updatePosition(strum);
__spr.start();
add(__spr);

// max 16 rendered covers
while(members.length > 16)
remove(members[0], true);
}

function coverSpark(strum:Strum, delay:Float = 0, showSplash:Bool) {
var __data = cacheStuff(strum.ID);

new FlxTimer().start(0.01 * delay, function() {
if (!showSplash)
{
var splash = __data.splash.start();
splash.setPosition(cover.x = strum.x + cover.posX, cover.y = strum.y + cover.posY);
splash.angle = cover.angle = strum.angle;
splash.antialiasing = cover.antialiasing;
splash.visible = cover.visible;
splash.cameras = cover.cameras;
add(splash);
}

cover.visible = false;
});
}
}

class CoverData
{
public var cover:NoteHoldCover;
public var splash:NoteHoldSplash;

function new(cover:NoteHoldCover, splash:NoteHoldSplash):Void
{
super();

this.cover = cover;
this.splash = splash;

// immediatly draw once and put image in GPU to prevent freezes - Nex
cover.drawComplex(FlxG.camera);
splash.drawComplex(FlxG.camera);
}

public function draw()
{
cover.draw();
splash.draw();
}

public function destroy()
{
cover.destroy();
splash.destroy();
}

public static function initNcache(direction:Int):CoverData
return new CoverData(new NoteHoldCover(direction), new NoteHoldSplash(direction));
}
50 changes: 50 additions & 0 deletions source/notes/NoteHoldCover.hx
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
import game.NoteCoverHandler;

class NoteHoldCover extends funkin.backend.FunkinSprite
{
/*
* X Position of the hold cover.
*/
public var posX:Float = -107.5;

/*
* Array of the Y Position for the hold cover.
*/
public var posY:Float = 0;

public function new(direction:Int):Void
{
var suffix = NoteCoverHandler.getDirectionName(direction);
frames = Paths.getSparrowAtlas("game/splashes/hold/holdCover" + suffix);
animation.addByPrefix("start", "holdCoverStart" + suffix, 24, false);
animation.addByPrefix("hold", "holdCover" + suffix, 24, true);

antialiasing = true;
visible = false;

animation.finishCallback = this.onAnimationFinished;
}

public function updatePosition(object:FlxObject) {
x = object.x + posX;
y = object.y + posY;
angle = object.angle;
alpha = object.alpha;
}

public function onAnimationFinished(animName:String):Void
if (animName == 'start') playHold();

public function start() {
if (!visible && animation.name == "hold") playStart();
else playHold();
}

public function playStart() {
visible = true;
playAnim('start');
}

public function playHold()
playAnim('hold');
}
15 changes: 15 additions & 0 deletions source/notes/NoteHoldSplash.hx
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
import game.NoteCoverHandler;

class NoteHoldSplash extends funkin.backend.FunkinSprite
{
public function new(direction:Int) {
var suffix = NoteCoverHandler.getDirectionName(direction);
frames = Paths.getSparrowAtlas("game/splashes/hold/holdCover" + suffix);
animation.addByPrefix("holdEnd", "holdCoverEnd" + suffix, 24, false);
}

public function start() {
playAnim('holdEnd', true);
animation.finishCallback = () -> visible = false;
}
}