Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Various FlxAction changes #3277

Merged
merged 3 commits into from
Nov 1, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
40 changes: 17 additions & 23 deletions flixel/input/actions/FlxAction.hx
Original file line number Diff line number Diff line change
Expand Up @@ -342,6 +342,7 @@ class FlxAction implements IFlxDestroyable
var _y:Null<Float> = null;

var _timestamp:Int = 0;
@:deprecated("_checked is deprecated, use triggered, instead")
var _checked:Bool = false;

/**
Expand Down Expand Up @@ -435,40 +436,33 @@ class FlxAction implements IFlxDestroyable
*/
public function check():Bool
{
if (_timestamp == FlxG.game.ticks)
return triggered; // run no more than once per frame

_x = null;
_y = null;

if (_timestamp == FlxG.game.ticks)
{
triggered = _checked;
return _checked; // run no more than once per frame
}


_timestamp = FlxG.game.ticks;
_checked = false;

var len = inputs != null ? inputs.length : 0;
for (i in 0...len)
triggered = false;
var i = inputs != null ? inputs.length : 0;
while (i-- > 0) // Iterate backwards, since we may remove items
{
var j = len - i - 1;
var input = inputs[j];

final input = inputs[i];

if (input.destroyed)
{
inputs.splice(j, 1);
inputs.remove(input);
continue;
}

input.update();

if (input.check(this))
{
_checked = true;
}
triggered = true;
}

triggered = _checked;
return _checked;

return triggered;
}

/**
Expand Down
8 changes: 4 additions & 4 deletions flixel/input/actions/FlxActionInput.hx
Original file line number Diff line number Diff line change
Expand Up @@ -110,22 +110,22 @@ enum FlxInputDevice
* Just a bucket for some handy sentinel values.
* @since 4.6.0
*/
class FlxInputDeviceID
enum abstract FlxInputDeviceID(Int) from Int to Int
{
/**
* Means "every connected device of the given type" (ie all gamepads, all steam controllers, etc)
*/
public static inline var ALL:Int = -1;
var ALL = -1;

/**
* Means "the first connected device that has an active input" (ie a pressed button or moved analog stick/trigger/etc)
*/
public static inline var FIRST_ACTIVE:Int = -2;
var FIRST_ACTIVE = -2;

/**
* Means "no device"
*/
public static inline var NONE:Int = -3;
var NONE = -3;
}

/**
Expand Down
12 changes: 6 additions & 6 deletions flixel/input/actions/FlxActionInputAnalog.hx
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ class FlxActionInputAnalogMouseMotion extends FlxActionInputAnalog
deadZone = DeadZone;
invertX = InvertX;
invertY = InvertY;
super(FlxInputDevice.MOUSE, -1, cast Trigger, Axis);
super(FlxInputDevice.MOUSE, -1, Trigger, Axis);
}

override public function update():Void
Expand Down Expand Up @@ -144,7 +144,7 @@ class FlxActionInputAnalogMousePosition extends FlxActionInputAnalog
*/
public function new(Trigger:FlxAnalogState, Axis:FlxAnalogAxis = EITHER)
{
super(FlxInputDevice.MOUSE, -1, cast Trigger, Axis);
super(FlxInputDevice.MOUSE, -1, Trigger, Axis);
}

override public function update():Void
Expand Down Expand Up @@ -193,7 +193,7 @@ class FlxActionInputAnalogGamepad extends FlxActionInputAnalog
*/
public function new(InputID:FlxGamepadInputID, Trigger:FlxAnalogState, Axis:FlxAnalogAxis = EITHER, GamepadID:Int = FlxInputDeviceID.FIRST_ACTIVE)
{
super(FlxInputDevice.GAMEPAD, InputID, cast Trigger, Axis, GamepadID);
super(FlxInputDevice.GAMEPAD, InputID, Trigger, Axis, GamepadID);
}

override public function update():Void
Expand Down Expand Up @@ -265,7 +265,7 @@ class FlxActionInputAnalogSteam extends FlxActionInputAnalog
@:allow(flixel.input.actions.FlxActionSet)
function new(ActionHandle:Int, Trigger:FlxAnalogState, Axis:FlxAnalogAxis = EITHER, DeviceID:Int = FlxInputDeviceID.ALL)
{
super(FlxInputDevice.STEAM_CONTROLLER, ActionHandle, cast Trigger, Axis, DeviceID);
super(FlxInputDevice.STEAM_CONTROLLER, ActionHandle, Trigger, Axis, DeviceID);
#if FLX_NO_STEAM
FlxG.log.warn("steamwrap library not installed; steam inputs will be ignored.");
#end
Expand Down Expand Up @@ -310,9 +310,9 @@ class FlxActionInputAnalog extends FlxActionInput
static inline var A_X = true;
static inline var A_Y = false;

function new(Device:FlxInputDevice, InputID:Int, Trigger:FlxInputState, Axis:FlxAnalogAxis = EITHER, DeviceID:Int = FlxInputDeviceID.FIRST_ACTIVE)
function new(Device:FlxInputDevice, InputID:Int, Trigger:FlxAnalogState, Axis:FlxAnalogAxis = EITHER, DeviceID:Int = FlxInputDeviceID.FIRST_ACTIVE)
{
super(FlxInputType.ANALOG, Device, InputID, Trigger, DeviceID);
super(FlxInputType.ANALOG, Device, InputID, cast Trigger, DeviceID);
axis = Axis;
xMoved = new FlxInput<Int>(0);
yMoved = new FlxInput<Int>(1);
Expand Down
Loading