LoggerEngine을 이어붙이기

This commit is contained in:
2024-03-12 16:57:02 +00:00
parent cdfaac773a
commit 533400b1b9
3 changed files with 15 additions and 2 deletions
+9 -1
View File
@@ -29,8 +29,12 @@ export class GameLoggerEngine {
) {
}
public static initInstance(rsc: IResourceController) {
public static initInstance(rsc: IResourceController): GameLoggerEngine{
if(GameLoggerEngine.instance){
throw new Error("GameLogger is already initialized");
}
GameLoggerEngine.instance = new GameLoggerEngine(rsc);
return GameLoggerEngine.instance;
}
public static getInstance(): GameLoggerEngine {
@@ -61,8 +65,12 @@ export class GameLoggerEngine {
}
flushAll() {
if(this.logStack.size === 0){
return;
}
//rsc?
throw new Error("Not yet implemented");
this.logStack.clear();
}
}
+1
View File
@@ -2,5 +2,6 @@ export * from "./LogicFunc/generalStats.js";
export * as defs from "./defs.js";
export * from "./IResourceController.js";
export * from "./ActionRequest/index.js";
export * from "./GameLogger.js";
// NOTE: game_logic은 client, server 모두에서 사용되는 라이브러리이다.
// DB에 접근한다면 DI여야하나?
+5 -1
View File
@@ -5,7 +5,7 @@ import { entriesWithType } from "@sammo/util/converter";
import db from "./connectDB.js";
import type { Mongoose } from "mongoose";
import type { ActionPack, GameEngineMsg } from "./GameEngineDefs.js";
import { ActionRequestList, type QueueType } from "@sammo/game_logic";
import { ActionRequestList, GameLoggerEngine, type QueueType } from "@sammo/game_logic";
export interface ActionRequest {
name: keyof ActionPack;
args: Parameters<ActionPack[keyof ActionPack]>[1];
@@ -45,12 +45,14 @@ export class GameEngine {
} as const satisfies Record<QueueType, Denque<ActionRequestContainer>>;
private rsc: ResourceController
private loggerEngine: GameLoggerEngine;
private constructor(
db: Mongoose,
private postStatus: (msg: GameEngineMsg) => void,
) {
this.rsc = new ResourceController(db);
this.loggerEngine = GameLoggerEngine.initInstance(this.rsc);
}
private continueRun = true;
@@ -88,6 +90,7 @@ export class GameEngine {
if (processedGeneralCount > 0) {
await this.prevSaveWaiter;
const lastExecuted = this.rsc.gameEnv().raw.lastExecuted;
this.loggerEngine.flushAll();
this.prevSaveWaiter = this.rsc.saveAll().then(() => {
this.postStatus({
type: 'update',
@@ -132,6 +135,7 @@ export class GameEngine {
if (processEventCount > 0) {
await this.prevSaveWaiter;
this.prevSaveWaiter = null;
this.loggerEngine.flushAll();
await this.rsc.saveAll();
for (const response of responseQueue) {
response();