feat: add command module and update action resolvers with GeneralActionResolver implementation
This commit is contained in:
@@ -1,6 +1,7 @@
|
||||
export * from './definition.js';
|
||||
export * from './engine.js';
|
||||
export * from './turn/commandEnv.js';
|
||||
export * from './turn/commandModule.js';
|
||||
export * from './turn/commandProfile.js';
|
||||
export * from './turn/general/index.js';
|
||||
export * from './turn/nation/index.js';
|
||||
|
||||
@@ -0,0 +1,18 @@
|
||||
import type { GeneralActionDefinition } from '../definition.js';
|
||||
import type { GeneralActionResolver } from '../engine.js';
|
||||
import type { TurnCommandEnv } from './commandEnv.js';
|
||||
|
||||
export interface TurnCommandSpecBase<TKey extends string = string> {
|
||||
key: TKey;
|
||||
category: string;
|
||||
reqArg: boolean;
|
||||
args: Record<string, unknown>;
|
||||
createDefinition(env: TurnCommandEnv): GeneralActionDefinition;
|
||||
}
|
||||
|
||||
export interface TurnCommandModule<TSpec extends TurnCommandSpecBase = TurnCommandSpecBase> {
|
||||
commandSpec: TSpec;
|
||||
ActionDefinition: new (...args: any[]) => GeneralActionDefinition;
|
||||
ActionResolver?: new (...args: any[]) => GeneralActionResolver;
|
||||
CommandResolver?: new (...args: any[]) => unknown;
|
||||
}
|
||||
@@ -22,6 +22,7 @@ import type { GeneralActionDefinition } from '../../definition.js';
|
||||
import type {
|
||||
GeneralActionOutcome,
|
||||
GeneralActionResolveContext,
|
||||
GeneralActionResolver,
|
||||
} from '../../engine.js';
|
||||
import {
|
||||
createGeneralAddEffect,
|
||||
@@ -281,7 +282,8 @@ export class CommandResolver<
|
||||
// 인재탐색 실행 결과를 계산한다.
|
||||
export class ActionResolver<
|
||||
TriggerState extends GeneralTriggerState = GeneralTriggerState
|
||||
> {
|
||||
> implements GeneralActionResolver<TriggerState, TalentScoutArgs> {
|
||||
readonly key = 'che_인재탐색';
|
||||
private readonly env: TalentScoutEnvironment;
|
||||
private readonly command: CommandResolver<TriggerState>;
|
||||
|
||||
|
||||
@@ -28,6 +28,7 @@ import type { GeneralActionDefinition } from '../../definition.js';
|
||||
import type {
|
||||
GeneralActionOutcome,
|
||||
GeneralActionResolveContext,
|
||||
GeneralActionResolver,
|
||||
} from '../../engine.js';
|
||||
import type { MapDefinition, UnitSetDefinition } from '../../../world/types.js';
|
||||
import type { TurnCommandEnv } from '../commandEnv.js';
|
||||
@@ -326,7 +327,8 @@ export class CommandResolver<
|
||||
|
||||
export class ActionResolver<
|
||||
TriggerState extends GeneralTriggerState = GeneralTriggerState
|
||||
> {
|
||||
> implements GeneralActionResolver<TriggerState, RecruitArgs> {
|
||||
readonly key = 'che_징병';
|
||||
// 징병 실행 결과를 계산하고 효과로 변환한다.
|
||||
private readonly env: RecruitEnvironment;
|
||||
private readonly command: CommandResolver<TriggerState>;
|
||||
|
||||
@@ -1,47 +1,41 @@
|
||||
import type { GeneralActionDefinition } from '../../definition.js';
|
||||
import type { TurnCommandEnv } from '../commandEnv.js';
|
||||
import type * as UprisingModule from './che_거병.js';
|
||||
import type * as AppointmentModule from './che_임관.js';
|
||||
import type * as FoundingModule from './che_건국.js';
|
||||
import type * as TrainingModule from './che_훈련.js';
|
||||
import type * as BoostMoraleModule from './che_사기진작.js';
|
||||
import type * as RecoveryModule from './che_요양.js';
|
||||
import type * as DispatchModule from './che_출병.js';
|
||||
import type * as ResidentsSelectionModule from './che_주민선정.js';
|
||||
import type * as FarmingModule from './che_농지개간.js';
|
||||
import type * as CommerceInvestmentModule from './che_상업투자.js';
|
||||
import type * as TechResearchModule from './che_기술연구.js';
|
||||
import type * as SecurityUpgradeModule from './che_치안강화.js';
|
||||
import type * as DefenceUpgradeModule from './che_수비강화.js';
|
||||
import type * as WallRepairModule from './che_성벽보수.js';
|
||||
import type * as FireAttackModule from './che_화계.js';
|
||||
import type * as TalentScoutModule from './che_인재탐색.js';
|
||||
import type * as RecruitModule from './che_징병.js';
|
||||
import type * as RestModule from './휴식.js';
|
||||
import type { TurnCommandModule, TurnCommandSpecBase } from '../commandModule.js';
|
||||
|
||||
export const GENERAL_TURN_COMMAND_KEYS = [
|
||||
'che_거병',
|
||||
'che_임관',
|
||||
'che_건국',
|
||||
'che_훈련',
|
||||
'che_사기진작',
|
||||
'che_요양',
|
||||
'che_출병',
|
||||
'che_주민선정',
|
||||
'che_농지개간',
|
||||
'che_상업투자',
|
||||
'che_기술연구',
|
||||
'che_치안강화',
|
||||
'che_수비강화',
|
||||
'che_성벽보수',
|
||||
'che_화계',
|
||||
'che_인재탐색',
|
||||
'che_징병',
|
||||
'휴식',
|
||||
] as const;
|
||||
|
||||
export type GeneralTurnCommandKey =
|
||||
(typeof GENERAL_TURN_COMMAND_KEYS)[number];
|
||||
|
||||
export type GeneralTurnCommandSpec =
|
||||
TurnCommandSpecBase<GeneralTurnCommandKey>;
|
||||
|
||||
export type GeneralTurnCommandModule =
|
||||
| typeof UprisingModule
|
||||
| typeof AppointmentModule
|
||||
| typeof FoundingModule
|
||||
| typeof TrainingModule
|
||||
| typeof BoostMoraleModule
|
||||
| typeof RecoveryModule
|
||||
| typeof DispatchModule
|
||||
| typeof ResidentsSelectionModule
|
||||
| typeof FarmingModule
|
||||
| typeof CommerceInvestmentModule
|
||||
| typeof TechResearchModule
|
||||
| typeof SecurityUpgradeModule
|
||||
| typeof DefenceUpgradeModule
|
||||
| typeof WallRepairModule
|
||||
| typeof FireAttackModule
|
||||
| typeof TalentScoutModule
|
||||
| typeof RecruitModule
|
||||
| typeof RestModule;
|
||||
TurnCommandModule<GeneralTurnCommandSpec>;
|
||||
|
||||
export type GeneralTurnCommandImporter = () => Promise<GeneralTurnCommandModule>;
|
||||
|
||||
const defaultImporters = {
|
||||
const defaultImporters: Record<
|
||||
GeneralTurnCommandKey,
|
||||
GeneralTurnCommandImporter
|
||||
> = {
|
||||
che_거병: async () => import('./che_거병.js'),
|
||||
che_임관: async () => import('./che_임관.js'),
|
||||
che_건국: async () => import('./che_건국.js'),
|
||||
@@ -60,27 +54,13 @@ const defaultImporters = {
|
||||
che_인재탐색: async () => import('./che_인재탐색.js'),
|
||||
che_징병: async () => import('./che_징병.js'),
|
||||
휴식: async () => import('./휴식.js'),
|
||||
} as const satisfies Record<string, GeneralTurnCommandImporter>;
|
||||
|
||||
export type GeneralTurnCommandKey = keyof typeof defaultImporters;
|
||||
|
||||
|
||||
export const GENERAL_TURN_COMMAND_KEYS: readonly GeneralTurnCommandKey[] = [
|
||||
...Object.keys(defaultImporters),
|
||||
] as GeneralTurnCommandKey[];
|
||||
};
|
||||
|
||||
export const isGeneralTurnCommandKey = (
|
||||
value: string
|
||||
): value is GeneralTurnCommandKey =>
|
||||
(GENERAL_TURN_COMMAND_KEYS as string[]).includes(value);
|
||||
GENERAL_TURN_COMMAND_KEYS.includes(value as GeneralTurnCommandKey);
|
||||
|
||||
export interface GeneralTurnCommandSpec {
|
||||
key: GeneralTurnCommandKey;
|
||||
category: string;
|
||||
reqArg: boolean;
|
||||
args: Record<string, unknown>;
|
||||
createDefinition(env: TurnCommandEnv): GeneralActionDefinition;
|
||||
}
|
||||
|
||||
export class GeneralTurnCommandLoader {
|
||||
constructor(
|
||||
@@ -120,67 +100,3 @@ export const loadGeneralTurnCommandSpecs = async (
|
||||
}
|
||||
return specs;
|
||||
};
|
||||
|
||||
export {
|
||||
ActionDefinition as UprisingActionDefinition,
|
||||
} from './che_거병.js';
|
||||
export {
|
||||
ActionDefinition as AppointmentActionDefinition,
|
||||
} from './che_임관.js';
|
||||
export {
|
||||
ActionDefinition as FoundingActionDefinition,
|
||||
} from './che_건국.js';
|
||||
export {
|
||||
ActionDefinition as TrainingActionDefinition,
|
||||
} from './che_훈련.js';
|
||||
export {
|
||||
ActionDefinition as BoostMoraleActionDefinition,
|
||||
} from './che_사기진작.js';
|
||||
export {
|
||||
ActionDefinition as RecoveryActionDefinition,
|
||||
} from './che_요양.js';
|
||||
export {
|
||||
ActionDefinition as DispatchActionDefinition,
|
||||
} from './che_출병.js';
|
||||
export {
|
||||
ActionDefinition as ResidentsSelectionActionDefinition,
|
||||
} from './che_주민선정.js';
|
||||
export {
|
||||
ActionDefinition as FarmingActionDefinition,
|
||||
} from './che_농지개간.js';
|
||||
export {
|
||||
ActionDefinition as CommerceInvestmentActionDefinition,
|
||||
ActionResolver as CommerceInvestmentActionResolver,
|
||||
CommandResolver as CommerceInvestmentCommandResolver,
|
||||
} from './che_상업투자.js';
|
||||
export {
|
||||
ActionDefinition as TechResearchActionDefinition,
|
||||
} from './che_기술연구.js';
|
||||
export {
|
||||
ActionDefinition as SecurityUpgradeActionDefinition,
|
||||
} from './che_치안강화.js';
|
||||
export {
|
||||
ActionDefinition as DefenceUpgradeActionDefinition,
|
||||
} from './che_수비강화.js';
|
||||
export {
|
||||
ActionDefinition as WallRepairActionDefinition,
|
||||
} from './che_성벽보수.js';
|
||||
export {
|
||||
ActionDefinition as FireAttackActionDefinition,
|
||||
ActionResolver as FireAttackActionResolver,
|
||||
CommandResolver as FireAttackCommandResolver,
|
||||
} from './che_화계.js';
|
||||
export {
|
||||
ActionDefinition as TalentScoutActionDefinition,
|
||||
ActionResolver as TalentScoutActionResolver,
|
||||
CommandResolver as TalentScoutCommandResolver,
|
||||
} from './che_인재탐색.js';
|
||||
export {
|
||||
ActionDefinition as RecruitActionDefinition,
|
||||
ActionResolver as RecruitActionResolver,
|
||||
CommandResolver as RecruitCommandResolver,
|
||||
} from './che_징병.js';
|
||||
export {
|
||||
ActionDefinition as RestActionDefinition,
|
||||
ActionResolver as RestActionResolver,
|
||||
} from './휴식.js';
|
||||
|
||||
@@ -9,6 +9,7 @@ import type { GeneralActionDefinition } from '../../definition.js';
|
||||
import type {
|
||||
GeneralActionOutcome,
|
||||
GeneralActionResolveContext,
|
||||
GeneralActionResolver,
|
||||
} from '../../engine.js';
|
||||
import { LogCategory, LogFormat } from '../../../logging/types.js';
|
||||
import type { TurnCommandEnv } from '../commandEnv.js';
|
||||
@@ -20,7 +21,9 @@ const ACTION_NAME = '휴식';
|
||||
|
||||
export class ActionResolver<
|
||||
TriggerState extends GeneralTriggerState = GeneralTriggerState
|
||||
> {
|
||||
> implements GeneralActionResolver<TriggerState, RestArgs> {
|
||||
readonly key = '휴식';
|
||||
|
||||
resolve(
|
||||
context: GeneralActionResolveContext<TriggerState>,
|
||||
_args: RestArgs
|
||||
|
||||
@@ -24,6 +24,7 @@ import type {
|
||||
GeneralActionEffect,
|
||||
GeneralActionOutcome,
|
||||
GeneralActionResolveContext,
|
||||
GeneralActionResolver,
|
||||
} from '../../engine.js';
|
||||
import { createGeneralPatchEffect, createLogEffect } from '../../engine.js';
|
||||
import { LogCategory, LogFormat, LogScope } from '../../../logging/types.js';
|
||||
@@ -89,7 +90,8 @@ const addMetaValue = (
|
||||
// 발령 결과를 계산한다.
|
||||
export class ActionResolver<
|
||||
TriggerState extends GeneralTriggerState = GeneralTriggerState
|
||||
> {
|
||||
> implements GeneralActionResolver<TriggerState, AssignmentArgs> {
|
||||
readonly key = 'che_발령';
|
||||
private readonly env: AssignmentEnvironment;
|
||||
|
||||
constructor(env: AssignmentEnvironment) {
|
||||
|
||||
@@ -24,6 +24,7 @@ import type {
|
||||
GeneralActionEffect,
|
||||
GeneralActionOutcome,
|
||||
GeneralActionResolveContext,
|
||||
GeneralActionResolver,
|
||||
} from '../../engine.js';
|
||||
import {
|
||||
createGeneralAddEffect,
|
||||
@@ -230,7 +231,8 @@ export class CommandResolver<
|
||||
// 의병모집 실행 결과를 계산한다.
|
||||
export class ActionResolver<
|
||||
TriggerState extends GeneralTriggerState = GeneralTriggerState
|
||||
> {
|
||||
> implements GeneralActionResolver<TriggerState, VolunteerRecruitArgs> {
|
||||
readonly key = 'che_의병모집';
|
||||
private readonly env: VolunteerRecruitEnvironment;
|
||||
private readonly command: CommandResolver<TriggerState>;
|
||||
|
||||
|
||||
@@ -25,6 +25,7 @@ import type {
|
||||
GeneralActionEffect,
|
||||
GeneralActionOutcome,
|
||||
GeneralActionResolveContext,
|
||||
GeneralActionResolver,
|
||||
} from '../../engine.js';
|
||||
import {
|
||||
createGeneralPatchEffect,
|
||||
@@ -109,7 +110,8 @@ export class CommandResolver {
|
||||
// 포상 결과를 계산한다.
|
||||
export class ActionResolver<
|
||||
TriggerState extends GeneralTriggerState = GeneralTriggerState
|
||||
> {
|
||||
> implements GeneralActionResolver<TriggerState, AwardArgs> {
|
||||
readonly key = 'che_포상';
|
||||
private readonly env: AwardEnvironment;
|
||||
private readonly command: CommandResolver;
|
||||
|
||||
|
||||
@@ -1,49 +1,42 @@
|
||||
import type { GeneralActionDefinition } from '../../definition.js';
|
||||
import type { TurnCommandEnv } from '../commandEnv.js';
|
||||
import type * as NationRestModule from './휴식.js';
|
||||
import type * as AwardModule from './che_포상.js';
|
||||
import type * as AssignmentModule from './che_발령.js';
|
||||
import type * as DeclarationModule from './che_선전포고.js';
|
||||
import type * as NonAggressionProposalModule from './che_불가침제의.js';
|
||||
import type * as VolunteerRecruitModule from './che_의병모집.js';
|
||||
import type { TurnCommandModule, TurnCommandSpecBase } from '../commandModule.js';
|
||||
|
||||
export const NATION_TURN_COMMAND_KEYS = [
|
||||
'휴식',
|
||||
'che_포상',
|
||||
'che_발령',
|
||||
'che_선전포고',
|
||||
'che_불가침제의',
|
||||
'che_의병모집',
|
||||
] as const;
|
||||
|
||||
export type NationTurnCommandKey =
|
||||
(typeof NATION_TURN_COMMAND_KEYS)[number];
|
||||
|
||||
export type NationTurnCommandSpec =
|
||||
TurnCommandSpecBase<NationTurnCommandKey>;
|
||||
|
||||
export type NationTurnCommandModule =
|
||||
| typeof NationRestModule
|
||||
| typeof AwardModule
|
||||
| typeof AssignmentModule
|
||||
| typeof DeclarationModule
|
||||
| typeof NonAggressionProposalModule
|
||||
| typeof VolunteerRecruitModule;
|
||||
TurnCommandModule<NationTurnCommandSpec>;
|
||||
|
||||
export type NationTurnCommandImporter = () => Promise<NationTurnCommandModule>;
|
||||
|
||||
const defaultImporters = {
|
||||
const defaultImporters: Record<
|
||||
NationTurnCommandKey,
|
||||
NationTurnCommandImporter
|
||||
> = {
|
||||
휴식: async () => import('./휴식.js'),
|
||||
che_포상: async () => import('./che_포상.js'),
|
||||
che_발령: async () => import('./che_발령.js'),
|
||||
che_선전포고: async () => import('./che_선전포고.js'),
|
||||
che_불가침제의: async () => import('./che_불가침제의.js'),
|
||||
che_의병모집: async () => import('./che_의병모집.js'),
|
||||
} as const satisfies Record<string, NationTurnCommandImporter>;
|
||||
|
||||
export type NationTurnCommandKey = keyof typeof defaultImporters;
|
||||
|
||||
export const NATION_TURN_COMMAND_KEYS: readonly NationTurnCommandKey[] = [...Object.keys(defaultImporters)] as NationTurnCommandKey[];
|
||||
};
|
||||
|
||||
export const isNationTurnCommandKey = (
|
||||
value: string
|
||||
): value is NationTurnCommandKey =>
|
||||
(NATION_TURN_COMMAND_KEYS as string[]).includes(value);
|
||||
NATION_TURN_COMMAND_KEYS.includes(value as NationTurnCommandKey);
|
||||
|
||||
export interface NationTurnCommandSpec {
|
||||
key: NationTurnCommandKey;
|
||||
category: string;
|
||||
reqArg: boolean;
|
||||
args: Record<string, unknown>;
|
||||
createDefinition(env: TurnCommandEnv): GeneralActionDefinition;
|
||||
}
|
||||
|
||||
|
||||
export class NationTurnCommandLoader {
|
||||
@@ -84,28 +77,3 @@ export const loadNationTurnCommandSpecs = async (
|
||||
}
|
||||
return specs;
|
||||
};
|
||||
|
||||
export {
|
||||
ActionDefinition as NationRestActionDefinition,
|
||||
ActionResolver as NationRestActionResolver,
|
||||
} from './휴식.js';
|
||||
export {
|
||||
ActionDefinition as AwardActionDefinition,
|
||||
ActionResolver as AwardActionResolver,
|
||||
CommandResolver as AwardCommandResolver,
|
||||
} from './che_포상.js';
|
||||
export {
|
||||
ActionDefinition as AssignmentActionDefinition,
|
||||
ActionResolver as AssignmentActionResolver,
|
||||
} from './che_발령.js';
|
||||
export {
|
||||
ActionDefinition as DeclarationActionDefinition,
|
||||
} from './che_선전포고.js';
|
||||
export {
|
||||
ActionDefinition as NonAggressionProposalActionDefinition,
|
||||
} from './che_불가침제의.js';
|
||||
export {
|
||||
ActionDefinition as VolunteerRecruitActionDefinition,
|
||||
ActionResolver as VolunteerRecruitActionResolver,
|
||||
CommandResolver as VolunteerRecruitCommandResolver,
|
||||
} from './che_의병모집.js';
|
||||
|
||||
@@ -9,6 +9,7 @@ import type { GeneralActionDefinition } from '../../definition.js';
|
||||
import type {
|
||||
GeneralActionOutcome,
|
||||
GeneralActionResolveContext,
|
||||
GeneralActionResolver,
|
||||
} from '../../engine.js';
|
||||
import type { TurnCommandEnv } from '../commandEnv.js';
|
||||
import type { NationTurnCommandSpec } from './index.js';
|
||||
@@ -19,7 +20,9 @@ const ACTION_NAME = '휴식';
|
||||
|
||||
export class ActionResolver<
|
||||
TriggerState extends GeneralTriggerState = GeneralTriggerState
|
||||
> {
|
||||
> implements GeneralActionResolver<TriggerState, NationRestArgs> {
|
||||
readonly key = '휴식';
|
||||
|
||||
resolve(
|
||||
_context: GeneralActionResolveContext<TriggerState>,
|
||||
_args: NationRestArgs
|
||||
|
||||
Reference in New Issue
Block a user