1
0
Fork 0
mirror of https://github.com/ninjamuffin99/Funkin.git synced 2025-11-05 03:15:23 +00:00

Use cyn0x8's Sequence class to fix the nametags.

This commit is contained in:
EliteMasterEric 2025-07-09 00:50:21 -04:00 committed by Abnormal
parent 9e182f70d2
commit 1025fed57f
2 changed files with 45 additions and 25 deletions

View file

@ -3,6 +3,7 @@ package funkin.ui.charSelect;
import flixel.FlxSprite;
import funkin.graphics.shaders.MosaicEffect;
import flixel.util.FlxTimer;
import funkin.util.TimerUtil;
class Nametag extends FlxSprite
{
@ -12,6 +13,8 @@ class Nametag extends FlxSprite
var midpointY(default, set):Float = 100;
var mosaicShader:MosaicEffect;
var currentMosaicSequence:Sequence;
public function new(?x:Float = 0, ?y:Float = 0, character:String)
{
super(x, y);
@ -57,19 +60,30 @@ class Nametag extends FlxSprite
function shaderEffect(fadeOut:Bool = false):Void
{
if (currentMosaicSequence != null)
{
// Forcibly reset the shader to prevent overlapping blur sequences
mosaicShader.setBlockSize(1, 1);
currentMosaicSequence.destroy();
currentMosaicSequence = null;
}
if (fadeOut)
{
setBlockTimer(0, 1, 1);
setBlockTimer(1, width / 27, height / 26);
setBlockTimer(2, width / 10, height / 10);
setBlockTimer(3, 1, 1);
currentMosaicSequence = new Sequence([
{time: 0 / 30, callback: () -> mosaicShader.setBlockSize(1, 1)},
{time: 1 / 30, callback: () -> mosaicShader.setBlockSize(width / 27, height / 26)},
{time: 2 / 30, callback: () -> mosaicShader.setBlockSize(width / 10, height / 10)},
{time: 3 / 30, callback: () -> mosaicShader.setBlockSize(1, 1)},
]);
}
else
{
setBlockTimer(0, (width / 10), (height / 10));
setBlockTimer(1, width / 73, height / 6);
setBlockTimer(2, width / 10, height / 10);
currentMosaicSequence = new Sequence([
{time: 0 / 30, callback: () -> mosaicShader.setBlockSize(width / 10, height / 10)},
{time: 1 / 30, callback: () -> mosaicShader.setBlockSize(width / 73, height / 6)},
{time: 2 / 30, callback: () -> mosaicShader.setBlockSize(width / 10, height / 10)},
]);
}
}

View file

@ -3,8 +3,6 @@ package funkin.util;
import flixel.util.FlxSignal;
import flixel.util.FlxTimer;
import funkin.Conductor;
import funkin.util.tools.FloatTools;
import haxe.Timer;
import haxe.ds.ArraySort;
/**
@ -55,26 +53,29 @@ class Sequence
/**
* The list of uncompleted timers for their respective events.
*/
private final timers:Array<FlxTimer> = new Array<FlxTimer>();
final timers:Array<FlxTimer> = [];
/**
* Controls whether this sequence is running or not.
*/
public var running(get, set):Bool;
private var _running:Bool = false;
var _running:Bool = false;
@:noCompletion public function get_running():Bool
function get_running():Bool
{
return completed ? false : _running;
}
@:noCompletion public function set_running(v:Bool):Bool
function set_running(v:Bool):Bool
{
if (completed) return false;
for (timer in timers)
{
timer.active = v;
return _running = v;
}
_running = v;
return _running;
}
/**
@ -82,7 +83,7 @@ class Sequence
*/
public var completed(get, never):Bool;
@:noCompletion public function get_completed():Bool
function get_completed():Bool
{
return timers.length == 0;
}
@ -110,7 +111,7 @@ class SongSequence
/**
* Signal dispatched by `Conductor.instance.update`.
*/
private static final update:FlxSignal = new FlxSignal();
static final update:FlxSignal = new FlxSignal();
/**
* Create a new sequence.
@ -143,21 +144,23 @@ class SongSequence
/**
* Keeps track of the time this sequence started, or the relative time if it was previously stopped.
*/
private var startTime:Float = 0;
var startTime:Float = 0;
/**
* The list of uncompleted events.
*/
private final events:Array<SequenceEvent> = new Array<SequenceEvent>();
final events:Array<SequenceEvent> = [];
/**
* Update function invoked by the update signal.
*/
private function onUpdate():Void
function onUpdate():Void
{
if (!running) return;
while (events.length > 0 && events[0].time + startTime <= Conductor.instance.songPosition)
{
events.shift()?.callback();
}
if (completed) destroy();
}
@ -166,18 +169,19 @@ class SongSequence
*/
public var running(get, set):Bool;
private var _running:Bool = false;
var _running:Bool = false;
@:noCompletion public function get_running():Bool
function get_running():Bool
{
return _running && !completed;
}
@:noCompletion public function set_running(v:Bool):Bool
function set_running(v:Bool):Bool
{
if (completed) return false;
if (v != _running) startTime = Conductor.instance.songPosition - startTime; // it works trust me
return _running = v;
_running = v;
return _running;
}
/**
@ -185,7 +189,7 @@ class SongSequence
*/
public var completed(get, never):Bool;
@:noCompletion public function get_completed():Bool
function get_completed():Bool
{
return events.length == 0;
}
@ -197,6 +201,8 @@ class SongSequence
{
update.remove(onUpdate);
while (!completed)
{
events.pop();
}
}
}