ResourceController 란 것이 있을 것
This commit is contained in:
@@ -0,0 +1,8 @@
|
||||
import type { CityID } from "./defs.js";
|
||||
|
||||
export class City{
|
||||
constructor(
|
||||
public readonly id: CityID
|
||||
){
|
||||
}
|
||||
}
|
||||
@@ -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,
|
||||
){
|
||||
|
||||
}
|
||||
}
|
||||
@@ -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,
|
||||
) { }
|
||||
}
|
||||
@@ -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<boolean>;
|
||||
addNation(nation: Nation): Promise<boolean>;
|
||||
addGeneral(general: General): Promise<boolean>;
|
||||
|
||||
getCity(id: CityID, allowFromDB?: boolean): Promise<City | undefined>;
|
||||
getNation(id: NationID, allowFromDB?: boolean): Promise<Nation | undefined>;
|
||||
getGeneral(id: GeneralID, allowFromDB?: boolean): Promise<General | undefined>;
|
||||
|
||||
getGameEnv(): Promise<GameEnv>;
|
||||
|
||||
findAllNations(): Promise<Map<NationID, Nation>>;
|
||||
findAllCities(): Promise<Map<CityID, City>>;
|
||||
findAllGenerals(): Promise<Map<GeneralID, General>>;
|
||||
|
||||
findCityByNation(id: NationID): Promise<Map<CityID, City>>;
|
||||
findGeneralByNation(id: NationID): Promise<Map<GeneralID, General>>;
|
||||
findGeneralByCity(id: CityID, nationID?: NationID): Promise<Map<GeneralID, General>>;
|
||||
|
||||
findGeneralByQuery(query: unknown): Promise<Map<GeneralID, General>>;
|
||||
findCityByQuery(query: unknown): Promise<Map<CityID, City>>;
|
||||
findNationByQuery(query: unknown): Promise<Map<NationID, Nation>>;
|
||||
|
||||
reset(): void;
|
||||
save(): Promise<void>;
|
||||
}
|
||||
|
||||
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;
|
||||
}
|
||||
@@ -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" };
|
||||
Reference in New Issue
Block a user