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

View File

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