Skip to content

Group event notifications and inbound nukes in quick succession#4530

Open
blontd6 wants to merge 1 commit into
openfrontio:mainfrom
blontd6:feature/group-event-messages
Open

Group event notifications and inbound nukes in quick succession#4530
blontd6 wants to merge 1 commit into
openfrontio:mainfrom
blontd6:feature/group-event-messages

Conversation

@blontd6

@blontd6 blontd6 commented Jul 8, 2026

Copy link
Copy Markdown
Contributor

Add approved & assigned issue number here:

Resolves #4516

Description:

Restores real-time event notifications for structure capture, loss, and destruction (such as Cities, Ports, Silos, Factories, SAM Launchers, and Defense Posts), and aggregates these notifications alongside inbound atomic bombs, hydrogen bombs, and MIRVs when they occur in quick succession (within a 3-second / 30-tick window).
formats such as:

  • "Your 4 Cities were destroyed"
  • "Captured 4 Cities from [Player]"
  • "[Player] - 3 atom bombs inbound"

This provides clear, concise, and immediate tactical feedback to players in high-stress combat moments without sacrificing important event tracking.

Please complete the following:

  • I have added screenshots for all UI updates
  • I process any text displayed to the user through translateText() and I've added it to the en.json file
  • I have added relevant tests to the test directory

Please put your Discord username so you can be contacted if a bug or regression is found:

blontd6

@coderabbitai

coderabbitai Bot commented Jul 8, 2026

Copy link
Copy Markdown
Contributor

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: 5e333729-a0d4-4938-8cfd-f99d23581792

📥 Commits

Reviewing files that changed from the base of the PR and between f25a559 and e2fd466.

📒 Files selected for processing (3)
  • resources/lang/en.json
  • src/client/hud/layers/EventsDisplay.ts
  • src/core/game/UnitImpl.ts
💤 Files with no reviewable changes (3)
  • src/core/game/UnitImpl.ts
  • resources/lang/en.json
  • src/client/hud/layers/EventsDisplay.ts

Walkthrough

Adds grouping and pluralization for repeated event notifications (destroyed, captured, lost, inbound nukes) in EventsDisplay, with new localization strings. UnitImpl now emits capture/loss display messages for structures and widens the delete-message suppression filter to include structures.

Changes

Event grouping feature

Layer / File(s) Summary
Localization strings for grouped/plural events
resources/lang/en.json
Adds plural inbound nuke messages (atom, hydrogen, mirv) and captured/destroyed/lost unit message variants (singular and plural).
GameEvent grouping model and aggregation
src/client/hud/layers/EventsDisplay.ts
Extends GameEvent with groupKey, count, unitType, targetPlayerName; adds pluralization/inbound-nuke parsing helpers; updates addEvent to aggregate matching events within a 30-tick window, incrementing count and regenerating description.
Wiring groupKey into unit and nuke event handlers
src/client/hud/layers/EventsDisplay.ts
onDisplayMessageEvent derives groupKey/metadata for destroyed/captured/lost messages; onUnitIncomingEvent parses inbound nuke text into groupKey metadata before calling addEvent.
Structure-specific capture/loss/destroyed messages
src/core/game/UnitImpl.ts
Imports Structures; setOwner emits unit_captured/unit_lost messages when the unit is a structure; displayMessageOnDeleted suppression now also allows structures.

Estimated code review effort: 3 (Moderate) | ~25 minutes

Sequence Diagram(s)

sequenceDiagram
  participant UnitImpl
  participant EventsDisplay
  participant AddEvent as addEvent()
  participant UI as Event Log UI

  UnitImpl->>EventsDisplay: emit unit_captured / unit_lost / unit_destroyed
  EventsDisplay->>EventsDisplay: derive groupKey, unitType, targetPlayerName
  EventsDisplay->>AddEvent: pass event with groupKey
  alt matching groupKey within 30 ticks
    AddEvent->>AddEvent: increment count, refresh createdAt, regenerate description
  else no match
    AddEvent->>AddEvent: append new event row
  end
  AddEvent->>UI: render grouped/pluralized message
Loading

Possibly related PRs

  • openfrontio/OpenFrontIO#3913: Both PRs modify the EventsDisplay.ts event pipeline, overlapping on the internal GameEvent model and inbound/nuke message handling and rendering.

Suggested labels: Translation, UI/UX

Suggested reviewers: scottanderson, evanpelle

Poem

A city falls, then falls again,
no need to count each cry of pain —
"Four were lost!" the log now sings,
one tidy line for messy things.
Nukes inbound? Grouped with care,
🐇 less clutter now, more peace to spare.

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Title check ✅ Passed The title clearly describes grouping event notifications and inbound nukes, which matches the main change.
Description check ✅ Passed The description is directly related to grouped structure events and inbound nuclear alerts.
Linked Issues check ✅ Passed The changes group repeated structure notifications and inbound nuke alerts within the requested 30-tick window in #4516.
Out of Scope Changes check ✅ Passed The patch stays focused on event grouping, translations, and related display logic with no unrelated changes.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1

🧹 Nitpick comments (1)
src/client/hud/layers/EventsDisplay.ts (1)

37-42: 📐 Maintainability & Code Quality | 🔵 Trivial | ⚡ Quick win

Fragile string parsing with magic offsets.

parseInboundNuke reverse-engineers the player name from hardcoded lengths (-20, -24, 7, -22) of the exact English message. If any of these strings change (or the message is localized), the slice silently returns the wrong name or null, and grouping quietly stops working. The MIRV offsets are especially error-prone because each ⚠️ is 2 UTF-16 units.

Cleaner option: pass the nuke type and player name as structured fields on the incoming event so no string parsing is needed. If parsing must stay, at least compute offsets from the suffix constants instead of literals:

♻️ Derive offsets from the suffix strings
 function parseInboundNuke(m: string): { player: string; nukeType: string } | null {
-  if (m.endsWith(" - atom bomb inbound")) return { player: m.slice(0, -20), nukeType: "atom" };
-  if (m.endsWith(" - hydrogen bomb inbound")) return { player: m.slice(0, -24), nukeType: "hydrogen" };
-  if (m.startsWith("⚠️⚠️⚠️ ") && m.endsWith(" - MIRV INBOUND ⚠️⚠️⚠️")) return { player: m.slice(7, -22), nukeType: "mirv" };
+  const atom = " - atom bomb inbound";
+  const hydrogen = " - hydrogen bomb inbound";
+  const mirvPre = "⚠️⚠️⚠️ ";
+  const mirvSuf = " - MIRV INBOUND ⚠️⚠️⚠️";
+  if (m.endsWith(atom)) return { player: m.slice(0, -atom.length), nukeType: "atom" };
+  if (m.endsWith(hydrogen)) return { player: m.slice(0, -hydrogen.length), nukeType: "hydrogen" };
+  if (m.startsWith(mirvPre) && m.endsWith(mirvSuf)) return { player: m.slice(mirvPre.length, -mirvSuf.length), nukeType: "mirv" };
   return null;
 }
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@src/client/hud/layers/EventsDisplay.ts` around lines 37 - 42, The
parseInboundNuke helper is relying on fragile hardcoded slice offsets to recover
the player name from event text. Update EventsDisplay.parseInboundNuke to avoid
magic numbers by either passing structured player/nuke fields into the event
handling path, or by deriving the start/end offsets from the exact suffix
strings used in each message pattern. Keep the existing function and its MIRV
branch, but make the parsing length-safe so changes to the message text or
Unicode characters do not break grouping.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@src/client/hud/layers/EventsDisplay.ts`:
- Line 35: The pluralizeUnit helper in EventsDisplay hardcodes English plural
forms, so update it to use the translated unit-name keys from the language
resources instead of deriving text from the raw enum string. Locate the
pluralization logic in pluralizeUnit and switch it to resolve the appropriate
unit.* entries from the i18n layer so event text stays locale-safe.

---

Nitpick comments:
In `@src/client/hud/layers/EventsDisplay.ts`:
- Around line 37-42: The parseInboundNuke helper is relying on fragile hardcoded
slice offsets to recover the player name from event text. Update
EventsDisplay.parseInboundNuke to avoid magic numbers by either passing
structured player/nuke fields into the event handling path, or by deriving the
start/end offsets from the exact suffix strings used in each message pattern.
Keep the existing function and its MIRV branch, but make the parsing length-safe
so changes to the message text or Unicode characters do not break grouping.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: 24d4b3ef-03e5-4da4-a2fa-e002f60f946c

📥 Commits

Reviewing files that changed from the base of the PR and between 1db65a1 and 4e80a47.

📒 Files selected for processing (3)
  • resources/lang/en.json
  • src/client/hud/layers/EventsDisplay.ts
  • src/core/game/UnitImpl.ts

Comment thread src/client/hud/layers/EventsDisplay.ts
@github-project-automation github-project-automation Bot moved this from Triage to Development in OpenFront Release Management Jul 8, 2026
@blontd6 blontd6 force-pushed the feature/group-event-messages branch from f25a559 to e2fd466 Compare July 8, 2026 01:54
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Status: Development

Development

Successfully merging this pull request may close these issues.

Group captured/destroyed structures and inbound nuke notifications to reduce clutter

1 participant