mirror of
https://github.com/openfrontio/OpenFrontIO.git
synced 2026-07-25 16:57:16 +00:00
record game metadata to gcs
This commit is contained in:
+19
-4
@@ -1,5 +1,5 @@
|
||||
import { z } from 'zod';
|
||||
import { Difficulty, GameMap, PlayerType, UnitType } from './game/Game';
|
||||
import { Difficulty, GameMap, GameType, PlayerType, UnitType } from './game/Game';
|
||||
|
||||
export type GameID = string
|
||||
export type ClientID = string
|
||||
@@ -41,6 +41,8 @@ export type ClientPingMessage = z.infer<typeof ClientPingMessageSchema>
|
||||
export type ClientIntentMessage = z.infer<typeof ClientIntentMessageSchema>
|
||||
export type ClientJoinMessage = z.infer<typeof ClientJoinMessageSchema>
|
||||
|
||||
export type GameRecord = z.infer<typeof GameRecordSchema>
|
||||
|
||||
const PlayerTypeSchema = z.nativeEnum(PlayerType);
|
||||
|
||||
// TODO: create Cell schema
|
||||
@@ -53,7 +55,8 @@ export interface Lobby {
|
||||
|
||||
const GameConfigSchema = z.object({
|
||||
gameMap: z.nativeEnum(GameMap),
|
||||
difficulty: z.nativeEnum(Difficulty)
|
||||
difficulty: z.nativeEnum(Difficulty),
|
||||
gameType: z.nativeEnum(GameType)
|
||||
})
|
||||
|
||||
const EmojiSchema = z.string().refine(
|
||||
@@ -64,6 +67,8 @@ const EmojiSchema = z.string().refine(
|
||||
message: "Must contain at least one emoji character"
|
||||
}
|
||||
);
|
||||
|
||||
|
||||
// Zod schemas
|
||||
const BaseIntentSchema = z.object({
|
||||
type: z.enum(['attack', 'spawn', 'boat', 'name', 'targetPlayer', 'emoji', 'troop_ratio', 'build_unit']),
|
||||
@@ -81,7 +86,6 @@ export const AttackIntentSchema = BaseIntentSchema.extend({
|
||||
targetY: z.number().nullable()
|
||||
});
|
||||
|
||||
|
||||
export const SpawnIntentSchema = BaseIntentSchema.extend({
|
||||
type: z.literal('spawn'),
|
||||
playerID: z.string(),
|
||||
@@ -223,4 +227,15 @@ export const ClientJoinMessageSchema = ClientBaseMessageSchema.extend({
|
||||
lastTurn: z.number() // The last turn the client saw.
|
||||
})
|
||||
|
||||
export const ClientMessageSchema = z.union([ClientPingMessageSchema, ClientIntentMessageSchema, ClientJoinMessageSchema]);
|
||||
export const ClientMessageSchema = z.union([ClientPingMessageSchema, ClientIntentMessageSchema, ClientJoinMessageSchema]);
|
||||
|
||||
export const GameRecordSchema = z.object({
|
||||
id: z.string(),
|
||||
gameConfig: GameConfigSchema,
|
||||
startTimestampMS: z.number(),
|
||||
endTimestampMS: z.number(),
|
||||
durationSeconds: z.number(),
|
||||
date: z.string(),
|
||||
usernames: z.array(z.string()),
|
||||
turns: z.array(TurnSchema)
|
||||
})
|
||||
Reference in New Issue
Block a user