왕조 연감에 해당 기수의 지도 레이아웃을 적용한다
This commit is contained in:
@@ -66,8 +66,10 @@ const resolveMapName = async (
|
||||
}
|
||||
};
|
||||
|
||||
export const loadMapLayout = async (scenario: string, options: MapLayoutLoaderOptions = {}): Promise<MapLayout> => {
|
||||
const mapName = await resolveMapName(scenario, options.loadScenario ?? loadScenarioDefinitionById);
|
||||
export const loadMapLayoutByName = async (
|
||||
mapName: string,
|
||||
options: MapLayoutLoaderOptions = {}
|
||||
): Promise<MapLayout> => {
|
||||
const useCache = !options.loadScenario && !options.loadMap && !options.loadRegionMap;
|
||||
const cached = useCache ? layoutCache.get(mapName) : undefined;
|
||||
if (cached) {
|
||||
@@ -98,3 +100,8 @@ export const loadMapLayout = async (scenario: string, options: MapLayoutLoaderOp
|
||||
}
|
||||
return layout;
|
||||
};
|
||||
|
||||
export const loadMapLayout = async (scenario: string, options: MapLayoutLoaderOptions = {}): Promise<MapLayout> => {
|
||||
const mapName = await resolveMapName(scenario, options.loadScenario ?? loadScenarioDefinitionById);
|
||||
return loadMapLayoutByName(mapName, options);
|
||||
};
|
||||
|
||||
@@ -6,6 +6,7 @@ import { asRecord, isRecord } from '@sammo-ts/common';
|
||||
import { LogCategory, LogScope } from '@sammo-ts/logic';
|
||||
|
||||
import type { GameApiContext } from '../../context.js';
|
||||
import { loadMapLayout, loadMapLayoutByName } from '../../maps/mapLayout.js';
|
||||
import { loadPublicMap, type BaseMapResult } from '../../maps/worldMap.js';
|
||||
import {
|
||||
formatGeneralAccessLimitMessage,
|
||||
@@ -339,11 +340,23 @@ export const yearbookRouter = router({
|
||||
const firstYearMonth = firstRow ? joinYearMonth(firstRow.year, firstRow.month) : fallbackYearMonth;
|
||||
const lastYearMonth = lastRow ? joinYearMonth(lastRow.year, lastRow.month) : fallbackYearMonth;
|
||||
const selectedYearMonth = target.isCurrentProfile ? currentYearMonth : lastYearMonth;
|
||||
// Ref v_history.php resolves an archived generation's map from ng_games.map.
|
||||
const mapLayout = target.isCurrentProfile
|
||||
? await loadMapLayout(ctx.profile.scenario)
|
||||
: await loadMapLayoutByName(
|
||||
(
|
||||
await ctx.db.gameHistory.findUnique({
|
||||
where: { serverId: target.archiveKey },
|
||||
select: { map: true },
|
||||
})
|
||||
)?.map || 'che'
|
||||
);
|
||||
|
||||
return {
|
||||
firstYearMonth,
|
||||
lastYearMonth,
|
||||
currentYearMonth: selectedYearMonth,
|
||||
mapLayout,
|
||||
};
|
||||
}),
|
||||
getHistory: authedProcedure
|
||||
|
||||
@@ -142,6 +142,10 @@ const buildContext = (
|
||||
meta: options.worldMeta ?? { serverId: currentServerId },
|
||||
}),
|
||||
},
|
||||
gameHistory: {
|
||||
findUnique: async ({ where }: { where: { serverId: string } }) =>
|
||||
where.serverId === archiveServerId ? { map: 'miniche' } : null,
|
||||
},
|
||||
yearbookHistory: {
|
||||
findFirst: async (args: {
|
||||
where: { profileName: string; year?: number; month?: number };
|
||||
@@ -187,11 +191,13 @@ describe('historical yearbook access from dynasty', () => {
|
||||
const caller = appRouter.createCaller(buildContext(authFor('owner-a')));
|
||||
const result = await caller.yearbook.getRange({ serverID: archiveServerId });
|
||||
|
||||
expect(result).toEqual({
|
||||
expect(result).toMatchObject({
|
||||
firstYearMonth: 200 * 12,
|
||||
lastYearMonth: 200 * 12 + 1,
|
||||
currentYearMonth: 200 * 12 + 1,
|
||||
mapLayout: { mapName: 'miniche' },
|
||||
});
|
||||
expect(result.mapLayout.cityList.length).toBeGreaterThan(0);
|
||||
});
|
||||
|
||||
it('returns the same archived public history for distinct general owners', async () => {
|
||||
@@ -249,20 +255,22 @@ describe('historical yearbook access from dynasty', () => {
|
||||
|
||||
expect(canonical).toEqual(alias);
|
||||
expect(alias).toEqual(omitted);
|
||||
expect(canonical).toEqual({
|
||||
expect(canonical).toMatchObject({
|
||||
firstYearMonth: 219 * 12 + 11,
|
||||
lastYearMonth: 219 * 12 + 11,
|
||||
currentYearMonth: 220 * 12,
|
||||
mapLayout: { mapName: 'che' },
|
||||
});
|
||||
});
|
||||
|
||||
it('reads imported history under the short profile ID when world metadata has no server ID', async () => {
|
||||
const caller = appRouter.createCaller(buildContext(authFor('owner-a'), { worldMeta: {} }));
|
||||
|
||||
await expect(caller.yearbook.getRange()).resolves.toEqual({
|
||||
await expect(caller.yearbook.getRange()).resolves.toMatchObject({
|
||||
firstYearMonth: 219 * 12 + 10,
|
||||
lastYearMonth: 219 * 12 + 10,
|
||||
currentYearMonth: 220 * 12,
|
||||
mapLayout: { mapName: 'che' },
|
||||
});
|
||||
});
|
||||
|
||||
|
||||
Reference in New Issue
Block a user