Skip to content

Commit

Permalink
add input detection stuff to scripting util
Browse files Browse the repository at this point in the history
  • Loading branch information
ThatRozebudDude committed Feb 6, 2025
1 parent 9fe9ee7 commit 4d684b4
Showing 1 changed file with 43 additions and 0 deletions.
43 changes: 43 additions & 0 deletions source/modding/ScriptingUtil.hx
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package modding;

import flixel.input.gamepad.FlxGamepadInputID;
import openfl.display.BlendMode as BaseBlendMode;
import flixel.text.FlxText.FlxTextBorderStyle;
import flixel.input.keyboard.FlxKey;
Expand Down Expand Up @@ -58,6 +59,48 @@ class ScriptingUtil
if (x){ obj.x = (FlxG.width - obj.width) / 2; }
if (y){ obj.y = (FlxG.height - obj.height) / 2; }
}

//Stuff for getting input without using Binds. Useful for adding debug keys and stuff.
public static inline function anyPressed(keys:Array<String>):Bool{
var checkKeys:Array<FlxKey> = [];
for(key in keys){ checkKeys.push(FlxKey.fromString(key)); }
return FlxG.keys.anyPressed(checkKeys);
}
public static inline function anyJustPressed(keys:Array<String>):Bool{
var checkKeys:Array<FlxKey> = [];
for(key in keys){ checkKeys.push(FlxKey.fromString(key)); }
return FlxG.keys.anyJustPressed(checkKeys);
}
public static inline function anyJustReleased(keys:Array<String>):Bool{
var checkKeys:Array<FlxKey> = [];
for(key in keys){ checkKeys.push(FlxKey.fromString(key)); }
return FlxG.keys.anyJustReleased(checkKeys);
}

public static inline function anyPressedController(keys:Array<String>):Bool{
var r:Bool = false;
for(key in keys){
r = FlxG.gamepads.anyPressed(FlxGamepadInputID.fromString(key));
if(r){ break; }
}
return r;
}
public static inline function anyJustPressedController(keys:Array<String>):Bool{
var r:Bool = false;
for(key in keys){
r = FlxG.gamepads.anyJustPressed(FlxGamepadInputID.fromString(key));
if(r){ break; }
}
return r;
}
public static inline function anyJustReleasedController(keys:Array<String>):Bool{
var r:Bool = false;
for(key in keys){
r = FlxG.gamepads.anyJustReleased(FlxGamepadInputID.fromString(key));
if(r){ break; }
}
return r;
}
}

class BlendMode
Expand Down

0 comments on commit 4d684b4

Please sign in to comment.