feat: RSC TurntimeQueue
This commit is contained in:
@@ -19,7 +19,9 @@ export interface IResourceController {
|
|||||||
troop(id: TroopID, nation: NationID): Troop | undefined;
|
troop(id: TroopID, nation: NationID): Troop | undefined;
|
||||||
general(id: GeneralID): General | undefined;
|
general(id: GeneralID): General | undefined;
|
||||||
|
|
||||||
upcomingGeneral(): General | undefined;
|
peekGeneralTurntimeQueue(): General | undefined;
|
||||||
|
popGeneralTurntimeQueue(): General | undefined;
|
||||||
|
insertGeneralTurntimeQueue(general: General, maybeTail: boolean): void;
|
||||||
|
|
||||||
gameEnv(): GameEnv;
|
gameEnv(): GameEnv;
|
||||||
|
|
||||||
@@ -50,6 +52,7 @@ export interface IResourceController {
|
|||||||
createNation(raw: INationEntity): Nation;
|
createNation(raw: INationEntity): Nation;
|
||||||
createTroop(raw: ITroopEntity): Troop;
|
createTroop(raw: ITroopEntity): Troop;
|
||||||
|
|
||||||
|
|
||||||
_getAllChanges(): Record<
|
_getAllChanges(): Record<
|
||||||
ValidEntityType,
|
ValidEntityType,
|
||||||
Map<number, [op: 'insert' | 'update' | 'delete', value: LazyEntityUpdater<any>]>
|
Map<number, [op: 'insert' | 'update' | 'delete', value: LazyEntityUpdater<any>]>
|
||||||
|
|||||||
@@ -2,16 +2,20 @@ import type { IResourceController } from "@sammo/game_logic";
|
|||||||
import type { City } from "@sammo/game_logic/src/City.js";
|
import type { City } from "@sammo/game_logic/src/City.js";
|
||||||
import type { CityID, GeneralID, NationID, TroopID } from "@sammo/game_logic/src/defs.js";
|
import type { CityID, GeneralID, NationID, TroopID } from "@sammo/game_logic/src/defs.js";
|
||||||
import type { IGeneralEntity } from "@sammo/game_logic/src/Entity/GeneralEntity.js";
|
import type { IGeneralEntity } from "@sammo/game_logic/src/Entity/GeneralEntity.js";
|
||||||
import type { ValidEntityType } from "@sammo/game_logic/src/Entity/index.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 { INationEntity } from "@sammo/game_logic/src/Entity/NationEntity.js";
|
||||||
import type { IReservedTurn } from "@sammo/game_logic/src/Entity/ReservedTurn.js";
|
import type { IReservedTurn } from "@sammo/game_logic/src/Entity/ReservedTurn.js";
|
||||||
import type { ITroopEntity } from "@sammo/game_logic/src/Entity/TroopEntity.js";
|
import type { ITroopEntity } from "@sammo/game_logic/src/Entity/TroopEntity.js";
|
||||||
import type { GameEnv } from "@sammo/game_logic/src/GameEnv.js";
|
import type { GameEnv } from "@sammo/game_logic/src/GameEnv.js";
|
||||||
import type { General } from "@sammo/game_logic/src/General.js";
|
import { General } from "@sammo/game_logic/src/General.js";
|
||||||
import type { LazyEntityUpdater } from "@sammo/game_logic/src/LazyEntityUpdater.js";
|
import type { LazyEntityUpdater } from "@sammo/game_logic/src/LazyEntityUpdater.js";
|
||||||
import type { Nation } from "@sammo/game_logic/src/Nation.js";
|
import type { Nation } from "@sammo/game_logic/src/Nation.js";
|
||||||
import type { Troop } from "@sammo/game_logic/src/Troop.js";
|
import type { Troop } from "@sammo/game_logic/src/Troop.js";
|
||||||
import { NotYetImplemented } from "@sammo/util";
|
import { insertItemAtArrayLike, NotYetImplemented } from "@sammo/util";
|
||||||
|
import Denque from "denque";
|
||||||
|
|
||||||
|
|
||||||
|
type ChangeType = "insert" | "update" | "delete";
|
||||||
|
|
||||||
//TODO: Implement!
|
//TODO: Implement!
|
||||||
export class ResourceController implements IResourceController{
|
export class ResourceController implements IResourceController{
|
||||||
@@ -19,6 +23,24 @@ export class ResourceController implements IResourceController{
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private _nation: Map<number, Nation> = new Map();
|
||||||
|
private _city: Map<number, City> = new Map();
|
||||||
|
private _troop: Map<number, Troop> = 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]>(),
|
||||||
|
Troop: new Map<number, [ChangeType, Troop]>(),
|
||||||
|
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 {
|
nation(id: NationID): Nation | undefined {
|
||||||
throw new NotYetImplemented();
|
throw new NotYetImplemented();
|
||||||
}
|
}
|
||||||
@@ -35,8 +57,16 @@ export class ResourceController implements IResourceController{
|
|||||||
throw new NotYetImplemented();
|
throw new NotYetImplemented();
|
||||||
}
|
}
|
||||||
|
|
||||||
upcomingGeneral(): General | undefined {
|
peekGeneralTurntimeQueue(): General | undefined {
|
||||||
throw new NotYetImplemented();
|
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 {
|
gameEnv(): GameEnv {
|
||||||
@@ -110,8 +140,9 @@ export class ResourceController implements IResourceController{
|
|||||||
throw new NotYetImplemented();
|
throw new NotYetImplemented();
|
||||||
}
|
}
|
||||||
|
|
||||||
_getAllChanges(): Record<ValidEntityType, Map<number, [op: "insert" | "update" | "delete", value: LazyEntityUpdater<any>]>> {
|
|
||||||
throw new NotYetImplemented();
|
_getAllChanges(): Record<ValidEntityType, Map<number, [op: ChangeType, value: LazyEntityUpdater<any>]>> {
|
||||||
|
return this.changes;
|
||||||
}
|
}
|
||||||
|
|
||||||
//---- DB 접근 ---
|
//---- DB 접근 ---
|
||||||
|
|||||||
Reference in New Issue
Block a user