add 'newKeys' field (list of key codes pressed in frame) to frame input type, so we can change key bindings at runtime later
This commit is contained in:
@@ -8,5 +8,6 @@ struct
|
||||
, attackHeld: bool
|
||||
, jumpHeld: bool
|
||||
, escapeHeld: bool
|
||||
, newKeys: CoreKey.key_code list
|
||||
}
|
||||
end
|
||||
|
||||
@@ -190,7 +190,7 @@ struct
|
||||
else
|
||||
helpGetMainAttackPatches (attackHeld, mainAttackPressed, charge, acc)
|
||||
|
||||
fun getInputPatches (player: player, input) =
|
||||
fun getInputPatches (player: player, input: FrameInputType.t) =
|
||||
let
|
||||
val
|
||||
{ x
|
||||
@@ -206,15 +206,8 @@ struct
|
||||
, ...
|
||||
} = player
|
||||
|
||||
val
|
||||
{ leftHeld
|
||||
, rightHeld
|
||||
, upHeld
|
||||
, downHeld
|
||||
, attackHeld
|
||||
, jumpHeld
|
||||
, escapeHeld
|
||||
} = input
|
||||
val {leftHeld, rightHeld, upHeld, downHeld, attackHeld, jumpHeld, ...} =
|
||||
input
|
||||
|
||||
val xAxis = getXAxis (leftHeld, rightHeld)
|
||||
val facing = getFacing (facing, xAxis)
|
||||
|
||||
22
oms.mlb
22
oms.mlb
@@ -13,15 +13,6 @@ vendored/brolib-sml/src/gap_map.sml
|
||||
fcore/bin-search.sml
|
||||
fcore/bin-vec.sml
|
||||
|
||||
ann
|
||||
"allowVectorExps true"
|
||||
in
|
||||
vendored/cozette-sml/fonts/cozette-ascii.mlb
|
||||
fcore/block.sml
|
||||
fcore/level/player/player-sprite.sml
|
||||
fcore/field.sml
|
||||
fcore/level/chain-edge.sml
|
||||
end
|
||||
fcore/make-text-vec.sml
|
||||
|
||||
fcore/level/wall.sml
|
||||
@@ -69,19 +60,6 @@ fcore/game-update.sml
|
||||
(* shell *)
|
||||
$(SML_LIB)/basis/mlton.mlb
|
||||
|
||||
ann
|
||||
"allowFFI true"
|
||||
in
|
||||
ffi/gles3-import.sml
|
||||
ffi/glfw-import.sml
|
||||
ffi/glfw-input.sml
|
||||
end
|
||||
|
||||
ann
|
||||
"allowVectorExps true"
|
||||
in
|
||||
shell/glfw-key-map.sml
|
||||
end
|
||||
|
||||
shell/input-state.sml
|
||||
shell/parse-controls.sml
|
||||
|
||||
@@ -21,19 +21,27 @@ struct
|
||||
, jumpHeld = ref false
|
||||
, attackHeld = ref false
|
||||
, escapeHeld = ref false
|
||||
, newKeys = ref []
|
||||
, width = ref (1920.0 : Real32.real)
|
||||
, height = ref (1080.0 : Real32.real)
|
||||
}
|
||||
|
||||
fun getSnapshot () =
|
||||
{ leftHeld = !(#leftHeld state)
|
||||
, rightHeld = !(#rightHeld state)
|
||||
, upHeld = !(#upHeld state)
|
||||
, downHeld = !(#downHeld state)
|
||||
, attackHeld = !(#attackHeld state)
|
||||
, jumpHeld = !(#jumpHeld state)
|
||||
, escapeHeld = !(#escapeHeld state)
|
||||
}
|
||||
let
|
||||
val input =
|
||||
{ leftHeld = !(#leftHeld state)
|
||||
, rightHeld = !(#rightHeld state)
|
||||
, upHeld = !(#upHeld state)
|
||||
, downHeld = !(#downHeld state)
|
||||
, attackHeld = !(#attackHeld state)
|
||||
, jumpHeld = !(#jumpHeld state)
|
||||
, escapeHeld = !(#escapeHeld state)
|
||||
, newKeys = !(#newKeys state)
|
||||
}
|
||||
val () = #newKeys state := []
|
||||
in
|
||||
input
|
||||
end
|
||||
|
||||
(* there are three action states reported by OS: PRESS, REPEAT and RELEASE.
|
||||
* If input is PRESS or REPEAT, then return true, or else return false. *)
|
||||
@@ -43,6 +51,7 @@ struct
|
||||
case GlfwKeyMap.codeFromKey key of
|
||||
SOME code =>
|
||||
let
|
||||
val () = #newKeys state := code :: !(#newKeys state)
|
||||
val {left, right, down, up, attack, jump, escape} = !keyMappings
|
||||
val action = actionToBool action
|
||||
in
|
||||
@@ -58,9 +67,7 @@ struct
|
||||
| NONE => ()
|
||||
|
||||
fun keyCallback (key, scancode, action, mods) =
|
||||
let open Input
|
||||
in if mods = 0 then handleKey (key, action) else ()
|
||||
end
|
||||
if mods = 0 then handleKey (key, action) else ()
|
||||
|
||||
fun getWidth () =
|
||||
!(#width state)
|
||||
|
||||
Reference in New Issue
Block a user