mirror of
https://github.com/db9979/uconsole_asw_game.git
synced 2026-12-06 12:54:18 +01:00
The F11 log kept the night colours (FEED_CATEGORIES captured config.COLOR_* at import), so lines were pale on the light "Tactical Day" scheme, and the station showed through its translucent ground. Feed categories (and the other module-level colour tables: debrief, campaign map, U-boat threat and radio pages, lookout, weather station, SimLog) now resolve their colour when drawn. The log is opaque, has a close cross, and a pointer blocker keeps every click, hover and lamp note on it from reaching the station behind. In the browser the dimmed backdrop around an open sheet takes the click and closes the sheet. Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_019qjxcbV9CMLtJjU6pPHW28
51 lines
1.7 KiB
Python
51 lines
1.7 KiB
Python
"""W0: stationsübergreifender Ereignis-Feed für operative Meldungen.
|
|
|
|
Ersetzt/erweitert das alte Teletype (nur Funk): Navigation, Funk, Sonar, Waffen,
|
|
OPZ, Schaden, Mission und Weltzustand werden kategorisiert und farbcodiert in
|
|
der Bottom-Leiste gehalten. Max. FEED_MAX_ENTRIES Einträge.
|
|
"""
|
|
|
|
from src.core import config
|
|
|
|
|
|
class FeedEntry:
|
|
__slots__ = ("stamp", "category", "text")
|
|
|
|
def __init__(self, stamp: str, category: str, text: str):
|
|
self.stamp = stamp
|
|
self.category = category
|
|
self.text = text
|
|
|
|
def color(self) -> tuple:
|
|
name = config.FEED_CATEGORIES.get(self.category, ("COLOR_TEXT", "?"))[0]
|
|
# Resolved now, not at import: the colour scheme may have changed.
|
|
return getattr(config, name)
|
|
|
|
def tag(self) -> str:
|
|
return config.FEED_CATEGORIES.get(self.category,
|
|
(None, "?"))[1]
|
|
|
|
|
|
class EventFeed:
|
|
def __init__(self, cap: int = config.FEED_MAX_ENTRIES, sink=None):
|
|
self.cap = cap
|
|
self.entries: list[FeedEntry] = []
|
|
# Entries ever added (never reset), so a reader such as the Remote
|
|
# Crew log can tell new entries from old ones after the cap trims.
|
|
self.added = 0
|
|
self._sink = sink
|
|
|
|
def add(self, stamp: str, category: str, text: str) -> None:
|
|
self.entries.append(FeedEntry(stamp, category, text))
|
|
self.added += 1
|
|
if len(self.entries) > self.cap:
|
|
self.entries.pop(0)
|
|
if self._sink is not None:
|
|
self._sink(stamp, category, text)
|
|
|
|
def recent(self, n: int) -> list[FeedEntry]:
|
|
return self.entries[-n:]
|
|
|
|
def clear(self) -> None:
|
|
self.entries = []
|