From 6d421e81a07eee4f6fc17874811675cdb8449b48 Mon Sep 17 00:00:00 2001 From: Hide_D Date: Thu, 1 Jan 2026 19:12:50 +0000 Subject: [PATCH] feat: Refactor General and Nation Turn Command types and importers for improved structure and consistency --- .../logic/src/actions/turn/general/index.ts | 85 +++++-------------- .../logic/src/actions/turn/nation/index.ts | 49 +++++------ 2 files changed, 43 insertions(+), 91 deletions(-) diff --git a/packages/logic/src/actions/turn/general/index.ts b/packages/logic/src/actions/turn/general/index.ts index 90174ff..838b5d5 100644 --- a/packages/logic/src/actions/turn/general/index.ts +++ b/packages/logic/src/actions/turn/general/index.ts @@ -20,62 +20,6 @@ import type * as VolunteerRecruitModule from './che_의병모집.js'; import type * as RecruitModule from './che_징병.js'; import type * as RestModule from './휴식.js'; -export type GeneralTurnCommandKey = - | 'che_거병' - | 'che_임관' - | 'che_건국' - | 'che_훈련' - | 'che_사기진작' - | 'che_요양' - | 'che_출병' - | 'che_주민선정' - | 'che_농지개간' - | 'che_상업투자' - | 'che_기술연구' - | 'che_치안강화' - | 'che_수비강화' - | 'che_성벽보수' - | 'che_화계' - | 'che_인재탐색' - | 'che_의병모집' - | 'che_징병' - | '휴식'; - -export const GENERAL_TURN_COMMAND_KEYS: GeneralTurnCommandKey[] = [ - 'che_거병', - 'che_임관', - 'che_건국', - 'che_훈련', - 'che_사기진작', - 'che_요양', - 'che_출병', - 'che_주민선정', - 'che_농지개간', - 'che_상업투자', - 'che_기술연구', - 'che_치안강화', - 'che_수비강화', - 'che_성벽보수', - 'che_화계', - 'che_인재탐색', - 'che_의병모집', - 'che_징병', - '휴식', -]; - -export const isGeneralTurnCommandKey = ( - value: string -): value is GeneralTurnCommandKey => - (GENERAL_TURN_COMMAND_KEYS as string[]).includes(value); - -export interface GeneralTurnCommandSpec { - key: GeneralTurnCommandKey; - category: string; - reqArg: boolean; - args: Record; - createDefinition(env: TurnCommandEnv): GeneralActionDefinition; -} - export type GeneralTurnCommandModule = | typeof UprisingModule | typeof AppointmentModule @@ -99,10 +43,7 @@ export type GeneralTurnCommandModule = export type GeneralTurnCommandImporter = () => Promise; -const defaultImporters: Record< - GeneralTurnCommandKey, - GeneralTurnCommandImporter -> = { +const defaultImporters = { che_거병: async () => import('./che_거병.js'), che_임관: async () => import('./che_임관.js'), che_건국: async () => import('./che_건국.js'), @@ -122,7 +63,27 @@ const defaultImporters: Record< 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); + +export interface GeneralTurnCommandSpec { + key: GeneralTurnCommandKey; + category: string; + reqArg: boolean; + args: Record; + createDefinition(env: TurnCommandEnv): GeneralActionDefinition; +} export class GeneralTurnCommandLoader { constructor( @@ -130,7 +91,7 @@ export class GeneralTurnCommandLoader { GeneralTurnCommandKey, GeneralTurnCommandImporter > = defaultImporters - ) {} + ) { } async load( key: GeneralTurnCommandKey diff --git a/packages/logic/src/actions/turn/nation/index.ts b/packages/logic/src/actions/turn/nation/index.ts index 4249e77..61f8cbf 100644 --- a/packages/logic/src/actions/turn/nation/index.ts +++ b/packages/logic/src/actions/turn/nation/index.ts @@ -5,18 +5,26 @@ import type * as AwardModule from './che_포상.js'; import type * as AssignmentModule from './che_발령.js'; import type * as DeclarationModule from './che_선전포고.js'; -export type NationTurnCommandKey = - | '휴식' - | 'che_포상' - | 'che_발령' - | 'che_선전포고'; -export const NATION_TURN_COMMAND_KEYS: NationTurnCommandKey[] = [ - '휴식', - 'che_포상', - 'che_발령', - 'che_선전포고', -]; + +export type NationTurnCommandModule = + | typeof NationRestModule + | typeof AwardModule + | typeof AssignmentModule + | typeof DeclarationModule; + +export type NationTurnCommandImporter = () => Promise; + +const defaultImporters = { + 휴식: async () => import('./휴식.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 @@ -31,23 +39,6 @@ export interface NationTurnCommandSpec { createDefinition(env: TurnCommandEnv): GeneralActionDefinition; } -export type NationTurnCommandModule = - | typeof NationRestModule - | typeof AwardModule - | typeof AssignmentModule - | typeof DeclarationModule; - -export type NationTurnCommandImporter = () => Promise; - -const defaultImporters: Record< - NationTurnCommandKey, - NationTurnCommandImporter -> = { - 휴식: async () => import('./휴식.js'), - che_포상: async () => import('./che_포상.js'), - che_발령: async () => import('./che_발령.js'), - che_선전포고: async () => import('./che_선전포고.js'), -}; export class NationTurnCommandLoader { constructor( @@ -55,7 +46,7 @@ export class NationTurnCommandLoader { NationTurnCommandKey, NationTurnCommandImporter > = defaultImporters - ) {} + ) { } async load( key: NationTurnCommandKey