Files
core_ng/@sammo/server/src/ResourceController.ts
T
2024-03-11 17:05:00 +00:00

168 lines
5.0 KiB
TypeScript

import type { IResourceController } from "@sammo/game_logic";
import type { City } from "@sammo/game_logic/src/City.js";
import type { CityID, GeneralID, NationID, SquadID } from "@sammo/game_logic/src/defs.js";
import type { IGeneralEntity } from "@sammo/game_logic/src/Entity/GeneralEntity.js";
import type { ICityEntity, ValidEntityType } from "@sammo/game_logic/src/Entity/index.js";
import type { INationEntity } from "@sammo/game_logic/src/Entity/NationEntity.js";
import type { ReservedTurn } from "@sammo/game_logic/src/defs.js";
import type { ISquadEntity } from "@sammo/game_logic/src/Entity/SquadEntity.js";
import type { GameEnv } from "@sammo/game_logic/src/GameEnv.js";
import { General } from "@sammo/game_logic/src/General.js";
import type { LazyEntityUpdater } from "@sammo/game_logic/src/LazyEntityUpdater.js";
import type { Nation } from "@sammo/game_logic/src/Nation.js";
import type { Squad } from "@sammo/game_logic/src/Squad.js";
import { insertItemAtArrayLike, NotYetImplemented } from "@sammo/util";
import Denque from "denque";
import type { Mongoose } from "mongoose";
type ChangeType = "insert" | "update" | "delete";
//TODO: Implement!
export class ResourceController implements IResourceController{
constructor(
private readonly db: Mongoose
) {
}
private _nation: Map<number, Nation> = new Map();
private _city: Map<number, City> = new Map();
private _squad: Map<number, Squad> = new Map();
private _general: Map<number, General> = new Map();
//내부적으로 turnTime asc, id asc로 동작하는 PriorityQueue
private _generalByTurnTime = new Denque<General>();
private changes = {
Nation: new Map<number, [ChangeType, Nation]>(),
City: new Map<number, [ChangeType, City]>(),
Squad: new Map<number, [ChangeType, Squad]>(),
General: new Map<number, [ChangeType, General]>(),
GameEnv: new Map<number, [ChangeType, GameEnv]>(),
} as const satisfies Record<ValidEntityType, Map<number, [ChangeType, LazyEntityUpdater<any>]>>;
nation(id: NationID): Nation | undefined {
throw new NotYetImplemented();
}
city(id: CityID): City | undefined {
throw new NotYetImplemented();
}
squad(id: SquadID, nation: NationID): Squad | undefined {
throw new NotYetImplemented();
}
general(id: GeneralID): General | undefined {
throw new NotYetImplemented();
}
peekGeneralTurnTimeQueue(): General | undefined {
return this._generalByTurnTime.peekFront();
}
popGeneralTurnTimeQueue(): General | undefined {
return this._generalByTurnTime.shift();
}
insertGeneralTurnTimeQueue(general: General, maybeTail: boolean): void {
insertItemAtArrayLike(this._generalByTurnTime, general, (a, b)=>a.compareTurnTime(b), maybeTail);
}
gameEnv(): GameEnv {
throw new NotYetImplemented();
}
allNations(): Map<NationID, Nation> {
throw new NotYetImplemented();
}
allCities(): Map<CityID, City> {
throw new NotYetImplemented();
}
allCitiesByNation(): Map<NationID, Map<CityID, City>> {
throw new NotYetImplemented();
}
allSquads(): Map<NationID, Map<SquadID, Squad>> {
throw new NotYetImplemented();
}
allGenerals(): Map<GeneralID, General> {
throw new NotYetImplemented();
}
generalByNation(id: NationID): Map<GeneralID, General> {
throw new NotYetImplemented();
}
generalByCity(id: CityID, nationID?: NationID): Map<GeneralID, General> {
throw new NotYetImplemented();
}
generalBySquad(id: SquadID): Map<GeneralID, General> {
throw new NotYetImplemented();
}
cityByNation(id: NationID): Map<CityID, City> {
throw new NotYetImplemented();
}
squadByNation(id: NationID): Map<SquadID, Squad> {
throw new NotYetImplemented();
}
//----Insert, Update, Delete
reserveUpdate(entity: LazyEntityUpdater<any>): void {
throw new NotYetImplemented();
}
reserveDelete(entity: LazyEntityUpdater<any>): void {
throw new NotYetImplemented();
}
reserveInsert(entity: LazyEntityUpdater<any>): void {
throw new NotYetImplemented();
}
createGeneral(raw: IGeneralEntity): General {
throw new NotYetImplemented();
}
createNation(raw: INationEntity): Nation {
throw new NotYetImplemented();
}
createSquad(raw: ISquadEntity): Squad {
throw new NotYetImplemented();
}
_getAllChanges(): Record<ValidEntityType, Map<number, [op: ChangeType, value: LazyEntityUpdater<any>]>> {
return this.changes;
}
//---- DB 접근 ---
getReservedTurn(general: General): Promise<ReservedTurn> {
throw new NotYetImplemented();
}
nationReservedTurn(general: General): Promise<ReservedTurn | undefined> {
throw new NotYetImplemented();
}
resetAndFill(): Promise<void> {
throw new NotYetImplemented();
}
saveAll(): Promise<void> {
throw new NotYetImplemented();
}
}