refac: bootstrap arg 정리

This commit is contained in:
2024-03-14 16:58:51 +00:00
parent b4b00e1983
commit 39e8eab6cb
3 changed files with 85 additions and 45 deletions
+43 -20
View File
@@ -19,7 +19,7 @@ import type { IGameEnvEntity } from "@sammo/game_logic/src/Entity/GameEnvEntity.
type ChangeType = "insert" | "update" | "delete";
//TODO: Implement!
export class ResourceController implements IResourceController{
export class ResourceController implements IResourceController {
constructor(
private readonly db: Mongoose
) {
@@ -59,10 +59,10 @@ export class ResourceController implements IResourceController{
squad(id: SquadID, nation: NationID): Squad | undefined {
const squad = this.squadList.get(id);
if(!squad){
if (!squad) {
return undefined;
}
if(squad.raw.nationID !== nation){
if (squad.raw.nationID !== nation) {
return undefined;
}
return squad;
@@ -81,7 +81,7 @@ export class ResourceController implements IResourceController{
}
insertGeneralTurnTimeQueue(general: General, maybeTail: boolean): void {
insertItemAtArrayLike(this._generalByTurnTime, general, (a, b)=>a.compareTurnTime(b), maybeTail);
insertItemAtArrayLike(this._generalByTurnTime, general, (a, b) => a.compareTurnTime(b), maybeTail);
}
allNations(): Map<NationID, Nation> {
@@ -185,44 +185,67 @@ export class ResourceController implements IResourceController{
const rawGeneralList = new Map<GeneralID, IGeneralEntity>();
const rawGeneralListBySquad = new Map<SquadID, GeneralID[]>();
for(const rawSquad of rawSquadList.values()){
rawGeneralListBySquad.set(rawSquad.id, []);
const generalIDByNation = new Map<NationID, GeneralID[]>();
const generalIDListBySquad = new Map<SquadID, GeneralID[]>();
for (const rawSquad of rawSquadList.values()) {
generalIDListBySquad.set(rawSquad.id, []);
}
for(const rawGeneral of rawGeneralList.values()){
if(!rawGeneral.squadID){
for (const rawGeneral of rawGeneralList.values()) {
if (!rawGeneral.squadID) {
continue;
}
const list = must(rawGeneralListBySquad.get(rawGeneral.squadID));
const list = must(generalIDListBySquad.get(rawGeneral.squadID));
list.push(rawGeneral.id);
}
const cityIDByNation = new Map<NationID, CityID[]>();
for (const rawCity of rawCityList.values()) {
const list = must(cityIDByNation.get(rawCity.nationID));
list.push(rawCity.id);
}
const squadIDByNation = new Map<NationID, SquadID[]>();
for (const rawSquad of rawSquadList.values()) {
const list = must(squadIDByNation.get(rawSquad.nationID));
list.push(rawSquad.id);
}
this._gameEnv = new GameEnv(rawGameEnv, this);
this._gameEnv.bootstrap();
for(const rawNation of rawNationList.values()){
const nation = new Nation(rawNation, this);
for (const rawNation of rawNationList.values()) {
const nation = new Nation(
rawNation,
this,
{
general: must(generalIDByNation.get(rawNation.id)),
squad: squadIDByNation.get(rawNation.id) ?? [],
city: cityIDByNation.get(rawNation.id) ?? [],
}
);
this.nationList.set(nation.id, nation);
}
for(const rawCity of rawCityList.values()){
for (const rawCity of rawCityList.values()) {
const city = new City(rawCity, this);
this.cityList.set(city.id, city);
}
for(const rawSquad of rawSquadList.values()){
const squad = new Squad(rawSquad, this, must(rawGeneralListBySquad.get(rawSquad.id)));
for (const rawSquad of rawSquadList.values()) {
const squad = new Squad(rawSquad, this, {
general: generalIDListBySquad.get(rawSquad.id) ?? []
});
this.squadList.set(squad.id, squad);
}
for(const rawGeneral of rawGeneralList.values()){
for (const rawGeneral of rawGeneralList.values()) {
const general = new General(rawGeneral, this);
this.generalList.set(general.id, general);
}
//lazyInit()을 호출한다.
this.nationList.forEach(nation=>nation.bootstrap());
this.cityList.forEach(city=>city.bootstrap());
this.squadList.forEach(squad=>squad.bootstrap());
this.nationList.forEach(nation => nation.bootstrap());
this.cityList.forEach(city => city.bootstrap());
this.squadList.forEach(squad => squad.bootstrap());
//iAction때문에 general의 lazyInit이 가장 마지막
this.generalList.forEach(general=>general.bootstrap());
this.generalList.forEach(general => general.bootstrap());
throw new NotYetImplemented();
}