feat: Mongoose를 GameEngine으로 전달

This commit is contained in:
2024-03-09 14:54:25 +00:00
parent bf8ad0a78c
commit 5928655bc1
5 changed files with 13 additions and 10 deletions
+1 -1
View File
@@ -1,5 +1,5 @@
import './dotenv.js'; import './dotenv.js';
import { connect, Mongoose } from "mongoose"; import { connect,type Mongoose } from "mongoose";
import { unwrap } from '@sammo/util'; import { unwrap } from '@sammo/util';
const dbConfig = { const dbConfig = {
@@ -1,5 +1,5 @@
import { type UserIDType } from "./User.js"; import { type UserIDType } from "./User.js";
import { Mongoose, Schema, model } from "mongoose"; import { type Mongoose, Schema, model } from "mongoose";
export interface ILoginToken { export interface ILoginToken {
userID: UserIDType; userID: UserIDType;
+5 -5
View File
@@ -2,7 +2,8 @@ import { Signal, delay, must, must_err } from "@sammo/util";
import Denque from "denque"; import Denque from "denque";
import { ResourceController } from "./ResourceController.js"; import { ResourceController } from "./ResourceController.js";
import { entriesWithType } from "@sammo/util/converter"; import { entriesWithType } from "@sammo/util/converter";
import db from "./connectDB.js";
import type { Mongoose } from "mongoose";
export interface ActionRequest { export interface ActionRequest {
} }
@@ -44,9 +45,8 @@ export class GameEngine {
private rsc: ResourceController private rsc: ResourceController
private constructor() { private constructor(db: Mongoose) {
//TODO MongoDB를 넘겨줘야함 this.rsc = new ResourceController(db);
this.rsc = new ResourceController();
} }
private continueRun = true; private continueRun = true;
@@ -177,7 +177,7 @@ export class GameEngine {
throw new Error('GameEngine is already initialized'); throw new Error('GameEngine is already initialized');
} }
GameEngine.instance = new GameEngine(); GameEngine.instance = new GameEngine(await db);
return GameEngine.instance; return GameEngine.instance;
} }
+5 -2
View File
@@ -13,13 +13,15 @@ import type { Nation } from "@sammo/game_logic/src/Nation.js";
import type { Troop } from "@sammo/game_logic/src/Troop.js"; import type { Troop } from "@sammo/game_logic/src/Troop.js";
import { insertItemAtArrayLike, NotYetImplemented } from "@sammo/util"; import { insertItemAtArrayLike, NotYetImplemented } from "@sammo/util";
import Denque from "denque"; import Denque from "denque";
import type { Mongoose } from "mongoose";
type ChangeType = "insert" | "update" | "delete"; type ChangeType = "insert" | "update" | "delete";
//TODO: Implement! //TODO: Implement!
export class ResourceController implements IResourceController{ export class ResourceController implements IResourceController{
constructor() { constructor(
private readonly db: Mongoose
) {
} }
@@ -32,6 +34,7 @@ export class ResourceController implements IResourceController{
private _generalByTurntime = new Denque<General>(); private _generalByTurntime = new Denque<General>();
private changes = { private changes = {
Nation: new Map<number, [ChangeType, Nation]>(), Nation: new Map<number, [ChangeType, Nation]>(),
City: new Map<number, [ChangeType, City]>(), City: new Map<number, [ChangeType, City]>(),
+1 -1
View File
@@ -1,5 +1,5 @@
import './dotenv.js'; import './dotenv.js';
import { connect, Mongoose } from "mongoose"; import { connect, type Mongoose } from "mongoose";
import { unwrap } from '@sammo/util'; import { unwrap } from '@sammo/util';
const dbConfig = { const dbConfig = {