InputActionSystem Wrapped Module
With the recent introduction of the InputActionSystem (IAS), I felt while it was easier to create inputs bindings in studio, it was more difficult to manage in code. So here is a simple IAS wrapper sort of thing for those who would prefer to code it:
*to install either use the link roblox model or the sources code from the github releases
Here is some more information about the module:
API
InputActionSystem.new() -> InputContext
InputActionSystem.InputActionType: {
Bool: type
Direction1D: type
Direction2D: type
} -- list of custom InputActionTypes
InputActionSystem.Priority: {
High: {Value: number}
Default: {Value: number}
Low: {Value: number}
}
InputContext:AddAction() -> InputAction
InputAction:AddBinding() -> InputBinding
Examples
Player Input
local InputActionSystem = require(path.to.InputActionSystem)
-- create input
local PlayerContext = InputActionSystem.new("PlayerInput", true, InputActionSystem.Priority.Default.Value, false)
-- add actions
local moveDirectionAction = PlayerContext:AddAction("MoveDirection", InputActionSystem.InputActionType.Direction2D)
moveDirectionAction:AddBinding(Enum.KeyCode.W, 1, {
Up = Enum.KeyCode.W,
Down = Enum.KeyCode.S,
Right = Enum.KeyCode.D,
Left = Enum.KeyCode.A,
})
local jumpAction = PlayerContext:AddAction("JumpAction", InputActionSystem.InputActionType.Bool)
jumpAction:AddBinding(Enum.KeyCode.Space, 1)
jumpAction:AddBinding(Enum.KeyCode.Up, 1)
return {
Context = PlayerContext,
MoveDirection = moveDirectionAction,
JumpAction = jumpAction,
}
Player Controls
local InputActionSystem = require(path.to.InputActionSystem)
-- create input
local PlayerContext = InputActionSystem.new("PlayerInput", true, InputActionSystem.Priority.Default.Value, false)
-- add actions
local moveDirectionAction = PlayerContext:AddAction("MoveDirection", InputActionSystem.InputActionType.Direction2D)
moveDirectionAction:AddBinding(Enum.KeyCode.W, 1, {
Up = Enum.KeyCode.W,
Down = Enum.KeyCode.S,
Right = Enum.KeyCode.D,
Left = Enum.KeyCode.A,
})
local jumpAction = PlayerContext:AddAction("JumpAction", InputActionSystem.InputActionType.Bool)
jumpAction:AddBinding(Enum.KeyCode.Space, 1)
jumpAction:AddBinding(Enum.KeyCode.Up, 1)
return {
Context = PlayerContext,
MoveDirection = moveDirectionAction,
JumpAction = jumpAction,
}
Disclaimer: This is one of my first projects and I struggled a lot with the type checking (plus the code is a bit messy
) but feel free to tell me if you notice any bugs or have suggestions! Thanks!