1 file changed, +46, -0
595e4e4Add Broadcast to render base
src/render/base.py
+46, -0
+46, -0
@@ -38,3 +38,49 @@ class Renderer(ABC):
3838 Args:
3939 total_turns: Length of the run, which is its score.
4040 """
41+
42+
43+class Broadcast(Renderer):
44+ """Shows one run on several views at once.
45+
46+ It exists so :meth:`src.simulate.Simulation.run` keeps taking a
47+ single renderer while the graphical view runs alongside the text
48+ one. Widening the simulator to accept a list would move this loop
49+ into the part of the program that enforces the rules.
50+ """
51+
52+ def __init__(self, *views: Renderer) -> None:
53+ """Group several views behind one.
54+
55+ Args:
56+ *views: The views to show the run on, in order.
57+ """
58+ self._views = views
59+
60+ def begin(self, scenario: Scenario) -> None:
61+ """Open every view.
62+
63+ Args:
64+ scenario: The map and drone count about to be replayed.
65+ """
66+ for view in self._views:
67+ view.begin(scenario)
68+
69+ def show_turn(self, index: int, moves: list[Move]) -> None:
70+ """Show one turn on every view.
71+
72+ Args:
73+ index: 1-based number of the turn.
74+ moves: The drones that moved.
75+ """
76+ for view in self._views:
77+ view.show_turn(index, moves)
78+
79+ def finish(self, total_turns: int) -> None:
80+ """Close every view.
81+
82+ Args:
83+ total_turns: Length of the run.
84+ """
85+ for view in self._views:
86+ view.finish(total_turns)