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

Custom and extendable devices #2

Open
nezuo opened this issue Jan 12, 2022 · 2 comments
Open

Custom and extendable devices #2

nezuo opened this issue Jan 12, 2022 · 2 comments

Comments

@nezuo
Copy link
Owner

nezuo commented Jan 12, 2022

Instead of the built-in devices we have now we could let the user create their own devices or extend the default ones we provide.

Potential API:

local device = Device.new("Keyboard")
	:addControl("Space", Enum.KeyCode.Space, ButtonControl.new())

inputState:addDevice(device)

Considerations:

  1. More boilerplate, user has to specify what devices they want.
  2. Is it even helpful for the user to add their own devices or extend the existing ones?
  3. How should the user access device's controls now? device:get("control") or device.control?
  4. Is our definition of a control good enough for it to be a public API?
  5. We would also need to export classes like ButtonControl and Axis2dControl.
@nezuo
Copy link
Owner Author

nezuo commented Jan 26, 2022

I think I might want to change the definition of controls which would help with 5.

:addControl("Space", Enum.KeyCode.Space, ValueKind.Boolean, function(input)
    return input.UserInputState == Enum.UserInputState.Begin
end)

The control's value would be calculated with the function when the Enum.KeyCode.Space input changes.
If we specify the ValueKind of the control we can derive information like it's default value and actuation.

@nezuo
Copy link
Owner Author

nezuo commented Apr 26, 2022

3 can be solved easily by turning Device into DeviceBuilder that has a build method that just returns the dictionary that maps name to control.

local device = DeviceBuilder.new("Keyboard")
	:addControl("Space", Enum.KeyCode.Space, ValueKind.Boolean, function(input)
		return input.UserInputState == Enum.UserInputState.Begin
	end)
	:build()

print(device.Space)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant