Skip to content

turinghunt-frontend


turinghunt-frontend / context/gameReducer

context/gameReducer

类型别名

GameAction

ts
type GameAction = 
  | {
  type: "WS_CONNECTED";
}
  | {
  type: "WS_DISCONNECTED";
}
  | {
  type: "WS_AUTH_ERROR";
}
  | {
  message: ServerMessage;
  type: "SERVER_MESSAGE";
}
  | {
  type: "SET_ME";
  userId: string;
  username: string;
}
  | {
  type: "CLEAR_ERROR";
}
  | {
  type: "CLEAR_VOTE_RESULT";
}
  | {
  type: "CLEAR_MISSION_RESULT";
}
  | {
  payload: Partial<GameState>;
  type: "SET_MOCK_STATE";
};

定义于: context/gameReducer.ts:53

所有可被 dispatch 的 Action 判别联合。

  • WS_CONNECTED / WS_DISCONNECTED / WS_AUTH_ERROR — WebSocket 连接生命周期
  • SERVER_MESSAGE — 封装一条服务端推送的 WebSocket 消息
  • SET_ME — 设置当前登录玩家的基础信息
  • CLEAR_* — 清除临时 overlay 状态(动画播完后调用)
  • SET_MOCK_STATE — 仅开发/测试用,直接覆盖部分状态

变量

initialGameState

ts
const initialGameState: GameState;

定义于: context/gameReducer.ts:15

gameReducer 的初始化状态。

备注

驱动 GameProvideruseReducer,也用于 E2E 测试中的状态重置。

函数

gameReducer()

ts
function gameReducer(state, action): GameState;

定义于: context/gameReducer.ts:73

游戏主状态 Reducer。

处理所有 GameAction,包括 WebSocket 连接状态变化、服务端消息到状态字段的映射。

参数

state

GameState

当前游戏状态对象

action

GameAction

要处理的 Action

返回

GameState

更新后的游戏状态(不可变更新模式)

TuringHunt Frontend