I'm trying to create custom keyboard controls for a 4 player game. Right now, the keys are predetermined like this:
type Orient = { x:Int, y:Int }
type GameInput = { space:Bool, delta:Time, so1:Orient, so2:Orient, so3:Orient,
so4:Orient, amount:Int }
gameInput : Signal GameInput
gameInput =
let sampledInput = sampleOn delta
<| GameInput <~ Keyboard.space
~ delta
~ Keyboard.arrows
~ Keyboard.wasd
~ Keyboard.directions (toCode 'O')
(toCode 'L')
(toCode 'K')
(toCode 'M')
~ Keyboard.directions (toCode 'Y')
(toCode 'H')
(toCode 'G')
(toCode 'J')
~ amountPlayers.signal
in lift (Debug.watch "input") sampledInput
I have created (for each player) input of the form:
type CustomKeys = { up:Char, down:Char, left:Char, right:Char }
customKeys2 : Signal CustomKeys
customKeys2 = CustomKeys <~ ck2up.signal
~ ck2down.signal
~ ck2left.signal
~ ck2right.signal
ck2up : Input Char
ck2up = input 'W'
ck2down : Input Char
ck2down = input 'S'
ck2left : Input Char
ck2left = input 'A'
ck2right : Input Char
ck2right = input 'D'
A handler elsewhere will adjust the values of the input as needed by the player. But I'm having a hard time figuring out how to insert these values into the arguments for Keyboard.directions
.
I have tried lifting the arguments into Keyboard.directions
directly:
~ Keyboard.directions <~ ...
Any result will become a Signal of a Signal, which cannot be lifted onto GameInput
(correctly).
I have tried passing on the chars as arguments into gameInput
:
gameInput2 : Signal GameInput
gameInput2 = gameInput <~ customKeys2
gameInput : CustomKeys -> Signal GameInput
gameInput { up,down,left,right } = GameInput <~ Keyboard.directions (toCode up)
(toCode down)
(toCode left)
(toCode right)
Now gameInput2
will have as result a signal of a signal.
My last idea is to combine signals, but that doesn't seem like an option to me since I want one signal to depend on another signal.