74 lines
2.5 KiB
TypeScript
74 lines
2.5 KiB
TypeScript
import type { General } from "./General.js";
|
|
import type { City } from "./City.js";
|
|
import type { Nation } from "./Nation.js";
|
|
import type { CityID, GeneralID, NationID, TroopID } from "./defs.js";
|
|
import type { GameEnv } from "./GameEnv.js";
|
|
import type { IGeneralEntity } from "./GeneralEntity.js";
|
|
import type { Troop } from "./Troop.js";
|
|
import type { ITroopEntity } from "./TroopEntity.js";
|
|
import type { LazyEntityUpdater } from "./LazyEntityUpdater.js";
|
|
import type { ICityEntity } from "./CityEntity.js";
|
|
import type { INationEntity } from "./NationEntity.js";
|
|
import type { ValuesOf } from "@sammo/util";
|
|
|
|
export type ValidEntityList = {
|
|
'General': IGeneralEntity;
|
|
'City': ICityEntity;
|
|
'Nation': INationEntity;
|
|
'Troop': ITroopEntity;
|
|
};
|
|
|
|
export type ValidEntity = ValuesOf<ValidEntityList>;
|
|
export type ValidEntityType<Entity> = Entity extends ValidEntityList[infer T extends keyof ValidEntityList] ? T : never;
|
|
|
|
export interface IResourceController{
|
|
addCity(city: City): boolean;
|
|
addNation(nation: Nation): boolean;
|
|
addGeneral(general: General): boolean;
|
|
|
|
getCity(id: CityID): City | undefined;
|
|
getNation(id: NationID): Nation | undefined;
|
|
getGeneral(id: GeneralID): General | undefined;
|
|
|
|
getGameEnv(): GameEnv;
|
|
|
|
findAllNations(): Map<NationID, Nation>;
|
|
findAllCities(): Map<CityID, City>;
|
|
findAllGenerals(): Map<GeneralID, General>;
|
|
|
|
findGeneralByTroop(id: TroopID): Map<GeneralID, General>;
|
|
|
|
findCityByNation(id: NationID): Map<CityID, City>;
|
|
findGeneralByNation(id: NationID): Map<GeneralID, General>;
|
|
findGeneralByCity(id: CityID, nationID?: NationID): Map<GeneralID, General>;
|
|
|
|
getTroop(id: TroopID, nation: NationID): Troop | undefined;
|
|
|
|
_getAllChanges(): Map<unknown, unknown>;
|
|
|
|
setDirty(entity: LazyEntityUpdater<any>): void;
|
|
|
|
createGeneral(raw: IGeneralEntity): General;
|
|
createNation(raw: INationEntity): Nation;
|
|
createTroop(raw: ITroopEntity): Troop;
|
|
|
|
reserveDeleteTroop(id: TroopID): void;
|
|
reserveDeleteGeneral(id: GeneralID): void;
|
|
reserveDeleteNation(id: NationID): void;
|
|
|
|
resetAndFill(): Promise<void>;
|
|
saveAll(): 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;
|
|
} |