Skip to content

Commit

Permalink
app: inline the key press functions
Browse files Browse the repository at this point in the history
There's no need for the extra abstraction here.
  • Loading branch information
jnikula committed Mar 1, 2024
1 parent 91aadf4 commit 708c0d9
Showing 1 changed file with 16 additions and 43 deletions.
59 changes: 16 additions & 43 deletions src/App.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -267,41 +267,6 @@
return value;
}
function ui_key_end_turn(): void {
if ($game.state.can_end_turn())
game.end_turn();
}
function ui_key_pot_ball(value: number): void {
if ($game.state.can_pot_ball(value))
game.pot_ball(value);
}
function ui_key_commit_foul(value: number): void {
if ($game.state.can_commit_foul(value))
game.commit_foul(value);
}
function ui_key_undo(): void {
if ($game.can_undo)
game.undo();
}
function ui_key_redo(): void {
if ($game.can_redo)
game.redo();
}
function ui_key_plus_balls(): void {
if ($game.state.can_plus_balls())
game.plus_balls();
}
function ui_key_minus_balls(): void {
if ($game.state.can_minus_balls())
game.minus_balls();
}
function ui_key_down(event: KeyboardEvent) {
if (event.repeat)
return;
Expand All @@ -325,30 +290,38 @@
if (value >= 1 && value <= 7) {
if (modifier == 'f') {
if (value >= 4)
ui_key_commit_foul(value);
if (value >= 4) {
if ($game.state.can_commit_foul(value))
game.commit_foul(value);
}
} else {
ui_key_pot_ball(value);
if ($game.state.can_pot_ball(value))
game.pot_ball(value);
}
}
break;
case ' ':
ui_key_end_turn();
if ($game.state.can_end_turn())
game.end_turn();
break;
case 'z':
ui_key_undo();
if ($game.can_undo)
game.undo();
break;
case 'y':
ui_key_redo();
if ($game.can_redo)
game.redo();
break;
case 'f':
ui_key_modifier_set(event.key);
break;
case '+':
ui_key_plus_balls();
if ($game.state.can_plus_balls())
game.plus_balls();
break;
case '-':
ui_key_minus_balls();
if ($game.state.can_minus_balls())
game.minus_balls();
break;
case 'ArrowRight':
ui_next_page();
Expand Down

0 comments on commit 708c0d9

Please sign in to comment.