mirror of
https://github.com/openfrontio/OpenFrontIO.git
synced 2026-07-16 20:30:11 +00:00
better game join logic, create dev and prod configs
This commit is contained in:
+7
-2
@@ -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]);
|
||||
@@ -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;
|
||||
|
||||
@@ -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()
|
||||
|
||||
@@ -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
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user