websocket reconnect on failure

This commit is contained in:
evanpelle
2024-08-16 11:06:01 -07:00
parent d062d1ac79
commit 332c2cfcac
13 changed files with 159 additions and 200 deletions
+4 -9
View File
@@ -1,13 +1,8 @@
import {GameEvent} from "./EventBus"
export type ClientID = string
import {GameID} from "./Schemas"
export type PlayerID = number // TODO: make string?
export type GameID = string
export type LobbyID = string
export class Cell {
private strRepr: string
@@ -38,7 +33,7 @@ export class PlayerInfo {
public readonly name: string,
public readonly isBot: boolean,
// null if bot.
public readonly clientID: ClientID | null
public readonly gameID: GameID | null
) { }
}
@@ -133,8 +128,8 @@ export interface Game {
forEachTile(fn: (tile: Tile) => void): void
executions(): ExecutionView[]
terraNullius(): TerraNullius
tick()
addExecution(...exec: Execution[])
tick(): void
addExecution(...exec: Execution[]): void
}
export interface MutableGame extends Game {
+4 -1
View File
@@ -1,5 +1,8 @@
import {z} from 'zod';
export type GameID = string
export type ClientID = string
export type Intent = SpawnIntent | AttackIntent | BoatAttackIntent
export type AttackIntent = z.infer<typeof AttackIntentSchema>
@@ -96,7 +99,7 @@ export const ClientIntentMessageSchema = ClientBaseMessageSchema.extend({
export const ClientJoinMessageSchema = ClientBaseMessageSchema.extend({
type: z.literal('join'),
clientID: z.string(),
lobbyID: z.string()
gameID: z.string()
})
export const ClientMessageSchema = z.union([ClientIntentMessageSchema, ClientJoinMessageSchema]);
+1 -1
View File
@@ -6,7 +6,7 @@ export interface Config {
theme(): Theme;
player(): PlayerConfig
turnIntervalMs(): number
lobbyCreationRate(): number
gameCreationRate(): number
lobbyLifetime(): number
}
+1 -1
View File
@@ -9,7 +9,7 @@ export const defaultConfig = new class implements Config {
turnIntervalMs(): number {
return 100
}
lobbyCreationRate(): number {
gameCreationRate(): number {
return 2 * 1000
}
lobbyLifetime(): number {
-1
View File
@@ -26,7 +26,6 @@ export class SpawnExecution implements Execution {
}
const player = this.gs.addPlayer(this.playerInfo, this.playerConfig.startTroops(this.playerInfo))
getSpawnCells(this.gs, this.cell).forEach(c => {
console.log('conquering cell')
player.conquer(this.gs.tile(c))
})
this.gs.addExecution(new PlayerExecution(player.id(), this.playerConfig))