Skip to content

Commit 60a99a5

Browse files
committed
disable controls in initial game counter loop
1 parent cbd542a commit 60a99a5

File tree

7 files changed

+36
-22
lines changed

7 files changed

+36
-22
lines changed

backend/src/game/Game.ts

+1-3
Original file line numberDiff line numberDiff line change
@@ -13,9 +13,6 @@ class Game {
1313
/** users ids mapped to the index to improve performance for incremental updates */
1414
indexIdMap: Record<number, string>;
1515

16-
/** ensure game is started */
17-
isStarted = false;
18-
1916
/** started date */
2017
started: Date;
2118

@@ -92,6 +89,7 @@ class Game {
9289
logger.debug(`Game started with: ${this.userIds.join(', ')}`);
9390
// show countdown
9491
await this.initLoop();
92+
9593
// start the actual game log
9694
this.users.forEach((user) => user.start());
9795
// directly show new blocks for the users

backend/src/game/GameUser.ts

+1
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,7 @@ class BackendGameUser extends GameUser {
8080
}
8181

8282
start() {
83+
this.gameIsStarted = true;
8384
this.map = mapHelper.getEmptyMap(20);
8485
// ensure random game block
8586
this.setNewBlock();

frontend/src/components/SinglePlayer.vue

+5-4
Original file line numberDiff line numberDiff line change
@@ -87,15 +87,16 @@ import Loading from './Loading.vue';
8787
starting.value = true;
8888
8989
await props.onStart();
90-
if (!roomConn.ws) {
91-
await roomConn.connect();
92-
await new Promise((resolve) => setTimeout(resolve, 300));
93-
}
9490
await roomConn.send(WsMessageType.GAME_JOIN);
9591
await new Promise((resolve) => setTimeout(resolve, 300));
9692
await roomConn.send(WsMessageType.GAME_ACCEPT);
9793
};
9894
95+
(async () => {
96+
await roomConn.connect();
97+
isMatchRunning.value = roomConn?.isMatchRunning;
98+
})();
99+
99100
return {
100101
currUserId,
101102
isMatchRunning,

frontend/src/game/KeyHandler.ts

+14-14
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,8 @@ export default class KeyHandler implements KeyMapInterface {
5858
/** prevent duplicated key presses */
5959
keyLock: Record<number, boolean> = {};
6060

61+
rts: number;
62+
6163
constructor(user: UserInterface, gameUser: GameUser) {
6264
let activeKeyMap = user.keyMaps.find(
6365
(keyMap) => keyMap.id === user.activeKeyMap,
@@ -78,6 +80,7 @@ export default class KeyHandler implements KeyMapInterface {
7880
this.id = activeKeyMap.id;
7981
this.keys = activeKeyMap.keys;
8082
this.name = activeKeyMap.name;
83+
this.rts = activeKeyMap.rts;
8184
this.sdf = activeKeyMap.sdf;
8285

8386
Object.keys(this.keys).forEach((stateChange: string) => {
@@ -88,17 +91,12 @@ export default class KeyHandler implements KeyMapInterface {
8891
});
8992
}
9093

91-
rts: number;
92-
9394
listen() {
9495
const keyToStateChange = this.keyToStateChange;
9596
const keyDownListener = ($event: KeyboardEvent) => {
9697
const actionCode = parseInt(keyToStateChange[$event.keyCode], 10);
9798
// only react on known and single key presses, when command is pressed
9899
if (typeof keyToStateChange[$event.keyCode] !== 'undefined') {
99-
$event.preventDefault();
100-
$event.stopPropagation();
101-
102100
if (!this.keyLock[actionCode] && !this.keyDas[actionCode] && !this.keyArr[actionCode]) {
103101
if (repeatKeys.includes(actionCode)) {
104102
this.sendKey(actionCode);
@@ -125,20 +123,24 @@ export default class KeyHandler implements KeyMapInterface {
125123
// wait for the dcd timeout and retrigger arr, if the keys are still pressed
126124
setTimeout(() => {
127125
if (this.keyArr[key]) {
126+
const parsedKey = parseInt(key, 10);
128127
this.keyArr[key] = setInterval(
129-
() => this.sendKey(parseInt(key, 10)),
128+
() => this.sendKey(parsedKey),
130129
// use different speed for soft drop, turn and arrow keys
131-
this.getRepeatValue(this.keyArr[key]),
130+
this.getRepeatValue(parsedKey),
132131
);
133132
}
134133
}, this.dcd);
135134
});
136135
}
137136
}
138137
}
139-
140-
return false;
141138
}
139+
140+
$event.preventDefault();
141+
$event.stopPropagation();
142+
143+
return false;
142144
};
143145

144146
const keyUpListener = ($event: KeyboardEvent) => {
@@ -156,12 +158,10 @@ export default class KeyHandler implements KeyMapInterface {
156158
delete this.keyLock[actionCode];
157159

158160
// clear pressed key stack
159-
if (typeof keyToStateChange[$event.keyCode] !== 'undefined') {
160-
$event.preventDefault();
161-
$event.stopPropagation();
161+
$event.preventDefault();
162+
$event.stopPropagation();
162163

163-
return false;
164-
}
164+
return false;
165165
};
166166

167167
// bind listeners and unmount functions

frontend/src/lib/versions.ts

+10
Original file line numberDiff line numberDiff line change
@@ -92,6 +92,16 @@ const versions: Record<string, VersionInterface> = {
9292
],
9393
title: 'Custom Controls & Hold',
9494
},
95+
'1.4.1': {
96+
bugs: [],
97+
classes: [],
98+
features: [
99+
'disable controls in initial game counter loop',
100+
'load last session in laboratory',
101+
'broken game state',
102+
],
103+
title: 'Bug Fix Round',
104+
},
95105
};
96106

97107
export {

shared/functions/GameUser.ts

+4-1
Original file line numberDiff line numberDiff line change
@@ -123,6 +123,9 @@ class GameUser {
123123
/** hold will be blocked, until the next stone was set */
124124
holdLock: boolean;
125125

126+
/** disable controls, when the game is not started (e.g. in init number loop) */
127+
gameIsStarted: boolean;
128+
126129
constructor(
127130
user: Partial<GameUser>|GameUser,
128131
gameUserIndex = -1,
@@ -346,7 +349,7 @@ class GameUser {
346349
*/
347350
onNewStateChange(key: GameStateChange|UserStateChange): void {
348351
// disable keys when lost
349-
if (this.lost) {
352+
if (this.lost || !this.gameIsStarted) {
350353
return;
351354
}
352355

shared/functions/gameHelper.ts

+1
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ export enum GameUserMapping {
2828
cooldowns = 24,
2929
hold = 25,
3030
holdLock = 26,
31+
gameIsStarted = 27,
3132
}
3233

3334
/**

0 commit comments

Comments
 (0)