From 6060032235f0cb9de6238f919b2b5b1fda95d1b1 Mon Sep 17 00:00:00 2001 From: Yoshman29 <81191621+YoshiCrafter29@users.noreply.github.com> Date: Mon, 9 Jan 2023 16:51:14 +0100 Subject: [PATCH] pooled events --- buildnumber.txt | 2 +- source/funkin/game/Character.hx | 8 +- source/funkin/game/Note.hx | 2 +- source/funkin/game/PlayState.hx | 30 ++--- source/funkin/import.hx | 4 +- source/funkin/macros/BuildCounterMacro.hx | 2 + source/funkin/macros/EventMacro.hx | 115 ++++++++++++++++++ source/funkin/macros/FlxSpriteProxyMacro.hx | 5 - source/funkin/macros/import.hx | 5 + source/funkin/menus/MainMenuState.hx | 4 +- source/funkin/menus/PauseSubState.hx | 4 +- source/funkin/menus/StoryMenuState.hx | 6 +- source/funkin/scripting/EventManager.hx | 22 ++++ .../funkin/scripting/events/CamMoveEvent.hx | 9 -- .../scripting/events/CancellableEvent.hx | 7 ++ .../funkin/scripting/events/CountdownEvent.hx | 10 -- source/funkin/scripting/events/DanceEvent.hx | 4 - .../scripting/events/DirectionAnimEvent.hx | 21 +--- .../scripting/events/InputSystemEvent.hx | 7 -- .../scripting/events/MenuChangeEvent.hx | 18 +-- source/funkin/scripting/events/NameEvent.hx | 5 - .../scripting/events/NoteCreationEvent.hx | 20 --- .../funkin/scripting/events/NoteHitEvent.hx | 37 +----- .../scripting/events/NoteUpdateEvent.hx | 7 -- .../scripting/events/PauseCreationEvent.hx | 7 -- .../funkin/scripting/events/PlayAnimEvent.hx | 9 -- source/funkin/scripting/events/PointEvent.hx | 5 - .../scripting/events/RatingUpdateEvent.hx | 5 - source/funkin/scripting/events/ResizeEvent.hx | 7 -- .../scripting/events/SimpleNoteEvent.hx | 5 - source/funkin/scripting/events/StateEvent.hx | 5 - .../scripting/events/StrumCreationEvent.hx | 11 +- .../scripting/events/WeekSelectEvent.hx | 9 -- source/funkin/system/MusicBeatState.hx | 6 +- source/funkin/system/MusicBeatSubstate.hx | 6 +- 35 files changed, 207 insertions(+), 222 deletions(-) create mode 100644 source/funkin/macros/EventMacro.hx create mode 100644 source/funkin/macros/import.hx create mode 100644 source/funkin/scripting/EventManager.hx diff --git a/buildnumber.txt b/buildnumber.txt index e4e379e8..398d2f0b 100644 --- a/buildnumber.txt +++ b/buildnumber.txt @@ -1 +1 @@ -1962 \ No newline at end of file +1965 \ No newline at end of file diff --git a/source/funkin/game/Character.hx b/source/funkin/game/Character.hx index c922b76f..279521d0 100644 --- a/source/funkin/game/Character.hx +++ b/source/funkin/game/Character.hx @@ -64,7 +64,7 @@ class Character extends FunkinSprite implements IBeatReceiver implements IOffset public inline function getCameraPosition() { var midpoint = getMidpoint(); - var event = new PointEvent( + var event = EventManager.get(PointEvent).recycle( midpoint.x + (isPlayer ? -100 : 150) + globalOffset.x + cameraOffset.x, midpoint.y - 100 + globalOffset.y + cameraOffset.y); script.call("onGetCamPos", [event]); @@ -76,7 +76,7 @@ class Character extends FunkinSprite implements IBeatReceiver implements IOffset public function playSingAnim(direction:Int, suffix:String = "", Context:PlayAnimContext = SING, Reversed:Bool = false, Frame:Int = 0) { var anims = ["singLEFT", "singDOWN", "singUP", "singRIGHT"]; - var event = new DirectionAnimEvent('${anims[direction]}$suffix', direction, suffix, Context, Reversed, Frame); + var event = EventManager.get(DirectionAnimEvent).recycle('${anims[direction]}$suffix', direction, suffix, Context, Reversed, Frame); script.call("onPlaySingAnim", [event]); if (!event.cancelled) playAnim(event.animName, event.force, Context, event.reversed, event.frame); } @@ -217,7 +217,7 @@ class Character extends FunkinSprite implements IBeatReceiver implements IOffset { if (!debugMode) { - var event = new DanceEvent(danced); + var event = EventManager.get(DanceEvent).recycle(danced); script.call("onDance", [event]); if (event.cancelled) return; @@ -328,7 +328,7 @@ class Character extends FunkinSprite implements IBeatReceiver implements IOffset public override function playAnim(AnimName:String, Force:Bool = false, Context:PlayAnimContext = NONE, Reversed:Bool = false, Frame:Int = 0):Void { - var event = new PlayAnimEvent(AnimName, Force, Reversed, Frame, Context); + var event = EventManager.get(PlayAnimEvent).recycle(AnimName, Force, Reversed, Frame, Context); script.call("onPlayAnim", [event]); if (event.cancelled) return; diff --git a/source/funkin/game/Note.hx b/source/funkin/game/Note.hx index 781d3f5d..9baa107f 100644 --- a/source/funkin/game/Note.hx +++ b/source/funkin/game/Note.hx @@ -98,7 +98,7 @@ class Note extends FlxSprite this.noteData = noteData; var customType = Paths.image('game/notes/${this.noteType}'); - var event = new NoteCreationEvent(this, strumID, this.noteType, noteTypeID, mustPress, Assets.exists(customType) ? 'game/notes/${this.noteType}' : 'game/NOTE_assets', 0.7, animSuffix); + var event = EventManager.get(NoteCreationEvent).recycle(this, strumID, this.noteType, noteTypeID, mustPress, Assets.exists(customType) ? 'game/notes/${this.noteType}' : 'game/NOTE_assets', 0.7, animSuffix); if (PlayState.instance != null) event = PlayState.instance.scripts.event("onNoteCreation", event); diff --git a/source/funkin/game/PlayState.hx b/source/funkin/game/PlayState.hx index a7fdbac0..c6858322 100644 --- a/source/funkin/game/PlayState.hx +++ b/source/funkin/game/PlayState.hx @@ -460,7 +460,7 @@ class PlayState extends MusicBeatState rating = e; } - var event = scripts.event("onRatingUpdate", new RatingUpdateEvent(rating, curRating)); + var event = scripts.event("onRatingUpdate", EventManager.get(RatingUpdateEvent).recycle(rating, curRating)); if (!event.cancelled) curRating = event.rating; } @@ -730,11 +730,12 @@ class PlayState extends MusicBeatState * Creates a fake countdown. */ public function countdown(swagCounter:Int) { - var event:CountdownEvent = scripts.event("onCountdown", new CountdownEvent( + var event:CountdownEvent = scripts.event("onCountdown", EventManager.get(CountdownEvent).recycle( swagCounter, - introSprites[swagCounter], + 1, introSounds[swagCounter], - 1, 0.6, true)); + introSprites[swagCounter], + 0.6, true, null, null, null)); var sprite:FlxSprite = null; var sound:FlxSound = null; @@ -935,7 +936,7 @@ class PlayState extends MusicBeatState var babyArrow:Strum = new Strum((FlxG.width * 0.25) + (Note.swagWidth * (i - 2)) + ((FlxG.width / 2) * player), strumLine.y); babyArrow.ID = i; - var event = scripts.event("onStrumCreation", new StrumCreationEvent(babyArrow, player, i)); + var event = scripts.event("onStrumCreation", EventManager.get(StrumCreationEvent).recycle(babyArrow, player, i)); if (!event.cancelled) { switch (curStage) @@ -997,7 +998,7 @@ class PlayState extends MusicBeatState override function openSubState(SubState:FlxSubState) { - var event = scripts.event("onSubstateOpen", new StateEvent(SubState)); + var event = scripts.event("onSubstateOpen", EventManager.get(StateEvent).recycle(SubState)); if (!postCreated) FlxTransitionableState.skipNextTransIn = true; @@ -1021,7 +1022,7 @@ class PlayState extends MusicBeatState override function closeSubState() { - var event = scripts.event("onSubstateClose", new StateEvent(subState)); + var event = scripts.event("onSubstateClose", EventManager.get(StateEvent).recycle(subState)); if (event.cancelled) return; if (paused) @@ -1237,7 +1238,7 @@ class PlayState extends MusicBeatState else ratio = section.mustHitSection ? 1 : 0; - var event = scripts.event("onCameraMove", new CamMoveEvent(bfPos, dadPos, ratio, FlxPoint.get(FlxMath.lerp(dadPos.x, bfPos.x, ratio), FlxMath.lerp(dadPos.y, bfPos.y, ratio)))); + var event = scripts.event("onCameraMove", EventManager.get(CamMoveEvent).recycle(FlxPoint.get(FlxMath.lerp(dadPos.x, bfPos.x, ratio), FlxMath.lerp(dadPos.y, bfPos.y, ratio)), bfPos, dadPos, ratio, ratio >= 0.5)); if (!event.cancelled) { camFollow.setPosition( @@ -1296,7 +1297,7 @@ class PlayState extends MusicBeatState } } - var event = PlayState.instance.scripts.event("onNoteUpdate", new NoteUpdateEvent(daNote, FlxG.elapsed, __updateNote_strum)); + var event = PlayState.instance.scripts.event("onNoteUpdate", EventManager.get(NoteUpdateEvent).recycle(daNote, FlxG.elapsed, __updateNote_strum)); if (!event.cancelled) { if (event.__updateHitWindow) { if (daNote.mustPress) @@ -1440,7 +1441,7 @@ class PlayState extends MusicBeatState __justPressed.pushGroup(controls.NOTE_LEFT_P, controls.NOTE_DOWN_P, controls.NOTE_UP_P, controls.NOTE_RIGHT_P); __justReleased.pushGroup(controls.NOTE_LEFT_R, controls.NOTE_DOWN_R, controls.NOTE_UP_R, controls.NOTE_RIGHT_R); - var event = scripts.event("onKeyShit", new InputSystemEvent(__pressed, __justPressed, __justReleased)); + var event = scripts.event("onKeyShit", EventManager.get(InputSystemEvent).recycle(__pressed, __justPressed, __justReleased)); if (event.cancelled) return; __pressed = CoolUtil.getDefault(event.pressed, []); @@ -1487,7 +1488,7 @@ class PlayState extends MusicBeatState { if (!boyfriend.stunned) { - var event:NoteHitEvent = scripts.event("onPlayerMiss", new NoteHitEvent(note, [boyfriend], true, note.noteType, note.strumID, -0.04, false, -10, "", "shit", 0)); + var event:NoteHitEvent = scripts.event("onPlayerMiss", EventManager.get(NoteHitEvent).recycle(true, false, false, note, [boyfriend], true, note.noteType, "", "", "", note.strumID, -10, 0, -0.04, "shit")); if (event.cancelled) return; @@ -1563,9 +1564,10 @@ class PlayState extends MusicBeatState var event:NoteHitEvent; if (note.mustPress) - event = scripts.event("onPlayerHit", new NoteHitEvent(note, [boyfriend], true, note.noteType, note.strumID, note.noteData > 0 ? 0.023 : 0.004, score, note.animSuffix, daRating, note.isSustainNote ? null : accuracy, "game/score/", '')); + // event = scripts.event("onPlayerHit", EventManager.get(NoteHitEvent).recycle(note, [boyfriend], true, note.noteType, note.strumID, note.noteData > 0 ? 0.023 : 0.004, score, note.animSuffix, daRating, note.isSustainNote ? null : accuracy, "game/score/", '')); + event = scripts.event("onPlayerHit", EventManager.get(NoteHitEvent).recycle(false, true, !note.isSustainNote, note, [boyfriend], true, note.noteType, "", "game/score/", "", note.strumID, score, accuracy, note.noteData > 0 ? 0.023 : 0.004, daRating)); else - event = scripts.event("onDadHit", new NoteHitEvent(note, [dad], false, note.noteType, note.strumID, 0, 0, note.animSuffix, daRating, null, "game/score/", '')); + event = scripts.event("onDadHit", EventManager.get(NoteHitEvent).recycle(false, false, false, note, [dad], false, note.noteType, "", "game/score/", "", note.strumID, 0, null, 0, daRating)); if (!event.cancelled) { if (event.accuracy != null) { @@ -1680,7 +1682,7 @@ class PlayState extends MusicBeatState } public function deleteNote(note:Note) { - var event:SimpleNoteEvent = scripts.event("onNoteDelete", new SimpleNoteEvent(note)); + var event:SimpleNoteEvent = scripts.event("onNoteDelete", EventManager.get(SimpleNoteEvent).recycle(note)); if (!event.cancelled) { scripts.call("onNoteDelete", [note]); note.kill(); diff --git a/source/funkin/import.hx b/source/funkin/import.hx index 82b5a17c..1570bdec 100644 --- a/source/funkin/import.hx +++ b/source/funkin/import.hx @@ -6,6 +6,8 @@ import funkin.system.CoolUtil; import funkin.system.Logs; import funkin.game.PlayState; +import funkin.scripting.EventManager; + using StringTools; using funkin.system.CoolUtil; -#end \ No newline at end of file +#end diff --git a/source/funkin/macros/BuildCounterMacro.hx b/source/funkin/macros/BuildCounterMacro.hx index aae7b022..48a07d5f 100644 --- a/source/funkin/macros/BuildCounterMacro.hx +++ b/source/funkin/macros/BuildCounterMacro.hx @@ -1,7 +1,9 @@ package funkin.macros; +#if !macro import haxe.macro.Expr.Field; import haxe.macro.Context; +#end #if sys import sys.io.File; #end diff --git a/source/funkin/macros/EventMacro.hx b/source/funkin/macros/EventMacro.hx new file mode 100644 index 00000000..bbcb8b37 --- /dev/null +++ b/source/funkin/macros/EventMacro.hx @@ -0,0 +1,115 @@ +package funkin.macros; + +#if macro + +class EventMacro { + public static function build():Array { + var fields = Context.getBuildFields(); + + var curClassRest = Context.getLocalClass(); + if (curClassRest == null) return fields; + + var curClass = curClassRest.get(); + if (curClass == null || curClass.name == "CancellableEvent") return fields; + + + // gets all fields + var values:Array = []; + var hiddenValues:Array = []; + for(field in fields) { + if (field.access.contains(AStatic)) continue; + + var hidden = false; + if (field.meta != null) + for(m in field.meta) + if (m.name == ":dox") + hidden = true; + if (!field.access.contains(APublic)) hidden = true; + + switch(field.kind) { + case FVar(type, expr): + (hidden ? hiddenValues : values).push({ + name: field.name, + type: type, + expr: expr + }); + default: + continue; + } + } + + // add recycle option + var func:Function = { + args: [for(a in values) { + value: a.expr, + type: a.type, + opt: false, + name: a.name + }], + expr: { + pos: Context.currentPos(), + expr: EBlock([]) + } + }; + + var funcField:Field = { + pos: Context.currentPos(), + name: "recycle", + kind: FFun(func), + access: [APublic] + }; + + fields.push(funcField); + + var p = new Printer(); + switch(func.expr.expr) { + case EBlock(exprs): + // add a "set this" expr for each variable + for(v in values) { + var name = v.name; + exprs.push({ + pos: Context.currentPos(), + expr: EBinop(OpAssign, { + pos: Context.currentPos(), + expr: EField({ + pos: Context.currentPos(), + expr: EConst(CIdent("this")) + }, name) + }, { + pos: Context.currentPos(), + expr: EConst(CIdent(name)) + }) + }); + } + + // add a "set this" expr to reset each private/hidden variables + for(v in hiddenValues) { + var name = v.name; + exprs.push({ + pos: Context.currentPos(), + expr: EBinop(OpAssign, { + pos: Context.currentPos(), + expr: EField({ + pos: Context.currentPos(), + expr: EConst(CIdent("this")) + }, name) + }, v.expr) + }); + } + + exprs.push(macro return this); + exprs.insert(0, macro recycleBase()); + default: + // nothing + } + + return fields; + } +} + +typedef EventVar = { + var name:String; + var type:ComplexType; + var expr:Expr; +} +#end \ No newline at end of file diff --git a/source/funkin/macros/FlxSpriteProxyMacro.hx b/source/funkin/macros/FlxSpriteProxyMacro.hx index c9ca76ec..1e111619 100644 --- a/source/funkin/macros/FlxSpriteProxyMacro.hx +++ b/source/funkin/macros/FlxSpriteProxyMacro.hx @@ -1,10 +1,5 @@ package funkin.macros; #if macro -import haxe.macro.Expr; -import haxe.macro.Context; -import haxe.macro.Printer; -import haxe.macro.Type.ClassField; -import haxe.macro.TypeTools; class FlxSpriteProxyMacro { public static function build() { diff --git a/source/funkin/macros/import.hx b/source/funkin/macros/import.hx new file mode 100644 index 00000000..a4ee0488 --- /dev/null +++ b/source/funkin/macros/import.hx @@ -0,0 +1,5 @@ +#if macro +import haxe.macro.*; +import haxe.macro.Expr; +import haxe.macro.Type; +#end \ No newline at end of file diff --git a/source/funkin/menus/MainMenuState.hx b/source/funkin/menus/MainMenuState.hx index f5d5b677..0f97cf77 100644 --- a/source/funkin/menus/MainMenuState.hx +++ b/source/funkin/menus/MainMenuState.hx @@ -169,7 +169,7 @@ class MainMenuState extends MusicBeatState { var daChoice:String = optionShit[curSelected]; - var event = event("onSelectItem", new NameEvent(daChoice)); + var event = event("onSelectItem", EventManager.get(NameEvent).recycle(daChoice)); if (event.cancelled) return; switch (daChoice) { @@ -192,7 +192,7 @@ class MainMenuState extends MusicBeatState } function changeItem(huh:Int = 0) { - var event = event("onChangeItem", new MenuChangeEvent(curSelected, FlxMath.wrap(curSelected + huh, 0, menuItems.length-1), huh, huh != 0)); + var event = event("onChangeItem", EventManager.get(MenuChangeEvent).recycle(curSelected, FlxMath.wrap(curSelected + huh, 0, menuItems.length-1), huh, huh != 0)); if (event.cancelled) return; curSelected = event.value; diff --git a/source/funkin/menus/PauseSubState.hx b/source/funkin/menus/PauseSubState.hx index 76fcbc5d..7b329cfb 100644 --- a/source/funkin/menus/PauseSubState.hx +++ b/source/funkin/menus/PauseSubState.hx @@ -45,7 +45,7 @@ class PauseSubState extends MusicBeatSubstate pauseScript.setParent(this); pauseScript.load(); - var event = new PauseCreationEvent('breakfast', menuItems); + var event = EventManager.get(PauseCreationEvent).recycle('breakfast', menuItems); pauseScript.call('create', [event]); menuItems = event.options; @@ -129,7 +129,7 @@ class PauseSubState extends MusicBeatSubstate } public function selectOption() { - var event = new NameEvent(menuItems[curSelected]); + var event = EventManager.get(NameEvent).recycle(menuItems[curSelected]); pauseScript.call("onSelectOption", [event]); if (event.cancelled) return; diff --git a/source/funkin/menus/StoryMenuState.hx b/source/funkin/menus/StoryMenuState.hx index 49c8dcfd..6be885f7 100644 --- a/source/funkin/menus/StoryMenuState.hx +++ b/source/funkin/menus/StoryMenuState.hx @@ -161,7 +161,7 @@ class StoryMenuState extends MusicBeatState { public function changeWeek(change:Int, force:Bool = false) { if (change == 0 && !force) return; - var event = event("onChangeWeek", new MenuChangeEvent(curWeek, FlxMath.wrap(curWeek + change, 0, weeks.length-1), change)); + var event = event("onChangeWeek", EventManager.get(MenuChangeEvent).recycle(curWeek, FlxMath.wrap(curWeek + change, 0, weeks.length-1), change)); if (event.cancelled) return; curWeek = event.value; @@ -181,7 +181,7 @@ class StoryMenuState extends MusicBeatState { public function changeDifficulty(change:Int, force:Bool = false) { if (change == 0 && !force) return; - var event = event("onChangeDifficulty", new MenuChangeEvent(curDifficulty, FlxMath.wrap(curDifficulty + change, 0, weeks[curWeek].difficulties.length-1), change)); + var event = event("onChangeDifficulty", EventManager.get(MenuChangeEvent).recycle(curDifficulty, FlxMath.wrap(curDifficulty + change, 0, weeks[curWeek].difficulties.length-1), change)); if (event.cancelled) return; curDifficulty = event.value; @@ -218,7 +218,7 @@ class StoryMenuState extends MusicBeatState { public function selectWeek() { - var event = event("onWeekSelect", new WeekSelectEvent(weeks[curWeek], weeks[curWeek].difficulties[curDifficulty], curWeek, curDifficulty)); + var event = event("onWeekSelect", EventManager.get(WeekSelectEvent).recycle(weeks[curWeek], weeks[curWeek].difficulties[curDifficulty], curWeek, curDifficulty)); if (event.cancelled) return; canSelect = false; diff --git a/source/funkin/scripting/EventManager.hx b/source/funkin/scripting/EventManager.hx new file mode 100644 index 00000000..beb0b1eb --- /dev/null +++ b/source/funkin/scripting/EventManager.hx @@ -0,0 +1,22 @@ +package funkin.scripting; + +import funkin.scripting.events.*; + +class EventManager { + // map doesnt work for that + public static var eventValues:Array = []; + public static var eventKeys:Array> = []; + + public static function get(cl:Class):T { + var c:Class = cast cl; + + var index = eventKeys.indexOf(c); + if (index < 0) { + eventKeys.push(c); + eventValues.push(Type.createInstance(c, [])); + return cast eventValues.last(); + } + + return cast eventValues[index]; + } +} \ No newline at end of file diff --git a/source/funkin/scripting/events/CamMoveEvent.hx b/source/funkin/scripting/events/CamMoveEvent.hx index 7f33f557..2d05f9d3 100644 --- a/source/funkin/scripting/events/CamMoveEvent.hx +++ b/source/funkin/scripting/events/CamMoveEvent.hx @@ -30,13 +30,4 @@ class CamMoveEvent extends CancellableEvent { * Whenever the camera focuses BF more than dad. */ public var focusBF:Bool = false; - - public function new(bfCamPos:FlxPoint, dadCamPos:FlxPoint, ratio:Float, position:FlxPoint) { - super(); - this.bfCamPos = bfCamPos; - this.dadCamPos = dadCamPos; - this.ratio = ratio; - this.position = position; - this.focusBF = ratio >= 0.5; - } } \ No newline at end of file diff --git a/source/funkin/scripting/events/CancellableEvent.hx b/source/funkin/scripting/events/CancellableEvent.hx index 8aa998e0..44cab794 100644 --- a/source/funkin/scripting/events/CancellableEvent.hx +++ b/source/funkin/scripting/events/CancellableEvent.hx @@ -3,6 +3,7 @@ package funkin.scripting.events; import funkin.scripting.ScriptPack; @:allow(ScriptPack) +@:autoBuild(funkin.macros.EventMacro.build()) class CancellableEvent { @:dox(hide) public var cancelled:Bool = false; @:dox(hide) private var __continueCalls:Bool = true; @@ -30,6 +31,12 @@ class CancellableEvent { */ public function new() {} + public function recycleBase() { + data = {}; + cancelled = false; + __continueCalls = true; + } + /** * Returns a string representation of the event, in this format: * `[CancellableEvent]` diff --git a/source/funkin/scripting/events/CountdownEvent.hx b/source/funkin/scripting/events/CountdownEvent.hx index ac2cd55d..fb0adc61 100644 --- a/source/funkin/scripting/events/CountdownEvent.hx +++ b/source/funkin/scripting/events/CountdownEvent.hx @@ -43,14 +43,4 @@ class CountdownEvent extends CancellableEvent { * Created sound, only available in `onPostCountdown` */ public var sound:FlxSound; - - public function new(swagCounter:Int, spritePath:String, soundPath:String, scale:Float = 1, volume:Float = 1, antialiasing:Bool = true) { - super(); - this.swagCounter = swagCounter; - this.volume = volume; - this.soundPath = soundPath; - this.spritePath = spritePath; - this.scale = scale; - this.antialiasing = antialiasing; - } } \ No newline at end of file diff --git a/source/funkin/scripting/events/DanceEvent.hx b/source/funkin/scripting/events/DanceEvent.hx index f13ae7ef..57c980d3 100644 --- a/source/funkin/scripting/events/DanceEvent.hx +++ b/source/funkin/scripting/events/DanceEvent.hx @@ -2,8 +2,4 @@ package funkin.scripting.events; class DanceEvent extends CancellableEvent { public var danced:Bool; - public function new(danced:Bool = false) { - super(); - this.danced = danced; - } } \ No newline at end of file diff --git a/source/funkin/scripting/events/DirectionAnimEvent.hx b/source/funkin/scripting/events/DirectionAnimEvent.hx index f76a54ed..2367a1f0 100644 --- a/source/funkin/scripting/events/DirectionAnimEvent.hx +++ b/source/funkin/scripting/events/DirectionAnimEvent.hx @@ -15,10 +15,6 @@ class DirectionAnimEvent extends CancellableEvent { The suffix of the animation (ex: "-alt") - Defaults to "" **/ public var suffix:String; - /** - Whenever the animation will play reversed or not. - **/ - public var reversed:Bool; /** Context of the animation. Is either equal to `SING` or `MISS`. **/ @@ -26,20 +22,13 @@ class DirectionAnimEvent extends CancellableEvent { /** Whenever the animation will play reversed or not. **/ - public var force:Bool; + public var reversed:Bool; /** At what frame the animation will start playing **/ public var frame:Int; - - public function new(animName:String, direction:Int, suffix:String = "", context:PlayAnimContext = SING, reversed:Bool = false, frame:Int = 0) { - super(); - this.animName = animName; - this.direction = direction; - this.suffix = suffix; - this.context = context; - this.reversed = reversed; - this.force = true; - this.frame = frame; - } + /** + Whenever the animation will play reversed or not. + **/ + public var force:Bool = true; } \ No newline at end of file diff --git a/source/funkin/scripting/events/InputSystemEvent.hx b/source/funkin/scripting/events/InputSystemEvent.hx index 5f2760fb..1a676e1a 100644 --- a/source/funkin/scripting/events/InputSystemEvent.hx +++ b/source/funkin/scripting/events/InputSystemEvent.hx @@ -18,11 +18,4 @@ class InputSystemEvent extends CancellableEvent { * For example, `justReleased[0]` will return whenever the left strum was just released. */ public var justReleased:Array; - - public function new(pressed:Array, justPressed:Array, justReleased:Array) { - super(); - this.pressed = pressed; - this.justPressed = justPressed; - this.justReleased = justReleased; - } } \ No newline at end of file diff --git a/source/funkin/scripting/events/MenuChangeEvent.hx b/source/funkin/scripting/events/MenuChangeEvent.hx index 6000aef1..1871a7b7 100644 --- a/source/funkin/scripting/events/MenuChangeEvent.hx +++ b/source/funkin/scripting/events/MenuChangeEvent.hx @@ -1,16 +1,16 @@ package funkin.scripting.events; class MenuChangeEvent extends CancellableEvent { - /** - * Value after the change - */ - public var value:Int; - /** * Value before the change */ public var oldValue:Int; + /** + * Value after the change + */ + public var value:Int; + /** * Amount of change */ @@ -20,12 +20,4 @@ class MenuChangeEvent extends CancellableEvent { * Whenever the menu SFX should be played. */ public var playMenuSFX:Bool = true; - - public function new(oldValue:Int, value:Int, change:Int, playMenuSFX:Bool = true) { - super(); - this.value = value; - this.oldValue = value; - this.change = change; - this.playMenuSFX = playMenuSFX; - } } \ No newline at end of file diff --git a/source/funkin/scripting/events/NameEvent.hx b/source/funkin/scripting/events/NameEvent.hx index 5e4d4db2..f259c56c 100644 --- a/source/funkin/scripting/events/NameEvent.hx +++ b/source/funkin/scripting/events/NameEvent.hx @@ -5,9 +5,4 @@ class NameEvent extends CancellableEvent { * Name */ public var name:String; - - public function new(name:String) { - super(); - this.name = name; - } } \ No newline at end of file diff --git a/source/funkin/scripting/events/NoteCreationEvent.hx b/source/funkin/scripting/events/NoteCreationEvent.hx index b08ddf70..06095fff 100644 --- a/source/funkin/scripting/events/NoteCreationEvent.hx +++ b/source/funkin/scripting/events/NoteCreationEvent.hx @@ -42,24 +42,4 @@ class NoteCreationEvent extends CancellableEvent { * Sing animation suffix. "-alt" for alt anim or "" for normal notes. */ public var animSuffix:String; - - /** - * [Description] Creates a new NoteCreationEvent - * @param note - * @param strumID - * @param noteType - * @param noteTypeID - * @param mustHit - */ - public function new(note:Note, strumID:Int, noteType:String, noteTypeID:Int, mustHit:Bool, noteSprite:String, noteScale:Float, animSuffix:String) { - super(); - this.note = note; - this.strumID = strumID; - this.noteType = noteType; - this.noteTypeID = noteTypeID; - this.mustHit = mustHit; - this.noteSprite = noteSprite; - this.noteScale = noteScale; - this.animSuffix = animSuffix; - } } \ No newline at end of file diff --git a/source/funkin/scripting/events/NoteHitEvent.hx b/source/funkin/scripting/events/NoteHitEvent.hx index 7f6afe7e..0fa00d07 100644 --- a/source/funkin/scripting/events/NoteHitEvent.hx +++ b/source/funkin/scripting/events/NoteHitEvent.hx @@ -75,14 +75,6 @@ class NoteHitEvent extends CancellableEvent { * Rating name. Defaults to "sick", "good", "bad" and "shit". Customisable. */ public var rating:String = "sick"; - /** - * Scale of ratings. - */ - public var ratingScale:Float = 0.7; - /** - * Whenever antialiasing should be enabled on ratings. - */ - public var ratingAntialiasing:Bool = true; /** * Scale of combo numbers. */ @@ -91,31 +83,14 @@ class NoteHitEvent extends CancellableEvent { * Whenever antialiasing should be enabled on combo number. */ public var numAntialiasing:Bool = true; - /** - * Creates a new NoteHitEvent. + * Scale of ratings. */ - public function new(note:Note, characters:Array, player:Bool, noteType:String, - direction:Int, healthGain:Float, unmuteVocals:Bool = true, score:Int = 350, - animSuffix:String = "", rating:String = "sick", ?accuracy:Null, ratingPrefix:String = "", - ratingSuffix:String = "") { - super(); - - this.note = note; - this.characters = characters; - this.player = player; - this.noteType = noteType; - this.direction = direction; - this.healthGain = healthGain; - this.unmuteVocals = unmuteVocals; - this.score = score; - this.animSuffix = animSuffix; - this.countAsCombo = !note.isSustainNote && note.mustPress; - this.rating = rating; - this.accuracy = accuracy; - this.ratingPrefix = ratingPrefix; - this.ratingSuffix = ratingSuffix; - } + public var ratingScale:Float = 0.7; + /** + * Whenever antialiasing should be enabled on ratings. + */ + public var ratingAntialiasing:Bool = true; /** * Prevents the default sing animation from being played. diff --git a/source/funkin/scripting/events/NoteUpdateEvent.hx b/source/funkin/scripting/events/NoteUpdateEvent.hx index 0d1ef9ea..0a93d754 100644 --- a/source/funkin/scripting/events/NoteUpdateEvent.hx +++ b/source/funkin/scripting/events/NoteUpdateEvent.hx @@ -22,13 +22,6 @@ class NoteUpdateEvent extends CancellableEvent { */ public var strum:Strum; - public function new(note:Note, elapsed:Float, strum:Strum) { - super(); - this.note = note; - this.elapsed = elapsed; - this.strum = strum; - } - /** * Cancels the hit window update. */ diff --git a/source/funkin/scripting/events/PauseCreationEvent.hx b/source/funkin/scripting/events/PauseCreationEvent.hx index 5957462e..3d4884ef 100644 --- a/source/funkin/scripting/events/PauseCreationEvent.hx +++ b/source/funkin/scripting/events/PauseCreationEvent.hx @@ -13,11 +13,4 @@ class PauseCreationEvent extends CancellableEvent { * All option names */ public var options:Array; - - public function new(music:String, options:Array) { - super(); - - this.music = music; - this.options = options; - } } \ No newline at end of file diff --git a/source/funkin/scripting/events/PlayAnimEvent.hx b/source/funkin/scripting/events/PlayAnimEvent.hx index 00c65054..2e5ffc2d 100644 --- a/source/funkin/scripting/events/PlayAnimEvent.hx +++ b/source/funkin/scripting/events/PlayAnimEvent.hx @@ -25,15 +25,6 @@ class PlayAnimEvent extends CancellableEvent { Context of the animation **/ public var context:PlayAnimContext; - - public function new(animName:String, force:Bool, reverse:Bool, startingFrame:Int, context:PlayAnimContext) { - super(); - this.animName = animName; - this.force = force; - this.reverse = reverse; - this.startingFrame = startingFrame; - this.context = context; - } } /** diff --git a/source/funkin/scripting/events/PointEvent.hx b/source/funkin/scripting/events/PointEvent.hx index 5b8fe215..28d7e198 100644 --- a/source/funkin/scripting/events/PointEvent.hx +++ b/source/funkin/scripting/events/PointEvent.hx @@ -9,9 +9,4 @@ class PointEvent extends CancellableEvent { Y position **/ public var y:Float; - public function new(x:Float, y:Float) { - super(); - this.x = x; - this.y = y; - } } \ No newline at end of file diff --git a/source/funkin/scripting/events/RatingUpdateEvent.hx b/source/funkin/scripting/events/RatingUpdateEvent.hx index 1bd036ff..811fc230 100644 --- a/source/funkin/scripting/events/RatingUpdateEvent.hx +++ b/source/funkin/scripting/events/RatingUpdateEvent.hx @@ -10,9 +10,4 @@ class RatingUpdateEvent extends CancellableEvent { **/ public var oldRating:ComboRating; - public function new(rating:ComboRating, oldRating:ComboRating) { - super(); - this.rating = rating; - this.oldRating = oldRating; - } } \ No newline at end of file diff --git a/source/funkin/scripting/events/ResizeEvent.hx b/source/funkin/scripting/events/ResizeEvent.hx index 8abaa0ea..7ae8da61 100644 --- a/source/funkin/scripting/events/ResizeEvent.hx +++ b/source/funkin/scripting/events/ResizeEvent.hx @@ -19,11 +19,4 @@ class ResizeEvent extends CancellableEvent { * Old height (may be null) */ public var oldHeight:Null; - public function new(width:Int, height:Int, ?oldWidth:Int, ?oldHeight:Int) { - super(); - this.width = width; - this.height = height; - this.oldWidth = oldWidth; - this.oldHeight = oldHeight; - } } \ No newline at end of file diff --git a/source/funkin/scripting/events/SimpleNoteEvent.hx b/source/funkin/scripting/events/SimpleNoteEvent.hx index d4c86368..db2b7e62 100644 --- a/source/funkin/scripting/events/SimpleNoteEvent.hx +++ b/source/funkin/scripting/events/SimpleNoteEvent.hx @@ -7,9 +7,4 @@ class SimpleNoteEvent extends CancellableEvent { Note that is affected. **/ public var note:Note; - - public function new(note:Note) { - super(); - this.note = note; - } } \ No newline at end of file diff --git a/source/funkin/scripting/events/StateEvent.hx b/source/funkin/scripting/events/StateEvent.hx index 6b5e625e..8adaa51b 100644 --- a/source/funkin/scripting/events/StateEvent.hx +++ b/source/funkin/scripting/events/StateEvent.hx @@ -7,9 +7,4 @@ class StateEvent extends CancellableEvent { * Substate that is about to be opened/closed */ public var substate:FlxState; - - public function new(substate:FlxState) { - super(); - this.substate = substate; - } } \ No newline at end of file diff --git a/source/funkin/scripting/events/StrumCreationEvent.hx b/source/funkin/scripting/events/StrumCreationEvent.hx index 4ef8a03e..5b986c20 100644 --- a/source/funkin/scripting/events/StrumCreationEvent.hx +++ b/source/funkin/scripting/events/StrumCreationEvent.hx @@ -3,7 +3,7 @@ package funkin.scripting.events; import funkin.game.Strum; class StrumCreationEvent extends CancellableEvent { - @:dox(hide) public var __doAnimation = !PlayState.isStoryMode; + @:dox(hide) public var __doAnimation = true; /** @@ -11,7 +11,7 @@ class StrumCreationEvent extends CancellableEvent { */ public var strum:Strum; - /** + /**s * Player ID */ public var player:Int; @@ -26,13 +26,6 @@ class StrumCreationEvent extends CancellableEvent { */ public var sprite:String = "game/NOTE_assets"; - public function new(strum:Strum, player:Int, strumID:Int) { - super(); - this.strum = strum; - this.player = player; - this.strumID = strumID; - } - /** * Cancels the animation that makes the strum "land" in the strumline. */ diff --git a/source/funkin/scripting/events/WeekSelectEvent.hx b/source/funkin/scripting/events/WeekSelectEvent.hx index 5f1ae9a8..03d889eb 100644 --- a/source/funkin/scripting/events/WeekSelectEvent.hx +++ b/source/funkin/scripting/events/WeekSelectEvent.hx @@ -22,13 +22,4 @@ class WeekSelectEvent extends CancellableEvent { * At which emplacement the difficulty is. Goes from 0 to the number of weeks - 1. */ public var difficultyID:Int; - - public override function new(week:WeekData, difficulty:String, weekID:Int, difficultyID:Int) { - super(); - - this.week = week; - this.difficulty = difficulty; - this.weekID = weekID; - this.difficultyID = difficultyID; - } } \ No newline at end of file diff --git a/source/funkin/system/MusicBeatState.hx b/source/funkin/system/MusicBeatState.hx index fa0bf115..64d572b7 100644 --- a/source/funkin/system/MusicBeatState.hx +++ b/source/funkin/system/MusicBeatState.hx @@ -178,14 +178,14 @@ class MusicBeatState extends FlxUIState implements IBeatReceiver * SCRIPTING STUFF */ public override function openSubState(subState:FlxSubState) { - var e = event("onOpenSubState", new StateEvent(subState)); + var e = event("onOpenSubState", EventManager.get(StateEvent).recycle(subState)); if (!e.cancelled) super.openSubState(subState); } public override function onResize(w:Int, h:Int) { super.onResize(w, h); - event("onResize", new ResizeEvent(w, h)); + event("onResize", EventManager.get(ResizeEvent).recycle(w, h, null, null)); } public override function destroy() { @@ -202,7 +202,7 @@ class MusicBeatState extends FlxUIState implements IBeatReceiver } public override function switchTo(nextState:FlxState) { - var e = event("onStateSwitch", new StateEvent(nextState)); + var e = event("onStateSwitch", EventManager.get(StateEvent).recycle(nextState)); if (e.cancelled) return false; return super.switchTo(nextState); diff --git a/source/funkin/system/MusicBeatSubstate.hx b/source/funkin/system/MusicBeatSubstate.hx index 4a5622c9..06de0add 100644 --- a/source/funkin/system/MusicBeatSubstate.hx +++ b/source/funkin/system/MusicBeatSubstate.hx @@ -181,14 +181,14 @@ class MusicBeatSubstate extends FlxSubState implements IBeatReceiver * SCRIPTING STUFF */ public override function openSubState(subState:FlxSubState) { - var e = event("onOpenSubState", new StateEvent(subState)); + var e = event("onOpenSubState", EventManager.get(StateEvent).recycle(subState)); if (!e.cancelled) super.openSubState(subState); } public override function onResize(w:Int, h:Int) { super.onResize(w, h); - event("onResize", new ResizeEvent(w, h)); + event("onResize", EventManager.get(ResizeEvent).recycle(w, h, null, null)); } public override function destroy() { @@ -198,7 +198,7 @@ class MusicBeatSubstate extends FlxSubState implements IBeatReceiver } public override function switchTo(nextState:FlxState) { - var e = event("onStateSwitch", new StateEvent(nextState)); + var e = event("onStateSwitch", EventManager.get(StateEvent).recycle(nextState)); if (e.cancelled) return false; return super.switchTo(nextState);