From 56bba6a822be6fb9e6ec5f0f7e04dd45f9d42221 Mon Sep 17 00:00:00 2001 From: NeeEoo Date: Sat, 16 Mar 2024 21:44:28 +0100 Subject: [PATCH] Cleanup --- source/funkin/backend/FunkinSprite.hx | 13 +++++- .../editors/character/CharacterInfoScreen.hx | 2 +- source/funkin/editors/ui/UIColorwheel.hx | 2 +- source/funkin/game/Character.hx | 44 ++++++++++--------- source/funkin/game/PlayState.hx | 4 +- source/funkin/options/OptionsTree.hx | 5 +-- 6 files changed, 40 insertions(+), 30 deletions(-) diff --git a/source/funkin/backend/FunkinSprite.hx b/source/funkin/backend/FunkinSprite.hx index 53925e5d..51a322c0 100644 --- a/source/funkin/backend/FunkinSprite.hx +++ b/source/funkin/backend/FunkinSprite.hx @@ -42,9 +42,9 @@ class FunkinSprite extends FlxSkewedSprite implements IBeatReceiver implements I public var animDatas:Map = []; /** - * ODD interval -> asycned; EVEN interval -> synced + * ODD interval -> asynced; EVEN interval -> synced */ - public var beatInterval:Int = 2; + public var beatInterval(default, set):Int = 2; public var beatOffset:Int = 0; public var skipNegativeBeats:Bool = false; @@ -361,4 +361,13 @@ class FunkinSprite extends FlxSkewedSprite implements IBeatReceiver implements I return animateAtlas != null ? (animateAtlas.anim.finished) : (animation.curAnim != null ? animation.curAnim.finished : true); } #end + + // Getter / Setters + + @:noCompletion private function set_beatInterval(v:Int) { + if (v < 1) + v = 1; + + return beatInterval = v; + } } diff --git a/source/funkin/editors/character/CharacterInfoScreen.hx b/source/funkin/editors/character/CharacterInfoScreen.hx index f7645ca0..28425c2e 100644 --- a/source/funkin/editors/character/CharacterInfoScreen.hx +++ b/source/funkin/editors/character/CharacterInfoScreen.hx @@ -181,7 +181,7 @@ class CharacterInfoScreen extends UISubstateWindow { xml.set("antialiasing", antialiasingCheckbox.checked ? "true" : "false"); xml.set("sprite", spriteTextBox.label.text); if (iconColorWheel.colorChanged) - xml.set("color", iconColorWheel.curColor.toHexString(false).replace("0x", "#")); + xml.set("color", iconColorWheel.curColor.toWebString()); for (val in customPropertiesButtonList.buttons.members) xml.set(val.propertyText.label.text, val.valueText.label.text); diff --git a/source/funkin/editors/ui/UIColorwheel.hx b/source/funkin/editors/ui/UIColorwheel.hx index 421814c4..0a28e20e 100644 --- a/source/funkin/editors/ui/UIColorwheel.hx +++ b/source/funkin/editors/ui/UIColorwheel.hx @@ -108,7 +108,7 @@ class UIColorwheel extends UISliceSprite { colorPickerSelector.curColor = color = curColor = FlxColor.fromHSB(hue, saturation, brightness); colorSliderSelector.curColor = FlxColor.fromHSB(hue, 1, 1); updateColorPickerSelector(); updateColorSliderPickerSelector(); - colorHexTextBox.label.text = curColorString = curColor.toHexString(false).replace("0x", "#"); + colorHexTextBox.label.text = curColorString = curColor.toWebString(); for (numStepper in rgbNumSteppers) { numStepper.label.text = Std.string(switch (numStepper.ID) { default: curColor.red; diff --git a/source/funkin/game/Character.hx b/source/funkin/game/Character.hx index 569b58dc..2087a91d 100644 --- a/source/funkin/game/Character.hx +++ b/source/funkin/game/Character.hx @@ -1,6 +1,5 @@ package funkin.game; -import haxe.xml.Printer; import flixel.util.FlxColor; import funkin.backend.FunkinSprite; import flixel.graphics.frames.FlxFrame; @@ -8,8 +7,6 @@ import flixel.math.FlxPoint; import funkin.backend.system.interfaces.IBeatReceiver; import funkin.backend.system.interfaces.IOffsetCompatible; import funkin.backend.utils.XMLUtil; -import flixel.animation.FlxBaseAnimation; -import flixel.graphics.frames.FlxAtlasFrames; import flixel.math.FlxRect; import haxe.xml.Access; import haxe.Exception; @@ -35,12 +32,6 @@ class Character extends FunkinSprite implements IBeatReceiver implements IOffset public var stunned(default, set):Bool = false; - private function set_stunned(b:Bool) - { - __stunnedTime = 0; - return stunned = b; - } - public var isPlayer:Bool = false; public var isGF:Bool = false; public var curCharacter:String = 'bf'; @@ -80,10 +71,10 @@ class Character extends FunkinSprite implements IBeatReceiver implements IOffset { var anims = ["singLEFT", "singDOWN", "singUP", "singRIGHT"]; - var event = EventManager.get(DirectionAnimEvent).recycle('${anims[direction]}$suffix', direction, suffix, Context, Reversed, Frame, Force); + var event = EventManager.get(DirectionAnimEvent).recycle(anims[direction] + suffix, direction, suffix, Context, Reversed, Frame, Force); script.call("onPlaySingAnim", [event]); if (!event.cancelled) - playAnim(event.animName, event.force, Context, event.reversed, event.frame); + playAnim(event.animName, event.force, event.context, event.reversed, event.frame); } public function new(x:Float, y:Float, ?character:String = "bf", isPlayer:Bool = false, switchAnims:Bool = true) @@ -250,17 +241,10 @@ class Character extends FunkinSprite implements IBeatReceiver implements IOffset */ public var danceOnBeat:Bool = true; - /** - * Interval at which the character will dance (higher number = slower dance) - */ - public var danceInterval:Int = 1; - public override function beatHit(curBeat:Int) { script.call("beatHit", [curBeat]); - if (danceInterval < 1) - danceInterval = 1; - if (danceOnBeat && curBeat % danceInterval == 0 && !__lockAnimThisFrame) + if (danceOnBeat && (curBeat + beatOffset) % beatInterval == 0 && !__lockAnimThisFrame) { tryDance(); } @@ -448,7 +432,7 @@ class Character extends FunkinSprite implements IBeatReceiver implements IOffset xml.set("flipX", Std.string(flipX)); xml.set("icon", getIcon()); if (iconColor != null) - xml.set("color", iconColor.toHexString(false).replace("0x", "#")); + xml.set("color", iconColor.toWebString()); xml.set("scale", Std.string(scale.x)); xml.set("antialiasing", antialiasing == true ? "true" : "false"); xml.set("sprite", sprite); @@ -474,6 +458,7 @@ class Character extends FunkinSprite implements IBeatReceiver implements IOffset var offset:FlxPoint = getAnimOffset(anim.name); animXml.set("x", Std.string(offset.x)); animXml.set("y", Std.string(offset.y)); + offset.putWeak(); if (anim.indices.length > 0) animXml.set("indices", anim.indices.join(",")); xml.addChild(animXml); @@ -490,6 +475,25 @@ class Character extends FunkinSprite implements IBeatReceiver implements IOffset return [for(a in xml.nodes.anim) if(a.has.name) a.att.name]; } + // Getters / Setters + + @:noCompletion private function set_stunned(b:Bool) + { + __stunnedTime = 0; + return stunned = b; + } + + // Backwards Compat + + /** + * Interval at which the character will dance (higher number = slower dance) + */ + @:noCompletion public var danceInterval(get, set):Int; + @:noCompletion private function set_danceInterval(v:Int) + return beatInterval = v; + @:noCompletion private function get_danceInterval() + return beatInterval; + // Statics public static function getIconFromCharName(?curCharacter:String) { diff --git a/source/funkin/game/PlayState.hx b/source/funkin/game/PlayState.hx index fd9b13e7..c7364225 100644 --- a/source/funkin/game/PlayState.hx +++ b/source/funkin/game/PlayState.hx @@ -1846,10 +1846,10 @@ class PlayState extends MusicBeatState private inline function get_playerStrums():StrumLine return strumLines.members[1]; private inline function get_gfSpeed():Int - return (strumLines.members[2] != null && strumLines.members[2].characters[0] != null) ? strumLines.members[2].characters[0].danceInterval : 1; + return (strumLines.members[2] != null && strumLines.members[2].characters[0] != null) ? strumLines.members[2].characters[0].beatInterval : 1; private inline function set_gfSpeed(v:Int):Int { if (strumLines.members[2] != null && strumLines.members[2].characters[0] != null) - strumLines.members[2].characters[0].danceInterval = v; + strumLines.members[2].characters[0].beatInterval = v; return v; } diff --git a/source/funkin/options/OptionsTree.hx b/source/funkin/options/OptionsTree.hx index ae4d599c..c457d52e 100644 --- a/source/funkin/options/OptionsTree.hx +++ b/source/funkin/options/OptionsTree.hx @@ -53,10 +53,7 @@ class OptionsTree extends FlxTypedGroup { } public function clearLastMenu() { - if (lastMenu != null) { - lastMenu.destroy(); - lastMenu = null; - } + lastMenu = FlxDestroyUtil.destroy(lastMenu); } public override function destroy() {