feat: Introduce action context builders for various turn actions

- Added `actionContextBuilder` to multiple turn action files to utilize the default action context builder.
- Implemented specific context builders for actions requiring additional context, such as war configurations, world summaries, and general statistics.
- Created new `actionContext.ts` and `actionContextHelpers.ts` files to define interfaces and helper functions for managing action contexts.
- Enhanced context handling for nation and general actions, ensuring proper data injection for turn execution.
This commit is contained in:
2026-01-03 06:28:50 +00:00
parent b628b32968
commit 4f90f50033
31 changed files with 613 additions and 429 deletions
@@ -0,0 +1,63 @@
import type { City, General, Nation } from '../../domain/entities.js';
import type { ScenarioConfig } from '../../scenario/types.js';
import type { ScenarioMeta } from '../../world/types.js';
import type { MapDefinition, UnitSetDefinition } from '../../world/types.js';
export interface ActionRandomSource {
nextFloat(): number;
nextBool(probability: number): boolean;
nextInt(minInclusive: number, maxExclusive: number): number;
}
export interface ActionContextGeneral extends General {
turnTime: Date;
}
export type ActionContextBase = {
general: ActionContextGeneral;
city?: City;
nation?: Nation | null;
rng: ActionRandomSource;
};
export type ActionResolveContext = ActionContextBase & Record<string, unknown>;
export interface ActionContextWorldState {
currentYear: number;
currentMonth: number;
tickSeconds: number;
}
export interface ActionContextWorldRef {
listGenerals(): ActionContextGeneral[];
listCities(): City[];
listNations(): Nation[];
listDiplomacy(): Array<{
fromNationId: number;
toNationId: number;
state: number;
}>;
getGeneralById(id: number): ActionContextGeneral | null;
getCityById(id: number): City | null;
getNationById(id: number): Nation | null;
}
export interface ActionContextOptions {
world: ActionContextWorldState;
scenarioConfig: ScenarioConfig;
scenarioMeta?: ScenarioMeta;
map?: MapDefinition;
unitSet?: UnitSetDefinition;
worldRef: ActionContextWorldRef | null;
actionArgs: Record<string, unknown>;
createGeneralId: () => number;
seedBase: string;
}
// 예약 턴 처리에서 커맨드별로 필요한 컨텍스트를 확장한다.
export type ActionContextBuilder = (
base: ActionContextBase,
options: ActionContextOptions
) => ActionResolveContext | null;
export const defaultActionContextBuilder: ActionContextBuilder = (base) => base;