LoggerEngine을 이어붙이기
This commit is contained in:
@@ -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);
|
GameLoggerEngine.instance = new GameLoggerEngine(rsc);
|
||||||
|
return GameLoggerEngine.instance;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static getInstance(): GameLoggerEngine {
|
public static getInstance(): GameLoggerEngine {
|
||||||
@@ -61,8 +65,12 @@ export class GameLoggerEngine {
|
|||||||
}
|
}
|
||||||
|
|
||||||
flushAll() {
|
flushAll() {
|
||||||
|
if(this.logStack.size === 0){
|
||||||
|
return;
|
||||||
|
}
|
||||||
//rsc?
|
//rsc?
|
||||||
throw new Error("Not yet implemented");
|
throw new Error("Not yet implemented");
|
||||||
|
this.logStack.clear();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -2,5 +2,6 @@ export * from "./LogicFunc/generalStats.js";
|
|||||||
export * as defs from "./defs.js";
|
export * as defs from "./defs.js";
|
||||||
export * from "./IResourceController.js";
|
export * from "./IResourceController.js";
|
||||||
export * from "./ActionRequest/index.js";
|
export * from "./ActionRequest/index.js";
|
||||||
|
export * from "./GameLogger.js";
|
||||||
// NOTE: game_logic은 client, server 모두에서 사용되는 라이브러리이다.
|
// NOTE: game_logic은 client, server 모두에서 사용되는 라이브러리이다.
|
||||||
// DB에 접근한다면 DI여야하나?
|
// DB에 접근한다면 DI여야하나?
|
||||||
@@ -5,7 +5,7 @@ import { entriesWithType } from "@sammo/util/converter";
|
|||||||
import db from "./connectDB.js";
|
import db from "./connectDB.js";
|
||||||
import type { Mongoose } from "mongoose";
|
import type { Mongoose } from "mongoose";
|
||||||
import type { ActionPack, GameEngineMsg } from "./GameEngineDefs.js";
|
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 {
|
export interface ActionRequest {
|
||||||
name: keyof ActionPack;
|
name: keyof ActionPack;
|
||||||
args: Parameters<ActionPack[keyof ActionPack]>[1];
|
args: Parameters<ActionPack[keyof ActionPack]>[1];
|
||||||
@@ -45,12 +45,14 @@ export class GameEngine {
|
|||||||
} as const satisfies Record<QueueType, Denque<ActionRequestContainer>>;
|
} as const satisfies Record<QueueType, Denque<ActionRequestContainer>>;
|
||||||
|
|
||||||
private rsc: ResourceController
|
private rsc: ResourceController
|
||||||
|
private loggerEngine: GameLoggerEngine;
|
||||||
|
|
||||||
private constructor(
|
private constructor(
|
||||||
db: Mongoose,
|
db: Mongoose,
|
||||||
private postStatus: (msg: GameEngineMsg) => void,
|
private postStatus: (msg: GameEngineMsg) => void,
|
||||||
) {
|
) {
|
||||||
this.rsc = new ResourceController(db);
|
this.rsc = new ResourceController(db);
|
||||||
|
this.loggerEngine = GameLoggerEngine.initInstance(this.rsc);
|
||||||
}
|
}
|
||||||
|
|
||||||
private continueRun = true;
|
private continueRun = true;
|
||||||
@@ -88,6 +90,7 @@ export class GameEngine {
|
|||||||
if (processedGeneralCount > 0) {
|
if (processedGeneralCount > 0) {
|
||||||
await this.prevSaveWaiter;
|
await this.prevSaveWaiter;
|
||||||
const lastExecuted = this.rsc.gameEnv().raw.lastExecuted;
|
const lastExecuted = this.rsc.gameEnv().raw.lastExecuted;
|
||||||
|
this.loggerEngine.flushAll();
|
||||||
this.prevSaveWaiter = this.rsc.saveAll().then(() => {
|
this.prevSaveWaiter = this.rsc.saveAll().then(() => {
|
||||||
this.postStatus({
|
this.postStatus({
|
||||||
type: 'update',
|
type: 'update',
|
||||||
@@ -132,6 +135,7 @@ export class GameEngine {
|
|||||||
if (processEventCount > 0) {
|
if (processEventCount > 0) {
|
||||||
await this.prevSaveWaiter;
|
await this.prevSaveWaiter;
|
||||||
this.prevSaveWaiter = null;
|
this.prevSaveWaiter = null;
|
||||||
|
this.loggerEngine.flushAll();
|
||||||
await this.rsc.saveAll();
|
await this.rsc.saveAll();
|
||||||
for (const response of responseQueue) {
|
for (const response of responseQueue) {
|
||||||
response();
|
response();
|
||||||
|
|||||||
Reference in New Issue
Block a user