Clamp goal milestone announcements
This commit is contained in:
18
src/goals.js
18
src/goals.js
@@ -107,21 +107,25 @@
|
|||||||
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),
|
||||||
|
);
|
||||||
|
if (newlyReached.length === 0) return;
|
||||||
|
const threshold = Math.max(...newlyReached);
|
||||||
|
newlyReached.forEach((t) => announcedGoalMilestones.add(t));
|
||||||
const text = config.messages?.text || formatGoalMessage(goal);
|
const text = config.messages?.text || formatGoalMessage(goal);
|
||||||
if (!text) {
|
if (!text) {
|
||||||
logGoalEvent("skip-progress-announcement", {
|
logGoalEvent("skip-progress-announcement", {
|
||||||
threshold,
|
threshold,
|
||||||
progress: goal.progress,
|
progress: goal.progress,
|
||||||
reason: "missing text",
|
reason: "missing text",
|
||||||
|
suppressed: newlyReached.filter((t) => t !== threshold),
|
||||||
});
|
});
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
const colors =
|
const colors =
|
||||||
(Array.isArray(config.messages?.colors) &&
|
(Array.isArray(config.messages?.colors) && config.messages.colors) ||
|
||||||
config.messages.colors) ||
|
|
||||||
goal?.colors ||
|
goal?.colors ||
|
||||||
null;
|
null;
|
||||||
logGoalEvent("announce-progress", {
|
logGoalEvent("announce-progress", {
|
||||||
@@ -129,6 +133,7 @@
|
|||||||
progress: goal.progress,
|
progress: goal.progress,
|
||||||
colors,
|
colors,
|
||||||
text,
|
text,
|
||||||
|
suppressed: newlyReached.filter((t) => t !== threshold),
|
||||||
});
|
});
|
||||||
ui.showFloatingMessage(
|
ui.showFloatingMessage(
|
||||||
{ text, colors },
|
{ text, colors },
|
||||||
@@ -137,9 +142,6 @@
|
|||||||
position: config.messages.position,
|
position: config.messages.position,
|
||||||
},
|
},
|
||||||
);
|
);
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
};
|
};
|
||||||
|
|
||||||
const showGoalIntro = () => {
|
const showGoalIntro = () => {
|
||||||
|
|||||||
@@ -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);
|
||||||
|
|||||||
Reference in New Issue
Block a user