mirror of
https://github.com/db9979/uconsole_asw_game.git
synced 2026-12-06 12:54:18 +01:00
46 lines
1.4 KiB
Python
46 lines
1.4 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:
|
|
return config.FEED_CATEGORIES.get(self.category,
|
|
(config.COLOR_TEXT, "?"))[0]
|
|
|
|
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] = []
|
|
self._sink = sink
|
|
|
|
def add(self, stamp: str, category: str, text: str) -> None:
|
|
self.entries.append(FeedEntry(stamp, category, text))
|
|
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 = []
|