fledge_input library
Input handling plugin for the Fledge ECS game framework.
Provides a Unity-style action-based input system with:
- Named actions mapped to multiple physical inputs
- Context switching via game states
- Support for keyboard, mouse, and gamepad
Quick Start
import 'package:flutter/services.dart';
import 'package:fledge_ecs/fledge_ecs.dart';
import 'package:fledge_input/fledge_input.dart';
// Define your actions
enum Actions { jump, move, attack }
// Create an input map
final inputMap = InputMap.builder()
.bindKey(LogicalKeyboardKey.space, ActionId.fromEnum(Actions.jump))
.bindWasd(ActionId.fromEnum(Actions.move))
.bindGamepadButton('a', ActionId.fromEnum(Actions.jump))
.bindLeftStick(ActionId.fromEnum(Actions.move))
.build();
// Configure the plugin
final inputPlugin = InputPlugin.simple(
context: InputContext(name: 'default', map: inputMap),
);
// Use in your app
await App()
.addPlugin(inputPlugin)
.addSystem(playerSystem)
.run();
// Wrap your game widget with InputWidget
InputWidget(
world: app.world,
child: GameWidget(app: app),
)
// Read actions in a system
@system
void playerSystem(World world) {
final actions = world.getResource<ActionState>()!;
if (actions.justPressed(ActionId.fromEnum(Actions.jump))) {
// Jump!
}
final (mx, my) = actions.vector2Value(ActionId.fromEnum(Actions.move));
// Move player by (mx, my)
}
Context Switching with Game States
enum GameState { menu, playing }
final menuMap = InputMap.builder()
.bindArrows(ActionId('navigate'))
.bindKey(LogicalKeyboardKey.enter, ActionId('select'))
.build();
final gameplayMap = InputMap.builder()
.bindWasd(ActionId('move'))
.bindKey(LogicalKeyboardKey.space, ActionId('jump'))
.build();
final inputPlugin = InputPlugin<GameState>(
contexts: [
InputContext(name: 'menu', map: menuMap),
InputContext(name: 'gameplay', map: gameplayMap),
],
stateBindings: {
GameState.menu: 'menu',
GameState.playing: 'gameplay',
},
defaultContext: 'menu',
);
await App()
.addState<GameState>(GameState.menu)
.addPlugin(inputPlugin)
.run();
Classes
- ActionId
- Identifier for an action. Can be a string or created from an enum value.
- ActionResolutionSystem
- System that resolves actions from raw input based on the active input map.
- ActionState
- Resource containing the resolved action values for the current frame.
- ActionValue
- The current value and state of a resolved action.
- AxisValue
- Value for axis-type actions.
- BindingSource
- Source of an input binding (which device and input).
- ButtonInputState
- State of a single button.
- ButtonValue
- Value for button-type actions.
- CompositeVector2Binding
- Composite binding that combines multiple sources into a Vector2.
-
ContextUpdateSystem<
S extends Enum> - System that updates the active input context based on game state.
- CursorState
- Tracks cursor state for the input system.
- GamepadAxisBinding
- Gamepad axis binding.
- GamepadButtonBinding
- Gamepad button binding.
- GamepadState
- Tracks the state of all connected gamepads.
- InputBinding
- A complete binding from a source to an action with configuration.
- InputContext
- An input context that can be activated based on game state.
- InputContextRegistry
- Registry for input contexts, supporting state-based activation.
- InputFrameEndSystem
- System that clears input transition flags at the end of each frame.
- InputMap
- Configuration for how actions are bound to inputs.
- InputMapBuilder
- Fluent builder for InputMap.
-
InputPlugin<
S extends Enum> - Plugin that adds comprehensive input handling to a Fledge app.
- InputPluginConfig
- Configuration for the input plugin.
- InputPollingSystem
- System that updates raw input state at the start of each frame.
- InputWidget
- A widget that captures all input for a Fledge game.
- KeyboardBinding
- Keyboard key binding.
- KeyboardState
- Tracks the state of all keyboard keys.
- MouseAxisBinding
- Mouse axis binding.
- MouseButtonBinding
- Mouse button binding.
- MouseState
- Tracks mouse state including position, buttons, and scroll.
- PointerLockDelegate
- Abstraction for pointer lock implementations.
- PointerLockDelta
- A delta event from pointer lock, providing raw mouse movement.
- SingleGamepadState
- State for a single gamepad.
- Vector2Value
- Value for vector2-type actions.
Enums
- ActionType
- The type of input an action expects.
- ButtonPhase
- The phase of a button action within a frame.
- CursorMode
- Cursor visibility and capture mode.
- MouseAxis
- Mouse axes available.