1
0
Fork 0
mirror of https://github.com/ninjamuffin99/Funkin.git synced 2025-09-03 20:28:04 +00:00
Funkin/source/funkin/ui/charSelect/CharSelectGF.hx

124 lines
3.5 KiB
Haxe
Raw Permalink Normal View History

2024-06-15 04:59:58 +00:00
package funkin.ui.charSelect;
import funkin.graphics.FunkinSprite;
2024-09-01 07:22:34 +00:00
import funkin.modding.IScriptedClass.IBPMSyncedScriptedClass;
import funkin.modding.events.ScriptEvent;
2024-08-22 21:36:43 +00:00
import funkin.vis.dsp.SpectralAnalyzer;
2024-09-18 15:32:37 +00:00
import funkin.data.freeplay.player.PlayerRegistry;
import funkin.ui.FullScreenScaleMode;
import flixel.math.FlxPoint;
2024-06-15 04:59:58 +00:00
class CharSelectGF extends FunkinSprite implements IBPMSyncedScriptedClass
2024-06-15 04:59:58 +00:00
{
2024-08-22 21:36:43 +00:00
var analyzer:SpectralAnalyzer;
2024-06-15 04:59:58 +00:00
2024-09-19 08:16:40 +00:00
var currentGFPath:Null<String>;
var enableVisualizer:Bool = false;
2024-08-29 18:32:10 +00:00
var danceEvery:Int = 2;
2024-06-15 04:59:58 +00:00
public function new()
{
super();
this.applyStageMatrix = true;
2024-06-15 04:59:58 +00:00
switchGF("bf");
}
2024-09-01 07:22:34 +00:00
public function onStepHit(event:SongTimeScriptEvent):Void {}
public function onBeatHit(event:SongTimeScriptEvent):Void
{
// TODO: There's a minor visual bug where there's a little stutter.
// This happens because the animation is getting restarted while it's already playing.
// I tried make this not interrupt an existing idle,
// but isAnimationFinished() and isLoopComplete() both don't work! What the hell?
// danceEvery isn't necessary if that gets fixed.
if (getCurrentAnimation() == "idle" && (event.beat % danceEvery == 0))
{
trace('GF beat hit');
anim.play("idle", true);
2024-09-01 07:22:34 +00:00
}
};
2024-08-22 21:36:43 +00:00
override public function draw()
{
if (analyzer != null) drawFFT();
super.draw();
}
function drawFFT()
{
2024-09-19 08:16:40 +00:00
if (enableVisualizer)
2024-08-22 21:36:43 +00:00
{
var levels = analyzer.getLevels();
var frame = this.timeline.getLayer("VIZ_bars").getFrameAtIndex(anim.curAnim.curFrame);
var elements = frame.elements;
2024-08-22 21:36:43 +00:00
var len:Int = cast Math.min(elements.length, 7);
for (i in 0...len)
{
2025-06-25 05:24:37 +00:00
var animFrame:Int = (FlxG.sound.volume == 0 || FlxG.sound.muted) ? 0 : Math.round(levels[i].value * 12);
2024-08-22 21:36:43 +00:00
#if sys
2024-09-04 14:58:18 +00:00
// Web version scales with the Flixel volume level.
// This line brings platform parity but looks worse.
// animFrame = Math.round(animFrame * FlxG.sound.volume);
2024-08-22 21:36:43 +00:00
#end
animFrame = Math.floor(Math.min(12, animFrame));
animFrame = Math.floor(Math.max(0, animFrame));
animFrame = Std.int(Math.abs(animFrame - 12)); // shitty dumbass flip, cuz dave got da shit backwards lol!
var convertedSymbol = elements[i].toSymbolInstance();
convertedSymbol.firstFrame = animFrame;
elements[i] = convertedSymbol;
2024-06-15 04:59:58 +00:00
}
}
}
2024-08-29 18:32:10 +00:00
/**
* For switching between "GFs" such as gf, nene, etc
* @param bf Which BF we are selecting, so that we know the accompyaning GF
*/
public function switchGF(bf:String):Void
2024-06-15 04:59:58 +00:00
{
2024-09-19 08:16:40 +00:00
var previousGFPath = currentGFPath;
2024-09-18 15:32:37 +00:00
var bfObj = PlayerRegistry.instance.fetchEntry(bf);
2024-09-19 08:16:40 +00:00
var gfData = bfObj?.getCharSelectData()?.gf;
currentGFPath = gfData?.assetPath ?? null;
2024-06-15 04:59:58 +00:00
2024-08-29 18:32:10 +00:00
// We don't need to update any anims if we didn't change GF
2024-09-19 08:16:40 +00:00
trace('currentGFPath(${currentGFPath})');
if (currentGFPath == null)
{
this.visible = false;
return;
}
else if (previousGFPath != currentGFPath)
2024-09-01 07:22:34 +00:00
{
2024-09-19 08:16:40 +00:00
this.visible = true;
frames = CharSelectAtlasHandler.loadAtlas(currentGFPath,
{
swfMode: true
});
2024-06-15 04:59:58 +00:00
2024-09-19 08:16:40 +00:00
enableVisualizer = gfData?.visualizer ?? false;
2024-09-01 07:22:34 +00:00
}
2024-06-15 04:59:58 +00:00
anim.play("idle", true);
2024-06-15 04:59:58 +00:00
updateHitbox();
}
2024-09-01 07:22:34 +00:00
public function onScriptEvent(event:ScriptEvent):Void {};
public function onCreate(event:ScriptEvent):Void {};
public function onDestroy(event:ScriptEvent):Void {};
public function onUpdate(event:UpdateScriptEvent):Void {};
2024-06-15 04:59:58 +00:00
}