diff --git a/source/modding/ModchartUtilities.hx b/source/modding/ModchartUtilities.hx index 75d5d3dd46..255617e45d 100644 --- a/source/modding/ModchartUtilities.hx +++ b/source/modding/ModchartUtilities.hx @@ -2148,23 +2148,19 @@ class ModchartUtilities { funnyCustomShader.setFloat(property, value); }); + setLuaFunction("tweenShader", function(id:String, property:String, value:Float, duration:Float, ease:String, ?startDelay:Float = 0.0, ?onComplete:Dynamic) { + var shader:CustomShader = lua_Custom_Shaders.get(id); + if (shader != null) { + shader.tween(property, value, duration, easeFromString(ease), startDelay, onComplete); + } else { + trace('Shader named $shader doesn\'t exist!', ERROR); + } + }); + setLuaFunction("updateRating", function() { PlayState.instance.updateRating(); }); - setLuaFunction("runTimer", function(tag:String, time:Float = 1, loops:Int = 1) { - cancelTimer(tag); - PlayState.instance.luaTimers.set(tag, new FlxTimer().start(time, function(tmr:FlxTimer) { - if(tmr.finished) { - PlayState.instance.luaTimers.remove(tag); - } - PlayState.instance.executeALuaState('onTimerCompleted', [tag, tmr.loops, tmr.loopsLeft]); - //trace('Timer Completed: ' + tag); - }, loops)); - }); - setLuaFunction("cancelTimer", function(tag:String) { - cancelTimer(tag); - }); #if MODCHARTING_TOOLS if (PlayState.SONG.modchartingTools){ @@ -2350,14 +2346,6 @@ class ModchartUtilities { return PlayState.instance.camGame; } - function cancelTimer(tag:String) { - if(PlayState.instance.luaTimers.exists(tag)) { - var theTimer:FlxTimer = PlayState.instance.luaTimers.get(tag); - theTimer.cancel(); - theTimer.destroy(); - PlayState.instance.luaTimers.remove(tag); - } - } @:access(openfl.display.BlendMode) function blendModeFromString(blend:String):BlendMode { diff --git a/source/shaders/custom/CustomShader.hx b/source/shaders/custom/CustomShader.hx index f81c907b61..d8673bdfad 100644 --- a/source/shaders/custom/CustomShader.hx +++ b/source/shaders/custom/CustomShader.hx @@ -1,9 +1,29 @@ package shaders.custom; import flixel.addons.display.FlxRuntimeShader; +import flixel.tweens.FlxEase; +import flixel.tweens.FlxTween; +/** + * Basically just FlxRuntimeShader but it has tween support + */ class CustomShader extends FlxRuntimeShader { public function update(elapsed:Float) { // nothing yet } + /** + * Tweens a shader to a value + * @param property The property to tween + * @param to The value of the property to end up at + * @param duration How long it will take + * @param ease What ease should be used + * @param startDelay The delay to start + * @param onComplete When to do when the tween is done + */ + public function tween(property:String, to:Float, duration:Float = 1, ease:EaseFunction, ?startDelay:Float = 0.0, ?onComplete:Dynamic){ + FlxTween.num(getFloat(property), to, duration, {ease: ease, onComplete: function(twn) { + if (onComplete != null) + onComplete(); + },startDelay: startDelay,}, (value)->{setFloat(property, value);}); + } } diff --git a/source/states/PlayState.hx b/source/states/PlayState.hx index d4e22346bb..7f4ab1de68 100644 --- a/source/states/PlayState.hx +++ b/source/states/PlayState.hx @@ -2026,9 +2026,6 @@ class PlayState extends MusicBeatState { if (!startTimer.finished) startTimer.active = false; - for (timer in luaTimers) { - timer.active = false; - } } super.openSubState(SubState); @@ -2054,9 +2051,6 @@ class PlayState extends MusicBeatState { } #end - for (timer in luaTimers) { - timer.active = true; - } } super.closeSubState(); @@ -2408,11 +2402,6 @@ class PlayState extends MusicBeatState { vocals.stop(); FlxG.sound.music.stop(); - - for (timer in luaTimers) { - timer.active = true; - } - if (boyfriend.otherCharacters == null) openSubState(new GameOverSubstate(boyfriend.getScreenPosition().x, boyfriend.getScreenPosition().y)); else @@ -4487,7 +4476,6 @@ class PlayState extends MusicBeatState { } - public var luaTimers:Map = new Map(); public function executeALuaState(name:String, arguments:Array, ?execute_on:Execute_On = BOTH, ?stage_arguments:Array) {