feat: GameEngineController
This commit is contained in:
@@ -4,6 +4,7 @@ import { ResourceController } from "./ResourceController.js";
|
||||
import { entriesWithType } from "@sammo/util/converter";
|
||||
import db from "./connectDB.js";
|
||||
import type { Mongoose } from "mongoose";
|
||||
import type { GameEngineMsg } from "./GameEngineDefs.js";
|
||||
export interface ActionRequest {
|
||||
|
||||
}
|
||||
@@ -45,7 +46,10 @@ export class GameEngine {
|
||||
|
||||
private rsc: ResourceController
|
||||
|
||||
private constructor(db: Mongoose) {
|
||||
private constructor(
|
||||
db: Mongoose,
|
||||
private postStatus: (msg: GameEngineMsg) => void,
|
||||
) {
|
||||
this.rsc = new ResourceController(db);
|
||||
}
|
||||
|
||||
@@ -122,7 +126,13 @@ export class GameEngine {
|
||||
|
||||
if (processedGeneralCount > 0) {
|
||||
await prevSaveWaiter;
|
||||
prevSaveWaiter = this.rsc.saveAll();
|
||||
const lastExecuted = this.rsc.gameEnv().raw.lastExecuted;
|
||||
prevSaveWaiter = this.rsc.saveAll().then(()=>{
|
||||
this.postStatus({
|
||||
type: 'update',
|
||||
lastExecuted: lastExecuted.toISOString()
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
//서버 이벤트 처리
|
||||
@@ -172,12 +182,12 @@ export class GameEngine {
|
||||
|
||||
private gameLoopPromise: Promise<void> | null = null;
|
||||
|
||||
public static async initInstance(): Promise<GameEngine> {
|
||||
public static async initInstance(updateHandler: (msg: GameEngineMsg)=>void): Promise<GameEngine> {
|
||||
if (GameEngine.instance) {
|
||||
throw new Error('GameEngine is already initialized');
|
||||
}
|
||||
|
||||
GameEngine.instance = new GameEngine(await db);
|
||||
GameEngine.instance = new GameEngine(await db, updateHandler);
|
||||
return GameEngine.instance;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user