From a0a9a234b6501065da00a5795fad45b882fb3170 Mon Sep 17 00:00:00 2001 From: Brian Jewkes Date: Sun, 4 Aug 2019 15:30:44 -0700 Subject: [PATCH 1/2] Update input handling to use 'a' key instead of ctrl --- client/app.ts | 22 +++++++++++----------- 1 file changed, 11 insertions(+), 11 deletions(-) diff --git a/client/app.ts b/client/app.ts index 4621236..c132836 100644 --- a/client/app.ts +++ b/client/app.ts @@ -35,7 +35,7 @@ export function initialize(){ let input = handleKeyDown(e); if(input){sendAction(socket, input)} }, false); - document.addEventListener("keyup", handleKeyUp, false); + document.addEventListener("keypress", handleKeyPress, false); socket.on('world', (state: World) => { world = state; update(getRenderContext(), world, scale, socket.id); @@ -81,22 +81,22 @@ function update(c: RenderContext, world: World, scale: number, clientId?: string // TODO - move to an input module -let CTRL_DOWN = false; -function handleKeyUp(event: KeyboardEvent){ +let ATK_PRESSED = false; +function handleKeyPress(event: KeyboardEvent){ switch (event.key){ - case "Control": - CTRL_DOWN = false; + case "a": + case "A": + ATK_PRESSED = true; } } function handleKeyDown(event: KeyboardEvent): Action | undefined { - let action: ActionKind = CTRL_DOWN ? "Attack" : "Move"; + // if the attack button has been pressed, set the action to Attack + // and clear the ATK_PRESSED input state + let action: ActionKind = ATK_PRESSED ? "Attack" : "Move"; + ATK_PRESSED = false; + switch (event.key) { - case "Control": - event.preventDefault(); - console.log("key down"); - CTRL_DOWN = true - break; case "ArrowLeft": event.preventDefault(); return { direction: "West", kind: action }; From 5148fdb5c579ddf2344c15da4a15bd426544bda8 Mon Sep 17 00:00:00 2001 From: Brian Jewkes Date: Sun, 4 Aug 2019 16:38:04 -0700 Subject: [PATCH 2/2] Add break --- client/app.ts | 1 + 1 file changed, 1 insertion(+) diff --git a/client/app.ts b/client/app.ts index c132836..78b20bd 100644 --- a/client/app.ts +++ b/client/app.ts @@ -87,6 +87,7 @@ function handleKeyPress(event: KeyboardEvent){ case "a": case "A": ATK_PRESSED = true; + break; } }