diff --git a/TODO.md b/TODO.md index 9ee95f22..e2bd26ac 100644 --- a/TODO.md +++ b/TODO.md @@ -16,6 +16,7 @@ - [ ] Metadata Editing - [ ] Cap zoom in & out - [ ] Step based zooming +- [ ] Use latest hxCodec - [ ] Multiple state scripts & Multiple global scripts - [ ] Make update.bat use libs.xml instead of hmm.json - [ ] New Switch Mod menu diff --git a/source/funkin/backend/scripting/HScript.hx b/source/funkin/backend/scripting/HScript.hx index 9de25980..1e68bead 100644 --- a/source/funkin/backend/scripting/HScript.hx +++ b/source/funkin/backend/scripting/HScript.hx @@ -135,10 +135,11 @@ class HScript extends Script { private override function onCall(funcName:String, parameters:Array):Dynamic { if (interp == null) return null; + if (!interp.variables.exists(funcName)) return null; var func = interp.variables.get(funcName); if (func != null && Reflect.isFunction(func)) - return (parameters != null && parameters.length > 0) ? Reflect.callMethod(null, func, parameters) : func(); + return Reflect.callMethod(null, func, parameters); return null; } diff --git a/source/funkin/backend/scripting/ScriptPack.hx b/source/funkin/backend/scripting/ScriptPack.hx index 893aaa98..2105e2c6 100644 --- a/source/funkin/backend/scripting/ScriptPack.hx +++ b/source/funkin/backend/scripting/ScriptPack.hx @@ -62,7 +62,7 @@ class ScriptPack extends Script { * @param event Event (will be the first parameter of the function) * @return (modified by scripts) */ - public function event(func:String, event:T):T { + public inline function event(func:String, event:T):T { for(e in scripts) { e.call(func, [event]); @:privateAccess diff --git a/source/funkin/game/Note.hx b/source/funkin/game/Note.hx index c2ab5696..3210375d 100644 --- a/source/funkin/game/Note.hx +++ b/source/funkin/game/Note.hx @@ -58,7 +58,7 @@ class Note extends FlxSprite * Name of the splash. */ public var splash:String = "default"; - + public var strumID(get, never):Int; private function get_strumID() { var id = noteData % 4; @@ -102,7 +102,7 @@ class Note extends FlxSprite public function new(strumLine:StrumLine, noteData:ChartNote, sustain:Bool = false, sustainLength:Float = 0, sustainOffset:Float = 0) { super(); - + moves = false; this.prevNote = strumLine.notes.members.last(); @@ -114,8 +114,8 @@ class Note extends FlxSprite x += 50; // MAKE SURE ITS DEFINITELY OFF SCREEN? y -= 2000; - this.strumTime = noteData.time.getDefault(0) + sustainOffset; + this.strumTime = noteData.time.getDefault(0) + sustainOffset; this.noteData = noteData.id.getDefault(0); var customType = Paths.image('game/notes/${this.noteType}'); @@ -199,7 +199,7 @@ class Note extends FlxSprite override function draw() { @:privateAccess var oldDefaultCameras = FlxCamera._defaultCameras; @:privateAccess if (__strumCameras != null) FlxCamera._defaultCameras = __strumCameras; - + var negativeScroll = isSustainNote && nextSustain != null && lastScrollSpeed < 0; if (negativeScroll) offset.y *= -1; @@ -233,10 +233,6 @@ class Note extends FlxSprite // The * 0.5 is so that it's easier to hit them too late, instead of too early public var earlyPressWindow:Float = 0.5; public var latePressWindow:Float = 1; - override function update(elapsed:Float) - { - super.update(elapsed); - } public function updateSustain(strum:Strum) { var scrollSpeed = strum.getScrollSpeed(this); diff --git a/source/funkin/game/NoteGroup.hx b/source/funkin/game/NoteGroup.hx index daf5de14..bd680539 100644 --- a/source/funkin/game/NoteGroup.hx +++ b/source/funkin/game/NoteGroup.hx @@ -8,12 +8,12 @@ class NoteGroup extends FlxTypedGroup { var i:Int = 0; var __currentlyLooping:Bool = false; - public function addNotes(notes:Array) { + public inline function addNotes(notes:Array) { for(e in notes) add(e); sortNotes(); } - public function sortNotes() { + public inline function sortNotes() { sort(function(i, n1, n2) { if (n1.strumTime == n2.strumTime) return n1.isSustainNote ? -1 : 1; diff --git a/source/funkin/game/PlayState.hx b/source/funkin/game/PlayState.hx index e0f26b6e..8690dfd3 100644 --- a/source/funkin/game/PlayState.hx +++ b/source/funkin/game/PlayState.hx @@ -1054,17 +1054,16 @@ class PlayState extends MusicBeatState scoreTxt.text = 'Score:$songScore'; missesTxt.text = '${comboBreaks ? "Combo Breaks" : "Misses"}:$misses'; - var rating:ComboRating = curRating == null ? new ComboRating(0, "[N/A]", 0xFF888888) : curRating; + if (curRating == null) + curRating = new ComboRating(0, "[N/A]", 0xFF888888); @:privateAccess { - accFormat.format.color = rating.color; - accuracyTxt.text = 'Accuracy:${accuracy < 0 ? "-%" : '${FlxMath.roundDecimal(accuracy * 100, 2)}%'} - ${rating.rating}'; + accFormat.format.color = curRating.color; + accuracyTxt.text = 'Accuracy:${accuracy < 0 ? "-%" : '${FlxMath.roundDecimal(accuracy * 100, 2)}%'} - ${curRating.rating}'; - accuracyTxt._formatRanges[0].range.start = accuracyTxt.text.length - rating.rating.length; + accuracyTxt._formatRanges[0].range.start = accuracyTxt.text.length - curRating.rating.length; accuracyTxt._formatRanges[0].range.end = accuracyTxt.text.length; } - // accuracyTxt.addFormat(accFormat, accuracyTxt.text.length - rating.rating.length, accuracyTxt.text.length); - if (controls.PAUSE && startedCountdown && canPause) pauseGame(); @@ -1327,13 +1326,12 @@ class PlayState extends MusicBeatState var __justReleased:Array = []; private function keyShit():Void { - for(id=>p in strumLines) { p.updateNotes(); if (p.cpu) continue; - __funcsToExec.clear(); + __funcsToExec = [null, null]; __pressed.clear(); __justPressed.clear(); __justReleased.clear(); @@ -1355,27 +1353,27 @@ class PlayState extends MusicBeatState if (c.lastAnimContext != DANCE) c.__lockAnimThisFrame = true; - __funcsToExec.push(function(note:Note) { + __funcsToExec[0] = function(note:Note) { if (__pressed[note.strumID] && note.isSustainNote && note.canBeHit && !note.wasGoodHit) { goodNoteHit(p, note); } - }); + }; } var notePerStrum = [for(_ in 0...4) null]; if (__justPressed.contains(true)) { - __funcsToExec.push(function(note:Note) { + __funcsToExec[1] = function(note:Note) { if (__justPressed[note.strumID] && !note.isSustainNote && !note.wasGoodHit && note.canBeHit) { if (notePerStrum[note.strumID] == null) notePerStrum[note.strumID] = note; else if (Math.abs(notePerStrum[note.strumID].strumTime - note.strumTime) <= 2) p.deleteNote(note); else if (note.strumTime < notePerStrum[note.strumID].strumTime) notePerStrum[note.strumID] = note; } - }); + }; } if (__funcsToExec.length > 0) { p.notes.forEachAlive(function(note:Note) { - for(e in __funcsToExec) e(note); + for(e in __funcsToExec) if (e != null) e(note); }); } diff --git a/source/funkin/game/Strum.hx b/source/funkin/game/Strum.hx index 36f9c404..f06d6b82 100644 --- a/source/funkin/game/Strum.hx +++ b/source/funkin/game/Strum.hx @@ -85,7 +85,7 @@ class Strum extends FlxSprite { } } - public function updateSustain(daNote:Note) { + public inline function updateSustain(daNote:Note) { if (!daNote.isSustainNote) return; daNote.updateSustain(this); } @@ -108,7 +108,7 @@ class Strum extends FlxSprite { centerOrigin(); } - public function press(time:Float) { + public inline function press(time:Float) { lastHit = time; playAnim("confirm"); } diff --git a/source/funkin/game/StrumLine.hx b/source/funkin/game/StrumLine.hx index 2fd68f71..d8ab2b16 100644 --- a/source/funkin/game/StrumLine.hx +++ b/source/funkin/game/StrumLine.hx @@ -118,13 +118,9 @@ class StrumLine extends FlxTypedGroup { var __updateNote_strum:Strum; public function updateNote(daNote:Note) { + __updateNote_strum = members[daNote.noteData]; + if (__updateNote_strum == null) return; - for(e in members) { - if (e.ID == daNote.noteData % 4) { - __updateNote_strum = e; - break; //ing bad - } - } PlayState.instance.scripts.event("onNoteUpdate", PlayState.instance.__updateNote_event.recycle(daNote, FlxG.elapsed, __updateNote_strum)); onNoteUpdate.dispatch(PlayState.instance.__updateNote_event); if (PlayState.instance.__updateNote_event.cancelled) return;