Spaces:
Sleeping
Sleeping
File size: 1,168 Bytes
90cbf22 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 |
import { ObjectType, v } from 'convex/values';
import { GameId, parseGameId, playerId } from './ids';
export type CharacterType = 'villager' | 'werewolf';
export const CharacterTypeSchema = v.union(v.literal('villager'), v.literal('werewolf'));
export const serializedPlayerDescription = {
playerId,
name: v.string(),
description: v.string(),
character: v.string(),
type: CharacterTypeSchema,
};
export type SerializedPlayerDescription = ObjectType<typeof serializedPlayerDescription>;
export class PlayerDescription {
playerId: GameId<'players'>;
name: string;
description: string;
character: string;
type: CharacterType;
constructor(serialized: SerializedPlayerDescription) {
const { playerId, name, description, character, type } = serialized;
this.playerId = parseGameId('players', playerId);
this.name = name;
this.description = description;
this.character = character;
this.type = type;
}
serialize(): SerializedPlayerDescription {
const { playerId, name, description, character, type } = this;
return {
playerId,
name,
description,
type: type,
character,
};
}
}
|