diff --git a/@sammo/game_logic/src/City.ts b/@sammo/game_logic/src/City.ts new file mode 100644 index 0000000..0902ab0 --- /dev/null +++ b/@sammo/game_logic/src/City.ts @@ -0,0 +1,8 @@ +import type { CityID } from "./defs.js"; + +export class City{ + constructor( + public readonly id: CityID + ){ + } +} \ No newline at end of file diff --git a/@sammo/game_logic/src/General.ts b/@sammo/game_logic/src/General.ts index a026ae4..a3f1bff 100644 --- a/@sammo/game_logic/src/General.ts +++ b/@sammo/game_logic/src/General.ts @@ -1,3 +1,10 @@ -export class General { +import type { GeneralID, GeneralName } from "./defs.js"; +export class General { + constructor( + public readonly id: GeneralID, + public name: GeneralName, + ){ + + } } \ No newline at end of file diff --git a/@sammo/game_logic/src/Nation.ts b/@sammo/game_logic/src/Nation.ts new file mode 100644 index 0000000..a02bd67 --- /dev/null +++ b/@sammo/game_logic/src/Nation.ts @@ -0,0 +1,9 @@ +import type { NationID, NationName, NationType } from "./defs.js"; + +export class Nation { + constructor( + public readonly id: NationID, + public readonly name: NationName, + public readonly type: NationType, + ) { } +} \ No newline at end of file diff --git a/@sammo/game_logic/src/ResourceController.ts b/@sammo/game_logic/src/ResourceController.ts new file mode 100644 index 0000000..a07ac5f --- /dev/null +++ b/@sammo/game_logic/src/ResourceController.ts @@ -0,0 +1,45 @@ +import type { General } from "./General.js"; +import type { City } from "./City.js"; +import type { Nation } from "./Nation.js"; +import type { CityID, GeneralID, NationID } from "./defs.js"; +import type { GameEnv } from "./GameEnv.js"; + +export interface IResourceController{ + addCity(city: City): Promise; + addNation(nation: Nation): Promise; + addGeneral(general: General): Promise; + + getCity(id: CityID, allowFromDB?: boolean): Promise; + getNation(id: NationID, allowFromDB?: boolean): Promise; + getGeneral(id: GeneralID, allowFromDB?: boolean): Promise; + + getGameEnv(): Promise; + + findAllNations(): Promise>; + findAllCities(): Promise>; + findAllGenerals(): Promise>; + + findCityByNation(id: NationID): Promise>; + findGeneralByNation(id: NationID): Promise>; + findGeneralByCity(id: CityID, nationID?: NationID): Promise>; + + findGeneralByQuery(query: unknown): Promise>; + findCityByQuery(query: unknown): Promise>; + findNationByQuery(query: unknown): Promise>; + + reset(): void; + save(): Promise; +} + +let _resourceController: IResourceController | undefined = undefined; + +export const setResourceController = (resourceController: IResourceController) => { + _resourceController = resourceController; +} + +export const getResourceController = () => { + if (_resourceController === undefined) { + throw new Error("ResourceController not set"); + } + return _resourceController; +} \ No newline at end of file diff --git a/@sammo/game_logic/src/defs.ts b/@sammo/game_logic/src/defs.ts index 7edfe93..d88e258 100644 --- a/@sammo/game_logic/src/defs.ts +++ b/@sammo/game_logic/src/defs.ts @@ -1,4 +1,15 @@ //Type 정의 -export type GeneralName = string & { zz_t?: "GeneralName" }; +import { type } from "os"; + export type GeneralID = number & { zz_t?: "GeneralID" }; +export type GeneralName = string & { zz_t?: "GeneralName" }; + +export type CityID = number & { zz_t?: "CityID" }; +export type CityName = string & { zz_t?: "CityName" }; + +export type NationID = number & { zz_t?: "NationID" }; +export type NationName = string & { zz_t?: "NationName" }; + +//TODO: 무언가의 keyof 로 바꿔야함 +export type NationType = string & { zz_t?: "NationType" }; \ No newline at end of file