diff --git a/app/game-api/src/messages/targets.ts b/app/game-api/src/messages/targets.ts index 7990f85f..644bd168 100644 --- a/app/game-api/src/messages/targets.ts +++ b/app/game-api/src/messages/targets.ts @@ -7,8 +7,6 @@ const DEFAULT_NATION = { color: '#000000', }; -const DEFAULT_SHARED_ICON_PUBLIC_URL = 'https://sam-image.hided.net/icons'; - export const resolveNationInfo = async ( db: DatabaseClient, nationId: number @@ -25,14 +23,13 @@ export const resolveNationInfo = async ( export const buildTargetFromGeneral = async (db: DatabaseClient, general: GeneralRow): Promise => { const nation = await resolveNationInfo(db, general.nationId); - const picture = general.picture?.trim() || 'default.jpg'; return { generalId: general.id, generalName: general.name, nationId: general.nationId, nationName: nation.name, color: nation.color, - icon: general.imageServer ? `d_pic/${picture}` : `${DEFAULT_SHARED_ICON_PUBLIC_URL}/${picture}`, + icon: resolveMessageTargetIcon({ picture: general.picture, imageServer: general.imageServer }), }; }; diff --git a/app/game-engine/src/auction/bidder.ts b/app/game-engine/src/auction/bidder.ts index b0c9a5a2..7b68fbec 100644 --- a/app/game-engine/src/auction/bidder.ts +++ b/app/game-engine/src/auction/bidder.ts @@ -1,3 +1,4 @@ +import { resolveMessageTargetIcon } from '@sammo-ts/logic'; import { randomUUID } from 'node:crypto'; import { createGamePostgresConnector, GamePrisma, type GamePrismaClient } from '@sammo-ts/infra'; @@ -106,7 +107,7 @@ export const buildAuctionOutbidRefundMessage = (options: { nationId: options.bidder.nationId, nationName: options.nation?.name ?? '재야', color: options.nation?.color ?? '#000000', - icon: options.bidder.picture ?? '', + icon: resolveMessageTargetIcon(options.bidder), }, text: `${options.auctionId}번 ${options.title ?? '경매'}에 상회입찰자가 나타났습니다.`, time: new Date(options.time.getTime()), diff --git a/app/game-engine/src/auction/finalizer.ts b/app/game-engine/src/auction/finalizer.ts index 4700dd7b..deaffc17 100644 --- a/app/game-engine/src/auction/finalizer.ts +++ b/app/game-engine/src/auction/finalizer.ts @@ -1,3 +1,4 @@ +import { resolveMessageTargetIcon } from '@sammo-ts/logic'; import { createGamePostgresConnector, GamePrisma } from '@sammo-ts/infra'; import { ActionLogger, ItemLoader, LogFormat, isItemKey, type MessageDraft } from '@sammo-ts/logic'; import { resolveLegacyCompatibleUniqueConfig } from '@sammo-ts/logic/rewards/legacyUniqueItemPool.js'; @@ -124,7 +125,7 @@ export const buildAuctionBidderSystemMessage = (options: { nationId: options.bidder.nationId, nationName: options.nation?.name ?? '재야', color: options.nation?.color ?? '#000000', - icon: options.bidder.picture ?? '', + icon: resolveMessageTargetIcon(options.bidder), }, text: options.text, time: new Date(options.time.getTime()), diff --git a/app/game-engine/src/turn/monthlyNationBettingAction.ts b/app/game-engine/src/turn/monthlyNationBettingAction.ts index d769b4bf..807d1d85 100644 --- a/app/game-engine/src/turn/monthlyNationBettingAction.ts +++ b/app/game-engine/src/turn/monthlyNationBettingAction.ts @@ -1,3 +1,4 @@ +import { resolveMessageTargetIcon } from '@sammo-ts/logic'; import { LogCategory, LogFormat, LogScope } from '@sammo-ts/logic'; import type { InMemoryTurnWorld } from './inMemoryWorld.js'; @@ -127,7 +128,7 @@ export const createOpenNationBettingHandler = (options: { nationId: general.nationId, nationName: nation?.name ?? '재야', color: nation?.color ?? '#000000', - icon: general.picture ?? '', + icon: resolveMessageTargetIcon(general), }, text, time: now, diff --git a/app/game-engine/src/turn/reservedTurnHandler.ts b/app/game-engine/src/turn/reservedTurnHandler.ts index b33e4651..adad2135 100644 --- a/app/game-engine/src/turn/reservedTurnHandler.ts +++ b/app/game-engine/src/turn/reservedTurnHandler.ts @@ -1,3 +1,4 @@ +import { resolveMessageTargetIcon } from '@sammo-ts/logic'; import type { ActionContextBase, ActionContextBuilder, @@ -2121,7 +2122,7 @@ export const createReservedTurnHandler = async (options: { nationId: currentGeneral.nationId, nationName: currentNation?.name ?? '재야', color: currentNation?.color ?? '#000000', - icon: currentGeneral.picture ?? '', + icon: resolveMessageTargetIcon(currentGeneral), }; messages.push({ msgType: 'public', diff --git a/app/game-engine/src/turn/unificationHandler.ts b/app/game-engine/src/turn/unificationHandler.ts index 5e85643f..cf60ca39 100644 --- a/app/game-engine/src/turn/unificationHandler.ts +++ b/app/game-engine/src/turn/unificationHandler.ts @@ -1,3 +1,4 @@ +import { resolveMessageTargetIcon } from '@sammo-ts/logic'; import { createHash } from 'node:crypto'; import { asNumber, asRecord, JosaUtil } from '@sammo-ts/common'; @@ -156,7 +157,7 @@ export const createUnificationHandler = (options: { nationId: winner.id, nationName: winner.name, color: winner.color, - icon: recipient.picture ?? '', + icon: resolveMessageTargetIcon(recipient), }, text: `이벤트 게임으로 이민족[${invader.difficulty}]을 소환`, time: context.turnTime, diff --git a/app/game-engine/src/turn/unificationPersistence.ts b/app/game-engine/src/turn/unificationPersistence.ts index d4cfbc8e..6f51db89 100644 --- a/app/game-engine/src/turn/unificationPersistence.ts +++ b/app/game-engine/src/turn/unificationPersistence.ts @@ -1,3 +1,4 @@ +import { resolveMessageTargetIcon } from '@sammo-ts/logic'; import { areSeasonRecordsFinalized } from './seasonRecords.js'; import { asRecord, HALL_OF_FAME_TYPES, resolveLegacyTextColor, type HallOfFameType } from '@sammo-ts/common'; import { @@ -246,7 +247,7 @@ const cancelPendingUniqueAuctions = async ( nationId: bidder.nationId, nationName: nation?.name ?? '재야', color: nation?.color ?? '#000000', - icon: bidder.picture ?? '', + icon: resolveMessageTargetIcon(bidder), }, text: `${planned.auctionId}번 ${planned.title}가 취소되었습니다.`, time: input.completedAt, diff --git a/app/game-engine/test/npcGeneralDomesticTurn.test.ts b/app/game-engine/test/npcGeneralDomesticTurn.test.ts index a16ea720..1bbf2f45 100644 --- a/app/game-engine/test/npcGeneralDomesticTurn.test.ts +++ b/app/game-engine/test/npcGeneralDomesticTurn.test.ts @@ -105,6 +105,8 @@ describe('NPC 일반 내정 턴', () => { { id: 1, name: 'NPC_무장', + picture: '롤시나리오/다이애나.png', + imageServer: 0, nationId: 1, cityId: 1, troopId: 0, @@ -297,7 +299,12 @@ describe('NPC 일반 내정 턴', () => { expect.objectContaining({ msgType: 'public', text: '기부는 저처럼 돈 많은 사람들이 많이 하면 됩니다', - src: expect.objectContaining({ generalId: 1, generalName: 'NPC_무장', nationId: 1 }), + src: expect.objectContaining({ + generalId: 1, + generalName: 'NPC_무장', + nationId: 1, + icon: 'https://sam-image.hided.net/icons/롤시나리오/다이애나.png', + }), time: logicalGameNow, }) ); diff --git a/app/game-frontend/e2e/mainNavigation.spec.ts b/app/game-frontend/e2e/mainNavigation.spec.ts index c7241af9..269f50bd 100644 --- a/app/game-frontend/e2e/mainNavigation.spec.ts +++ b/app/game-frontend/e2e/mainNavigation.spec.ts @@ -6302,3 +6302,89 @@ for (const viewport of [ } }); } + +for (const viewport of [ + { width: 1200, height: 900 }, + { width: 390, height: 844 }, +]) { + test(`NPC message portraits resolve stored and new scenario icons at ${viewport.width}px`, async ({ + page, + }, testInfo) => { + const picture = '롤시나리오/다이애나.png'; + const iconUrl = `https://sam-image.hided.net/icons/${picture.split('/').map(encodeURIComponent).join('/')}`; + const asset = await readFile(resolve(process.cwd(), '../../../image/icons', picture)); + const defaultAsset = await readFile(resolve(process.cwd(), '../../../image/icons/default.jpg')); + const state: NavigationFixture = { + officerLevel: 1, + permission: 0, + nationLevel: 1, + stage: 0, + npcMode: 1, + generalMeCalls: 0, + operations: [], + messages: { + ...emptyMessages(0), + public: [picture, `https://sam-image.hided.net/icons/${picture}`, ''].map((icon, index) => ({ + id: 801 + index, + text: '새로운 달이 떠오르고 있다.', + time: '2026-09-07 12:00:00', + msgType: 'public', + src: { + generalId: 22 + index, + generalName: index === 2 ? '유저' : '다이애나', + nationId: 1, + nationName: '위', + color: '#008000', + icon, + }, + dest: null, + option: {}, + })), + }, + }; + await installFixture(page, state); + await page.route('https://sam-image.hided.net/icons/**', (route) => + route.fulfill({ + contentType: route.request().url() === iconUrl ? 'image/png' : 'image/jpeg', + body: route.request().url() === iconUrl ? asset : defaultAsset, + }) + ); + await page.setViewportSize(viewport); + await waitForMain(page); + const measurements = []; + for (const id of [801, 802, 803]) { + const icon = page.locator(`.msg-plate[data-id="${id}"]:visible img.general-icon`).first(); + await expect(icon).toBeVisible(); + await expect + .poll(() => icon.evaluate((element) => (element as HTMLImageElement).naturalWidth)) + .toBe(id === 803 ? 64 : 128); + const result = await icon.evaluate((element) => { + const image = element as HTMLImageElement; + const rect = image.getBoundingClientRect(); + return { + src: image.src, + width: rect.width, + height: rect.height, + naturalWidth: image.naturalWidth, + naturalHeight: image.naturalHeight, + objectFit: getComputedStyle(image).objectFit, + }; + }); + expect(result.src).toBe(id === 803 ? 'https://sam-image.hided.net/icons/default.jpg' : iconUrl); + expect(result.width).toBe(64); + expect(result.height).toBe(64); + measurements.push(result); + } + await page.reload(); + await expect(page.locator('.msg-plate[data-id="801"]:visible img').first()).toHaveAttribute('src', iconUrl); + await writeFile(testInfo.outputPath('icon-geometry.json'), JSON.stringify({ viewport, measurements }, null, 2)); + await writeFile( + testInfo.outputPath('messages.html'), + await page + .locator('.msg-plate[data-id="801"]:visible') + .first() + .evaluate((el) => el.outerHTML) + ); + await page.screenshot({ path: testInfo.outputPath('npc-message-icons.png'), fullPage: true }); + }); +} diff --git a/app/game-frontend/src/utils/generalIcon.ts b/app/game-frontend/src/utils/generalIcon.ts index 17be127f..4f6c07eb 100644 --- a/app/game-frontend/src/utils/generalIcon.ts +++ b/app/game-frontend/src/utils/generalIcon.ts @@ -4,7 +4,6 @@ import { DEFAULT_USER_ICON_PUBLIC_URL, externalizeLegacyImageUrl, } from './imageAssets.ts'; -import { gameFrontendRuntimeConfig } from '../config/runtimeConfig.ts'; export const DEFAULT_GENERAL_ICON_URL = `${configuredSharedIconPublicUrl()}/default.jpg`; export const DEFAULT_GATEWAY_USER_ICON_BASE_URL = DEFAULT_USER_ICON_PUBLIC_URL; @@ -69,7 +68,8 @@ export const resolveMessageGeneralIconUrl = ( if (normalized.startsWith('/') || /^https?:\/\//iu.test(normalized)) { return normalized; } - return `${gameFrontendRuntimeConfig.appBasePath}${normalized.replace(/^\/+/u, '')}`; + // 기존 NPC 대사와 알림에는 URL 대신 picture 상대 경로가 저장되어 있다. + return resolveGeneralIconUrl({ picture: normalized, imageServer: 0 }); }; export const useDefaultGeneralIcon = (event: Event): void => { diff --git a/app/game-frontend/test/generalIcon.test.ts b/app/game-frontend/test/generalIcon.test.ts index c2fc3ed7..8d67cbf5 100644 --- a/app/game-frontend/test/generalIcon.test.ts +++ b/app/game-frontend/test/generalIcon.test.ts @@ -52,6 +52,13 @@ void describe('generalIcon', () => { ); }); + void it('resolves stored NPC message pictures like directory icons across scenarios', () => { + for (const picture of ['롤시나리오/다이애나.png', '장수/관우 1.png', '22.jpg', 'default.jpg']) { + assert.equal(resolveMessageGeneralIconUrl(picture), resolveGeneralIconUrl({ picture, imageServer: 0 })); + } + assert.equal(resolveMessageGeneralIconUrl(null), resolveGeneralIconUrl({ picture: null })); + }); + void it('translates legacy message d_pic references without changing absolute or external icons', () => { assert.equal( resolveMessageGeneralIconUrl('d_pic/users/core2026/user name.jpg', '/gateway/api/user-icons/'),