refac: rsc -> rc
This commit is contained in:
@@ -6,20 +6,20 @@ import { NotYetImplemented } from "@sammo/util";
|
||||
export type QueueType = 'server' | 'api';
|
||||
//type QueueType = 'server' | 'npc' | 'api';
|
||||
|
||||
export function setDefenceTrained(invoker: QueueType, arg: { generalID: GeneralID, defenceTrained: number }, rsc: IResourceController): void{
|
||||
export function setDefenceTrained(invoker: QueueType, arg: { generalID: GeneralID, defenceTrained: number }, rc: IResourceController): void{
|
||||
throw new NotYetImplemented();
|
||||
}
|
||||
|
||||
export function kickSquadMember(invoker: QueueType, arg: { nationID: NationID, squadID: SquadID, memberID: GeneralID }, rsc: IResourceController): void {
|
||||
export function kickSquadMember(invoker: QueueType, arg: { nationID: NationID, squadID: SquadID, memberID: GeneralID }, rc: IResourceController): void {
|
||||
throw new NotYetImplemented();
|
||||
}
|
||||
|
||||
|
||||
export function blockAttackCommand(invoker: QueueType, arg: { nationID: NationID, block: boolean }, rsc: IResourceController): void {
|
||||
export function blockAttackCommand(invoker: QueueType, arg: { nationID: NationID, block: boolean }, rc: IResourceController): void {
|
||||
throw new NotYetImplemented();
|
||||
}
|
||||
|
||||
export function blockJoinNation(invoker: QueueType, arg: { nationID: NationID, block: boolean }, rsc: IResourceController): void {
|
||||
export function blockJoinNation(invoker: QueueType, arg: { nationID: NationID, block: boolean }, rc: IResourceController): void {
|
||||
throw new NotYetImplemented();
|
||||
}
|
||||
|
||||
@@ -40,11 +40,11 @@ export function createGeneral(invoker: QueueType, arg: {
|
||||
bonusStat?: [number, number, number],
|
||||
|
||||
//penalty: Record<GeneralPenalty, number>,
|
||||
}, rsc: IResourceController):void{
|
||||
}, rc: IResourceController):void{
|
||||
throw new NotYetImplemented();
|
||||
}
|
||||
|
||||
type ActionFunc<Arg extends Record<string, any>, Res> = (invoker: QueueType, arg: Arg, rsc: IResourceController)=>Res;
|
||||
type ActionFunc<Arg extends Record<string, any>, Res> = (invoker: QueueType, arg: Arg, rc: IResourceController)=>Res;
|
||||
export type ActionPackDef = {
|
||||
[key: string]: ActionFunc<any, any>
|
||||
}
|
||||
|
||||
@@ -15,7 +15,7 @@ export class City extends LazyEntityUpdater<ICityEntity>{
|
||||
|
||||
constructor(
|
||||
raw: ICityEntity,
|
||||
protected readonly rsc: IResourceController,
|
||||
protected readonly rc: IResourceController,
|
||||
bootstrapInfo: {
|
||||
general: GeneralID[];
|
||||
}
|
||||
@@ -27,7 +27,7 @@ export class City extends LazyEntityUpdater<ICityEntity>{
|
||||
|
||||
private _bootstrapInfo?: ConstructorParameters<typeof City>[2];
|
||||
public bootstrap(){
|
||||
const rsc = this.rsc;
|
||||
const rc = this.rc;
|
||||
|
||||
const bootstrapInfo = must(this._bootstrapInfo);
|
||||
delete this._bootstrapInfo;
|
||||
@@ -35,7 +35,7 @@ export class City extends LazyEntityUpdater<ICityEntity>{
|
||||
const nationID = this._raw.nationID;
|
||||
|
||||
for(const id of bootstrapInfo.general){
|
||||
const general = must(rsc.general(id));
|
||||
const general = must(rc.general(id));
|
||||
this.notifyJoinGeneral(general);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -11,7 +11,7 @@ export class GameEnv extends LazyEntityUpdater<IGameEnvEntity>{
|
||||
|
||||
constructor(
|
||||
raw: IGameEnvEntity,
|
||||
protected readonly rsc: IResourceController
|
||||
protected readonly rc: IResourceController
|
||||
){
|
||||
super();
|
||||
this._raw = raw;
|
||||
|
||||
@@ -25,15 +25,15 @@ export class GameLoggerEngine {
|
||||
private static instance: GameLoggerEngine;
|
||||
|
||||
private constructor(
|
||||
private rsc: IResourceController
|
||||
private rc: IResourceController
|
||||
) {
|
||||
}
|
||||
|
||||
public static initInstance(rsc: IResourceController): GameLoggerEngine{
|
||||
public static initInstance(rc: IResourceController): GameLoggerEngine{
|
||||
if(GameLoggerEngine.instance){
|
||||
throw new Error("GameLogger is already initialized");
|
||||
}
|
||||
GameLoggerEngine.instance = new GameLoggerEngine(rsc);
|
||||
GameLoggerEngine.instance = new GameLoggerEngine(rc);
|
||||
return GameLoggerEngine.instance;
|
||||
}
|
||||
|
||||
@@ -68,7 +68,7 @@ export class GameLoggerEngine {
|
||||
if(this.logStack.size === 0){
|
||||
return;
|
||||
}
|
||||
//rsc?
|
||||
//rc?
|
||||
throw new Error("Not yet implemented");
|
||||
this.logStack.clear();
|
||||
}
|
||||
|
||||
@@ -25,20 +25,20 @@ export class General extends LazyEntityUpdater<IGeneralEntity> {
|
||||
|
||||
constructor(
|
||||
raw: IGeneralEntity,
|
||||
protected readonly rsc: IResourceController
|
||||
protected readonly rc: IResourceController
|
||||
){
|
||||
super();
|
||||
this._raw = raw;
|
||||
}
|
||||
|
||||
public bootstrap(){
|
||||
const rsc = this.rsc;
|
||||
const rc = this.rc;
|
||||
const raw = this._raw;
|
||||
this._city = new WeakRef(must(rsc.city(raw.cityID)));
|
||||
this._nation = new WeakRef(must(rsc.nation(raw.nationID)));
|
||||
this._city = new WeakRef(must(rc.city(raw.cityID)));
|
||||
this._nation = new WeakRef(must(rc.nation(raw.nationID)));
|
||||
|
||||
if(raw.squadID){
|
||||
this._squad = new WeakRef(must(rsc.squad(raw.squadID, raw.nationID)));
|
||||
this._squad = new WeakRef(must(rc.squad(raw.squadID, raw.nationID)));
|
||||
}
|
||||
|
||||
this.reconfigureIActionHandlers();
|
||||
@@ -141,7 +141,7 @@ export class General extends LazyEntityUpdater<IGeneralEntity> {
|
||||
else{
|
||||
raw.officerLevel = OfficerLevel.normal;
|
||||
}
|
||||
raw.nationJoinedYearMonth = this.rsc.gameEnv.raw.yearMonth;
|
||||
raw.nationJoinedYearMonth = this.rc.gameEnv.raw.yearMonth;
|
||||
});
|
||||
nation.notifyJoinGeneral(this);
|
||||
|
||||
@@ -153,7 +153,7 @@ export class General extends LazyEntityUpdater<IGeneralEntity> {
|
||||
}
|
||||
|
||||
public updateTurnTime(){
|
||||
const secondsPerTurn = this.rsc.gameEnv.raw.secondsPerTurn;
|
||||
const secondsPerTurn = this.rc.gameEnv.raw.secondsPerTurn;
|
||||
|
||||
this.forceUpdate((raw) => {
|
||||
raw.turnTime = addSeconds(raw.turnTime, secondsPerTurn);
|
||||
|
||||
@@ -60,8 +60,8 @@ export interface IResourceController {
|
||||
|
||||
let _resourceController: IResourceController | undefined = undefined;
|
||||
|
||||
export const setResourceController = (rsc: IResourceController) => {
|
||||
_resourceController = rsc;
|
||||
export const setResourceController = (rc: IResourceController) => {
|
||||
_resourceController = rc;
|
||||
}
|
||||
|
||||
export const getResourceController = () => {
|
||||
|
||||
@@ -7,7 +7,7 @@ export abstract class LazyEntityUpdater<Entity extends ValidEntity>{
|
||||
|
||||
protected abstract readonly _raw: Entity;
|
||||
|
||||
protected abstract readonly rsc: IResourceController;
|
||||
protected abstract readonly rc: IResourceController;
|
||||
|
||||
public abstract bootstrap(): void;
|
||||
|
||||
@@ -21,7 +21,7 @@ export abstract class LazyEntityUpdater<Entity extends ValidEntity>{
|
||||
|
||||
protected forceUpdate(callback: (raw: Entity) => void) {
|
||||
callback(this._raw);
|
||||
this.rsc.reserveUpdate(this);
|
||||
this.rc.reserveUpdate(this);
|
||||
}
|
||||
|
||||
public update(callback: (raw: Entity) => void) {
|
||||
@@ -34,6 +34,6 @@ export abstract class LazyEntityUpdater<Entity extends ValidEntity>{
|
||||
throw new Error(`${String(indirectName)} change by update() is not allowed`);
|
||||
}
|
||||
}
|
||||
this.rsc.reserveUpdate(this);
|
||||
this.rc.reserveUpdate(this);
|
||||
}
|
||||
}
|
||||
@@ -41,7 +41,7 @@ export class Nation extends LazyEntityUpdater<INationEntity> {
|
||||
|
||||
constructor(
|
||||
raw: INationEntity,
|
||||
protected readonly rsc: IResourceController,
|
||||
protected readonly rc: IResourceController,
|
||||
bootstrapInfo: {
|
||||
general: GeneralID[];
|
||||
squad: SquadID[];
|
||||
@@ -55,23 +55,23 @@ export class Nation extends LazyEntityUpdater<INationEntity> {
|
||||
|
||||
private _bootstrapInfo?: ConstructorParameters<typeof Nation>[2];
|
||||
bootstrap() {
|
||||
const rsc = this.rsc;
|
||||
const rc = this.rc;
|
||||
|
||||
const bootstrapInfo = must(this._bootstrapInfo);
|
||||
delete this._bootstrapInfo;
|
||||
|
||||
const bootstrapCityID = bootstrapInfo.city;
|
||||
for (const city of bootstrapCityID.map((id) => must(rsc.cityList.get(id)))) {
|
||||
for (const city of bootstrapCityID.map((id) => must(rc.cityList.get(id)))) {
|
||||
this.notifyJoinCity(city);
|
||||
}
|
||||
|
||||
const bootstrapSquadID = bootstrapInfo.squad;
|
||||
for(const squad of bootstrapSquadID.map((id) => must(rsc.squadList.get(id)))){
|
||||
for(const squad of bootstrapSquadID.map((id) => must(rc.squadList.get(id)))){
|
||||
this.notifyAddSquad(squad);
|
||||
}
|
||||
|
||||
const bootstrapGeneralID = bootstrapInfo.general;
|
||||
for (const general of bootstrapGeneralID.map((id) => must(rsc.generalList.get(id)))) {
|
||||
for (const general of bootstrapGeneralID.map((id) => must(rc.generalList.get(id)))) {
|
||||
this.notifyJoinGeneral(general);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -14,7 +14,7 @@ export class Squad extends LazyEntityUpdater<ISquadEntity> {
|
||||
|
||||
constructor(
|
||||
raw: ISquadEntity,
|
||||
protected rsc: IResourceController,
|
||||
protected rc: IResourceController,
|
||||
bootstrapInfo: {
|
||||
general: GeneralID[]
|
||||
}
|
||||
@@ -26,13 +26,13 @@ export class Squad extends LazyEntityUpdater<ISquadEntity> {
|
||||
|
||||
private _bootstrapInfo?: ConstructorParameters<typeof Squad>[2];
|
||||
public bootstrap() {
|
||||
const rsc = this.rsc;
|
||||
const rc = this.rc;
|
||||
|
||||
const bootstrapInfo = must(this._bootstrapInfo);
|
||||
delete this._bootstrapInfo;
|
||||
|
||||
this._members = new Map(bootstrapInfo.general.map((id) => {
|
||||
return [id, new WeakRef(must(rsc.general(id)))];
|
||||
return [id, new WeakRef(must(rc.general(id)))];
|
||||
}));
|
||||
|
||||
const leaderID = this._raw.id as GeneralID;
|
||||
@@ -64,7 +64,7 @@ export class Squad extends LazyEntityUpdater<ISquadEntity> {
|
||||
|
||||
this.leader.nation.notifyDestroySquad(this);
|
||||
|
||||
this.rsc.reserveDelete(this);
|
||||
this.rc.reserveDelete(this);
|
||||
}
|
||||
|
||||
public changeName(name: string) {
|
||||
|
||||
Reference in New Issue
Block a user