Skip to content

Commit

Permalink
fix input and make sure window is scrolled to top
Browse files Browse the repository at this point in the history
  • Loading branch information
qchateau committed Sep 19, 2020
1 parent 95281ab commit d8c4442
Showing 1 changed file with 7 additions and 2 deletions.
9 changes: 7 additions & 2 deletions client/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -259,13 +259,14 @@ class CanvasManager {
}

class GameEngine {
constructor(url, canvasManager, playerId, playerName) {
constructor(url, canvasManager, input, playerId, playerName) {
this.playerId = playerId;
this.playerName = playerName;
this.inputRefX = null;
this.inputRefY = null;
this.gameIsOver = false;
this.canvas = canvasManager;
this.input = input;

this.sock = new WebSocket(url);

Expand Down Expand Up @@ -301,13 +302,16 @@ class GameEngine {

onOpen() {
console.log("Starting communication");
window.scrollTo(0, 0);
this.input.preventDefaultTouchStart = true;
this.send({
command: { register: { id: this.playerId, name: this.playerName } },
});
}

onClose(event) {
console.log("Closing communication");
this.input.preventDefaultTouchStart = false;
if (event.reason) {
this.canvas.drawError(event.reason);
} else {
Expand All @@ -317,6 +321,7 @@ class GameEngine {

onError(error) {
console.error("WebSocket error", error);
this.input.preventDefaultTouchStart = false;
this.canvas.drawError("CONNECTION ERROR");
}

Expand Down Expand Up @@ -410,11 +415,11 @@ class GameManager {
}

newGame() {
this.input.preventDefaultTouchStart = true;
const playerName = this.getPlayerName();
this.currentGame = new GameEngine(
this.getWsHref(),
this.canvas,
this.input,
this.getPlayerId(),
playerName
);
Expand Down

0 comments on commit d8c4442

Please sign in to comment.