summaryrefslogtreecommitdiff
path: root/web/src/lib/protocol
diff options
context:
space:
mode:
Diffstat (limited to 'web/src/lib/protocol')
-rw-r--r--web/src/lib/protocol/connection.ts50
-rw-r--r--web/src/lib/protocol/types.ts103
2 files changed, 152 insertions, 1 deletions
diff --git a/web/src/lib/protocol/connection.ts b/web/src/lib/protocol/connection.ts
index 51305a1..a553481 100644
--- a/web/src/lib/protocol/connection.ts
+++ b/web/src/lib/protocol/connection.ts
@@ -20,7 +20,18 @@ import type {
ErrorMessage,
ServerMessage
} from './types';
-import { claimMessage, helloMessage, pingMessage } from './types';
+import {
+ claimMessage,
+ deleteCharacterSaveMessage,
+ deleteSaveMessage,
+ helloMessage,
+ loadCharacterSaveMessage,
+ loadSaveMessage,
+ pingMessage,
+ saveCharacterMessage,
+ saveMessage,
+ setSettingMessage
+} from './types';
export type ConnectionStatus =
| 'connecting'
@@ -219,4 +230,41 @@ export class GameConnection {
resync(): void {
this.sendRaw(helloMessage());
}
+
+ // --- Phase 6 (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.sendRaw(setSettingMessage(name, value));
+ }
+
+ /** Save the current game state to a named slot. */
+ save(name: string): void {
+ this.sendRaw(saveMessage(name));
+ }
+
+ /** Load a named save (an undoable action on the server). */
+ loadSave(name: string): void {
+ this.sendRaw(loadSaveMessage(name));
+ }
+
+ /** Delete a named save. */
+ deleteSave(name: string): void {
+ this.sendRaw(deleteSaveMessage(name));
+ }
+
+ /** Save one character's state under [name]. */
+ saveCharacter(name: string, characterId: string): void {
+ this.sendRaw(saveCharacterMessage(name, characterId));
+ }
+
+ /** Load a character save ([saveId] = `"$name\n$characterId"`). */
+ loadCharacterSave(saveId: string): void {
+ this.sendRaw(loadCharacterSaveMessage(saveId));
+ }
+
+ /** Delete a character save. */
+ deleteCharacterSave(saveId: string): void {
+ this.sendRaw(deleteCharacterSaveMessage(saveId));
+ }
}
diff --git a/web/src/lib/protocol/types.ts b/web/src/lib/protocol/types.ts
index 2042692..6e78d02 100644
--- a/web/src/lib/protocol/types.ts
+++ b/web/src/lib/protocol/types.ts
@@ -284,6 +284,42 @@ export interface GameState {
elementState: Record<string, number>;
}
+// --- Server-side settings (Phase 6) ------------------------------------------
+
+/** A character save entry (the server splits the save id for display). */
+export interface CharacterSaveEntry {
+ name: string;
+ characterId: string;
+}
+
+/**
+ * The server-side (game-relevant) settings payload — the server's
+ * `Settings.forClient()`, embedded in `welcome` and sent as the `settings`
+ * broadcast (PLAN.md section 4). The save *content* never crosses the wire;
+ * only the names do.
+ */
+export interface SettingsPayload {
+ noInit: boolean;
+ noStandees: boolean;
+ randomStandees: boolean;
+ expireConditions: boolean;
+ autoAddStandees: boolean;
+ autoAddSpawns: boolean;
+ hideLootDeck: boolean;
+ /** The server's `Style` enum index (0 frosthaven, 1 gloomhaven, 2 original). */
+ style: number;
+ showBattleGoalReminder: boolean;
+ showReminders: boolean;
+ showAmdDeck: boolean;
+ fhHazTerrainCalcInOGGloom: boolean;
+ /** The locale the command descriptions are generated in (server-side l10n). */
+ locale: string;
+ /** The names of the available game-state saves. */
+ saves: string[];
+ /** The character saves (name + character id). */
+ characterSaves: CharacterSaveEntry[];
+}
+
// --- Messages --------------------------------------------------------------
export interface GameEvent {
@@ -298,20 +334,42 @@ export interface WelcomeMessage {
role: Role;
index: number;
description: string | null;
+ /** The number of undoable actions in the history. */
+ historyLength: number;
+ /** The action the redo would re-execute (null when exhausted). */
+ redoDescription: string | null;
+ /** The action the undo would roll back (null at the baseline). */
+ undoDescription: string | null;
event: GameEvent | null;
state: GameState;
/** character id → owning session id (null when unclaimed). */
seats: Record<string, string | null>;
+ settings: SettingsPayload;
}
export interface UpdateMessage {
t: 'update';
index: number;
description: string;
+ /** The number of undoable actions in the history. */
+ historyLength: number;
+ /** The action the redo would re-execute (null when exhausted). */
+ redoDescription: string | null;
+ /** The action the undo would roll back (null at the baseline). */
+ undoDescription: string | null;
event: GameEvent;
state: GameState;
}
+/**
+ * The server-side settings broadcast (sent when a setting or the save list
+ * changes). Same payload as `welcome.settings`.
+ */
+export interface SettingsMessage {
+ t: 'settings';
+ settings: SettingsPayload;
+}
+
export interface SeatsMessage {
t: 'seats';
seats: Record<string, string | null>;
@@ -331,6 +389,7 @@ export type ServerMessage =
| WelcomeMessage
| UpdateMessage
| SeatsMessage
+ | SettingsMessage
| ErrorMessage
| PongMessage;
@@ -355,3 +414,47 @@ export function pingMessage() {
}
export const undoMessage = () => ({ t: 'undo' }) as const;
export const redoMessage = () => ({ t: 'redo' }) as const;
+
+// --- Phase 6 client messages (players only on the server side) ---------------
+
+/**
+ * Set one server-side (game-relevant) setting. [name] is one of the known
+ * setting names; [value] its new value (booleans, the style enum index, or
+ * the locale code string).
+ */
+export function setSettingMessage(
+ name: string,
+ value: boolean | number | string
+) {
+ return { t: 'setSetting', name, value } as const;
+}
+
+/** Save the current game state to a named save slot. */
+export function saveMessage(name: string) {
+ return { t: 'save', name } as const;
+}
+
+/** Load a named save (an undoable action on the server). */
+export function loadSaveMessage(name: string) {
+ return { t: 'loadSave', name } as const;
+}
+
+/** Delete a named save. */
+export function deleteSaveMessage(name: string) {
+ return { t: 'deleteSave', name } as const;
+}
+
+/** Save one character's state under [name]. */
+export function saveCharacterMessage(name: string, characterId: string) {
+ return { t: 'saveCharacter', name, characterId } as const;
+}
+
+/** Load a character save ([saveId] = `"$name\n$characterId"`). */
+export function loadCharacterSaveMessage(saveId: string) {
+ return { t: 'loadCharacterSave', saveId } as const;
+}
+
+/** Delete a character save. */
+export function deleteCharacterSaveMessage(saveId: string) {
+ return { t: 'deleteCharacterSave', saveId } as const;
+}