Clamp goal milestone announcements

This commit is contained in:
Daddy32
2025-12-16 13:25:18 +01:00
parent 1bef87022b
commit d4fbd0247b
2 changed files with 35 additions and 32 deletions

View File

@@ -107,39 +107,41 @@
const maybeAnnounceGoalProgress = (goal) => { const maybeAnnounceGoalProgress = (goal) => {
if (!goal || !Number.isFinite(goal.progress)) return; if (!goal || !Number.isFinite(goal.progress)) return;
const fraction = Math.max(0, Math.min(1, goal.progress / 100)); const fraction = Math.max(0, Math.min(1, goal.progress / 100));
for (const threshold of goalMilestoneThresholds) { const newlyReached = goalMilestoneThresholds.filter(
if (fraction >= threshold && !announcedGoalMilestones.has(threshold)) { (threshold) =>
announcedGoalMilestones.add(threshold); fraction >= threshold && !announcedGoalMilestones.has(threshold),
const text = config.messages?.text || formatGoalMessage(goal); );
if (!text) { if (newlyReached.length === 0) return;
logGoalEvent("skip-progress-announcement", { const threshold = Math.max(...newlyReached);
threshold, newlyReached.forEach((t) => announcedGoalMilestones.add(t));
progress: goal.progress, const text = config.messages?.text || formatGoalMessage(goal);
reason: "missing text", if (!text) {
}); logGoalEvent("skip-progress-announcement", {
return; threshold,
} progress: goal.progress,
const colors = reason: "missing text",
(Array.isArray(config.messages?.colors) && suppressed: newlyReached.filter((t) => t !== threshold),
config.messages.colors) || });
goal?.colors || return;
null;
logGoalEvent("announce-progress", {
threshold,
progress: goal.progress,
colors,
text,
});
ui.showFloatingMessage(
{ text, colors },
{
durationMs: config.messages.durationMs,
position: config.messages.position,
},
);
break;
}
} }
const colors =
(Array.isArray(config.messages?.colors) && config.messages.colors) ||
goal?.colors ||
null;
logGoalEvent("announce-progress", {
threshold,
progress: goal.progress,
colors,
text,
suppressed: newlyReached.filter((t) => t !== threshold),
});
ui.showFloatingMessage(
{ text, colors },
{
durationMs: config.messages.durationMs,
position: config.messages.position,
},
);
}; };
const showGoalIntro = () => { const showGoalIntro = () => {

View File

@@ -281,6 +281,7 @@
state.lastTimerDisplay = null; state.lastTimerDisplay = null;
} }
resetChainVisuals(); resetChainVisuals();
ui.clearMessages();
state.balls.forEach((ball) => { state.balls.forEach((ball) => {
spawnSystem.cleanupBall(ball); spawnSystem.cleanupBall(ball);
World.remove(world, ball); World.remove(world, ball);