Save gamestate and use that when updating visibility (#35)
This commit is contained in:
1 parent
03f970d3e8
commit
4069f3df3b
1 file changed
+24
-17
@@ -42,6 +42,7 @@ export class LobbyScene extends BaseScene {
|
||||
private _noConnectionErrorHandle: (() => void) | null = null;
|
||||
|
||||
private _screen: "join" | "lobby" = "join";
|
||||
private _gameState?: LobbyState;
|
||||
|
||||
constructor(private _connection: Connection) {
|
||||
super();
|
||||
@@ -187,15 +188,9 @@ export class LobbyScene extends BaseScene {
|
||||
return bar;
|
||||
}
|
||||
|
||||
private _updateVisibility(gameState?: LobbyState): void {
|
||||
private _updateVisibility(): void {
|
||||
const gameState = this._gameState;
|
||||
const isJoinScreen = this._screen === "join";
|
||||
const setVisible = (g: ex.Actor, visible: boolean): void => {
|
||||
if (visible) {
|
||||
this.add(g);
|
||||
} else {
|
||||
this.remove(g);
|
||||
}
|
||||
};
|
||||
|
||||
const isPlayer = gameState?.isPlayer ?? false;
|
||||
const isSpectator = gameState?.isSpectator ?? false;
|
||||
@@ -204,18 +199,27 @@ export class LobbyScene extends BaseScene {
|
||||
isPlayer && ((gameState != null && !gameState.isReady) ?? false);
|
||||
const isLobbyFull = gameState?.isFull ?? false;
|
||||
|
||||
setVisible(this._playerNameInput, isJoinScreen);
|
||||
setVisible(this._playerList, !isJoinScreen);
|
||||
setVisible(
|
||||
this.updateActorVisibility(this._playerNameInput, isJoinScreen);
|
||||
this.updateActorVisibility(this._playerList, !isJoinScreen);
|
||||
this.updateActorVisibility(
|
||||
this._joinPlayerButton,
|
||||
!isJoinScreen && isSpectator && !isLobbyFull,
|
||||
);
|
||||
setVisible(this._spectatorsList, !isJoinScreen);
|
||||
setVisible(this._bar3, !isJoinScreen);
|
||||
setVisible(this._joinSpectatorButton, !isJoinScreen && isPlayer);
|
||||
this.updateActorVisibility(this._spectatorsList, !isJoinScreen);
|
||||
this.updateActorVisibility(this._bar3, !isJoinScreen);
|
||||
this.updateActorVisibility(
|
||||
this._joinSpectatorButton,
|
||||
!isJoinScreen && isPlayer,
|
||||
);
|
||||
|
||||
setVisible(this._readyButton, !isJoinScreen && isNotReadyVisible);
|
||||
setVisible(this._unreadyButton, !isJoinScreen && isReadyVisible);
|
||||
this.updateActorVisibility(
|
||||
this._readyButton,
|
||||
!isJoinScreen && isNotReadyVisible,
|
||||
);
|
||||
this.updateActorVisibility(
|
||||
this._unreadyButton,
|
||||
!isJoinScreen && isReadyVisible,
|
||||
);
|
||||
}
|
||||
|
||||
private _updatePositions(): void {
|
||||
@@ -267,8 +271,11 @@ export class LobbyScene extends BaseScene {
|
||||
gameState.spectators,
|
||||
gameState.client,
|
||||
);
|
||||
|
||||
this._gameState = gameState;
|
||||
|
||||
this._updatePositions();
|
||||
this._updateVisibility(gameState);
|
||||
this._updateVisibility();
|
||||
}
|
||||
|
||||
public setScreen(screen: Screens): void {
|
||||
|
||||
Reference in new issue
Block a user