refac: bootstrap arg 정리
This commit is contained in:
@@ -41,33 +41,42 @@ export class Nation extends LazyEntityUpdater<INationEntity> {
|
|||||||
|
|
||||||
constructor(
|
constructor(
|
||||||
raw: INationEntity,
|
raw: INationEntity,
|
||||||
protected readonly rsc: IResourceController
|
protected readonly rsc: IResourceController,
|
||||||
|
bootstrapInfo: {
|
||||||
|
general: GeneralID[];
|
||||||
|
squad: SquadID[];
|
||||||
|
city: CityID[];
|
||||||
|
},
|
||||||
) {
|
) {
|
||||||
super();
|
super();
|
||||||
this._raw = raw;
|
this._raw = raw;
|
||||||
|
this._bootstrapInfo = bootstrapInfo;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private _bootstrapInfo?: ConstructorParameters<typeof Nation>[2];
|
||||||
bootstrap() {
|
bootstrap() {
|
||||||
const rsc = this.rsc;
|
const rsc = this.rsc;
|
||||||
const raw = this._raw;
|
|
||||||
|
|
||||||
//raw값만 읽을것
|
const bootstrapInfo = must(this._bootstrapInfo);
|
||||||
for (const city of rsc.cityList.values()) {
|
delete this._bootstrapInfo;
|
||||||
if (city.raw.nationID !== raw.id) {
|
|
||||||
continue;
|
const nationID = this._raw.id;
|
||||||
}
|
|
||||||
|
const bootstrapCityID = bootstrapInfo.city;
|
||||||
|
for (const city of bootstrapCityID.map((id) => must(rsc.cityList.get(id)))) {
|
||||||
this.cityList.set(city.id, new WeakRef(city));
|
this.cityList.set(city.id, new WeakRef(city));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const bootstrapSquadID = bootstrapInfo.squad;
|
||||||
for (const squad of rsc.squadList.values()) {
|
for (const squad of rsc.squadList.values()) {
|
||||||
if (squad.raw.nationID !== raw.id) {
|
if (squad.raw.nationID !== nationID) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
this.squadList.set(squad.id, new WeakRef(squad));
|
this.squadList.set(squad.id, new WeakRef(squad));
|
||||||
}
|
}
|
||||||
for (const general of rsc.generalList.values()) {
|
|
||||||
if (general.raw.nationID !== raw.id) {
|
const bootstrapGeneralID = bootstrapInfo.general;
|
||||||
continue;
|
for (const general of bootstrapGeneralID.map((id) => must(rsc.generalList.get(id)))) {
|
||||||
}
|
|
||||||
this.generalList.set(general.id, new WeakRef(general));
|
this.generalList.set(general.id, new WeakRef(general));
|
||||||
|
|
||||||
if (general.isUser) {
|
if (general.isUser) {
|
||||||
@@ -93,7 +102,6 @@ export class Nation extends LazyEntityUpdater<INationEntity> {
|
|||||||
this.staffList.set(staffLevel, new WeakRef(general));
|
this.staffList.set(staffLevel, new WeakRef(general));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public get id(): NationID {
|
public get id(): NationID {
|
||||||
|
|||||||
@@ -15,15 +15,24 @@ export class Squad extends LazyEntityUpdater<ISquadEntity> {
|
|||||||
constructor(
|
constructor(
|
||||||
raw: ISquadEntity,
|
raw: ISquadEntity,
|
||||||
protected rsc: IResourceController,
|
protected rsc: IResourceController,
|
||||||
private _rawMembers: GeneralID[]
|
bootstrapInfo: {
|
||||||
){
|
general: GeneralID[]
|
||||||
|
}
|
||||||
|
) {
|
||||||
super();
|
super();
|
||||||
this._raw = raw;
|
this._raw = raw;
|
||||||
|
this._bootstrapInfo = bootstrapInfo;
|
||||||
}
|
}
|
||||||
|
|
||||||
public bootstrap(){
|
private _bootstrapInfo?: ConstructorParameters<typeof Squad>[2];
|
||||||
this._members = new Map(this._rawMembers.map((id)=>{
|
public bootstrap() {
|
||||||
return [id, new WeakRef(must(this.rsc.general(id)))];
|
const rsc = this.rsc;
|
||||||
|
|
||||||
|
const bootstrapInfo = must(this._bootstrapInfo);
|
||||||
|
delete this._bootstrapInfo;
|
||||||
|
|
||||||
|
this._members = new Map(bootstrapInfo.general.map((id) => {
|
||||||
|
return [id, new WeakRef(must(rsc.general(id)))];
|
||||||
}));
|
}));
|
||||||
|
|
||||||
const leaderID = this._raw.id as GeneralID;
|
const leaderID = this._raw.id as GeneralID;
|
||||||
@@ -32,11 +41,11 @@ export class Squad extends LazyEntityUpdater<ISquadEntity> {
|
|||||||
this._members.delete(leaderID);
|
this._members.delete(leaderID);
|
||||||
}
|
}
|
||||||
|
|
||||||
public get id(){
|
public get id() {
|
||||||
return this._raw.id;
|
return this._raw.id;
|
||||||
}
|
}
|
||||||
|
|
||||||
public get leader(){
|
public get leader() {
|
||||||
return must(this._leader.deref());
|
return must(this._leader.deref());
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -44,12 +53,12 @@ export class Squad extends LazyEntityUpdater<ISquadEntity> {
|
|||||||
return this._members;
|
return this._members;
|
||||||
}
|
}
|
||||||
|
|
||||||
public destroySquad(withLeader = true){
|
public destroySquad(withLeader = true) {
|
||||||
this._members.forEach((member)=>{
|
this._members.forEach((member) => {
|
||||||
const general = must(member.deref());
|
const general = must(member.deref());
|
||||||
general.quitSquad();
|
general.quitSquad();
|
||||||
});
|
});
|
||||||
if(withLeader){
|
if (withLeader) {
|
||||||
this.leader.quitSquad();
|
this.leader.quitSquad();
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -58,8 +67,8 @@ export class Squad extends LazyEntityUpdater<ISquadEntity> {
|
|||||||
this.rsc.reserveDelete(this);
|
this.rsc.reserveDelete(this);
|
||||||
}
|
}
|
||||||
|
|
||||||
public changeName(name: string){
|
public changeName(name: string) {
|
||||||
this.update((raw)=>{
|
this.update((raw) => {
|
||||||
raw.name = name;
|
raw.name = name;
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -19,7 +19,7 @@ import type { IGameEnvEntity } from "@sammo/game_logic/src/Entity/GameEnvEntity.
|
|||||||
type ChangeType = "insert" | "update" | "delete";
|
type ChangeType = "insert" | "update" | "delete";
|
||||||
|
|
||||||
//TODO: Implement!
|
//TODO: Implement!
|
||||||
export class ResourceController implements IResourceController{
|
export class ResourceController implements IResourceController {
|
||||||
constructor(
|
constructor(
|
||||||
private readonly db: Mongoose
|
private readonly db: Mongoose
|
||||||
) {
|
) {
|
||||||
@@ -59,10 +59,10 @@ export class ResourceController implements IResourceController{
|
|||||||
|
|
||||||
squad(id: SquadID, nation: NationID): Squad | undefined {
|
squad(id: SquadID, nation: NationID): Squad | undefined {
|
||||||
const squad = this.squadList.get(id);
|
const squad = this.squadList.get(id);
|
||||||
if(!squad){
|
if (!squad) {
|
||||||
return undefined;
|
return undefined;
|
||||||
}
|
}
|
||||||
if(squad.raw.nationID !== nation){
|
if (squad.raw.nationID !== nation) {
|
||||||
return undefined;
|
return undefined;
|
||||||
}
|
}
|
||||||
return squad;
|
return squad;
|
||||||
@@ -81,7 +81,7 @@ export class ResourceController implements IResourceController{
|
|||||||
}
|
}
|
||||||
|
|
||||||
insertGeneralTurnTimeQueue(general: General, maybeTail: boolean): void {
|
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> {
|
allNations(): Map<NationID, Nation> {
|
||||||
@@ -185,44 +185,67 @@ export class ResourceController implements IResourceController{
|
|||||||
const rawGeneralList = new Map<GeneralID, IGeneralEntity>();
|
const rawGeneralList = new Map<GeneralID, IGeneralEntity>();
|
||||||
|
|
||||||
|
|
||||||
const rawGeneralListBySquad = new Map<SquadID, GeneralID[]>();
|
const generalIDByNation = new Map<NationID, GeneralID[]>();
|
||||||
for(const rawSquad of rawSquadList.values()){
|
const generalIDListBySquad = new Map<SquadID, GeneralID[]>();
|
||||||
rawGeneralListBySquad.set(rawSquad.id, []);
|
for (const rawSquad of rawSquadList.values()) {
|
||||||
|
generalIDListBySquad.set(rawSquad.id, []);
|
||||||
}
|
}
|
||||||
for(const rawGeneral of rawGeneralList.values()){
|
for (const rawGeneral of rawGeneralList.values()) {
|
||||||
if(!rawGeneral.squadID){
|
if (!rawGeneral.squadID) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
const list = must(rawGeneralListBySquad.get(rawGeneral.squadID));
|
const list = must(generalIDListBySquad.get(rawGeneral.squadID));
|
||||||
list.push(rawGeneral.id);
|
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 = new GameEnv(rawGameEnv, this);
|
||||||
this._gameEnv.bootstrap();
|
this._gameEnv.bootstrap();
|
||||||
|
|
||||||
for(const rawNation of rawNationList.values()){
|
for (const rawNation of rawNationList.values()) {
|
||||||
const nation = new Nation(rawNation, this);
|
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);
|
this.nationList.set(nation.id, nation);
|
||||||
}
|
}
|
||||||
for(const rawCity of rawCityList.values()){
|
for (const rawCity of rawCityList.values()) {
|
||||||
const city = new City(rawCity, this);
|
const city = new City(rawCity, this);
|
||||||
this.cityList.set(city.id, city);
|
this.cityList.set(city.id, city);
|
||||||
}
|
}
|
||||||
for(const rawSquad of rawSquadList.values()){
|
for (const rawSquad of rawSquadList.values()) {
|
||||||
const squad = new Squad(rawSquad, this, must(rawGeneralListBySquad.get(rawSquad.id)));
|
const squad = new Squad(rawSquad, this, {
|
||||||
|
general: generalIDListBySquad.get(rawSquad.id) ?? []
|
||||||
|
});
|
||||||
this.squadList.set(squad.id, squad);
|
this.squadList.set(squad.id, squad);
|
||||||
}
|
}
|
||||||
for(const rawGeneral of rawGeneralList.values()){
|
for (const rawGeneral of rawGeneralList.values()) {
|
||||||
const general = new General(rawGeneral, this);
|
const general = new General(rawGeneral, this);
|
||||||
this.generalList.set(general.id, general);
|
this.generalList.set(general.id, general);
|
||||||
}
|
}
|
||||||
|
|
||||||
//lazyInit()을 호출한다.
|
//lazyInit()을 호출한다.
|
||||||
this.nationList.forEach(nation=>nation.bootstrap());
|
this.nationList.forEach(nation => nation.bootstrap());
|
||||||
this.cityList.forEach(city=>city.bootstrap());
|
this.cityList.forEach(city => city.bootstrap());
|
||||||
this.squadList.forEach(squad=>squad.bootstrap());
|
this.squadList.forEach(squad => squad.bootstrap());
|
||||||
//iAction때문에 general의 lazyInit이 가장 마지막
|
//iAction때문에 general의 lazyInit이 가장 마지막
|
||||||
this.generalList.forEach(general=>general.bootstrap());
|
this.generalList.forEach(general => general.bootstrap());
|
||||||
|
|
||||||
throw new NotYetImplemented();
|
throw new NotYetImplemented();
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user