summaryrefslogtreecommitdiff
path: root/web/src/lib/state/session.ts
diff options
context:
space:
mode:
authorJoel Klinghed <the_jk@spawned.biz>2026-11-19 08:53:51 +0100
committerJoel Klinghed <the_jk@spawned.biz>2026-11-19 08:53:51 +0100
commitb884441ba0d10bdd3559748507a0991888f66194 (patch)
tree074321d353c1153e8d95191eecf5a61b2eec1096 /web/src/lib/state/session.ts
parentd64cf3514e5ff1ddb1c7f3ddac9a769db3e7dde0 (diff)
Phase 6: settings, saves, localization parity (M6)
Diffstat (limited to 'web/src/lib/state/session.ts')
-rw-r--r--web/src/lib/state/session.ts59
1 files changed, 58 insertions, 1 deletions
diff --git a/web/src/lib/state/session.ts b/web/src/lib/state/session.ts
index c8820d4..75f4299 100644
--- a/web/src/lib/state/session.ts
+++ b/web/src/lib/state/session.ts
@@ -18,8 +18,10 @@ import {
import type {
GameState,
Role,
- ServerMessage
+ ServerMessage,
+ SettingsPayload
} from '../protocol/types';
+import { serverSettings } from '../settings';
export interface SessionInfo {
id: string;
@@ -38,6 +40,14 @@ export class GameSession {
readonly status: Writable<ConnectionStatus> = writable('connecting');
readonly index: Writable<number> = writable(-1);
readonly description: Writable<string | null> = writable<string | null>(null);
+ /** The number of undoable actions in the history. */
+ readonly historyLength: Writable<number> = writable(0);
+ /** The action an undo would roll back (null at the baseline). */
+ readonly undoDescription: Writable<string | null> =
+ writable<string | null>(null);
+ /** The action a redo would re-execute (null when exhausted). */
+ readonly redoDescription: Writable<string | null> =
+ writable<string | null>(null);
readonly lastError: Writable<ProtocolError | null> =
writable<ProtocolError | null>(null);
@@ -77,15 +87,25 @@ export class GameSession {
this.seats.set(message.seats);
this.index.set(message.index);
this.description.set(message.description);
+ this.historyLength.set(message.historyLength);
+ this.undoDescription.set(message.undoDescription);
+ this.redoDescription.set(message.redoDescription);
+ serverSettings.set(message.settings);
break;
case 'update':
this.state.set(message.state);
this.index.set(message.index);
this.description.set(message.description);
+ this.historyLength.set(message.historyLength);
+ this.undoDescription.set(message.undoDescription);
+ this.redoDescription.set(message.redoDescription);
break;
case 'seats':
this.seats.set(message.seats);
break;
+ case 'settings':
+ serverSettings.set(message.settings);
+ break;
case 'error':
this.lastError.set({ code: message.code, message: message.message });
break;
@@ -153,6 +173,43 @@ export class GameSession {
this.connection.redo();
}
+ // --- Phase 6: settings + saves (players only on the server side) --------
+
+ /** Set a server-side (game-relevant) setting (the server broadcasts it). */
+ setSetting(name: string, value: boolean | number | string): void {
+ this.connection.setSetting(name, value);
+ }
+
+ /** Save the current game state to a named slot. */
+ save(name: string): void {
+ this.connection.save(name);
+ }
+
+ /** Load a named save (an undoable action on the server). */
+ loadSave(name: string): void {
+ this.connection.loadSave(name);
+ }
+
+ /** Delete a named save. */
+ deleteSave(name: string): void {
+ this.connection.deleteSave(name);
+ }
+
+ /** Save one character's state under [name]. */
+ saveCharacter(name: string, characterId: string): void {
+ this.connection.saveCharacter(name, characterId);
+ }
+
+ /** Load a character save ([saveId] = `"$name\n$characterId"`). */
+ loadCharacterSave(saveId: string): void {
+ this.connection.loadCharacterSave(saveId);
+ }
+
+ /** Delete a character save. */
+ deleteCharacterSave(saveId: string): void {
+ this.connection.deleteCharacterSave(saveId);
+ }
+
/** Clear a surfaced protocol error (call after toasting it). */
clearError(): void {
this.lastError.set(null);