Files
myrzx_bot/ranch_assistant/presentation.py
T

62 lines
2.6 KiB
Python

"""Pure presentation calculations: run in account workers, never touch Qt."""
from dataclasses import dataclass
from .maps import stages
def monster_rows(catalog, snapshot, managed, room_id=0):
planner = None
def tp_values(mon):
nonlocal planner
if planner is None:
# Snapshot formatting shares the pure TP calculation with policy planning.
from .model import Planner
planner = Planner(catalog)
thresholds = planner.tp_thresholds(mon)
return thresholds[4] if thresholds is not None else None
return [[m["id"], m.get("nicName") or catalog.monster(m["typeId"]).get("name", "未知"), catalog.monster(m["typeId"]).get("star", "?"),
f"{m.get('level', 1)} / {catalog.max_level(m) or '?'}", catalog.quality_text(m),
"培育室 · " + snapshot.phase_text(m, catalog) if m.get("process") == 2 else f"牧场 {m.get('roomId', 0)}",
"系统锁定" if m.get("sysLock") else "是" if m.get("lock") else "否",
"本次培育" if int(m["id"]) in managed else "已有:不自动处理", "", "", m.get("potentialLevel", "?"),
*catalog.reference_stats(m), f"{m.get('feel', 0)} / {catalog.max_feel(m)}", catalog.likes_text(m["typeId"]), "", "",
"", "", f"{m.get('tpLevel', 0)} / 4", f"{m.get('tpExp', 0)} / {tp_values(m) or '?'}"] for m in snapshot.raw["monsters"]
if not room_id or m.get("process") == 3 and int(m.get("roomId") or 0) == room_id]
def map_source(snapshot):
return repr((snapshot.raw.get("history"), snapshot.raw["master"].get("level")))
@dataclass
class Views:
snapshot: object
monster_source: str | None
managed: set
monsters: list | None
map_source: str
maps: list
stage_cache: object = None
statistics_store: object = None
drop_statistics: dict = None
progression: object = None
exploration: object = None
@dataclass
class Presented:
value: object
views: Views
prepare_ms: float = 0
worker_ms: float = 0
def prepare_views(catalog, snapshot, managed, stage_cache=None, statistics=None, *, include_monsters=True):
"""Omitted monster rows stay dirty; the default preserves the full view API."""
source = repr(snapshot.raw["monsters"]) if include_monsters else None
monsters = monster_rows(catalog, snapshot, managed) if include_monsters else None
views = Views(snapshot, source, set(managed), monsters,
str(snapshot.raw["master"]["id"]), stage_cache.get(snapshot) if stage_cache else stages(catalog, snapshot), stage_cache,
statistics, statistics.snapshot(snapshot.raw["master"]["id"]) if statistics else None)
return views