From 78bcc95e2e553c38431fe792c3c5e401351a3710 Mon Sep 17 00:00:00 2001 From: Hide_D Date: Fri, 15 Mar 2024 16:13:27 +0000 Subject: [PATCH] refac: rsc -> rc --- @sammo/game_logic/src/ActionRequest/index.ts | 12 +++++------ @sammo/game_logic/src/City.ts | 6 +++--- @sammo/game_logic/src/GameEnv.ts | 2 +- @sammo/game_logic/src/GameLogger.ts | 8 +++---- @sammo/game_logic/src/General.ts | 14 ++++++------- @sammo/game_logic/src/IResourceController.ts | 4 ++-- @sammo/game_logic/src/LazyEntityUpdater.ts | 6 +++--- @sammo/game_logic/src/Nation.ts | 10 ++++----- @sammo/game_logic/src/Squad.ts | 8 +++---- @sammo/server/src/GameEngine.ts | 22 ++++++++++---------- 10 files changed, 46 insertions(+), 46 deletions(-) diff --git a/@sammo/game_logic/src/ActionRequest/index.ts b/@sammo/game_logic/src/ActionRequest/index.ts index cc5e0ea..4287d43 100644 --- a/@sammo/game_logic/src/ActionRequest/index.ts +++ b/@sammo/game_logic/src/ActionRequest/index.ts @@ -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, -}, rsc: IResourceController):void{ +}, rc: IResourceController):void{ throw new NotYetImplemented(); } -type ActionFunc, Res> = (invoker: QueueType, arg: Arg, rsc: IResourceController)=>Res; +type ActionFunc, Res> = (invoker: QueueType, arg: Arg, rc: IResourceController)=>Res; export type ActionPackDef = { [key: string]: ActionFunc } diff --git a/@sammo/game_logic/src/City.ts b/@sammo/game_logic/src/City.ts index f030bf9..7996dfa 100644 --- a/@sammo/game_logic/src/City.ts +++ b/@sammo/game_logic/src/City.ts @@ -15,7 +15,7 @@ export class City extends LazyEntityUpdater{ constructor( raw: ICityEntity, - protected readonly rsc: IResourceController, + protected readonly rc: IResourceController, bootstrapInfo: { general: GeneralID[]; } @@ -27,7 +27,7 @@ export class City extends LazyEntityUpdater{ private _bootstrapInfo?: ConstructorParameters[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{ 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); } } diff --git a/@sammo/game_logic/src/GameEnv.ts b/@sammo/game_logic/src/GameEnv.ts index 413b083..124a2ed 100644 --- a/@sammo/game_logic/src/GameEnv.ts +++ b/@sammo/game_logic/src/GameEnv.ts @@ -11,7 +11,7 @@ export class GameEnv extends LazyEntityUpdater{ constructor( raw: IGameEnvEntity, - protected readonly rsc: IResourceController + protected readonly rc: IResourceController ){ super(); this._raw = raw; diff --git a/@sammo/game_logic/src/GameLogger.ts b/@sammo/game_logic/src/GameLogger.ts index ffedae1..0705bf7 100644 --- a/@sammo/game_logic/src/GameLogger.ts +++ b/@sammo/game_logic/src/GameLogger.ts @@ -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(); } diff --git a/@sammo/game_logic/src/General.ts b/@sammo/game_logic/src/General.ts index b9ca34b..0abdce3 100644 --- a/@sammo/game_logic/src/General.ts +++ b/@sammo/game_logic/src/General.ts @@ -25,20 +25,20 @@ export class General extends LazyEntityUpdater { 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 { 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 { } 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); diff --git a/@sammo/game_logic/src/IResourceController.ts b/@sammo/game_logic/src/IResourceController.ts index 9cb74db..92cf0a8 100644 --- a/@sammo/game_logic/src/IResourceController.ts +++ b/@sammo/game_logic/src/IResourceController.ts @@ -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 = () => { diff --git a/@sammo/game_logic/src/LazyEntityUpdater.ts b/@sammo/game_logic/src/LazyEntityUpdater.ts index 4b6519a..f932726 100644 --- a/@sammo/game_logic/src/LazyEntityUpdater.ts +++ b/@sammo/game_logic/src/LazyEntityUpdater.ts @@ -7,7 +7,7 @@ export abstract class LazyEntityUpdater{ 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{ 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{ throw new Error(`${String(indirectName)} change by update() is not allowed`); } } - this.rsc.reserveUpdate(this); + this.rc.reserveUpdate(this); } } \ No newline at end of file diff --git a/@sammo/game_logic/src/Nation.ts b/@sammo/game_logic/src/Nation.ts index 384ad1b..048b8c6 100644 --- a/@sammo/game_logic/src/Nation.ts +++ b/@sammo/game_logic/src/Nation.ts @@ -41,7 +41,7 @@ export class Nation extends LazyEntityUpdater { 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 { private _bootstrapInfo?: ConstructorParameters[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); } } diff --git a/@sammo/game_logic/src/Squad.ts b/@sammo/game_logic/src/Squad.ts index dcd3aab..a13d209 100644 --- a/@sammo/game_logic/src/Squad.ts +++ b/@sammo/game_logic/src/Squad.ts @@ -14,7 +14,7 @@ export class Squad extends LazyEntityUpdater { constructor( raw: ISquadEntity, - protected rsc: IResourceController, + protected rc: IResourceController, bootstrapInfo: { general: GeneralID[] } @@ -26,13 +26,13 @@ export class Squad extends LazyEntityUpdater { private _bootstrapInfo?: ConstructorParameters[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 { this.leader.nation.notifyDestroySquad(this); - this.rsc.reserveDelete(this); + this.rc.reserveDelete(this); } public changeName(name: string) { diff --git a/@sammo/server/src/GameEngine.ts b/@sammo/server/src/GameEngine.ts index 4d5dcb8..3fe8484 100644 --- a/@sammo/server/src/GameEngine.ts +++ b/@sammo/server/src/GameEngine.ts @@ -44,15 +44,15 @@ export class GameEngine { api: new Denque(), } as const satisfies Record>; - private rsc: ResourceController + private rc: ResourceController private loggerEngine: GameLoggerEngine; private constructor( db: Mongoose, private postStatus: (msg: GameEngineMsg) => void, ) { - this.rsc = new ResourceController(db); - this.loggerEngine = GameLoggerEngine.initInstance(this.rsc); + this.rc = new ResourceController(db); + this.loggerEngine = GameLoggerEngine.initInstance(this.rc); } private continueRun = true; @@ -67,7 +67,7 @@ export class GameEngine { while (true) { //장수턴 부터 처리 - const upcomingGeneral = this.rsc.popGeneralTurnTimeQueue(); + const upcomingGeneral = this.rc.popGeneralTurnTimeQueue(); if (!upcomingGeneral) { break; } @@ -80,8 +80,8 @@ export class GameEngine { //TODO: 턴 수행해야지! upcomingGeneral.updateTurnTime(); - this.rsc.insertGeneralTurnTimeQueue(upcomingGeneral, true); - this.rsc.gameEnv.update((env) => { + this.rc.insertGeneralTurnTimeQueue(upcomingGeneral, true); + this.rc.gameEnv.update((env) => { env.lastExecuted = generalTurnTime; }) processedGeneralCount++; @@ -89,9 +89,9 @@ export class GameEngine { if (processedGeneralCount > 0) { await this.prevSaveWaiter; - const lastExecuted = this.rsc.gameEnv.raw.lastExecuted; + const lastExecuted = this.rc.gameEnv.raw.lastExecuted; this.loggerEngine.flushAll(); - this.prevSaveWaiter = this.rsc.saveAll().then(() => { + this.prevSaveWaiter = this.rc.saveAll().then(() => { this.postStatus({ type: 'update', lastExecuted: lastExecuted.toISOString() @@ -136,7 +136,7 @@ export class GameEngine { await this.prevSaveWaiter; this.prevSaveWaiter = null; this.loggerEngine.flushAll(); - await this.rsc.saveAll(); + await this.rc.saveAll(); for (const response of responseQueue) { response(); } @@ -151,7 +151,7 @@ export class GameEngine { //가장 빠른 장수 do { const now = new Date(); - const upcomingGeneral = this.rsc.peekGeneralTurnTimeQueue(); + const upcomingGeneral = this.rc.peekGeneralTurnTimeQueue(); if (!upcomingGeneral) { break; } @@ -244,7 +244,7 @@ export class GameEngine { const actionArgs = action.args; try{ - const result = ActionRequestList[actionName](invoker, actionArgs as any, this.rsc); + const result = ActionRequestList[actionName](invoker, actionArgs as any, this.rc); return { success: true, value: result