Skip to content

Commit

Permalink
FlxAction API (#1805)
Browse files Browse the repository at this point in the history
  • Loading branch information
larsiusprime authored and Gama11 committed Sep 7, 2018
1 parent 9c97ab1 commit a8440a4
Show file tree
Hide file tree
Showing 28 changed files with 6,794 additions and 20 deletions.
484 changes: 484 additions & 0 deletions flixel/input/actions/FlxAction.hx

Large diffs are not rendered by default.

140 changes: 140 additions & 0 deletions flixel/input/actions/FlxActionInput.hx
Original file line number Diff line number Diff line change
@@ -0,0 +1,140 @@
package flixel.input.actions;

import flixel.input.FlxInput.FlxInputState;
import flixel.util.FlxDestroyUtil.IFlxDestroyable;

@:allow(flixel.input.actions.FlxActionInputDigital, flixel.input.actions.FlxActionInputAnalog)
class FlxActionInput implements IFlxDestroyable
{
/**
* Digital or Analog
*/
public var type:FlxInputType;

/**
* Mouse, Keyboard, Gamepad, SteamController, etc.
*/
public var device:FlxInputDevice;

/**
* Gamepad ID or Steam Controller handle (ignored for Mouse & Keyboard)
*/
public var deviceID:Int;

public var destroyed(default, null):Bool = false;

/**
* Input code (FlxMouseButtonID, FlxKey, FlxGamepadInputID, or Steam Controller action handle)
*/
public var inputID(default, null):Int;

/**
* What state triggers this action (PRESSED, JUST_PRESSED, RELEASED, JUST_RELEASED)
*/
public var trigger(default, null):FlxInputState;

function new(InputType:FlxInputType, Device:FlxInputDevice, InputID:Int, Trigger:FlxInputState, DeviceID:Int = FlxInputDeviceID.FIRST_ACTIVE)
{
type = InputType;
device = Device;
inputID = InputID;
trigger = Trigger;
deviceID = DeviceID;
}

public function update():Void {}

public function destroy():Void
{
destroyed = true;
}

/**
* Check whether this action has just been triggered
*/
public function check(action:FlxAction):Bool
{
return false;
}

/**
* Check whether `state` fulfills `condition`. Note: order of operations is
* important here. `compareState(JUST_PRESSED, PRESSED) == false`, while
* `compareState(PRESSED, JUST_PRESSED) == true`.
* @return Whether or not the condition is satisfied by state.
*/
inline function compareState(condition:FlxInputState, state:FlxInputState):Bool
{
return switch (condition)
{
case PRESSED: state == PRESSED || state == JUST_PRESSED;
case RELEASED: state == RELEASED || state == JUST_RELEASED;
case JUST_PRESSED: state == JUST_PRESSED;
case JUST_RELEASED: state == JUST_RELEASED;
default: false;
}
}
}

enum FlxInputType
{
DIGITAL;
ANALOG;
}

enum FlxInputDevice
{
UNKNOWN;
MOUSE;
MOUSE_WHEEL;
KEYBOARD;
GAMEPAD;
STEAM_CONTROLLER;
IFLXINPUT_OBJECT;
OTHER;
ALL;
NONE;
}

/**
* Just a bucket for some handy sentinel values.
*/
class FlxInputDeviceID
{
/**
* Means "every connected device of the given type" (ie all gamepads, all steam controllers, etc)
*/
public static inline var ALL:Int = -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;

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

/**
* Just a bucket for being able to refer to a specific device by type & slot number
*/
class FlxInputDeviceObject
{
public var device:FlxInputDevice;
public var id:Int;
public var model:String;

public function new(Device:FlxInputDevice, ID:Int, Model:String = "")
{
device = Device;
id = ID;
model = Model;
}

public function toString():String
{
return "{device:" + device + ",id:" + id + ",model:" + model + "}";
}
}
Loading

0 comments on commit a8440a4

Please sign in to comment.