Co-Authored-By: sector-a <82838084+sector-a@users.noreply.github.com> Co-Authored-By: mcagabe19 <egzozu.be.bas@gmail.com> Co-Authored-By: Mihai Alexandru <77043862+majigsaw77@users.noreply.github.com> Co-Authored-By: MoonDroid <81515012+moondroidcoder@users.noreply.github.com> Co-Authored-By: luckydog7 <59097731+luckydog7@users.noreply.github.com>
99 lines
3.3 KiB
Haxe
99 lines
3.3 KiB
Haxe
package funkin.mobile.input;
|
|
|
|
import funkin.input.Controls;
|
|
import flixel.input.FlxInput;
|
|
import flixel.input.actions.FlxAction;
|
|
import flixel.input.actions.FlxActionInput;
|
|
import flixel.input.actions.FlxActionInputDigital;
|
|
import funkin.mobile.ui.FunkinButton;
|
|
import funkin.mobile.ui.FunkinHitbox;
|
|
import funkin.play.notes.NoteDirection;
|
|
|
|
/**
|
|
* Handles setting up and managing input controls for the game.
|
|
*/
|
|
class ControlsHandler
|
|
{
|
|
/**
|
|
* Adds a button input to a given FlxActionDigital and caches it.
|
|
*
|
|
* @param action The FlxActionDigital to add the button input to.
|
|
* @param button The FunkinButton associated with the action.
|
|
* @param state The input state to associate with the action.
|
|
* @param cachedInput The array of FlxActionInput objects to cache the input.
|
|
*/
|
|
public static function addButton(action:FlxActionDigital, button:FunkinButton, state:FlxInputState, cachedInput:Array<FlxActionInput>):Void
|
|
{
|
|
if (action == null || button == null || cachedInput == null) return;
|
|
|
|
final input:FlxActionInputDigitalIFlxInput = new FlxActionInputDigitalIFlxInput(button, state);
|
|
cachedInput.push(input);
|
|
action.add(input);
|
|
}
|
|
|
|
/**
|
|
* Sets up hitbox controls based on game controls and hitbox hints.
|
|
*
|
|
* @param controls The controls instance defining game controls.
|
|
* @param hitbox The hitbox to associate with the controls.
|
|
* @param cachedInput The array of action input objects to cache the input.
|
|
*/
|
|
@:access(funkin.input.Controls)
|
|
public static function setupHitbox(controls:Controls, hitbox:FunkinHitbox, cachedInput:Array<FlxActionInput>):Void
|
|
{
|
|
if (controls == null || hitbox == null) return;
|
|
|
|
for (hint in hitbox.members)
|
|
{
|
|
@:privateAccess
|
|
switch (hint.noteDirection)
|
|
{
|
|
case NoteDirection.LEFT:
|
|
controls.forEachBound(Control.NOTE_LEFT, function(action:FlxActionDigital, state:FlxInputState):Void {
|
|
addButton(action, hint, state, cachedInput);
|
|
});
|
|
case NoteDirection.DOWN:
|
|
controls.forEachBound(Control.NOTE_DOWN, function(action:FlxActionDigital, state:FlxInputState):Void {
|
|
addButton(action, hint, state, cachedInput);
|
|
});
|
|
case NoteDirection.UP:
|
|
controls.forEachBound(Control.NOTE_UP, function(action:FlxActionDigital, state:FlxInputState):Void {
|
|
addButton(action, hint, state, cachedInput);
|
|
});
|
|
case NoteDirection.RIGHT:
|
|
controls.forEachBound(Control.NOTE_RIGHT, function(action:FlxActionDigital, state:FlxInputState):Void {
|
|
addButton(action, hint, state, cachedInput);
|
|
});
|
|
}
|
|
}
|
|
}
|
|
|
|
/**
|
|
* Removes cached input associated with game controls.
|
|
*
|
|
* @param controls The Controls instance defining game controls.
|
|
* @param cachedInput The array of action input objects to clear cached input from.
|
|
*/
|
|
public static function removeCachedInput(controls:Controls, cachedInput:Array<FlxActionInput>):Void
|
|
{
|
|
for (action in controls.digitalActions)
|
|
{
|
|
var i:Int = action.inputs.length;
|
|
|
|
while (i-- > 0)
|
|
{
|
|
var j:Int = cachedInput.length;
|
|
|
|
while (j-- > 0)
|
|
{
|
|
if (cachedInput[j] == action.inputs[i])
|
|
{
|
|
action.remove(action.inputs[i]);
|
|
cachedInput.remove(cachedInput[j]);
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|