feat: add troop model and integrate troop handling in game logic
This commit is contained in:
@@ -147,6 +147,14 @@ model General {
|
||||
@@map("general")
|
||||
}
|
||||
|
||||
model Troop {
|
||||
troopLeaderId Int @id @map("troop_leader")
|
||||
nationId Int @map("nation")
|
||||
name String
|
||||
|
||||
@@map("troop")
|
||||
}
|
||||
|
||||
model GeneralTurn {
|
||||
id Int @id @default(autoincrement())
|
||||
generalId Int @map("general_id")
|
||||
|
||||
@@ -3,6 +3,7 @@
|
||||
export type GeneralId = number;
|
||||
export type CityId = number;
|
||||
export type NationId = number;
|
||||
export type TroopId = number;
|
||||
|
||||
export type ColorCode = string;
|
||||
|
||||
@@ -95,3 +96,9 @@ export interface Nation {
|
||||
typeCode: string;
|
||||
meta: Record<string, TriggerValue>;
|
||||
}
|
||||
|
||||
export interface Troop {
|
||||
id: TroopId;
|
||||
nationId: NationId;
|
||||
name: string;
|
||||
}
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
import type { City, General, Nation } from '../domain/entities.js';
|
||||
import type { City, General, Nation, Troop } from '../domain/entities.js';
|
||||
import type { ScenarioConfig } from '../scenario/types.js';
|
||||
import type { ScenarioMeta } from '../world/types.js';
|
||||
|
||||
@@ -6,11 +6,13 @@ import type { ScenarioMeta } from '../world/types.js';
|
||||
export interface WorldStateSnapshotSource<
|
||||
GeneralType extends General = General,
|
||||
CityType extends City = City,
|
||||
NationType extends Nation = Nation
|
||||
NationType extends Nation = Nation,
|
||||
TroopType extends Troop = Troop
|
||||
> {
|
||||
listGenerals(): Promise<GeneralType[]>;
|
||||
listCities(): Promise<CityType[]>;
|
||||
listNations(): Promise<NationType[]>;
|
||||
listTroops(): Promise<TroopType[]>;
|
||||
}
|
||||
|
||||
export interface ScenarioConfigSource {
|
||||
|
||||
@@ -676,6 +676,7 @@ export const buildScenarioBootstrap = (
|
||||
nations: seedNations,
|
||||
cities: seedCities,
|
||||
generals: allGeneralSeeds,
|
||||
troops: [],
|
||||
diplomacy: scenario.diplomacy,
|
||||
events: scenario.events,
|
||||
initialEvents: scenario.initialEvents,
|
||||
@@ -689,6 +690,7 @@ export const buildScenarioBootstrap = (
|
||||
nations: domainNations,
|
||||
cities: domainCities,
|
||||
generals: allGenerals,
|
||||
troops: [],
|
||||
diplomacy: scenario.diplomacy,
|
||||
events: scenario.events,
|
||||
initialEvents: scenario.initialEvents,
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
import type { City, General, Nation } from '../domain/entities.js';
|
||||
import type { City, General, Nation, Troop } from '../domain/entities.js';
|
||||
import type { ScenarioConfig, ScenarioDiplomacy } from '../scenario/types.js';
|
||||
import type { ScenarioConfigSource, WorldStateSnapshotSource } from '../ports/worldSnapshot.js';
|
||||
import type {
|
||||
@@ -11,9 +11,15 @@ import type {
|
||||
export interface WorldSnapshotLoadInput<
|
||||
GeneralType extends General = General,
|
||||
CityType extends City = City,
|
||||
NationType extends Nation = Nation
|
||||
NationType extends Nation = Nation,
|
||||
TroopType extends Troop = Troop
|
||||
> {
|
||||
worldSource: WorldStateSnapshotSource<GeneralType, CityType, NationType>;
|
||||
worldSource: WorldStateSnapshotSource<
|
||||
GeneralType,
|
||||
CityType,
|
||||
NationType,
|
||||
TroopType
|
||||
>;
|
||||
scenarioConfig?: ScenarioConfig;
|
||||
scenarioMeta?: ScenarioMeta;
|
||||
scenarioSource?: ScenarioConfigSource;
|
||||
@@ -28,9 +34,15 @@ export interface WorldSnapshotLoadInput<
|
||||
export const loadWorldSnapshot = async <
|
||||
GeneralType extends General,
|
||||
CityType extends City,
|
||||
NationType extends Nation
|
||||
NationType extends Nation,
|
||||
TroopType extends Troop
|
||||
>(
|
||||
input: WorldSnapshotLoadInput<GeneralType, CityType, NationType>
|
||||
input: WorldSnapshotLoadInput<
|
||||
GeneralType,
|
||||
CityType,
|
||||
NationType,
|
||||
TroopType
|
||||
>
|
||||
): Promise<WorldSnapshot> => {
|
||||
const { worldSource, scenarioSource } = input;
|
||||
|
||||
@@ -47,10 +59,11 @@ export const loadWorldSnapshot = async <
|
||||
? await scenarioSource.loadScenarioMeta()
|
||||
: undefined);
|
||||
|
||||
const [generals, cities, nations] = await Promise.all([
|
||||
const [generals, cities, nations, troops] = await Promise.all([
|
||||
worldSource.listGenerals(),
|
||||
worldSource.listCities(),
|
||||
worldSource.listNations(),
|
||||
worldSource.listTroops(),
|
||||
]);
|
||||
|
||||
return {
|
||||
@@ -61,6 +74,7 @@ export const loadWorldSnapshot = async <
|
||||
nations,
|
||||
cities,
|
||||
generals,
|
||||
troops,
|
||||
diplomacy: input.diplomacy ?? [],
|
||||
events: input.events ?? [],
|
||||
initialEvents: input.initialEvents ?? [],
|
||||
|
||||
@@ -1,4 +1,10 @@
|
||||
import type { City, General, Nation, StatBlock } from '../domain/entities.js';
|
||||
import type {
|
||||
City,
|
||||
General,
|
||||
Nation,
|
||||
StatBlock,
|
||||
Troop,
|
||||
} from '../domain/entities.js';
|
||||
import type {
|
||||
ScenarioConfig,
|
||||
ScenarioDiplomacy,
|
||||
@@ -136,6 +142,7 @@ export interface WorldSeedPayload {
|
||||
nations: NationSeed[];
|
||||
cities: CitySeed[];
|
||||
generals: GeneralSeed[];
|
||||
troops: Troop[];
|
||||
diplomacy: ScenarioDiplomacy[];
|
||||
events: unknown[];
|
||||
initialEvents: unknown[];
|
||||
@@ -149,6 +156,7 @@ export interface WorldSnapshot {
|
||||
nations: Nation[];
|
||||
cities: City[];
|
||||
generals: General[];
|
||||
troops: Troop[];
|
||||
diplomacy: ScenarioDiplomacy[];
|
||||
events: unknown[];
|
||||
initialEvents: unknown[];
|
||||
|
||||
Reference in New Issue
Block a user