better game join logic, create dev and prod configs

This commit is contained in:
evanpelle
2024-08-17 12:42:18 -07:00
parent ed4201ab8c
commit 0ea670d975
13 changed files with 92 additions and 44 deletions
+7 -2
View File
@@ -21,7 +21,10 @@ export type ServerStartGameMessage = z.infer<typeof ServerStartGameMessageSchema
export type ClientIntentMessage = z.infer<typeof ClientIntentMessageSchema>
export type ClientJoinMessage = z.infer<typeof ClientJoinMessageSchema>
export interface Lobby {
id: string;
startTime: number;
}
// Zod schemas
const BaseIntentSchema = z.object({
@@ -101,7 +104,9 @@ export const ClientIntentMessageSchema = ClientBaseMessageSchema.extend({
export const ClientJoinMessageSchema = ClientBaseMessageSchema.extend({
type: z.literal('join'),
clientID: z.string(),
gameID: z.string()
gameID: z.string(),
// The last turn the client saw.
lastTurn: z.number()
})
export const ClientMessageSchema = z.union([ClientIntentMessageSchema, ClientJoinMessageSchema]);
+11
View File
@@ -1,6 +1,17 @@
import {Player, PlayerID, PlayerInfo, TerrainType, TerrainTypes, TerraNullius, Tile} from "../Game";
import {Colord, colord} from "colord";
import {devConfig} from "./DevConfig";
import {defaultConfig} from "./DefaultConfig";
export function getConfig(): Config {
if (process.env.GAME_ENV == 'prod') {
console.log('Using prod config')
return defaultConfig
} else {
console.log('Using dev config')
return devConfig
}
}
export interface Config {
theme(): Theme;
+9 -5
View File
@@ -3,9 +3,11 @@ import {within} from "../Util";
import {Config, PlayerConfig, Theme} from "./Config";
import {pastelTheme} from "./PastelTheme";
export const defaultConfig = new class implements Config {
export class DefaultConfig implements Config {
turnsUntilGameStart(): number {
return 50
return 25
}
numBots(): number {
return 500
@@ -17,10 +19,10 @@ export const defaultConfig = new class implements Config {
return 100
}
gameCreationRate(): number {
return 2 * 1000
return 31.5 * 1000
}
lobbyLifetime(): number {
return 10 * 1000
return 30 * 1000
}
theme(): Theme {return pastelTheme;}
}
@@ -75,4 +77,6 @@ export const defaultPlayerConfig = new class implements PlayerConfig {
return Math.min(player.troops() + toAdd, max)
}
}
}
export const defaultConfig = new DefaultConfig()
+10
View File
@@ -0,0 +1,10 @@
import {DefaultConfig} from "./DefaultConfig";
export const devConfig = new class extends DefaultConfig {
gameCreationRate(): number {
return 2 * 1000
}
lobbyLifetime(): number {
return 10 * 1000
}
}