mirror of
https://github.com/openfrontio/OpenFrontIO.git
synced 2026-07-17 07:09:58 +00:00
move Game updates to GameUpdate.ts
This commit is contained in:
@@ -4,11 +4,14 @@ import { getConfig } from "./configuration/Config";
|
||||
import { EventBus } from "./EventBus";
|
||||
import { Executor } from "./execution/ExecutionManager";
|
||||
import { WinCheckExecution } from "./execution/WinCheckExecution";
|
||||
import { AllPlayers, Cell, DisplayMessageUpdate, Game, GameUpdateType, MessageType, NameViewData, Player, PlayerActions, PlayerID, PlayerProfile, PlayerType, UnitType } from "./game/Game";
|
||||
import { AllPlayers, Cell, Game, MessageType, Player, PlayerActions, PlayerID, PlayerProfile, PlayerType, UnitType } from "./game/Game";
|
||||
import { DisplayMessageUpdate } from "./game/GameUpdates";
|
||||
import { NameViewData } from './game/Game';
|
||||
import { GameUpdateType } from "./game/GameUpdates";
|
||||
import { createGame } from "./game/GameImpl";
|
||||
import { loadTerrainMap as loadGameMap } from "./game/TerrainMapLoader";
|
||||
import { GameConfig, Turn } from "./Schemas";
|
||||
import { GameUpdateViewData } from "./GameView";
|
||||
import { GameUpdateViewData } from './game/GameUpdates';
|
||||
import { andFN, manhattanDistFN, TileRef } from "./game/GameMap";
|
||||
import { targetTransportTile } from "./Util";
|
||||
|
||||
|
||||
@@ -1,4 +0,0 @@
|
||||
|
||||
|
||||
|
||||
|
||||
@@ -7,7 +7,7 @@ import { GameConfig } from "../Schemas";
|
||||
import { DefaultConfig } from "./DefaultConfig";
|
||||
import { DevConfig, DevServerConfig } from "./DevConfig";
|
||||
import { GameMap, TileRef } from "../game/GameMap";
|
||||
import { PlayerView } from "../GameView";
|
||||
import { PlayerView } from "../game/GameView";
|
||||
|
||||
export enum GameEnv {
|
||||
Dev,
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
import { Difficulty, GameType, Gold, Player, PlayerInfo, PlayerType, TerrainType, TerraNullius, Tick, UnitInfo, UnitType } from "../game/Game";
|
||||
import { GameMap, TileRef } from "../game/GameMap";
|
||||
import { PlayerView } from "../GameView";
|
||||
import { PlayerView } from "../game/GameView";
|
||||
import { GameConfig } from "../Schemas";
|
||||
import { assertNever, within } from "../Util";
|
||||
import { Config, ServerConfig, Theme } from "./Config";
|
||||
|
||||
@@ -1,4 +1,6 @@
|
||||
import { AllianceRequestUpdate, GameUpdateType, AllianceRequest, Player, Tick } from "./Game";
|
||||
import { AllianceRequest, Player, Tick } from "./Game";
|
||||
import { AllianceRequestUpdate } from "./GameUpdates";
|
||||
import { GameUpdateType } from "./GameUpdates";
|
||||
import { GameImpl } from "./GameImpl";
|
||||
|
||||
|
||||
|
||||
+9
-122
@@ -1,8 +1,9 @@
|
||||
import { Config } from "../configuration/Config"
|
||||
import { GameEvent } from "../EventBus"
|
||||
import { PlayerView } from "../GameView"
|
||||
import { PlayerView } from "./GameView"
|
||||
import { ClientID, GameConfig, GameID } from "../Schemas"
|
||||
import { GameMap, GameMapImpl, TileRef, TileUpdate } from "./GameMap"
|
||||
import { GameMap, GameMapImpl, TileRef } from "./GameMap"
|
||||
import { GameUpdate, GameUpdateType, PlayerUpdate, UnitUpdate } from "./GameUpdates"
|
||||
|
||||
export type PlayerID = string
|
||||
export type Tick = number
|
||||
@@ -326,26 +327,6 @@ export interface Game extends GameMap {
|
||||
nations(): Nation[]
|
||||
}
|
||||
|
||||
export enum GameUpdateType {
|
||||
Tile,
|
||||
Unit,
|
||||
Player,
|
||||
DisplayEvent,
|
||||
AllianceRequest,
|
||||
AllianceRequestReply,
|
||||
BrokeAlliance,
|
||||
AllianceExpired,
|
||||
TargetPlayer,
|
||||
EmojiUpdate,
|
||||
WinUpdate
|
||||
}
|
||||
|
||||
export interface NameViewData {
|
||||
x: number,
|
||||
y: number,
|
||||
size: number,
|
||||
}
|
||||
|
||||
export interface PlayerActions {
|
||||
canBoat: boolean
|
||||
canAttack: boolean
|
||||
@@ -368,89 +349,6 @@ export interface PlayerInteraction {
|
||||
canDonate: boolean
|
||||
}
|
||||
|
||||
export type GameUpdate = TileUpdateWrapper
|
||||
| UnitUpdate
|
||||
| PlayerUpdate
|
||||
| AllianceRequestUpdate
|
||||
| AllianceRequestReplyUpdate
|
||||
| BrokeAllianceUpdate
|
||||
| AllianceExpiredUpdate
|
||||
| DisplayMessageUpdate
|
||||
| TargetPlayerUpdate
|
||||
| EmojiUpdate
|
||||
| WinUpdate
|
||||
|
||||
export interface TileUpdateWrapper {
|
||||
type: GameUpdateType.Tile,
|
||||
update: TileUpdate
|
||||
}
|
||||
|
||||
export interface UnitUpdate {
|
||||
type: GameUpdateType.Unit
|
||||
unitType: UnitType
|
||||
troops: number
|
||||
id: number
|
||||
ownerID: number
|
||||
pos: MapPos
|
||||
lastPos: MapPos
|
||||
isActive: boolean
|
||||
health?: number
|
||||
}
|
||||
|
||||
export interface PlayerUpdate {
|
||||
type: GameUpdateType.Player
|
||||
nameViewData?: NameViewData,
|
||||
clientID: ClientID,
|
||||
name: string,
|
||||
displayName: string,
|
||||
id: PlayerID,
|
||||
smallID: number,
|
||||
playerType: PlayerType,
|
||||
isAlive: boolean,
|
||||
tilesOwned: number,
|
||||
gold: number,
|
||||
population: number,
|
||||
workers: number,
|
||||
troops: number,
|
||||
targetTroopRatio: number
|
||||
allies: number[]
|
||||
isTraitor: boolean
|
||||
targets: number[]
|
||||
outgoingEmojis: EmojiMessage[]
|
||||
}
|
||||
|
||||
|
||||
export interface AllianceRequestUpdate {
|
||||
type: GameUpdateType.AllianceRequest
|
||||
requestorID: number,
|
||||
recipientID: number,
|
||||
createdAt: Tick,
|
||||
}
|
||||
|
||||
export interface AllianceRequestReplyUpdate {
|
||||
type: GameUpdateType.AllianceRequestReply
|
||||
request: AllianceRequestUpdate
|
||||
accepted: boolean
|
||||
}
|
||||
|
||||
export interface BrokeAllianceUpdate {
|
||||
type: GameUpdateType.BrokeAlliance
|
||||
traitorID: number
|
||||
betrayedID: number
|
||||
}
|
||||
|
||||
export interface AllianceExpiredUpdate {
|
||||
type: GameUpdateType.AllianceExpired
|
||||
player1ID: number
|
||||
player2ID: number
|
||||
}
|
||||
|
||||
export interface TargetPlayerUpdate {
|
||||
type: GameUpdateType.TargetPlayer
|
||||
playerID: number
|
||||
targetID: number
|
||||
}
|
||||
|
||||
export interface EmojiMessage {
|
||||
message: string
|
||||
senderID: number
|
||||
@@ -458,23 +356,6 @@ export interface EmojiMessage {
|
||||
createdAt: Tick
|
||||
}
|
||||
|
||||
export interface EmojiUpdate {
|
||||
type: GameUpdateType.EmojiUpdate
|
||||
emoji: EmojiMessage
|
||||
}
|
||||
|
||||
export interface DisplayMessageUpdate {
|
||||
type: GameUpdateType.DisplayEvent
|
||||
message: string
|
||||
messageType: MessageType
|
||||
playerID: number | null
|
||||
}
|
||||
|
||||
export interface WinUpdate {
|
||||
type: GameUpdateType.WinUpdate
|
||||
winnerID: number,
|
||||
}
|
||||
|
||||
export enum MessageType {
|
||||
SUCCESS,
|
||||
INFO,
|
||||
@@ -482,3 +363,9 @@ export enum MessageType {
|
||||
ERROR
|
||||
}
|
||||
|
||||
export interface NameViewData {
|
||||
x: number;
|
||||
y: number;
|
||||
size: number;
|
||||
}
|
||||
|
||||
|
||||
@@ -1,5 +1,7 @@
|
||||
import { Config } from "../configuration/Config";
|
||||
import { Cell, Execution, Game, PlayerID, PlayerInfo, Player, TerraNullius, Unit, AllianceRequest, Alliance, Nation, UnitType, UnitInfo, DefenseBonus, GameUpdate, GameUpdateType, AllPlayers, GameUpdates, TerrainType, EmojiMessage } from "./Game";
|
||||
import { Cell, Execution, Game, PlayerID, PlayerInfo, Player, TerraNullius, Unit, AllianceRequest, Alliance, Nation, UnitType, UnitInfo, DefenseBonus, AllPlayers, GameUpdates, TerrainType, EmojiMessage } from "./Game";
|
||||
import { GameUpdate } from "./GameUpdates";
|
||||
import { GameUpdateType } from "./GameUpdates";
|
||||
import { NationMap } from "./TerrainMapLoader";
|
||||
import { PlayerImpl } from "./PlayerImpl";
|
||||
import { TerraNulliusImpl } from "./TerraNulliusImpl";
|
||||
|
||||
@@ -0,0 +1,125 @@
|
||||
import { ClientID } from '../Schemas';
|
||||
import { EmojiMessage, GameUpdates, MapPos, MessageType, NameViewData, PlayerID, PlayerType, Tick, UnitType } from './Game';
|
||||
import { TileUpdate } from './GameMap';
|
||||
|
||||
|
||||
export interface GameUpdateViewData {
|
||||
tick: number;
|
||||
updates: GameUpdates;
|
||||
packedTileUpdates: BigUint64Array;
|
||||
playerNameViewData: Record<number, NameViewData>;
|
||||
}
|
||||
|
||||
export enum GameUpdateType {
|
||||
Tile,
|
||||
Unit,
|
||||
Player,
|
||||
DisplayEvent,
|
||||
AllianceRequest,
|
||||
AllianceRequestReply,
|
||||
BrokeAlliance,
|
||||
AllianceExpired,
|
||||
TargetPlayer,
|
||||
EmojiUpdate,
|
||||
WinUpdate
|
||||
}
|
||||
|
||||
export type GameUpdate = TileUpdateWrapper |
|
||||
UnitUpdate |
|
||||
PlayerUpdate |
|
||||
AllianceRequestUpdate |
|
||||
AllianceRequestReplyUpdate |
|
||||
BrokeAllianceUpdate |
|
||||
AllianceExpiredUpdate |
|
||||
DisplayMessageUpdate |
|
||||
TargetPlayerUpdate |
|
||||
EmojiUpdate |
|
||||
WinUpdate
|
||||
|
||||
export interface TileUpdateWrapper {
|
||||
type: GameUpdateType.Tile
|
||||
update: TileUpdate
|
||||
}
|
||||
|
||||
export interface UnitUpdate {
|
||||
type: GameUpdateType.Unit
|
||||
unitType: UnitType
|
||||
troops: number
|
||||
id: number
|
||||
ownerID: number
|
||||
pos: MapPos
|
||||
lastPos: MapPos
|
||||
isActive: boolean
|
||||
health?: number
|
||||
}
|
||||
|
||||
export interface PlayerUpdate {
|
||||
type: GameUpdateType.Player
|
||||
nameViewData?: NameViewData
|
||||
clientID: ClientID
|
||||
name: string
|
||||
displayName: string
|
||||
id: PlayerID
|
||||
smallID: number
|
||||
playerType: PlayerType
|
||||
isAlive: boolean
|
||||
tilesOwned: number
|
||||
gold: number
|
||||
population: number
|
||||
workers: number
|
||||
troops: number
|
||||
targetTroopRatio: number
|
||||
allies: number[]
|
||||
isTraitor: boolean
|
||||
targets: number[]
|
||||
outgoingEmojis: EmojiMessage[]
|
||||
}
|
||||
|
||||
export interface AllianceRequestUpdate {
|
||||
type: GameUpdateType.AllianceRequest
|
||||
requestorID: number
|
||||
recipientID: number
|
||||
createdAt: Tick
|
||||
}
|
||||
|
||||
export interface AllianceRequestReplyUpdate {
|
||||
type: GameUpdateType.AllianceRequestReply
|
||||
request: AllianceRequestUpdate
|
||||
accepted: boolean
|
||||
}
|
||||
|
||||
export interface BrokeAllianceUpdate {
|
||||
type: GameUpdateType.BrokeAlliance
|
||||
traitorID: number
|
||||
betrayedID: number
|
||||
}
|
||||
|
||||
export interface AllianceExpiredUpdate {
|
||||
type: GameUpdateType.AllianceExpired
|
||||
player1ID: number
|
||||
player2ID: number
|
||||
}
|
||||
|
||||
export interface TargetPlayerUpdate {
|
||||
type: GameUpdateType.TargetPlayer
|
||||
playerID: number
|
||||
targetID: number
|
||||
}
|
||||
|
||||
export interface EmojiUpdate {
|
||||
type: GameUpdateType.EmojiUpdate
|
||||
emoji: EmojiMessage
|
||||
}
|
||||
|
||||
export interface DisplayMessageUpdate {
|
||||
type: GameUpdateType.DisplayEvent
|
||||
message: string
|
||||
messageType: MessageType
|
||||
playerID: number | null
|
||||
}
|
||||
|
||||
export interface WinUpdate {
|
||||
type: GameUpdateType.WinUpdate
|
||||
winnerID: number
|
||||
}
|
||||
|
||||
@@ -1,10 +1,15 @@
|
||||
import { GameUpdates, GameUpdateType, MapPos, MessageType, NameViewData, Player, PlayerActions, PlayerProfile, PlayerUpdate, Unit, UnitUpdate } from './game/Game';
|
||||
import { Config } from "./configuration/Config";
|
||||
import { Alliance, AllianceRequest, AllPlayers, Cell, DefenseBonus, EmojiMessage, Game, Gold, Nation, PlayerID, PlayerInfo, PlayerType, Relation, TerrainType, TerraNullius, Tick, UnitInfo, UnitType } from "./game/Game";
|
||||
import { ClientID } from "./Schemas";
|
||||
import { TerraNulliusImpl } from './game/TerraNulliusImpl';
|
||||
import { WorkerClient } from './worker/WorkerClient';
|
||||
import { GameMap, GameMapImpl, TileRef, TileUpdate } from './game/GameMap';
|
||||
import { GameUpdates, MapPos, MessageType, Player, PlayerActions, PlayerProfile, Unit } from './Game';
|
||||
import { PlayerUpdate } from "./GameUpdates";
|
||||
import { UnitUpdate } from "./GameUpdates";
|
||||
import { NameViewData } from './Game';
|
||||
import { GameUpdateType } from "./GameUpdates";
|
||||
import { Config } from "../configuration/Config";
|
||||
import { Alliance, AllianceRequest, AllPlayers, Cell, DefenseBonus, EmojiMessage, Game, Gold, Nation, PlayerID, PlayerInfo, PlayerType, Relation, TerrainType, TerraNullius, Tick, UnitInfo, UnitType } from "./Game";
|
||||
import { ClientID } from "../Schemas";
|
||||
import { TerraNulliusImpl } from './TerraNulliusImpl';
|
||||
import { WorkerClient } from '../worker/WorkerClient';
|
||||
import { GameMap, GameMapImpl, TileRef, TileUpdate } from './GameMap';
|
||||
import { GameUpdateViewData } from './GameUpdates';
|
||||
|
||||
export class UnitView {
|
||||
public _wasUpdated = true
|
||||
@@ -150,13 +155,6 @@ export class PlayerView {
|
||||
}
|
||||
}
|
||||
|
||||
export interface GameUpdateViewData {
|
||||
tick: number
|
||||
updates: GameUpdates
|
||||
packedTileUpdates: BigUint64Array
|
||||
playerNameViewData: Record<number, NameViewData>
|
||||
}
|
||||
|
||||
export class GameView implements GameMap {
|
||||
private lastUpdate: GameUpdateViewData
|
||||
private smallIDToID = new Map<number, PlayerID>()
|
||||
@@ -1,4 +1,6 @@
|
||||
import { Player, PlayerInfo, PlayerID, PlayerType, TerraNullius, Cell, Execution, AllianceRequest, MutableAlliance, Alliance, Tick, AllPlayers, Gold, UnitType, Unit, Relation, PlayerUpdate, GameUpdateType, EmojiMessage } from "./Game";
|
||||
import { Player, PlayerInfo, PlayerID, PlayerType, TerraNullius, Cell, Execution, AllianceRequest, MutableAlliance, Alliance, Tick, AllPlayers, Gold, UnitType, Unit, Relation, EmojiMessage } from "./Game";
|
||||
import { PlayerUpdate } from "./GameUpdates";
|
||||
import { GameUpdateType } from "./GameUpdates";
|
||||
import { ClientID } from "../Schemas";
|
||||
import { assertNever, closestOceanShoreFromPlayer, distSortUnit, simpleHash, sourceDstOceanShore, within } from "../Util";
|
||||
import { CellString, GameImpl } from "./GameImpl";
|
||||
|
||||
@@ -1,4 +1,6 @@
|
||||
import { GameUpdateType, MessageType, UnitUpdate } from './Game';
|
||||
import { MessageType } from './Game';
|
||||
import { UnitUpdate } from "./GameUpdates";
|
||||
import { GameUpdateType } from "./GameUpdates";
|
||||
import { simpleHash, within } from "../Util";
|
||||
import { Unit, TerraNullius, UnitType, Player, UnitInfo } from "./Game";
|
||||
import { GameImpl } from "./GameImpl";
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
import { createGameRunner, GameRunner } from "../GameRunner";
|
||||
import { GameUpdateViewData } from "../GameView";
|
||||
import { GameUpdateViewData } from '../game/GameUpdates';
|
||||
import {
|
||||
MainThreadMessage,
|
||||
WorkerMessage,
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
import { PlayerActions, PlayerID, PlayerInfo, PlayerProfile } from "../game/Game";
|
||||
import { GameUpdateViewData } from "../GameView";
|
||||
import { GameUpdateViewData } from '../game/GameUpdates';
|
||||
import { GameConfig, GameID, Turn } from "../Schemas";
|
||||
import { generateID } from "../Util";
|
||||
import { WorkerMessage } from "./WorkerMessages";
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
import { GameUpdateViewData } from "../GameView";
|
||||
import { GameUpdateViewData } from '../game/GameUpdates';
|
||||
import { GameConfig, GameID, Turn } from "../Schemas";
|
||||
import { PlayerActions, PlayerID, PlayerProfile } from "../game/Game";
|
||||
|
||||
|
||||
Reference in New Issue
Block a user