refac: bootstrap arg 정리
This commit is contained in:
@@ -41,33 +41,42 @@ export class Nation extends LazyEntityUpdater<INationEntity> {
|
||||
|
||||
constructor(
|
||||
raw: INationEntity,
|
||||
protected readonly rsc: IResourceController
|
||||
protected readonly rsc: IResourceController,
|
||||
bootstrapInfo: {
|
||||
general: GeneralID[];
|
||||
squad: SquadID[];
|
||||
city: CityID[];
|
||||
},
|
||||
) {
|
||||
super();
|
||||
this._raw = raw;
|
||||
this._bootstrapInfo = bootstrapInfo;
|
||||
}
|
||||
|
||||
private _bootstrapInfo?: ConstructorParameters<typeof Nation>[2];
|
||||
bootstrap() {
|
||||
const rsc = this.rsc;
|
||||
const raw = this._raw;
|
||||
|
||||
//raw값만 읽을것
|
||||
for (const city of rsc.cityList.values()) {
|
||||
if (city.raw.nationID !== raw.id) {
|
||||
continue;
|
||||
}
|
||||
const bootstrapInfo = must(this._bootstrapInfo);
|
||||
delete this._bootstrapInfo;
|
||||
|
||||
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));
|
||||
}
|
||||
|
||||
const bootstrapSquadID = bootstrapInfo.squad;
|
||||
for (const squad of rsc.squadList.values()) {
|
||||
if (squad.raw.nationID !== raw.id) {
|
||||
if (squad.raw.nationID !== nationID) {
|
||||
continue;
|
||||
}
|
||||
this.squadList.set(squad.id, new WeakRef(squad));
|
||||
}
|
||||
for (const general of rsc.generalList.values()) {
|
||||
if (general.raw.nationID !== raw.id) {
|
||||
continue;
|
||||
}
|
||||
|
||||
const bootstrapGeneralID = bootstrapInfo.general;
|
||||
for (const general of bootstrapGeneralID.map((id) => must(rsc.generalList.get(id)))) {
|
||||
this.generalList.set(general.id, new WeakRef(general));
|
||||
|
||||
if (general.isUser) {
|
||||
@@ -93,7 +102,6 @@ export class Nation extends LazyEntityUpdater<INationEntity> {
|
||||
this.staffList.set(staffLevel, new WeakRef(general));
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public get id(): NationID {
|
||||
|
||||
@@ -15,15 +15,24 @@ export class Squad extends LazyEntityUpdater<ISquadEntity> {
|
||||
constructor(
|
||||
raw: ISquadEntity,
|
||||
protected rsc: IResourceController,
|
||||
private _rawMembers: GeneralID[]
|
||||
){
|
||||
bootstrapInfo: {
|
||||
general: GeneralID[]
|
||||
}
|
||||
) {
|
||||
super();
|
||||
this._raw = raw;
|
||||
this._bootstrapInfo = bootstrapInfo;
|
||||
}
|
||||
|
||||
public bootstrap(){
|
||||
this._members = new Map(this._rawMembers.map((id)=>{
|
||||
return [id, new WeakRef(must(this.rsc.general(id)))];
|
||||
private _bootstrapInfo?: ConstructorParameters<typeof Squad>[2];
|
||||
public bootstrap() {
|
||||
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;
|
||||
@@ -32,11 +41,11 @@ export class Squad extends LazyEntityUpdater<ISquadEntity> {
|
||||
this._members.delete(leaderID);
|
||||
}
|
||||
|
||||
public get id(){
|
||||
public get id() {
|
||||
return this._raw.id;
|
||||
}
|
||||
|
||||
public get leader(){
|
||||
public get leader() {
|
||||
return must(this._leader.deref());
|
||||
}
|
||||
|
||||
@@ -44,12 +53,12 @@ export class Squad extends LazyEntityUpdater<ISquadEntity> {
|
||||
return this._members;
|
||||
}
|
||||
|
||||
public destroySquad(withLeader = true){
|
||||
this._members.forEach((member)=>{
|
||||
public destroySquad(withLeader = true) {
|
||||
this._members.forEach((member) => {
|
||||
const general = must(member.deref());
|
||||
general.quitSquad();
|
||||
});
|
||||
if(withLeader){
|
||||
if (withLeader) {
|
||||
this.leader.quitSquad();
|
||||
}
|
||||
|
||||
@@ -58,8 +67,8 @@ export class Squad extends LazyEntityUpdater<ISquadEntity> {
|
||||
this.rsc.reserveDelete(this);
|
||||
}
|
||||
|
||||
public changeName(name: string){
|
||||
this.update((raw)=>{
|
||||
public changeName(name: string) {
|
||||
this.update((raw) => {
|
||||
raw.name = name;
|
||||
});
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user