Skip to content

Commit

Permalink
shader tweens go brrrrrrrr
Browse files Browse the repository at this point in the history
  • Loading branch information
Vortex2Oblivion committed Nov 11, 2023
1 parent 7e10da9 commit a40ea1f
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 33 deletions.
30 changes: 9 additions & 21 deletions source/modding/ModchartUtilities.hx
Original file line number Diff line number Diff line change
Expand Up @@ -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){
Expand Down Expand Up @@ -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 {
Expand Down
20 changes: 20 additions & 0 deletions source/shaders/custom/CustomShader.hx
Original file line number Diff line number Diff line change
@@ -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);});
}
}
12 changes: 0 additions & 12 deletions source/states/PlayState.hx
Original file line number Diff line number Diff line change
Expand Up @@ -2026,9 +2026,6 @@ class PlayState extends MusicBeatState {
if (!startTimer.finished)
startTimer.active = false;

for (timer in luaTimers) {
timer.active = false;
}
}

super.openSubState(SubState);
Expand All @@ -2054,9 +2051,6 @@ class PlayState extends MusicBeatState {
}
#end

for (timer in luaTimers) {
timer.active = true;
}
}

super.closeSubState();
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -4487,7 +4476,6 @@ class PlayState extends MusicBeatState {
}


public var luaTimers:Map<String, FlxTimer> = new Map<String, FlxTimer>();


public function executeALuaState(name:String, arguments:Array<Dynamic>, ?execute_on:Execute_On = BOTH, ?stage_arguments:Array<Dynamic>) {
Expand Down

0 comments on commit a40ea1f

Please sign in to comment.