Skip to content

Commit 5cfe8d0

Browse files
committed
Genericize ScoreScreen input mapping.
1 parent a9b185f commit 5cfe8d0

File tree

2 files changed

+10
-8
lines changed

2 files changed

+10
-8
lines changed

src/nodes/ScoreScreen.ts

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import { Container, Graphics, HTMLText } from "pixi.js";
22
import { HEIGHT, TEXT_FONT, theme, WIDTH } from "../constants";
33
import GameNode from "./GameNode";
4-
import { inputs } from "../inputs";
4+
import { type PlayerInput } from "../inputs";
55
import { getScores, setScores, type Score } from "../storage";
66
import { playSound } from "../audio";
77
import { container } from "../util";
@@ -18,11 +18,13 @@ export default class ScoreScreen extends GameNode {
1818
nameEnter = new Container();
1919
arrows = new Container();
2020
state: State = "enter_name";
21+
inputMap: PlayerInput;
2122
onFinish?: () => void;
2223

23-
constructor(score: number) {
24+
constructor(score: number, inputMap: PlayerInput) {
2425
super();
2526
this.score = score;
27+
this.inputMap = inputMap;
2628
this.view.position = { x: WIDTH / 2, y: HEIGHT / 2 };
2729

2830
const containerSize = HEIGHT * 0.75;
@@ -167,15 +169,15 @@ export default class ScoreScreen extends GameNode {
167169
if (this.state === "enter_name") {
168170
switch (e.key) {
169171
// up/down: change letter
170-
case inputs.player1.up: {
172+
case this.inputMap.up: {
171173
const currentLetter = this.letters[this.#activeIndex];
172174
const letterIndex = LETTERS.indexOf(currentLetter.text);
173175
currentLetter.text = LETTERS[(letterIndex || LETTERS.length) - 1];
174176
pulse(currentLetter, 1.1);
175177
playSound("move");
176178
break;
177179
}
178-
case inputs.player1.down: {
180+
case this.inputMap.down: {
179181
const currentLetter = this.letters[this.#activeIndex];
180182
const letterIndex = LETTERS.indexOf(currentLetter.text);
181183
currentLetter.text = LETTERS[(letterIndex + 1) % LETTERS.length];
@@ -184,17 +186,17 @@ export default class ScoreScreen extends GameNode {
184186
break;
185187
}
186188
// left/right: change active index
187-
case inputs.player1.left: {
189+
case this.inputMap.left: {
188190
this.activeIndex = (this.activeIndex || this.letters.length) - 1;
189191
playSound("move");
190192
break;
191193
}
192-
case inputs.player1.right: {
194+
case this.inputMap.right: {
193195
this.activeIndex = (this.activeIndex + 1) % this.letters.length;
194196
playSound("move");
195197
break;
196198
}
197-
case inputs.player1.flip: {
199+
case this.inputMap.flip: {
198200
playSound("clear");
199201
this.showHighScores();
200202
break;

src/nodes/SinglePlayer.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ export default class SinglePlayer extends GameNode {
3939
this.view.removeChild(this.player.view);
4040
this.player.destroy();
4141
this.mode = "score";
42-
const scores = new ScoreScreen(score * 100);
42+
const scores = new ScoreScreen(score * 100, inputs.player1);
4343
this.view.addChild(scores.view);
4444
scores.onFinish = () => {
4545
scores.destroy();

0 commit comments

Comments
 (0)