fix: 커맨드 차등 생명주기와 로그 그래프를 보강
장수 55종과 수뇌 35종의 상태, 로그, 메시지, 예약 턴 비교를 닫습니다. 실제 시나리오 프로필과 대표 PostgreSQL 수명주기, 즉시 외교와 출병 회귀를 추가하고 발견된 Ref 로그 및 생성 장수 저장 차이를 교정합니다.
This commit is contained in:
@@ -1,5 +1,55 @@
|
||||
import { LogCategory, type LogEntryDraft, LogFormat, LogScope } from './types.js';
|
||||
|
||||
const legacyFlushBucket = (entry: LogEntryDraft): number => {
|
||||
if (entry.scope === LogScope.GENERAL) {
|
||||
switch (entry.category) {
|
||||
case LogCategory.HISTORY:
|
||||
return 0;
|
||||
case LogCategory.ACTION:
|
||||
return 1;
|
||||
case LogCategory.BATTLE_BRIEF:
|
||||
return 2;
|
||||
case LogCategory.BATTLE_DETAIL:
|
||||
return 3;
|
||||
}
|
||||
}
|
||||
if (entry.scope === LogScope.NATION && entry.category === LogCategory.HISTORY) {
|
||||
return 4;
|
||||
}
|
||||
if (entry.scope === LogScope.SYSTEM && entry.category === LogCategory.HISTORY) {
|
||||
return 5;
|
||||
}
|
||||
if (entry.scope === LogScope.SYSTEM && entry.category === LogCategory.SUMMARY) {
|
||||
return 6;
|
||||
}
|
||||
return 7;
|
||||
};
|
||||
|
||||
const orderLegacyFlushGroup = (entries: readonly LogEntryDraft[]): LogEntryDraft[] => {
|
||||
const buckets = Array.from({ length: 8 }, () => [] as LogEntryDraft[]);
|
||||
for (const entry of entries) {
|
||||
buckets[legacyFlushBucket(entry)]!.push(entry);
|
||||
}
|
||||
return buckets.flat();
|
||||
};
|
||||
|
||||
/** Ref ActionLogger별 flush 순서와 그 안의 대상/분류별 버퍼 순서를 보존한다. */
|
||||
export const orderLegacyActionLoggerFlush = (entries: readonly LogEntryDraft[]): LogEntryDraft[] => {
|
||||
const groups = new Map<number, LogEntryDraft[]>();
|
||||
for (const entry of entries) {
|
||||
const group = entry.legacyFlushGroup ?? 0;
|
||||
const groupedEntries = groups.get(group);
|
||||
if (groupedEntries) {
|
||||
groupedEntries.push(entry);
|
||||
} else {
|
||||
groups.set(group, [entry]);
|
||||
}
|
||||
}
|
||||
return [...groups.entries()]
|
||||
.sort(([left], [right]) => left - right)
|
||||
.flatMap(([, groupedEntries]) => orderLegacyFlushGroup(groupedEntries));
|
||||
};
|
||||
|
||||
export class ActionLogger {
|
||||
private readonly generalId: number | undefined;
|
||||
private readonly nationId: number | undefined;
|
||||
@@ -13,7 +63,7 @@ export class ActionLogger {
|
||||
// 장수/국가/전역 로그를 한번에 모아두고 외부에서 저장한다.
|
||||
public flush(): LogEntryDraft[] {
|
||||
const items = this.logs.splice(0, this.logs.length);
|
||||
return items;
|
||||
return orderLegacyActionLoggerFlush(items);
|
||||
}
|
||||
|
||||
public rollback(): LogEntryDraft[] {
|
||||
|
||||
@@ -33,6 +33,8 @@ export interface LogEntryDraft {
|
||||
month?: number;
|
||||
/** 로그를 만든 논리 게임 시각. 생략하면 flush context의 시각을 사용한다. */
|
||||
occurredAt?: Date;
|
||||
/** 하나의 명령에서 별도 Ref ActionLogger로 저장한 순서. 작은 그룹을 먼저 flush한다. */
|
||||
legacyFlushGroup?: number;
|
||||
}
|
||||
|
||||
export interface LogEntryRecord {
|
||||
|
||||
Reference in New Issue
Block a user