Skip to content

turinghunt-frontend


turinghunt-frontend / types

types

接口

ErrorData

定义于: types/index.ts:151

ERROR 消息的数据载荷。

属性

error
ts
error: string;

定义于: types/index.ts:152


GameOverData

定义于: types/index.ts:141

GAME_OVER 消息的数据载荷,包含游戏结果及全员角色公开信息。

属性

reason
ts
reason: 
  | "good_missions"
  | "evil_missions"
  | "vote_failures"
  | "assassin_success";

定义于: types/index.ts:145

结束原因:好人完成任务 / 邪恶完成任务 / 连续投票失败 / 刺客成功刺杀梅林。

role_reveal
ts
role_reveal: Record<string, string>;

定义于: types/index.ts:147

全员 user_id → role 映射,用于游戏结束后公开身份。

winner
ts
winner: "good" | "evil";

定义于: types/index.ts:143

获胜阵营。


GameState

定义于: types/index.ts:217

全局游戏状态,由 gameReducer 管理,通过 GameContext 向下传递。

状态完全由服务端 WebSocket 消息驱动,前端不持有任何独立业务逻辑。

属性

activeInputType
ts
activeInputType: InputType | null;

定义于: types/index.ts:231

authError
ts
authError: boolean;

定义于: types/index.ts:219

connected
ts
connected: boolean;

定义于: types/index.ts:218

currentRoundSpeeches
ts
currentRoundSpeeches: object[];

定义于: types/index.ts:248

content
ts
content: string;
player_id
ts
player_id: string;
username
ts
username: string;
currentSpeakerId
ts
currentSpeakerId: string | null;

定义于: types/index.ts:246

currentTeam
ts
currentTeam: string[];

定义于: types/index.ts:228

errorMessage
ts
errorMessage: string | null;

定义于: types/index.ts:235

evilWins
ts
evilWins: number;

定义于: types/index.ts:238

gameEnded
ts
gameEnded: boolean;

定义于: types/index.ts:250

gameOverData
ts
gameOverData: GameOverData | null;

定义于: types/index.ts:234

goodWins
ts
goodWins: number;

定义于: types/index.ts:237

inputLocked
ts
inputLocked: boolean;

定义于: types/index.ts:230

isSpeaker
ts
isSpeaker: boolean;

定义于: types/index.ts:244

leaderId
ts
leaderId: string | null;

定义于: types/index.ts:226

missionNumber
ts
missionNumber: number;

定义于: types/index.ts:225

missionOutcomes
ts
missionOutcomes: Record<number, MissionDetail>;

定义于: types/index.ts:240

myRole
ts
myRole: Role | null;

定义于: types/index.ts:222

myUserId
ts
myUserId: string | null;

定义于: types/index.ts:220

myUsername
ts
myUsername: string | null;

定义于: types/index.ts:221

pendingMissionResult
ts
pendingMissionResult: MissionResultData | null;

定义于: types/index.ts:233

pendingTeamVoteResult
ts
pendingTeamVoteResult: TeamVoteResultData | null;

定义于: types/index.ts:232

phase
ts
phase: Phase;

定义于: types/index.ts:224

players
ts
players: Player[];

定义于: types/index.ts:229

requiredTeamSize
ts
requiredTeamSize: number;

定义于: types/index.ts:227

speeches
ts
speeches: SpeechAddedData[];

定义于: types/index.ts:242

visibleOthers
ts
visibleOthers: Record<string, string>;

定义于: types/index.ts:223


GameStateData

定义于: types/index.ts:67

GAME_STATE 消息的数据载荷,携带完整的游戏快照。

属性

current_speaker_id
ts
current_speaker_id: string | null;

定义于: types/index.ts:76

current_team
ts
current_team: string[];

定义于: types/index.ts:74

input_locked
ts
input_locked: boolean;

定义于: types/index.ts:78

is_speaker
ts
is_speaker: boolean;

定义于: types/index.ts:75

leader_id
ts
leader_id: string | null;

定义于: types/index.ts:71

mission_number
ts
mission_number: number;

定义于: types/index.ts:73

needs_vote
ts
needs_vote: boolean;

定义于: types/index.ts:77

phase
ts
phase: Phase;

定义于: types/index.ts:70

player_count
ts
player_count: number;

定义于: types/index.ts:69

players
ts
players: Player[];

定义于: types/index.ts:68

required_team_size
ts
required_team_size: number;

定义于: types/index.ts:72


MissionDetail

定义于: types/index.ts:197

单次任务的完整记录,存储在 GameState.missionOutcomes 中。

用于 MissionTracker 组件展示任务历史详情。

属性

fail_votes
ts
fail_votes: number;

定义于: types/index.ts:203

投失败票的数量。

success
ts
success: boolean;

定义于: types/index.ts:199

任务是否成功。

success_votes
ts
success_votes: number;

定义于: types/index.ts:201

投成功票的数量。

team
ts
team: string[];

定义于: types/index.ts:205

参与该任务的玩家 user_id 列表。

teamNames
ts
teamNames: string[];

定义于: types/index.ts:207

对应的玩家用户名列表(与 team 索引对齐)。


MissionResultData

定义于: types/index.ts:124

MISSION_RESULT 消息的数据载荷,包含任务投票明细及累计分数。

属性

evil_wins
ts
evil_wins: number;

定义于: types/index.ts:130

fail_votes
ts
fail_votes: number;

定义于: types/index.ts:127

good_wins
ts
good_wins: number;

定义于: types/index.ts:129

mission_number
ts
mission_number: number;

定义于: types/index.ts:125

success
ts
success: boolean;

定义于: types/index.ts:126

success_votes
ts
success_votes: number;

定义于: types/index.ts:128


PhaseChangedData

定义于: types/index.ts:93

PHASE_CHANGED 消息的数据载荷,通知前端切换游戏阶段。

属性

current_speaker_id?
ts
optional current_speaker_id?: string | null;

定义于: types/index.ts:98

leader_id
ts
leader_id: string | null;

定义于: types/index.ts:95

mission_number
ts
mission_number: number;

定义于: types/index.ts:97

phase
ts
phase: Phase;

定义于: types/index.ts:94

required_team_size
ts
required_team_size: number;

定义于: types/index.ts:96


Player

定义于: types/index.ts:57

房间内的玩家基础信息。

属性

user_id
ts
user_id: string;

定义于: types/index.ts:59

全局唯一用户 ID。

username
ts
username: string;

定义于: types/index.ts:61

玩家用户名,用于 UI 展示。


RequestInputData

定义于: types/index.ts:102

REQUEST_INPUT 消息的数据载荷,请求玩家提交特定类型的输入。

属性

input_type
ts
input_type: InputType;

定义于: types/index.ts:103

mission_number
ts
mission_number: number;

定义于: types/index.ts:105

phase
ts
phase: Phase;

定义于: types/index.ts:104


RoleAssignedData

定义于: types/index.ts:87

ROLE_ASSIGNED 消息的数据载荷,告知本玩家角色及可见的其他玩家角色。

属性

role
ts
role: Role;

定义于: types/index.ts:88

visible_others
ts
visible_others: Record<string, string>;

定义于: types/index.ts:89


SpeechAddedData

定义于: types/index.ts:134

SPEECH_ADDED 消息的数据载荷,实时推送新增发言。

属性

content
ts
content: string;

定义于: types/index.ts:136

next_speaker_id
ts
next_speaker_id: string | null;

定义于: types/index.ts:137

player_id
ts
player_id: string;

定义于: types/index.ts:135


SpeechHistoryData

定义于: types/index.ts:82

SPEECH_HISTORY 消息的数据载荷,包含本轮发言完整记录。

属性

speeches
ts
speeches: object[];

定义于: types/index.ts:83

content
ts
content: string;
player_id
ts
player_id: string;
username
ts
username: string;

TeamProposedData

定义于: types/index.ts:109

TEAM_PROPOSED 消息的数据载荷,领袖提交的队伍方案。

属性

leader_id
ts
leader_id: string;

定义于: types/index.ts:110

mission_number
ts
mission_number: number;

定义于: types/index.ts:112

team
ts
team: string[];

定义于: types/index.ts:111


TeamVoteResultData

定义于: types/index.ts:116

TEAM_VOTE_RESULT 消息的数据载荷,包含全员投票明细及结果。

属性

approved
ts
approved: boolean;

定义于: types/index.ts:118

consecutive_vote_failures
ts
consecutive_vote_failures: number;

定义于: types/index.ts:119

mission_number
ts
mission_number: number;

定义于: types/index.ts:120

votes
ts
votes: Record<string, boolean>;

定义于: types/index.ts:117

类型别名

ClientMessage

ts
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

ts
type InputType = "SPEECH" | "SUBMIT_TEAM" | "VOTE" | "ASSASSIN_CHOOSE";

定义于: types/index.ts:50

服务端请求玩家输入的类型。

  • SPEECH — 提交发言内容
  • SUBMIT_TEAM — 提交任务队伍
  • VOTE — 对队伍投票
  • ASSASSIN_CHOOSE — 刺客选择目标

Phase

ts
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

ts
type Role = 
  | "merlin"
  | "percival"
  | "loyal_servant"
  | "assassin"
  | "morgana"
  | "mordred"
  | "oberon"
  | "minion";

定义于: types/index.ts:32

玩家角色枚举,涵盖好人方与邪恶方所有角色。

好人方merlinpercivalloyal_servant

邪恶方assassinmorganamordredoberonminion


ServerMessage

ts
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 类型。

TuringHunt Frontend