diff --git a/app/game-engine/src/turn/databaseHooks.ts b/app/game-engine/src/turn/databaseHooks.ts index cd64f02..8174f3c 100644 --- a/app/game-engine/src/turn/databaseHooks.ts +++ b/app/game-engine/src/turn/databaseHooks.ts @@ -18,7 +18,7 @@ import { finalizeLogEntry, type LogEntryDraft } from '@sammo-ts/logic'; import type { TurnDaemonHooks } from '../lifecycle/types.js'; import type { InMemoryTurnWorld } from './inMemoryWorld.js'; import type { InMemoryReservedTurnStore } from './reservedTurnStore.js'; -import { buildDiplomacyMeta } from './diplomacy.js'; +import { buildDiplomacyMeta } from '@sammo-ts/logic'; export interface DatabaseTurnHooks { hooks: TurnDaemonHooks; diff --git a/app/game-engine/src/turn/inMemoryWorld.ts b/app/game-engine/src/turn/inMemoryWorld.ts index ffe6ba7..2005680 100644 --- a/app/game-engine/src/turn/inMemoryWorld.ts +++ b/app/game-engine/src/turn/inMemoryWorld.ts @@ -20,7 +20,7 @@ import { buildDiplomacyKey, processDiplomacyMonth, type DiplomacyPatch, -} from './diplomacy.js'; +} from '@sammo-ts/logic'; export interface GeneralTurnContext { general: TurnGeneral; diff --git a/app/game-engine/src/turn/reservedTurnHandler.ts b/app/game-engine/src/turn/reservedTurnHandler.ts index 5e41a89..0cd3af9 100644 --- a/app/game-engine/src/turn/reservedTurnHandler.ts +++ b/app/game-engine/src/turn/reservedTurnHandler.ts @@ -35,7 +35,7 @@ import { buildDefaultDiplomacy, buildDiplomacyKey, type DiplomacyPatch, -} from './diplomacy.js'; +} from '@sammo-ts/logic'; import { buildCommandEnv, buildReservedTurnDefinitions, diff --git a/app/game-engine/src/turn/worldLoader.ts b/app/game-engine/src/turn/worldLoader.ts index 821c34f..3a82501 100644 --- a/app/game-engine/src/turn/worldLoader.ts +++ b/app/game-engine/src/turn/worldLoader.ts @@ -24,7 +24,7 @@ import { loadMapDefinitionByName } from '../scenario/mapLoader.js'; import type { UnitSetLoaderOptions } from '../scenario/unitSetLoader.js'; import { loadUnitSetDefinitionByName } from '../scenario/unitSetLoader.js'; import type { TurnDiplomacy, TurnGeneral, TurnWorldLoadResult } from './types.js'; -import { readDiplomacyMeta } from './diplomacy.js'; +import { readDiplomacyMeta } from '@sammo-ts/logic'; interface TurnWorldLoaderOptions { databaseUrl: string; diff --git a/app/game-engine/src/turn/diplomacy.ts b/packages/logic/src/diplomacy/index.ts similarity index 89% rename from app/game-engine/src/turn/diplomacy.ts rename to packages/logic/src/diplomacy/index.ts index ff2a509..8f421f1 100644 --- a/app/game-engine/src/turn/diplomacy.ts +++ b/packages/logic/src/diplomacy/index.ts @@ -1,4 +1,3 @@ -import type { TurnDiplomacy } from './types.js'; import { clamp } from 'es-toolkit'; // 외교 상태 코드 (legacy 기준). @@ -15,20 +14,14 @@ export const DEFAULT_WAR_TERM = 6; // TODO: 불가침 제의/수락 등 외교 커맨드 전환 규칙을 이 모듈에 추가 예정. const MAX_WAR_TERM = 13; -export const buildDiplomacyKey = (srcNationId: number, destNationId: number): string => - `${srcNationId}:${destNationId}`; - -export const buildDefaultDiplomacy = ( - srcNationId: number, - destNationId: number -): TurnDiplomacy => ({ - fromNationId: srcNationId, - toNationId: destNationId, - state: DIPLOMACY_STATE.TRADE, - term: 0, - dead: 0, - meta: {}, -}); +export interface DiplomacyEntry { + fromNationId: number; + toNationId: number; + state: number; + term: number; + dead: number; + meta: Record; +} export interface DiplomacyPatch { state?: number; @@ -38,10 +31,27 @@ export interface DiplomacyPatch { meta?: Record; } +export const buildDiplomacyKey = ( + srcNationId: number, + destNationId: number +): string => `${srcNationId}:${destNationId}`; + +export const buildDefaultDiplomacy = ( + srcNationId: number, + destNationId: number +): DiplomacyEntry => ({ + fromNationId: srcNationId, + toNationId: destNationId, + state: DIPLOMACY_STATE.TRADE, + term: 0, + dead: 0, + meta: {}, +}); + export const applyDiplomacyPatch = ( - entry: TurnDiplomacy, + entry: DiplomacyEntry, patch: DiplomacyPatch -): TurnDiplomacy => { +): DiplomacyEntry => { const nextDead = typeof patch.dead === 'number' ? patch.dead @@ -68,21 +78,22 @@ export const readDiplomacyMeta = ( }; export const buildDiplomacyMeta = ( - entry: TurnDiplomacy + entry: DiplomacyEntry ): Record => ({ ...entry.meta, dead: entry.dead, }); + export const processDiplomacyMonth = ( - diplomacy: TurnDiplomacy[], + diplomacy: DiplomacyEntry[], generalCounts: Map -): TurnDiplomacy[] => { +): DiplomacyEntry[] => { const next = diplomacy.map((entry) => ({ ...entry, meta: { ...entry.meta }, })); - const byKey = new Map( + const byKey = new Map( next.map((entry) => [ buildDiplomacyKey(entry.fromNationId, entry.toNationId), entry, diff --git a/packages/logic/src/index.ts b/packages/logic/src/index.ts index b0536cf..a756467 100644 --- a/packages/logic/src/index.ts +++ b/packages/logic/src/index.ts @@ -2,6 +2,7 @@ export * from './domain/entities.js'; export type { RandomGenerator } from '@sammo-ts/common'; export * from './actions/index.js'; export * from './constraints/index.js'; +export * from './diplomacy/index.js'; export * from './logging/index.js'; export * from './messages/index.js'; export * from './items/index.js'; diff --git a/app/game-engine/test/diplomacy.test.ts b/packages/logic/test/diplomacy.test.ts similarity index 95% rename from app/game-engine/test/diplomacy.test.ts rename to packages/logic/test/diplomacy.test.ts index 6486090..f351c9d 100644 --- a/app/game-engine/test/diplomacy.test.ts +++ b/packages/logic/test/diplomacy.test.ts @@ -4,8 +4,8 @@ import { DEFAULT_WAR_TERM, DIPLOMACY_STATE, processDiplomacyMonth, -} from '../src/turn/diplomacy.js'; -import type { TurnDiplomacy } from '../src/turn/types.js'; + type DiplomacyEntry, +} from '@sammo-ts/logic'; const buildEntry = ( fromNationId: number, @@ -13,7 +13,7 @@ const buildEntry = ( state: number, term: number, dead = 0 -): TurnDiplomacy => ({ +): DiplomacyEntry => ({ fromNationId, toNationId, state,