Clamp goal milestone announcements
This commit is contained in:
66
src/goals.js
66
src/goals.js
@@ -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 = () => {
|
||||
|
||||
@@ -281,6 +281,7 @@
|
||||
state.lastTimerDisplay = null;
|
||||
}
|
||||
resetChainVisuals();
|
||||
ui.clearMessages();
|
||||
state.balls.forEach((ball) => {
|
||||
spawnSystem.cleanupBall(ball);
|
||||
World.remove(world, ball);
|
||||
|
||||
Reference in New Issue
Block a user