mirror of
https://github.com/rr-/pq-cli.git
synced 2026-09-29 06:44:00 -06:00
ui: update ui for short fast forward bursts
This commit is contained in:
+19
-10
@@ -1,4 +1,5 @@
|
|||||||
import argparse
|
import argparse
|
||||||
|
import contextlib
|
||||||
import datetime
|
import datetime
|
||||||
import typing as T
|
import typing as T
|
||||||
|
|
||||||
@@ -414,23 +415,31 @@ class GameView(urwid.Pile):
|
|||||||
|
|
||||||
fast_forward = {"t": 1, "T": 100, "ctrl t": 10000}
|
fast_forward = {"t": 1, "T": 100, "ctrl t": 10000}
|
||||||
if key in fast_forward:
|
if key in fast_forward:
|
||||||
# hack to suppress UI updates
|
|
||||||
old = SignalMixin.emit
|
|
||||||
SignalMixin.emit = lambda *_: None
|
|
||||||
|
|
||||||
iterations = fast_forward[key]
|
iterations = fast_forward[key]
|
||||||
for i in range(iterations):
|
ctx_mgr = (
|
||||||
|
self.suppress_updates()
|
||||||
|
if iterations >= 1000
|
||||||
|
else contextlib.suppress()
|
||||||
|
)
|
||||||
|
|
||||||
|
with ctx_mgr:
|
||||||
|
for _ in range(iterations):
|
||||||
self.simulation.tick()
|
self.simulation.tick()
|
||||||
|
|
||||||
|
return True
|
||||||
|
|
||||||
|
return False
|
||||||
|
|
||||||
|
@contextlib.contextmanager
|
||||||
|
def suppress_updates(self) -> T.Generator:
|
||||||
|
old = SignalMixin.emit
|
||||||
|
SignalMixin.emit = lambda *_: None
|
||||||
|
yield
|
||||||
self.character_sheet_view.sync()
|
self.character_sheet_view.sync()
|
||||||
self.spell_book_view.sync()
|
self.spell_book_view.sync()
|
||||||
self.equipment_view.sync()
|
self.equipment_view.sync()
|
||||||
self.inventory_view.sync()
|
self.inventory_view.sync()
|
||||||
self.plot_view.sync()
|
self.plot_view.sync()
|
||||||
self.quest_view.sync()
|
self.quest_book_view.sync()
|
||||||
self.task_view.sync()
|
self.task_view.sync()
|
||||||
|
|
||||||
SignalMixin.emit = old
|
SignalMixin.emit = old
|
||||||
return True
|
|
||||||
|
|
||||||
return False
|
|
||||||
|
|||||||
Reference in New Issue
Block a user