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

Update input handling to use 'a' key instead of ctrl #28

Merged
merged 2 commits into from
Aug 4, 2019
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 12 additions & 11 deletions client/app.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -81,22 +81,23 @@ 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;
break;
}
}

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 };
Expand Down