Skip to content

Commit

Permalink
flashing lounge view fix
Browse files Browse the repository at this point in the history
  • Loading branch information
ppedziwiatr committed Sep 6, 2024
1 parent 5f69f83 commit cadb3e0
Show file tree
Hide file tree
Showing 2 changed files with 45 additions and 30 deletions.
73 changes: 44 additions & 29 deletions src/game/scenes/LoungeAreaScene.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ import { hideGui, showGui } from '../utils/mithril.js';
export default class LoungeAreaScene extends Phaser.Scene {
beaverId;
running;
viewMounted = false;

constructor() {
super(loungeAreaSceneKey);
Expand All @@ -40,28 +41,6 @@ export default class LoungeAreaScene extends Phaser.Scene {
this.server.subscribe(this);
this.server.send({ cmd: Const.Command.info });
var self = this;
m.mount(showGui(), {
view: function () {
return m(LoungeArenaSceneGui, {
gameTxId: self.processId,
walletAddress: self.walletAddress,
gameError: self.gameError,
gameStart: self.gameStart,
gameEnd: self.gameEnd,
walletsQueue: self.walletsQueue,
playersLimit: self.playersLimit,
diff: self.diff,
onJoin: () =>
setTimeout(async () => {
await self.server.send({ cmd: Const.Command.enqueue }, true);
}),
onBack: () => {
hideGui();
self.scene.start(gameHubSceneKey);
},
});
},
});
} else {
this.scene.start(connectWalletSceneKey);
}
Expand All @@ -87,7 +66,9 @@ export default class LoungeAreaScene extends Phaser.Scene {
await this.gameActive();
}
}
m.redraw();
if (this.viewMounted) {
m.redraw();
}
}
}

Expand All @@ -108,17 +89,46 @@ export default class LoungeAreaScene extends Phaser.Scene {

if (response.error) {
console.error('Failed to fetch game info', response.error);
hideGui();
this.doHideGui();
this.scene.start(connectWalletSceneKey);
} else if (!this.gameError) {
if (response.players && response.players[this.walletAddress]) {
this.beaverId = response.players[this.walletAddress].beaverId;
}
if (response.active) {
await this.gameActive();
} else {
if (!this.viewMounted) {
const self = this;
m.mount(showGui(), {
view: function () {
return m(LoungeArenaSceneGui, {
gameTxId: self.processId,
walletAddress: self.walletAddress,
gameError: self.gameError,
gameStart: self.gameStart,
gameEnd: self.gameEnd,
walletsQueue: self.walletsQueue,
playersLimit: self.playersLimit,
diff: self.diff,
onJoin: () =>
setTimeout(async () => {
await self.server.send({ cmd: Const.Command.enqueue }, true);
}),
onBack: () => {
self.doHideGui();
self.scene.start(gameHubSceneKey);
},
});
},
});
this.viewMounted = true;
}
}
}
m.redraw();
if (this.viewMounted) {
m.redraw();
}
}
break;
}
Expand Down Expand Up @@ -148,7 +158,7 @@ export default class LoungeAreaScene extends Phaser.Scene {

async gameActive() {
if (this.beaverId) {
hideGui();
this.doHideGui();
await this.goToMainScene();
} else if (this.canParticipate()) {
await this.goToPlayerPick();
Expand All @@ -158,7 +168,7 @@ export default class LoungeAreaScene extends Phaser.Scene {
}

goToLeaderboard(response) {
hideGui();
this.doHideGui();
this.scene.start(leaderboardSceneKey, {
players: response.players,
mainPlayer: {
Expand All @@ -168,7 +178,7 @@ export default class LoungeAreaScene extends Phaser.Scene {
}

async goToMainScene() {
hideGui();
this.doHideGui();
const mapTxId = await loadMapTxId();
this.scene.start(mainSceneKey, {
mapTxId,
Expand All @@ -182,7 +192,7 @@ export default class LoungeAreaScene extends Phaser.Scene {
async goToPlayerPick() {
if (!this.running) {
this.running = true;
hideGui();
this.doHideGui();
const mapTxId = await loadMapTxId();
this.scene.start(characterPickSceneKey, {
mapTxId,
Expand All @@ -193,4 +203,9 @@ export default class LoungeAreaScene extends Phaser.Scene {
});
}
}

doHideGui() {
this.viewMounted = false;
hideGui();
}
}
2 changes: 1 addition & 1 deletion src/game/scenes/main-scene/MainScene.js
Original file line number Diff line number Diff line change
Expand Up @@ -605,7 +605,7 @@ export default class MainScene extends Phaser.Scene {
}

createScoreText(player, score, options) {
if (!score || !parseInt(score.value)) {
if (!score || !parseInt(score.value) || !player) {
return '';
}
return new Text(
Expand Down

0 comments on commit cadb3e0

Please sign in to comment.