mirror of
https://github.com/rr-/pq-cli.git
synced 2026-09-29 06:44:00 -06:00
ui: add cheats
This commit is contained in:
+9
-1
@@ -1,3 +1,4 @@
|
||||
import argparse
|
||||
from pathlib import Path
|
||||
|
||||
import xdg
|
||||
@@ -8,11 +9,18 @@ from pqcli.ui import Ui
|
||||
SAVE_PATH = Path(xdg.XDG_CONFIG_HOME) / "pqcli" / "save.dat"
|
||||
|
||||
|
||||
def parse_args() -> argparse.Namespace:
|
||||
parser = argparse.ArgumentParser(prog="pqcli")
|
||||
parser.add_argument("--cheats", help="enable cheats", action="store_true")
|
||||
return parser.parse_args()
|
||||
|
||||
|
||||
def main() -> None:
|
||||
args = parse_args()
|
||||
roster = Roster.load(SAVE_PATH)
|
||||
|
||||
try:
|
||||
Ui(roster).run()
|
||||
Ui(roster, args).run()
|
||||
finally:
|
||||
roster.save(SAVE_PATH)
|
||||
|
||||
|
||||
@@ -1,3 +1,4 @@
|
||||
import argparse
|
||||
import typing as T
|
||||
|
||||
import urwid
|
||||
@@ -43,10 +44,11 @@ def bind_commands() -> None:
|
||||
|
||||
|
||||
class Ui:
|
||||
def __init__(self, roster: Roster) -> None:
|
||||
def __init__(self, roster: Roster, args: argparse.Namespace) -> None:
|
||||
bind_commands()
|
||||
|
||||
self.roster = roster
|
||||
self.args = args
|
||||
self.loop = urwid.MainLoop(
|
||||
None, PALETTE, unhandled_input=self.unhandled_input
|
||||
)
|
||||
@@ -98,7 +100,7 @@ class Ui:
|
||||
|
||||
def switch_to_game_view(self, player_idx: int) -> None:
|
||||
player = self.roster.players[player_idx]
|
||||
self.loop.widget = GameView(self.loop, player)
|
||||
self.loop.widget = GameView(self.loop, player, self.args)
|
||||
self._connect("cancel", self.switch_to_roster_view)
|
||||
|
||||
def switch_to_delete_player_view(self, player_idx: int) -> None:
|
||||
|
||||
+38
-2
@@ -1,3 +1,4 @@
|
||||
import argparse
|
||||
import datetime
|
||||
import typing as T
|
||||
|
||||
@@ -5,7 +6,13 @@ import urwid
|
||||
|
||||
from pqcli.config import EquipmentType, StatType
|
||||
from pqcli.lingo import act_name, to_roman
|
||||
from pqcli.mechanic import InventoryItem, Player, Simulation, Spell
|
||||
from pqcli.mechanic import (
|
||||
InventoryItem,
|
||||
Player,
|
||||
SignalMixin,
|
||||
Simulation,
|
||||
Spell,
|
||||
)
|
||||
from pqcli.ui.custom_line_box import CustomLineBox
|
||||
from pqcli.ui.custom_progress_bar import CustomProgressBar
|
||||
from pqcli.ui.read_only_check_box import ReadOnlyCheckBox
|
||||
@@ -292,9 +299,12 @@ class TaskView(urwid.Pile):
|
||||
class GameView(urwid.Pile):
|
||||
signals = ["cancel"]
|
||||
|
||||
def __init__(self, loop: urwid.MainLoop, player: Player) -> None:
|
||||
def __init__(
|
||||
self, loop: urwid.MainLoop, player: Player, args: argparse.Namespace
|
||||
) -> None:
|
||||
self.loop = loop
|
||||
self.player = player
|
||||
self.args = args
|
||||
self.simulation = Simulation(player)
|
||||
self.last_tick = datetime.datetime.now()
|
||||
|
||||
@@ -352,4 +362,30 @@ class GameView(urwid.Pile):
|
||||
self.cancel()
|
||||
return True
|
||||
|
||||
if self.args.cheats:
|
||||
if key == "e":
|
||||
self.simulation.player.exp_bar.increment(1)
|
||||
return True
|
||||
|
||||
fast_forward = {"t": 1, "T": 100, "ctrl t": 10000}
|
||||
if key in fast_forward:
|
||||
# hack to suppress UI updates
|
||||
old = SignalMixin.emit
|
||||
SignalMixin.emit = lambda *_: None
|
||||
|
||||
iterations = fast_forward[key]
|
||||
for i in range(iterations):
|
||||
self.simulation.tick()
|
||||
|
||||
self.character_sheet_view.sync()
|
||||
self.experience_view.sync()
|
||||
self.spell_book_view.sync()
|
||||
self.equipment_view.sync()
|
||||
self.inventory_view.sync()
|
||||
self.plot_view.sync()
|
||||
self.task_view.sync()
|
||||
|
||||
SignalMixin.emit = old
|
||||
return True
|
||||
|
||||
return False
|
||||
|
||||
Reference in New Issue
Block a user