turinghunt-frontend / types
types
接口
ErrorData
定义于: types/index.ts:151
ERROR 消息的数据载荷。
属性
error
error: string;定义于: types/index.ts:152
GameOverData
定义于: types/index.ts:141
GAME_OVER 消息的数据载荷,包含游戏结果及全员角色公开信息。
属性
reason
reason:
| "good_missions"
| "evil_missions"
| "vote_failures"
| "assassin_success";定义于: types/index.ts:145
结束原因:好人完成任务 / 邪恶完成任务 / 连续投票失败 / 刺客成功刺杀梅林。
role_reveal
role_reveal: Record<string, string>;定义于: types/index.ts:147
全员 user_id → role 映射,用于游戏结束后公开身份。
winner
winner: "good" | "evil";定义于: types/index.ts:143
获胜阵营。
GameState
定义于: types/index.ts:217
全局游戏状态,由 gameReducer 管理,通过 GameContext 向下传递。
状态完全由服务端 WebSocket 消息驱动,前端不持有任何独立业务逻辑。
属性
activeInputType
activeInputType: InputType | null;定义于: types/index.ts:231
authError
authError: boolean;定义于: types/index.ts:219
connected
connected: boolean;定义于: types/index.ts:218
currentRoundSpeeches
currentRoundSpeeches: object[];定义于: types/index.ts:248
content
content: string;player_id
player_id: string;username
username: string;currentSpeakerId
currentSpeakerId: string | null;定义于: types/index.ts:246
currentTeam
currentTeam: string[];定义于: types/index.ts:228
errorMessage
errorMessage: string | null;定义于: types/index.ts:235
evilWins
evilWins: number;定义于: types/index.ts:238
gameEnded
gameEnded: boolean;定义于: types/index.ts:250
gameOverData
gameOverData: GameOverData | null;定义于: types/index.ts:234
goodWins
goodWins: number;定义于: types/index.ts:237
inputLocked
inputLocked: boolean;定义于: types/index.ts:230
isSpeaker
isSpeaker: boolean;定义于: types/index.ts:244
leaderId
leaderId: string | null;定义于: types/index.ts:226
missionNumber
missionNumber: number;定义于: types/index.ts:225
missionOutcomes
missionOutcomes: Record<number, MissionDetail>;定义于: types/index.ts:240
myRole
myRole: Role | null;定义于: types/index.ts:222
myUserId
myUserId: string | null;定义于: types/index.ts:220
myUsername
myUsername: string | null;定义于: types/index.ts:221
pendingMissionResult
pendingMissionResult: MissionResultData | null;定义于: types/index.ts:233
pendingTeamVoteResult
pendingTeamVoteResult: TeamVoteResultData | null;定义于: types/index.ts:232
phase
phase: Phase;定义于: types/index.ts:224
players
players: Player[];定义于: types/index.ts:229
requiredTeamSize
requiredTeamSize: number;定义于: types/index.ts:227
speeches
speeches: SpeechAddedData[];定义于: types/index.ts:242
visibleOthers
visibleOthers: Record<string, string>;定义于: types/index.ts:223
GameStateData
定义于: types/index.ts:67
GAME_STATE 消息的数据载荷,携带完整的游戏快照。
属性
current_speaker_id
current_speaker_id: string | null;定义于: types/index.ts:76
current_team
current_team: string[];定义于: types/index.ts:74
input_locked
input_locked: boolean;定义于: types/index.ts:78
is_speaker
is_speaker: boolean;定义于: types/index.ts:75
leader_id
leader_id: string | null;定义于: types/index.ts:71
mission_number
mission_number: number;定义于: types/index.ts:73
needs_vote
needs_vote: boolean;定义于: types/index.ts:77
phase
phase: Phase;定义于: types/index.ts:70
player_count
player_count: number;定义于: types/index.ts:69
players
players: Player[];定义于: types/index.ts:68
required_team_size
required_team_size: number;定义于: types/index.ts:72
MissionDetail
定义于: types/index.ts:197
单次任务的完整记录,存储在 GameState.missionOutcomes 中。
用于 MissionTracker 组件展示任务历史详情。
属性
fail_votes
fail_votes: number;定义于: types/index.ts:203
投失败票的数量。
success
success: boolean;定义于: types/index.ts:199
任务是否成功。
success_votes
success_votes: number;定义于: types/index.ts:201
投成功票的数量。
team
team: string[];定义于: types/index.ts:205
参与该任务的玩家 user_id 列表。
teamNames
teamNames: string[];定义于: types/index.ts:207
对应的玩家用户名列表(与 team 索引对齐)。
MissionResultData
定义于: types/index.ts:124
MISSION_RESULT 消息的数据载荷,包含任务投票明细及累计分数。
属性
evil_wins
evil_wins: number;定义于: types/index.ts:130
fail_votes
fail_votes: number;定义于: types/index.ts:127
good_wins
good_wins: number;定义于: types/index.ts:129
mission_number
mission_number: number;定义于: types/index.ts:125
success
success: boolean;定义于: types/index.ts:126
success_votes
success_votes: number;定义于: types/index.ts:128
PhaseChangedData
定义于: types/index.ts:93
PHASE_CHANGED 消息的数据载荷,通知前端切换游戏阶段。
属性
current_speaker_id?
optional current_speaker_id?: string | null;定义于: types/index.ts:98
leader_id
leader_id: string | null;定义于: types/index.ts:95
mission_number
mission_number: number;定义于: types/index.ts:97
phase
phase: Phase;定义于: types/index.ts:94
required_team_size
required_team_size: number;定义于: types/index.ts:96
Player
定义于: types/index.ts:57
房间内的玩家基础信息。
属性
user_id
user_id: string;定义于: types/index.ts:59
全局唯一用户 ID。
username
username: string;定义于: types/index.ts:61
玩家用户名,用于 UI 展示。
RequestInputData
定义于: types/index.ts:102
REQUEST_INPUT 消息的数据载荷,请求玩家提交特定类型的输入。
属性
input_type
input_type: InputType;定义于: types/index.ts:103
mission_number
mission_number: number;定义于: types/index.ts:105
phase
phase: Phase;定义于: types/index.ts:104
RoleAssignedData
定义于: types/index.ts:87
ROLE_ASSIGNED 消息的数据载荷,告知本玩家角色及可见的其他玩家角色。
属性
role
role: Role;定义于: types/index.ts:88
visible_others
visible_others: Record<string, string>;定义于: types/index.ts:89
SpeechAddedData
定义于: types/index.ts:134
SPEECH_ADDED 消息的数据载荷,实时推送新增发言。
属性
content
content: string;定义于: types/index.ts:136
next_speaker_id
next_speaker_id: string | null;定义于: types/index.ts:137
player_id
player_id: string;定义于: types/index.ts:135
SpeechHistoryData
定义于: types/index.ts:82
SPEECH_HISTORY 消息的数据载荷,包含本轮发言完整记录。
属性
speeches
speeches: object[];定义于: types/index.ts:83
content
content: string;player_id
player_id: string;username
username: string;TeamProposedData
定义于: types/index.ts:109
TEAM_PROPOSED 消息的数据载荷,领袖提交的队伍方案。
属性
leader_id
leader_id: string;定义于: types/index.ts:110
mission_number
mission_number: number;定义于: types/index.ts:112
team
team: string[];定义于: types/index.ts:111
TeamVoteResultData
定义于: types/index.ts:116
TEAM_VOTE_RESULT 消息的数据载荷,包含全员投票明细及结果。
属性
approved
approved: boolean;定义于: types/index.ts:118
consecutive_vote_failures
consecutive_vote_failures: number;定义于: types/index.ts:119
mission_number
mission_number: number;定义于: types/index.ts:120
votes
votes: Record<string, boolean>;定义于: types/index.ts:117
类型别名
ClientMessage
type ClientMessage =
| {
data: null;
type: "START_GAME";
}
| {
data: {
content: string;
};
type: "SPEECH";
}
| {
data: null;
type: "END_SPEECH";
}
| {
data: {
team: string[];
};
type: "SUBMIT_TEAM";
}
| {
data: {
vote: boolean;
};
type: "VOTE";
}
| {
data: {
target_id: string;
};
type: "ASSASSIN_CHOOSE";
};定义于: types/index.ts:184
客户端 → 服务端所有 WebSocket 消息的判别联合类型。
通过 GameContext.sendMessage() 发送。
InputType
type InputType = "SPEECH" | "SUBMIT_TEAM" | "VOTE" | "ASSASSIN_CHOOSE";定义于: types/index.ts:50
服务端请求玩家输入的类型。
SPEECH— 提交发言内容SUBMIT_TEAM— 提交任务队伍VOTE— 对队伍投票ASSASSIN_CHOOSE— 刺客选择目标
Phase
type Phase =
| "waiting"
| "speaking"
| "team_select"
| "team_vote"
| "mission"
| "assassin"
| "game_over";定义于: types/index.ts:16
游戏阶段枚举。
| 值 | 说明 |
|---|---|
waiting | 等待玩家加入/开始游戏 |
speaking | 玩家轮流发言阶段 |
team_select | 领袖选择任务队员 |
team_vote | 全员对队伍进行投票 |
mission | 队员执行任务(成功/失败) |
assassin | 刺客猜测梅林身份 |
game_over | 游戏结束,公布身份 |
Role
type Role =
| "merlin"
| "percival"
| "loyal_servant"
| "assassin"
| "morgana"
| "mordred"
| "oberon"
| "minion";定义于: types/index.ts:32
玩家角色枚举,涵盖好人方与邪恶方所有角色。
好人方:merlin、percival、loyal_servant
邪恶方:assassin、morgana、mordred、oberon、minion
ServerMessage
type ServerMessage =
| {
data: GameStateData;
type: "GAME_STATE";
}
| {
data: RoleAssignedData;
type: "ROLE_ASSIGNED";
}
| {
data: PhaseChangedData;
type: "PHASE_CHANGED";
}
| {
data: RequestInputData;
type: "REQUEST_INPUT";
}
| {
data: null;
type: "INPUT_LOCKED";
}
| {
data: null;
type: "INPUT_UNLOCKED";
}
| {
data: TeamProposedData;
type: "TEAM_PROPOSED";
}
| {
data: TeamVoteResultData;
type: "TEAM_VOTE_RESULT";
}
| {
data: MissionResultData;
type: "MISSION_RESULT";
}
| {
data: GameOverData;
type: "GAME_OVER";
}
| {
data: SpeechAddedData;
type: "SPEECH_ADDED";
}
| {
data: SpeechHistoryData;
type: "SPEECH_HISTORY";
}
| {
data: ErrorData;
type: "ERROR";
};定义于: types/index.ts:162
服务端 → 客户端所有 WebSocket 消息的判别联合类型。
使用 message.type 字段作为判别子,在 switch-case 中自动收窄到对应的 data 类型。