refac: RSC
This commit is contained in:
@@ -23,11 +23,11 @@ export class General extends LazyEntityUpdater<IGeneralEntity> {
|
||||
){
|
||||
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<IGeneralEntity> {
|
||||
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<IGeneralEntity> {
|
||||
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<IGeneralEntity> {
|
||||
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}`);
|
||||
}
|
||||
|
||||
@@ -27,6 +27,6 @@ export abstract class LazyEntityUpdater<Entity extends ValidEntity>{
|
||||
}
|
||||
}
|
||||
}
|
||||
this.resourceController.setDirty(this);
|
||||
this.resourceController.reserveUpdate(this);
|
||||
}
|
||||
}
|
||||
@@ -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<NationID, Nation>;
|
||||
findAllCities(): Map<CityID, City>;
|
||||
findAllGenerals(): Map<GeneralID, General>;
|
||||
allNations(): Map<NationID, Nation>;
|
||||
allCities(): Map<CityID, City>;
|
||||
allGenerals(): Map<GeneralID, General>;
|
||||
|
||||
findGeneralByTroop(id: TroopID): Map<GeneralID, General>;
|
||||
generalByTroop(id: TroopID): Map<GeneralID, General>;
|
||||
|
||||
findCityByNation(id: NationID): Map<CityID, City>;
|
||||
findGeneralByNation(id: NationID): Map<GeneralID, General>;
|
||||
findGeneralByCity(id: CityID, nationID?: NationID): Map<GeneralID, General>;
|
||||
cityByNation(id: NationID): Map<CityID, City>;
|
||||
generalByNation(id: NationID): Map<GeneralID, General>;
|
||||
generalByCity(id: CityID, nationID?: NationID): Map<GeneralID, General>;
|
||||
|
||||
getTroop(id: TroopID, nation: NationID): Troop | undefined;
|
||||
|
||||
setDirty(entity: LazyEntityUpdater<any>): void;
|
||||
reserveUpdate(entity: LazyEntityUpdater<any>): void;
|
||||
reserveDelete(entity: LazyEntityUpdater<any>): void;
|
||||
|
||||
//TODO: create* 방식과 구현 방식 비교
|
||||
reserveNew(entity: LazyEntityUpdater<any>): void;
|
||||
reserveInsert(entity: LazyEntityUpdater<any>): void;
|
||||
|
||||
//TODO: reserveNew와 구현 방식 비교
|
||||
//TODO: reserveInsert와 구현 방식 비교
|
||||
createGeneral(raw: IGeneralEntity): General;
|
||||
createNation(raw: INationEntity): Nation;
|
||||
createTroop(raw: ITroopEntity): Troop;
|
||||
|
||||
_getAllChanges(): Record<ValidEntityType, Map<number, ['new'|'update'|'delete', LazyEntityUpdater<any>]>>;
|
||||
_getAllChanges(): Record<
|
||||
ValidEntityType,
|
||||
Map<number, [op: 'insert' | 'update' | 'delete', value: LazyEntityUpdater<any>]>
|
||||
>;
|
||||
|
||||
//---- DB 접근 ---
|
||||
|
||||
//예턴은 호출마다 DB에서 조회
|
||||
getReservedTurn(general: General): Promise<IReservedTurn>;
|
||||
getNationReservedTurn(general: General): Promise<IReservedTurn | undefined>;
|
||||
nationReservedTurn(general: General): Promise<IReservedTurn | undefined>;
|
||||
|
||||
resetAndFill(): Promise<void>;
|
||||
saveAll(): Promise<void>;
|
||||
|
||||
@@ -19,7 +19,7 @@ export class Troop extends LazyEntityUpdater<ITroopEntity> {
|
||||
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);
|
||||
|
||||
Reference in New Issue
Block a user