refac: boostrap

This commit is contained in:
2024-03-14 17:24:14 +00:00
parent 39e8eab6cb
commit 6a6bdba08b
5 changed files with 156 additions and 111 deletions
+26 -48
View File
@@ -1,4 +1,4 @@
import { InvalidArgument } from "@sammo/util";
import { InvalidArgument, NotYetImplemented } from "@sammo/util";
import { City } from "./City.js";
import type { IGeneralEntity } from "./Entity/GeneralEntity.js";
import type { IResourceController } from "./IResourceController.js";
@@ -41,7 +41,7 @@ export class General extends LazyEntityUpdater<IGeneralEntity> {
this._squad = new WeakRef(must(rsc.squad(raw.squadID, raw.nationID)));
}
//TODO: iActionHandlers 초기화
this.reconfigureIActionHandlers();
}
public get id(): GeneralID {
@@ -86,23 +86,16 @@ export class General extends LazyEntityUpdater<IGeneralEntity> {
return this._raw.officerLevel as number as CityOfficerLevel;
}
public changeCity(city: CityID | City){
const cityObj: City = (()=>{
if(city instanceof City){
return city;
}
const cityObj = this.rsc.city(city);
if(!cityObj){
throw new InvalidArgument(`City not found: ${city}`);
}
return cityObj;
})();
this._city = new WeakRef(cityObj);
public changeCity(city: City){
this.city.notifyQuitGeneral(this);
//TODO: ResourceController에게 알려야 하는가?
this._city = new WeakRef(city);
this.forceUpdate((raw) => {
raw.cityID = cityObj.id;
raw.cityID = city.id;
});
city.notifyJoinGeneral(this);
this.reconfigureIActionHandlers();
}
public quitSquad(){
@@ -115,7 +108,7 @@ export class General extends LazyEntityUpdater<IGeneralEntity> {
squad.destroySquad(false);
}
else{
squad.members.delete(this._raw.id);
squad.notifyQuitGeneral(this);
}
this._squad = undefined;
@@ -124,45 +117,25 @@ export class General extends LazyEntityUpdater<IGeneralEntity> {
});
}
public changeSquad(squad: SquadID | Squad){
public changeSquad(squad: Squad){
this.quitSquad();
const squadObj: Squad = (()=>{
if(squad instanceof Squad){
return squad;
}
const squadObj = this.rsc.squad(squad, this._raw.nationID);
if(!squadObj){
throw new InvalidArgument(`Squad not found: ${squad}`);
}
return squadObj;
})();
squadObj.members.set(this._raw.id, new WeakRef(this));
this._squad = new WeakRef(squadObj);
this._squad = new WeakRef(squad);
this.forceUpdate((raw) => {
raw.squadID = squadObj.id;
raw.squadID = squad.id;
});
squad.notifyJoinGeneral(this);
}
public changeNation(nation: NationID | Nation){
const nationObj: Nation = (()=>{
if(nation instanceof Nation){
return nation;
}
const nationObj = this.rsc.nation(nation);
if(!nationObj){
throw new InvalidArgument(`Nation not found: ${nation}`);
}
return nationObj;
})();
this._nation = new WeakRef(nationObj);
public changeNation(nation: Nation){
this.quitSquad();
this.nation.notifyQuitGeneral(this);
this._nation = new WeakRef(nation);
this.forceUpdate((raw) => {
raw.nationID = nationObj.id;
raw.nationID = nation.id;
raw.diplomaticPermission = DiplomaticPermission.none;
if(nationObj.id == 0){
if(nation.id == 0){
raw.officerLevel = OfficerLevel.none;
}
else{
@@ -170,6 +143,13 @@ export class General extends LazyEntityUpdater<IGeneralEntity> {
}
raw.nationJoinedYearMonth = this.rsc.gameEnv.raw.yearMonth;
});
nation.notifyJoinGeneral(this);
this.reconfigureIActionHandlers();
}
private reconfigureIActionHandlers(){
throw new NotYetImplemented();
}
public updateTurnTime(){
@@ -178,7 +158,6 @@ export class General extends LazyEntityUpdater<IGeneralEntity> {
this.forceUpdate((raw) => {
raw.turnTime = addSeconds(raw.turnTime, secondsPerTurn);
});
}
public compareTurnTime(other: General): number {
@@ -197,5 +176,4 @@ export class General extends LazyEntityUpdater<IGeneralEntity> {
}
return 0;
}
}