diff --git a/source/funkin/states/PlayState.hx b/source/funkin/states/PlayState.hx index 076db5f8..db08b623 100644 --- a/source/funkin/states/PlayState.hx +++ b/source/funkin/states/PlayState.hx @@ -346,7 +346,7 @@ class PlayState extends MusicBeatState { } public function startVideo(path:String, ?completeFunc:Dynamic):Void { - completeFunc = completeFunc == null ? startCountdown : completeFunc; + completeFunc = completeFunc ?? startCountdown; #if cpp var video:FlxVideo = new FlxVideo(); var vidFunc = function () { diff --git a/source/funkin/util/CoolUtil.hx b/source/funkin/util/CoolUtil.hx index ef25e0fa..96cf5fb6 100644 --- a/source/funkin/util/CoolUtil.hx +++ b/source/funkin/util/CoolUtil.hx @@ -94,9 +94,9 @@ class CoolUtil { } inline public static function playSound(key:String, volume:Float = 1, ?pitch:Float) { - var sound = getSound(key); + final sound = getSound(key); sound.volume = volume; - sound.pitch = (pitch == null ? FlxG.timeScale : pitch); + sound.pitch = pitch ?? FlxG.timeScale; sound.play(); return sound; } @@ -141,12 +141,13 @@ class CoolUtil { FlxG.sound.music = null; } + static final baseLerp = 1 / 60; inline public static function getLerp(ratio:Float):Float { - return FlxG.elapsed / (1 / 60) * ratio; + return FlxG.elapsed / baseLerp * ratio; } inline public static function coolLerp(a:Float, b:Float, ratio:Float):Float { - return FlxMath.lerp(a,b,getLerp(ratio)); + return FlxMath.lerp(a, b, getLerp(ratio)); } public static function sortByStrumTime(a:Dynamic, b:Dynamic) { @@ -177,9 +178,8 @@ class CoolUtil { public static function removeDuplicates(input:Array):Array { var result:Array = []; for (i in input) { - if (!result.contains(i)) { + if (!result.contains(i)) result.push(i); - } } return result; } @@ -214,6 +214,22 @@ class CoolUtil { return FlxG.cameras.list[FlxG.cameras.list.length - 1]; } + inline public static function switchState(newState:FlxState) { + if (MusicBeatState.instance == null) { + FlxG.switchState(newState); + return; + } + MusicBeatState.instance.switchState(newState); + } + + inline public static function resetState() { + if (MusicBeatState.instance == null) { + FlxG.resetState(); + return; + } + MusicBeatState.instance.resetState(); + } + /* * RATING UTIL */ @@ -242,20 +258,4 @@ class CoolUtil { inline public static function getNoteDiff(daNote:Note):Float { return Math.abs(daNote.strumTime - Conductor.songPosition); } - - inline public static function switchState(newState:FlxState) { - if (MusicBeatState.instance == null) { - FlxG.switchState(newState); - return; - } - MusicBeatState.instance.switchState(newState); - } - - inline public static function resetState() { - if (MusicBeatState.instance == null) { - FlxG.resetState(); - return; - } - MusicBeatState.instance.resetState(); - } } \ No newline at end of file diff --git a/source/funkin/util/backend/UnZipper.hx b/source/funkin/util/backend/UnZipper.hx index eeba6261..642d578a 100644 --- a/source/funkin/util/backend/UnZipper.hx +++ b/source/funkin/util/backend/UnZipper.hx @@ -5,6 +5,11 @@ import haxe.zip.Uncompress; import haxe.zip.Reader; import sys.io.File; +/* + Credits to part of this code to the Yoshi Crafter engine devs!! + I was way too dumb to figure out haxe zip by myself!! +*/ + class UnZipper { public static function getZipEntries(path:String) { var zipData = openZip(path); diff --git a/source/funkin/util/modding/PsychLuaConverter.hx b/source/funkin/util/modding/PsychLuaConverter.hx deleted file mode 100644 index 6e53a72b..00000000 --- a/source/funkin/util/modding/PsychLuaConverter.hx +++ /dev/null @@ -1,82 +0,0 @@ -package funkin.util.modding; - -/* - Yeah better if we DONT use this.. -*/ - -class PsychLuaConverter { - public var finalCode:String = '\n'; - public function new() {} - - var localVariables:Array = []; - - public function analyze(code:String): Void { - for (line in code.split('\n')) { - line = line.trim(); - if (line.endsWith(')') && !line.startsWith('function')) line += ';'; - else if (line.startsWith('function') || line.startsWith('else')) line += ' {'; - else if (line.startsWith('if')) { - line = line.substr(0, line.length - 'then'.length); - var split = line.split('if'); - line = 'if (${split[1]}) {'; - } - line = convertExpressions(line); - line = checkEndLine(line); - line = replaceFunctions(line); - finalCode += '$line\n'; - } - } - - var endLineExceptions = ['}', '{', ';']; - function checkEndLine(line:String) { - var addEnd:Bool = true; - for (i in endLineExceptions) { - if (line.endsWith(i)) { - addEnd = false; - break; - } - } - return (addEnd ? '\t$line;' : line); - } - - function convertExpressions(line:String) { - line = line.replace('~=', '!='); - line = line.replace('local', 'var'); - line = line.replace('end', '}'); - line = line.replace('--', '//'); - - if (line.contains('[')) { // Lua arrays start in 1 - var content = line.split('[')[1].split(']')[0]; - for (i in 0...10) { - if (content.startsWith(Std.string(i))) { - var num = Std.parseInt(content) - 1; - line = line.split('[')[0] + '[$num]' + line.split(']')[1]; - break; - } - } - } - - return line; - } - - var functionReplacements:Map = [ - 'onCreate' => 'create', - 'onCreatePost' => 'createPost', - 'onUpdate' => 'update', - 'onUpdatePost' => 'updatePost', - 'onBeatHit' => 'beatHit', - 'onStepHit' => 'stepHit', - 'onStartCountdown' => 'startTimer', - 'onSongStart' => 'startSong', - 'onEndSong' => 'endSong', - 'noteMissPress' => 'badNoteHit', - ]; - - function replaceFunctions(line:String) { - for (i in functionReplacements.keys()) { - line.replace(i, functionReplacements.get(i)); - } - return line; - } -} -