From 3ba579375576062b4ee7c488d966533d40e3773b Mon Sep 17 00:00:00 2001 From: Hide_D Date: Sat, 9 Mar 2024 05:26:13 +0000 Subject: [PATCH] refac: RSC --- @sammo/game_logic/src/General.ts | 12 +++--- @sammo/game_logic/src/LazyEntityUpdater.ts | 2 +- @sammo/game_logic/src/ResourceController.ts | 42 ++++++++++----------- @sammo/game_logic/src/Troop.ts | 2 +- 4 files changed, 28 insertions(+), 30 deletions(-) diff --git a/@sammo/game_logic/src/General.ts b/@sammo/game_logic/src/General.ts index 3cfd382..20a47fe 100644 --- a/@sammo/game_logic/src/General.ts +++ b/@sammo/game_logic/src/General.ts @@ -23,11 +23,11 @@ export class General extends LazyEntityUpdater { ){ super(); this._raw = raw; - this._city = new WeakRef(must(resourceController.getCity(raw.cityID))); - this._nation = new WeakRef(must(resourceController.getNation(raw.nationID))); + this._city = new WeakRef(must(resourceController.city(raw.cityID))); + this._nation = new WeakRef(must(resourceController.nation(raw.nationID))); if(raw.troopID){ - this._troop = new WeakRef(must(resourceController.getTroop(raw.troopID, raw.nationID))); + this._troop = new WeakRef(must(resourceController.troop(raw.troopID, raw.nationID))); } } @@ -56,7 +56,7 @@ export class General extends LazyEntityUpdater { if(city instanceof City){ return city; } - const cityObj = this.resourceController.getCity(city); + const cityObj = this.resourceController.city(city); if(!cityObj){ throw new InvalidArgument(`City not found: ${city}`); } @@ -96,7 +96,7 @@ export class General extends LazyEntityUpdater { if(troop instanceof Troop){ return troop; } - const troopObj = this.resourceController.getTroop(troop, this._raw.nationID); + const troopObj = this.resourceController.troop(troop, this._raw.nationID); if(!troopObj){ throw new InvalidArgument(`Troop not found: ${troop}`); } @@ -115,7 +115,7 @@ export class General extends LazyEntityUpdater { if(nation instanceof Nation){ return nation; } - const nationObj = this.resourceController.getNation(nation); + const nationObj = this.resourceController.nation(nation); if(!nationObj){ throw new InvalidArgument(`Nation not found: ${nation}`); } diff --git a/@sammo/game_logic/src/LazyEntityUpdater.ts b/@sammo/game_logic/src/LazyEntityUpdater.ts index 44c20db..c6b9734 100644 --- a/@sammo/game_logic/src/LazyEntityUpdater.ts +++ b/@sammo/game_logic/src/LazyEntityUpdater.ts @@ -27,6 +27,6 @@ export abstract class LazyEntityUpdater{ } } } - this.resourceController.setDirty(this); + this.resourceController.reserveUpdate(this); } } \ No newline at end of file diff --git a/@sammo/game_logic/src/ResourceController.ts b/@sammo/game_logic/src/ResourceController.ts index 2f5b5a2..b08f2de 100644 --- a/@sammo/game_logic/src/ResourceController.ts +++ b/@sammo/game_logic/src/ResourceController.ts @@ -12,47 +12,45 @@ import type { INationEntity } from "./Entity/NationEntity.js"; import type { EntityType, ValidEntityType } from "./Entity/index.js"; import type { IReservedTurn } from "./Entity/ReservedTurn.js"; -export interface IResourceController{ - addCity(city: City): boolean; - addNation(nation: Nation): boolean; - addGeneral(general: General): boolean; - - getCity(id: CityID): City | undefined; - getNation(id: NationID): Nation | undefined; - getGeneral(id: GeneralID): General | undefined; +export interface IResourceController { + city(id: CityID): City | undefined; + nation(id: NationID): Nation | undefined; + troop(id: TroopID, nation: NationID): Troop | undefined; + general(id: GeneralID): General | undefined; getGameEnv(): GameEnv; - findAllNations(): Map; - findAllCities(): Map; - findAllGenerals(): Map; + allNations(): Map; + allCities(): Map; + allGenerals(): Map; - findGeneralByTroop(id: TroopID): Map; + generalByTroop(id: TroopID): Map; - findCityByNation(id: NationID): Map; - findGeneralByNation(id: NationID): Map; - findGeneralByCity(id: CityID, nationID?: NationID): Map; + cityByNation(id: NationID): Map; + generalByNation(id: NationID): Map; + generalByCity(id: CityID, nationID?: NationID): Map; - getTroop(id: TroopID, nation: NationID): Troop | undefined; - - setDirty(entity: LazyEntityUpdater): void; + reserveUpdate(entity: LazyEntityUpdater): void; reserveDelete(entity: LazyEntityUpdater): void; //TODO: create* 방식과 구현 방식 비교 - reserveNew(entity: LazyEntityUpdater): void; + reserveInsert(entity: LazyEntityUpdater): void; - //TODO: reserveNew와 구현 방식 비교 + //TODO: reserveInsert와 구현 방식 비교 createGeneral(raw: IGeneralEntity): General; createNation(raw: INationEntity): Nation; createTroop(raw: ITroopEntity): Troop; - _getAllChanges(): Record]>>; + _getAllChanges(): Record< + ValidEntityType, + Map]> + >; //---- DB 접근 --- //예턴은 호출마다 DB에서 조회 getReservedTurn(general: General): Promise; - getNationReservedTurn(general: General): Promise; + nationReservedTurn(general: General): Promise; resetAndFill(): Promise; saveAll(): Promise; diff --git a/@sammo/game_logic/src/Troop.ts b/@sammo/game_logic/src/Troop.ts index 0e85d5b..eaa0571 100644 --- a/@sammo/game_logic/src/Troop.ts +++ b/@sammo/game_logic/src/Troop.ts @@ -19,7 +19,7 @@ export class Troop extends LazyEntityUpdater { super(); this._raw = raw; - const members = resourceController.findGeneralByTroop(raw.id); + const members = resourceController.generalByTroop(raw.id); const leaderID: GeneralID = raw.id as GeneralID; this._leader = new WeakRef(must(members.get(leaderID))); members.delete(leaderID);