merge: 턴 입력기 연월 경계 수정을 main에 반영한다
This commit is contained in:
@@ -45,6 +45,7 @@ import {
|
|||||||
import {
|
import {
|
||||||
resolveGeneralTypeCall,
|
resolveGeneralTypeCall,
|
||||||
resolveLeadershipBonus,
|
resolveLeadershipBonus,
|
||||||
|
resolveNextTurnMonthOffset,
|
||||||
resolveRefreshScoreText,
|
resolveRefreshScoreText,
|
||||||
resolveRemainingMinutes,
|
resolveRemainingMinutes,
|
||||||
} from '../../services/generalBasicCardProjection.js';
|
} from '../../services/generalBasicCardProjection.js';
|
||||||
@@ -265,6 +266,7 @@ export const getGeneralContext = async (ctx: GameApiContext) => {
|
|||||||
dedication: true,
|
dedication: true,
|
||||||
age: true,
|
age: true,
|
||||||
turnTime: true,
|
turnTime: true,
|
||||||
|
turnTick: true,
|
||||||
recentWarTime: true,
|
recentWarTime: true,
|
||||||
crewTypeId: true,
|
crewTypeId: true,
|
||||||
personalCode: true,
|
personalCode: true,
|
||||||
@@ -333,7 +335,14 @@ export const getGeneralContext = async (ctx: GameApiContext) => {
|
|||||||
})
|
})
|
||||||
: Promise.resolve(NEUTRAL_NATION_CONTEXT),
|
: Promise.resolve(NEUTRAL_NATION_CONTEXT),
|
||||||
ctx.db.worldState.findFirst({
|
ctx.db.worldState.findFirst({
|
||||||
select: { currentYear: true, currentMonth: true, tickSeconds: true, config: true, meta: true },
|
select: {
|
||||||
|
currentYear: true,
|
||||||
|
currentMonth: true,
|
||||||
|
tickSeconds: true,
|
||||||
|
lastTurnTick: true,
|
||||||
|
config: true,
|
||||||
|
meta: true,
|
||||||
|
},
|
||||||
}),
|
}),
|
||||||
officerCityId > 0
|
officerCityId > 0
|
||||||
? ctx.db.city.findUnique({ where: { id: officerCityId }, select: { name: true } })
|
? ctx.db.city.findUnique({ where: { id: officerCityId }, select: { name: true } })
|
||||||
@@ -521,6 +530,13 @@ export const getGeneralContext = async (ctx: GameApiContext) => {
|
|||||||
age: general.age,
|
age: general.age,
|
||||||
retirementYear,
|
retirementYear,
|
||||||
turnTime: general.turnTime.toISOString(),
|
turnTime: general.turnTime.toISOString(),
|
||||||
|
nextTurnMonthOffset: resolveNextTurnMonthOffset({
|
||||||
|
turnTime: general.turnTime,
|
||||||
|
turnTick: general.turnTick,
|
||||||
|
lastExecuted: parsedLastExecuted,
|
||||||
|
lastTurnTick: worldState?.lastTurnTick,
|
||||||
|
turnSeconds: worldState?.tickSeconds ?? 0,
|
||||||
|
}),
|
||||||
recentWar: general.recentWarTime?.toISOString() ?? null,
|
recentWar: general.recentWarTime?.toISOString() ?? null,
|
||||||
defenceTrain: settings.defence_train,
|
defenceTrain: settings.defence_train,
|
||||||
killTurn: readNumber(metaRecord.killturn ?? metaRecord.killTurn, 0),
|
killTurn: readNumber(metaRecord.killturn ?? metaRecord.killTurn, 0),
|
||||||
|
|||||||
@@ -1,3 +1,5 @@
|
|||||||
|
import { GAME_TICKS_PER_TURN } from '@sammo-ts/common';
|
||||||
|
|
||||||
export interface GeneralBasicStats {
|
export interface GeneralBasicStats {
|
||||||
leadership: number;
|
leadership: number;
|
||||||
strength: number;
|
strength: number;
|
||||||
@@ -53,3 +55,41 @@ export const resolveRemainingMinutes = (
|
|||||||
}
|
}
|
||||||
return Math.floor(Math.min(999, Math.max(0, (nextTurnMillis - lastExecuted.getTime()) / 60_000)));
|
return Math.floor(Math.min(999, Math.max(0, (nextTurnMillis - lastExecuted.getTime()) / 60_000)));
|
||||||
};
|
};
|
||||||
|
|
||||||
|
export interface NextTurnMonthOffsetInput {
|
||||||
|
turnTime: Date;
|
||||||
|
turnTick?: bigint | number | null;
|
||||||
|
lastExecuted: Date | null;
|
||||||
|
lastTurnTick?: bigint | number | null;
|
||||||
|
turnSeconds: number;
|
||||||
|
}
|
||||||
|
|
||||||
|
const normalizeTick = (value: bigint | number | null | undefined): bigint | null => {
|
||||||
|
if (typeof value === 'bigint') return value;
|
||||||
|
if (typeof value === 'number' && Number.isSafeInteger(value)) return BigInt(value);
|
||||||
|
return null;
|
||||||
|
};
|
||||||
|
|
||||||
|
const turnBucket = (tick: bigint): bigint => {
|
||||||
|
const ticksPerTurn = BigInt(GAME_TICKS_PER_TURN);
|
||||||
|
const quotient = tick / ticksPerTurn;
|
||||||
|
return tick % ticksPerTurn < 0 ? quotient - 1n : quotient;
|
||||||
|
};
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Ref Command.GetReservedCommand cuts both clocks to a gameplay-turn bucket.
|
||||||
|
* A general in the next bucket has already acted in the displayed world month,
|
||||||
|
* so the first reserved command belongs to the following month.
|
||||||
|
*/
|
||||||
|
export const resolveNextTurnMonthOffset = (input: NextTurnMonthOffsetInput): 0 | 1 => {
|
||||||
|
const turnTick = normalizeTick(input.turnTick);
|
||||||
|
const lastTurnTick = normalizeTick(input.lastTurnTick);
|
||||||
|
if (turnTick !== null && lastTurnTick !== null) {
|
||||||
|
return turnBucket(turnTick) > turnBucket(lastTurnTick) ? 1 : 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
const turnTimeMs = input.turnTime.getTime();
|
||||||
|
const lastExecutedMs = input.lastExecuted?.getTime() ?? Number.NaN;
|
||||||
|
if (!Number.isFinite(turnTimeMs) || !Number.isFinite(lastExecutedMs) || input.turnSeconds <= 0) return 0;
|
||||||
|
return turnTimeMs >= lastExecutedMs + input.turnSeconds * 1_000 ? 1 : 0;
|
||||||
|
};
|
||||||
|
|||||||
@@ -3,6 +3,7 @@ import { describe, expect, it } from 'vitest';
|
|||||||
import {
|
import {
|
||||||
resolveGeneralTypeCall,
|
resolveGeneralTypeCall,
|
||||||
resolveLeadershipBonus,
|
resolveLeadershipBonus,
|
||||||
|
resolveNextTurnMonthOffset,
|
||||||
resolveRefreshScoreText,
|
resolveRefreshScoreText,
|
||||||
resolveRemainingMinutes,
|
resolveRemainingMinutes,
|
||||||
} from '../src/services/generalBasicCardProjection.js';
|
} from '../src/services/generalBasicCardProjection.js';
|
||||||
@@ -41,4 +42,55 @@ describe('general basic card Ref projection', () => {
|
|||||||
expect(resolveRemainingMinutes(new Date('2026-08-12T23:59:00.000Z'), lastExecuted, 3_600)).toBe(59);
|
expect(resolveRemainingMinutes(new Date('2026-08-12T23:59:00.000Z'), lastExecuted, 3_600)).toBe(59);
|
||||||
expect(resolveRemainingMinutes(new Date('2026-08-13T00:07:06.000Z'), null, 3_600)).toBeNull();
|
expect(resolveRemainingMinutes(new Date('2026-08-13T00:07:06.000Z'), null, 3_600)).toBeNull();
|
||||||
});
|
});
|
||||||
|
|
||||||
|
it('moves the first reserved month only after the general turn bucket has passed', () => {
|
||||||
|
const lastExecuted = new Date('2026-08-13T00:00:00.000Z');
|
||||||
|
const lastTurnTick = 36_000_000n * 11n;
|
||||||
|
|
||||||
|
expect(
|
||||||
|
resolveNextTurnMonthOffset({
|
||||||
|
turnTime: new Date('2026-08-13T00:07:00.000Z'),
|
||||||
|
turnTick: lastTurnTick + 12_000_000n,
|
||||||
|
lastExecuted,
|
||||||
|
lastTurnTick,
|
||||||
|
turnSeconds: 600,
|
||||||
|
})
|
||||||
|
).toBe(0);
|
||||||
|
expect(
|
||||||
|
resolveNextTurnMonthOffset({
|
||||||
|
turnTime: new Date('2026-08-13T00:17:00.000Z'),
|
||||||
|
turnTick: lastTurnTick + 48_000_000n,
|
||||||
|
lastExecuted,
|
||||||
|
lastTurnTick,
|
||||||
|
turnSeconds: 600,
|
||||||
|
})
|
||||||
|
).toBe(1);
|
||||||
|
expect(
|
||||||
|
resolveNextTurnMonthOffset({
|
||||||
|
turnTime: new Date('2026-08-13T00:10:00.000Z'),
|
||||||
|
turnTick: 1n,
|
||||||
|
lastExecuted,
|
||||||
|
lastTurnTick: -1n,
|
||||||
|
turnSeconds: 600,
|
||||||
|
})
|
||||||
|
).toBe(1);
|
||||||
|
});
|
||||||
|
|
||||||
|
it('keeps the same boundary for legacy Date-only schedules', () => {
|
||||||
|
const lastExecuted = new Date('2026-08-13T00:00:00.000Z');
|
||||||
|
expect(
|
||||||
|
resolveNextTurnMonthOffset({
|
||||||
|
turnTime: new Date('2026-08-13T00:07:00.000Z'),
|
||||||
|
lastExecuted,
|
||||||
|
turnSeconds: 600,
|
||||||
|
})
|
||||||
|
).toBe(0);
|
||||||
|
expect(
|
||||||
|
resolveNextTurnMonthOffset({
|
||||||
|
turnTime: new Date('2026-08-13T00:10:00.000Z'),
|
||||||
|
lastExecuted,
|
||||||
|
turnSeconds: 600,
|
||||||
|
})
|
||||||
|
).toBe(1);
|
||||||
|
});
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -34,6 +34,7 @@ type NavigationFixture = {
|
|||||||
operations: string[];
|
operations: string[];
|
||||||
generalName?: string;
|
generalName?: string;
|
||||||
generalTurnTime?: string;
|
generalTurnTime?: string;
|
||||||
|
nextTurnMonthOffset?: 0 | 1;
|
||||||
serverTime?: string;
|
serverTime?: string;
|
||||||
serverWallTime?: string;
|
serverWallTime?: string;
|
||||||
clockMode?: 'realtime' | 'manual';
|
clockMode?: 'realtime' | 'manual';
|
||||||
@@ -440,6 +441,7 @@ const generalContext = (state: NavigationFixture) => ({
|
|||||||
crewTypeName: '보병',
|
crewTypeName: '보병',
|
||||||
traits: { personal: '대담', specialDomestic: '상재', specialWar: '무쌍' },
|
traits: { personal: '대담', specialDomestic: '상재', specialWar: '무쌍' },
|
||||||
turnTime: state.generalTurnTime ?? '0185-01-01T00:00:00.000Z',
|
turnTime: state.generalTurnTime ?? '0185-01-01T00:00:00.000Z',
|
||||||
|
nextTurnMonthOffset: state.nextTurnMonthOffset ?? 0,
|
||||||
},
|
},
|
||||||
city: {
|
city: {
|
||||||
id: 1,
|
id: 1,
|
||||||
@@ -1623,6 +1625,105 @@ test('the repeated bottom global menu opens upward on the mobile document', asyn
|
|||||||
await persistArtifact(page, `${basePath.slice(1)}-mobile-bottom-dropup`);
|
await persistArtifact(page, `${basePath.slice(1)}-mobile-bottom-dropup`);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
test('first reserved month crosses December only after the general turn has passed', async ({ page }, testInfo) => {
|
||||||
|
const state: NavigationFixture = {
|
||||||
|
officerLevel: 0,
|
||||||
|
permission: 0,
|
||||||
|
nationLevel: 0,
|
||||||
|
stage: 0,
|
||||||
|
npcMode: 1,
|
||||||
|
generalMeCalls: 0,
|
||||||
|
operations: [],
|
||||||
|
currentYear: 179,
|
||||||
|
currentMonth: 12,
|
||||||
|
nextTurnMonthOffset: 0,
|
||||||
|
validMapImages: true,
|
||||||
|
reservedTurns: [
|
||||||
|
{ index: 0, action: '휴식', args: {} },
|
||||||
|
{ index: 1, action: '휴식', args: {} },
|
||||||
|
],
|
||||||
|
};
|
||||||
|
await installRealtimeHarness(page);
|
||||||
|
await installFixture(page, state);
|
||||||
|
await page.setViewportSize({ width: 1200, height: 900 });
|
||||||
|
await waitForMain(page);
|
||||||
|
await waitForMainRealtime(page);
|
||||||
|
|
||||||
|
const map = page.locator('[data-main-target="map"] .map-viewer').first();
|
||||||
|
const commandPanel = page.locator('[data-main-target="commands"]').first();
|
||||||
|
const firstDate = commandPanel.locator('.date-column [data-turn-index="0"]');
|
||||||
|
const secondDate = commandPanel.locator('.date-column [data-turn-index="1"]');
|
||||||
|
|
||||||
|
await expect(map).toContainText('179年 12月');
|
||||||
|
await expect(firstDate).toHaveText('179年 12月');
|
||||||
|
await expect(secondDate).toHaveText('180年 1月');
|
||||||
|
const before = await firstDate.evaluate((element) => {
|
||||||
|
const rect = element.getBoundingClientRect();
|
||||||
|
const style = getComputedStyle(element);
|
||||||
|
return {
|
||||||
|
rect: rect.toJSON(),
|
||||||
|
fontSize: style.fontSize,
|
||||||
|
lineHeight: style.lineHeight,
|
||||||
|
color: style.color,
|
||||||
|
documentScrollWidth: document.documentElement.scrollWidth,
|
||||||
|
viewportWidth: window.innerWidth,
|
||||||
|
};
|
||||||
|
});
|
||||||
|
await commandPanel.screenshot({ path: testInfo.outputPath('turn-month-before.png') });
|
||||||
|
|
||||||
|
state.nextTurnMonthOffset = 1;
|
||||||
|
state.contextRevision = 'BBBBBBBBBBBBBBBBBBBBBB';
|
||||||
|
state.contextOperations = [{ op: 'replace', path: '/general/nextTurnMonthOffset', value: 1 }];
|
||||||
|
await emitReadModelInvalidation(page, readModelInvalidation({ context: true }));
|
||||||
|
|
||||||
|
await expect(map).toContainText('179年 12月');
|
||||||
|
await expect(firstDate).toHaveText('180年 1月');
|
||||||
|
await expect(secondDate).toHaveText('180年 2月');
|
||||||
|
await firstDate.hover();
|
||||||
|
const after = await firstDate.evaluate((element) => {
|
||||||
|
const rect = element.getBoundingClientRect();
|
||||||
|
const style = getComputedStyle(element);
|
||||||
|
return {
|
||||||
|
rect: rect.toJSON(),
|
||||||
|
fontSize: style.fontSize,
|
||||||
|
lineHeight: style.lineHeight,
|
||||||
|
color: style.color,
|
||||||
|
documentScrollWidth: document.documentElement.scrollWidth,
|
||||||
|
viewportWidth: window.innerWidth,
|
||||||
|
};
|
||||||
|
});
|
||||||
|
expect(after.rect.width).toBe(before.rect.width);
|
||||||
|
expect(after.rect.height).toBe(before.rect.height);
|
||||||
|
expect(after.rect.left).toBe(before.rect.left);
|
||||||
|
expect(after.rect.right).toBe(before.rect.right);
|
||||||
|
expect(after.fontSize).toBe(before.fontSize);
|
||||||
|
expect(after.lineHeight).toBe(before.lineHeight);
|
||||||
|
expect(after.color).toBe(before.color);
|
||||||
|
expect(before.documentScrollWidth).toBe(before.viewportWidth);
|
||||||
|
expect(after.documentScrollWidth).toBe(after.viewportWidth);
|
||||||
|
await commandPanel.screenshot({ path: testInfo.outputPath('turn-month-after.png') });
|
||||||
|
|
||||||
|
await page.setViewportSize({ width: 390, height: 844 });
|
||||||
|
await firstDate.scrollIntoViewIfNeeded();
|
||||||
|
await expect(firstDate).toHaveText('180年 1月');
|
||||||
|
const mobile = await firstDate.evaluate((element) => {
|
||||||
|
const rect = element.getBoundingClientRect();
|
||||||
|
const style = getComputedStyle(element);
|
||||||
|
return {
|
||||||
|
rect: rect.toJSON(),
|
||||||
|
fontSize: style.fontSize,
|
||||||
|
lineHeight: style.lineHeight,
|
||||||
|
documentScrollWidth: document.documentElement.scrollWidth,
|
||||||
|
};
|
||||||
|
});
|
||||||
|
expect(mobile.rect.left).toBeGreaterThanOrEqual(0);
|
||||||
|
expect(mobile.rect.right).toBeLessThanOrEqual(500);
|
||||||
|
expect(mobile.fontSize).toBe(before.fontSize);
|
||||||
|
expect(mobile.lineHeight).toBe(before.lineHeight);
|
||||||
|
expect(mobile.documentScrollWidth).toBe(500);
|
||||||
|
await commandPanel.screenshot({ path: testInfo.outputPath('turn-month-mobile.png') });
|
||||||
|
});
|
||||||
|
|
||||||
test('main general card uses local turn time and command clock tracks corrected server time', async ({ page }) => {
|
test('main general card uses local turn time and command clock tracks corrected server time', async ({ page }) => {
|
||||||
const state: NavigationFixture = {
|
const state: NavigationFixture = {
|
||||||
officerLevel: 0,
|
officerLevel: 0,
|
||||||
|
|||||||
@@ -15,7 +15,7 @@ const props = defineProps<{
|
|||||||
commandTable: CommandTable | null;
|
commandTable: CommandTable | null;
|
||||||
loading: boolean;
|
loading: boolean;
|
||||||
reservedGeneralTurns: Array<{ index: number; action: string; args?: unknown }> | null;
|
reservedGeneralTurns: Array<{ index: number; action: string; args?: unknown }> | null;
|
||||||
general: { id: number; turnTime?: string } | null;
|
general: { id: number; turnTime?: string; nextTurnMonthOffset?: 0 | 1 } | null;
|
||||||
currentYear?: number;
|
currentYear?: number;
|
||||||
currentMonth?: number;
|
currentMonth?: number;
|
||||||
turnTermMinutes?: number;
|
turnTermMinutes?: number;
|
||||||
@@ -44,13 +44,19 @@ const labelMap = computed(() => {
|
|||||||
return result;
|
return result;
|
||||||
});
|
});
|
||||||
|
|
||||||
|
const firstReservedMonth = computed(
|
||||||
|
() =>
|
||||||
|
(props.currentYear ?? 0) * 12 +
|
||||||
|
(props.currentMonth ?? 1) -
|
||||||
|
1 +
|
||||||
|
(props.general?.nextTurnMonthOffset ?? 0)
|
||||||
|
);
|
||||||
|
|
||||||
const rows = computed<ReservedCommandRow[]>(() => {
|
const rows = computed<ReservedCommandRow[]>(() => {
|
||||||
const base = props.general?.turnTime ? new Date(props.general.turnTime) : null;
|
const base = props.general?.turnTime ? new Date(props.general.turnTime) : null;
|
||||||
const term = props.turnTermMinutes ?? 0;
|
const term = props.turnTermMinutes ?? 0;
|
||||||
const baseYear = props.currentYear ?? 0;
|
|
||||||
const baseMonth = props.currentMonth ?? 1;
|
|
||||||
return (props.reservedGeneralTurns ?? []).map((turn, offset) => {
|
return (props.reservedGeneralTurns ?? []).map((turn, offset) => {
|
||||||
const absoluteMonth = baseYear * 12 + baseMonth - 1 + offset;
|
const absoluteMonth = firstReservedMonth.value + offset;
|
||||||
const date = base && Number.isFinite(base.getTime()) ? addMinutes(base, offset * term) : null;
|
const date = base && Number.isFinite(base.getTime()) ? addMinutes(base, offset * term) : null;
|
||||||
return {
|
return {
|
||||||
...turn,
|
...turn,
|
||||||
@@ -70,9 +76,7 @@ const rows = computed<ReservedCommandRow[]>(() => {
|
|||||||
|
|
||||||
const autonomousUntil = computed(() => {
|
const autonomousUntil = computed(() => {
|
||||||
if (props.autorunLimit == null) return null;
|
if (props.autorunLimit == null) return null;
|
||||||
const baseYear = props.currentYear ?? 0;
|
const currentAbsoluteMonth = firstReservedMonth.value;
|
||||||
const baseMonth = props.currentMonth ?? 1;
|
|
||||||
const currentAbsoluteMonth = baseYear * 12 + baseMonth - 1;
|
|
||||||
const lastAutonomousMonth = props.autorunLimit - 1;
|
const lastAutonomousMonth = props.autorunLimit - 1;
|
||||||
if (lastAutonomousMonth < currentAbsoluteMonth) return null;
|
if (lastAutonomousMonth < currentAbsoluteMonth) return null;
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user