Checkpoint current interactive fiction state
This commit is contained in:
@@ -27,6 +27,13 @@ class SocketClientModule extends BaseModule {
|
||||
'disconnect',
|
||||
'send',
|
||||
'sendCommand',
|
||||
'callGameApi',
|
||||
'newGame',
|
||||
'loadGame',
|
||||
'saveGame',
|
||||
'hasSaveGame',
|
||||
'getSaveGames',
|
||||
'isGameRunning',
|
||||
'requestStartGame',
|
||||
'requestSaveGame',
|
||||
'requestLoadGame',
|
||||
@@ -186,6 +193,9 @@ class SocketClientModule extends BaseModule {
|
||||
// Add text to the buffer if available
|
||||
if (this.textBuffer) {
|
||||
console.log(`Socket Client: Processing text fragment: "${text.substring(0, 50)}${text.length > 50 ? '...' : ''}"`);
|
||||
document.dispatchEvent(new CustomEvent('story:process-state', {
|
||||
detail: { state: 'waiting-generating', reason: 'server-response-received' }
|
||||
}));
|
||||
this.textBuffer.addText(text);
|
||||
} else {
|
||||
console.error('Socket Client: Text buffer not available');
|
||||
@@ -277,6 +287,9 @@ class SocketClientModule extends BaseModule {
|
||||
|
||||
try {
|
||||
this.socket.emit('playerCommand', { command });
|
||||
document.dispatchEvent(new CustomEvent('story:process-state', {
|
||||
detail: { state: 'command-waiting', reason: 'command-sent', command }
|
||||
}));
|
||||
return true;
|
||||
} catch (error) {
|
||||
console.error('Socket Client: Error sending command:', error);
|
||||
@@ -284,23 +297,57 @@ class SocketClientModule extends BaseModule {
|
||||
}
|
||||
}
|
||||
|
||||
async callGameApi(method, args = []) {
|
||||
if (!this.isConnected || !this.socket) {
|
||||
const connected = await this.connect();
|
||||
if (!connected || !this.socket) {
|
||||
return { success: false, error: 'not_connected' };
|
||||
}
|
||||
}
|
||||
|
||||
return new Promise((resolve) => {
|
||||
if (!this.socket) {
|
||||
resolve({ success: false, error: 'not_connected' });
|
||||
return;
|
||||
}
|
||||
|
||||
this.socket.emit('gameApi', { method, args }, (response) => {
|
||||
resolve(response || { success: false, error: 'empty_response' });
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
newGame() {
|
||||
return this.callGameApi('newGame', []);
|
||||
}
|
||||
|
||||
loadGame(slot = 1) {
|
||||
return this.callGameApi('loadGame', [slot]);
|
||||
}
|
||||
|
||||
saveGame(slot = 1) {
|
||||
return this.callGameApi('saveGame', [slot]);
|
||||
}
|
||||
|
||||
hasSaveGame(slot = 1) {
|
||||
return this.callGameApi('hasSaveGame', [slot]);
|
||||
}
|
||||
|
||||
getSaveGames() {
|
||||
return this.callGameApi('getSaveGames', []);
|
||||
}
|
||||
|
||||
isGameRunning() {
|
||||
return this.callGameApi('isGameRunning', []);
|
||||
}
|
||||
|
||||
/**
|
||||
* Request to start a new game
|
||||
* @returns {boolean} - Success status
|
||||
*/
|
||||
requestStartGame() {
|
||||
if (!this.isConnected || !this.socket) {
|
||||
console.error('Socket Client: Not connected, cannot start game');
|
||||
return false;
|
||||
}
|
||||
|
||||
try {
|
||||
this.socket.emit('startGame');
|
||||
return true;
|
||||
} catch (error) {
|
||||
console.error('Socket Client: Error starting game:', error);
|
||||
return false;
|
||||
}
|
||||
this.newGame();
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -308,18 +355,8 @@ class SocketClientModule extends BaseModule {
|
||||
* @returns {boolean} - Success status
|
||||
*/
|
||||
requestSaveGame() {
|
||||
if (!this.isConnected || !this.socket) {
|
||||
console.error('Socket Client: Not connected, cannot save game');
|
||||
return false;
|
||||
}
|
||||
|
||||
try {
|
||||
this.socket.emit('saveGame');
|
||||
return true;
|
||||
} catch (error) {
|
||||
console.error('Socket Client: Error saving game:', error);
|
||||
return false;
|
||||
}
|
||||
this.saveGame(1);
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -327,18 +364,8 @@ class SocketClientModule extends BaseModule {
|
||||
* @returns {boolean} - Success status
|
||||
*/
|
||||
requestLoadGame() {
|
||||
if (!this.isConnected || !this.socket) {
|
||||
console.error('Socket Client: Not connected, cannot load game');
|
||||
return false;
|
||||
}
|
||||
|
||||
try {
|
||||
this.socket.emit('loadGame');
|
||||
return true;
|
||||
} catch (error) {
|
||||
console.error('Socket Client: Error loading game:', error);
|
||||
return false;
|
||||
}
|
||||
this.loadGame(1);
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
Reference in New Issue
Block a user