0.1.39 P0: missionIds prune + chronicle smart trim
This commit is contained in:
@@ -334,6 +334,13 @@ export class World {
|
||||
this.out.forEach((o) => o.onLog(kind, text))
|
||||
}
|
||||
|
||||
/**
|
||||
* 0.1.39 根治:chronicle 智能裁剪——保留全部 important=true 里程碑 +
|
||||
* 最近 MAX_NON_IMPORTANT 条非重要记录。旧版无差别 splice 会丢失关键里程碑。
|
||||
* 裁剪在 push 后触发,对调用方透明(不改变确定性序列——裁剪不消耗 rng)。
|
||||
*/
|
||||
private static readonly CHRONICLE_MAX_NON_IMPORTANT = 400
|
||||
|
||||
chronicle(cat: ChronicleEntry['category'], text: string, memberId?: Id, important = false): void {
|
||||
const entry: ChronicleEntry = {
|
||||
id: this.seq(),
|
||||
@@ -345,7 +352,16 @@ export class World {
|
||||
important
|
||||
}
|
||||
this.state.chronicle.push(entry)
|
||||
if (this.state.chronicle.length > 520) this.state.chronicle.splice(0, this.state.chronicle.length - 520)
|
||||
// 0.1.39 智能裁剪:仅在总数超限时触发,保留全部 important +最近非 important
|
||||
const max = World.CHRONICLE_MAX_NON_IMPORTANT
|
||||
if (this.state.chronicle.length > max + 200) {
|
||||
const important_ones = this.state.chronicle.filter((e) => e.important)
|
||||
const non_important = this.state.chronicle.filter((e) => !e.important)
|
||||
const trimmed_non = non_important.slice(-max)
|
||||
this.state.chronicle = [...important_ones, ...trimmed_non].sort(
|
||||
(a, b) => (a.year - b.year) || (a.month - b.month) || (a.id < b.id ? -1 : 1)
|
||||
)
|
||||
}
|
||||
this.out.forEach((o) => o.onChronicle(entry, important))
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user