diff --git a/packages/logic/src/actions/index.ts b/packages/logic/src/actions/index.ts index e55e171..6aa8939 100644 --- a/packages/logic/src/actions/index.ts +++ b/packages/logic/src/actions/index.ts @@ -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'; diff --git a/packages/logic/src/actions/turn/commandModule.ts b/packages/logic/src/actions/turn/commandModule.ts new file mode 100644 index 0000000..a36b389 --- /dev/null +++ b/packages/logic/src/actions/turn/commandModule.ts @@ -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 { + key: TKey; + category: string; + reqArg: boolean; + args: Record; + createDefinition(env: TurnCommandEnv): GeneralActionDefinition; +} + +export interface TurnCommandModule { + commandSpec: TSpec; + ActionDefinition: new (...args: any[]) => GeneralActionDefinition; + ActionResolver?: new (...args: any[]) => GeneralActionResolver; + CommandResolver?: new (...args: any[]) => unknown; +} diff --git a/packages/logic/src/actions/turn/general/che_인재탐색.ts b/packages/logic/src/actions/turn/general/che_인재탐색.ts index 03c954e..bdde687 100644 --- a/packages/logic/src/actions/turn/general/che_인재탐색.ts +++ b/packages/logic/src/actions/turn/general/che_인재탐색.ts @@ -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 { + readonly key = 'che_인재탐색'; private readonly env: TalentScoutEnvironment; private readonly command: CommandResolver; diff --git a/packages/logic/src/actions/turn/general/che_징병.ts b/packages/logic/src/actions/turn/general/che_징병.ts index 2237919..788a059 100644 --- a/packages/logic/src/actions/turn/general/che_징병.ts +++ b/packages/logic/src/actions/turn/general/che_징병.ts @@ -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 { + readonly key = 'che_징병'; // 징병 실행 결과를 계산하고 효과로 변환한다. private readonly env: RecruitEnvironment; private readonly command: CommandResolver; diff --git a/packages/logic/src/actions/turn/general/index.ts b/packages/logic/src/actions/turn/general/index.ts index 74fb48b..df99b8d 100644 --- a/packages/logic/src/actions/turn/general/index.ts +++ b/packages/logic/src/actions/turn/general/index.ts @@ -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; 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; export type GeneralTurnCommandImporter = () => Promise; -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; - -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; - 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'; diff --git a/packages/logic/src/actions/turn/general/휴식.ts b/packages/logic/src/actions/turn/general/휴식.ts index 821f733..ecf2c22 100644 --- a/packages/logic/src/actions/turn/general/휴식.ts +++ b/packages/logic/src/actions/turn/general/휴식.ts @@ -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 { + readonly key = '휴식'; + resolve( context: GeneralActionResolveContext, _args: RestArgs diff --git a/packages/logic/src/actions/turn/nation/che_발령.ts b/packages/logic/src/actions/turn/nation/che_발령.ts index d6a4d16..d0f7115 100644 --- a/packages/logic/src/actions/turn/nation/che_발령.ts +++ b/packages/logic/src/actions/turn/nation/che_발령.ts @@ -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 { + readonly key = 'che_발령'; private readonly env: AssignmentEnvironment; constructor(env: AssignmentEnvironment) { diff --git a/packages/logic/src/actions/turn/nation/che_의병모집.ts b/packages/logic/src/actions/turn/nation/che_의병모집.ts index 0f0c432..3aa048d 100644 --- a/packages/logic/src/actions/turn/nation/che_의병모집.ts +++ b/packages/logic/src/actions/turn/nation/che_의병모집.ts @@ -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 { + readonly key = 'che_의병모집'; private readonly env: VolunteerRecruitEnvironment; private readonly command: CommandResolver; diff --git a/packages/logic/src/actions/turn/nation/che_포상.ts b/packages/logic/src/actions/turn/nation/che_포상.ts index b3cb389..35f4f6f 100644 --- a/packages/logic/src/actions/turn/nation/che_포상.ts +++ b/packages/logic/src/actions/turn/nation/che_포상.ts @@ -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 { + readonly key = 'che_포상'; private readonly env: AwardEnvironment; private readonly command: CommandResolver; diff --git a/packages/logic/src/actions/turn/nation/index.ts b/packages/logic/src/actions/turn/nation/index.ts index 5354e2f..0f7e224 100644 --- a/packages/logic/src/actions/turn/nation/index.ts +++ b/packages/logic/src/actions/turn/nation/index.ts @@ -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; export type NationTurnCommandModule = - | typeof NationRestModule - | typeof AwardModule - | typeof AssignmentModule - | typeof DeclarationModule - | typeof NonAggressionProposalModule - | typeof VolunteerRecruitModule; + TurnCommandModule; export type NationTurnCommandImporter = () => Promise; -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; - -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; - 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'; diff --git a/packages/logic/src/actions/turn/nation/휴식.ts b/packages/logic/src/actions/turn/nation/휴식.ts index b87101b..10890f5 100644 --- a/packages/logic/src/actions/turn/nation/휴식.ts +++ b/packages/logic/src/actions/turn/nation/휴식.ts @@ -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 { + readonly key = '휴식'; + resolve( _context: GeneralActionResolveContext, _args: NationRestArgs