Document markup and improve choice tags
This commit is contained in:
@@ -14,6 +14,8 @@ class GameLoopModule extends BaseModule {
|
||||
// Game state
|
||||
this.gameState = {
|
||||
started: false,
|
||||
startedOnce: false,
|
||||
ended: false,
|
||||
canLoad: false,
|
||||
currentRoom: null,
|
||||
inventory: [],
|
||||
@@ -71,6 +73,15 @@ class GameLoopModule extends BaseModule {
|
||||
document.addEventListener('ui:game:restart', () => this.requestStartGame());
|
||||
document.addEventListener('ui:game:save', () => this.requestSaveGame());
|
||||
document.addEventListener('ui:game:load', () => this.requestLoadGame());
|
||||
document.addEventListener('story:input-mode', (event) => {
|
||||
if (event.detail !== 'end') {
|
||||
return;
|
||||
}
|
||||
this.gameState.started = false;
|
||||
this.gameState.ended = true;
|
||||
this.gameState.canSave = false;
|
||||
this.updateUIState();
|
||||
});
|
||||
}
|
||||
|
||||
setupSocketEventListeners() {
|
||||
@@ -142,6 +153,10 @@ class GameLoopModule extends BaseModule {
|
||||
]);
|
||||
|
||||
this.gameState.started = Boolean(running?.result);
|
||||
if (this.gameState.started) {
|
||||
this.gameState.startedOnce = true;
|
||||
this.gameState.ended = false;
|
||||
}
|
||||
this.gameState.canSave = this.gameState.started;
|
||||
this.gameState.canLoad = Boolean(hasSave?.result);
|
||||
this.updateUIState();
|
||||
@@ -177,9 +192,9 @@ class GameLoopModule extends BaseModule {
|
||||
// Update UI components based on game state
|
||||
const state = {
|
||||
canRestart: true,
|
||||
canSave: Boolean(this.gameState.started),
|
||||
canSave: Boolean(this.gameState.canSave && this.gameState.started),
|
||||
canLoad: Boolean(this.gameState.canLoad),
|
||||
gameStarted: Boolean(this.gameState.started)
|
||||
gameStarted: Boolean(this.gameState.started || this.gameState.startedOnce || this.gameState.ended)
|
||||
};
|
||||
document.body.dataset.gameRunning = state.gameStarted ? 'true' : 'false';
|
||||
uiController.updateButtonStates(state);
|
||||
@@ -192,6 +207,11 @@ class GameLoopModule extends BaseModule {
|
||||
const socketClient = this.getModule('socket-client');
|
||||
if (!socketClient) return;
|
||||
|
||||
this.gameState.started = true;
|
||||
this.gameState.startedOnce = true;
|
||||
this.gameState.ended = false;
|
||||
this.gameState.canSave = true;
|
||||
this.updateUIState();
|
||||
await this.resetClientPlaybackAndDisplay();
|
||||
const storyHistory = this.getModule('story-history');
|
||||
if (storyHistory && typeof storyHistory.startNewGame === 'function') {
|
||||
@@ -200,9 +220,14 @@ class GameLoopModule extends BaseModule {
|
||||
const response = await socketClient.newGame();
|
||||
if (!response?.success) {
|
||||
console.error('GameLoop: newGame failed', response);
|
||||
this.gameState.started = false;
|
||||
this.gameState.canSave = false;
|
||||
this.updateUIState();
|
||||
return;
|
||||
}
|
||||
this.gameState.started = true;
|
||||
this.gameState.startedOnce = true;
|
||||
this.gameState.ended = false;
|
||||
this.gameState.canSave = true;
|
||||
this.gameState.canLoad = Boolean(response.canLoad);
|
||||
this.updateUIState();
|
||||
@@ -250,6 +275,12 @@ class GameLoopModule extends BaseModule {
|
||||
return;
|
||||
}
|
||||
|
||||
this.gameState.started = true;
|
||||
this.gameState.startedOnce = true;
|
||||
this.gameState.ended = false;
|
||||
this.gameState.canSave = true;
|
||||
this.gameState.canLoad = true;
|
||||
this.updateUIState();
|
||||
await this.resetClientPlaybackAndDisplay();
|
||||
document.dispatchEvent(new CustomEvent('story:history-restoring', {
|
||||
detail: { active: true, reason: 'load-game' }
|
||||
@@ -285,6 +316,8 @@ class GameLoopModule extends BaseModule {
|
||||
}
|
||||
if (response?.success) {
|
||||
this.gameState.started = true;
|
||||
this.gameState.startedOnce = true;
|
||||
this.gameState.ended = false;
|
||||
this.gameState.canSave = true;
|
||||
this.gameState.canLoad = true;
|
||||
this.updateUIState();
|
||||
|
||||
Reference in New Issue
Block a user