mirror of
https://github.com/rr-/pq-cli.git
synced 2026-11-12 22:40:36 -07:00
pqw: restore state through public methods
The importer assigned private attributes of QuestBook, Inventory and SpellBook. Each now has a restore() method that sets its state wholesale, and the importer uses those.
This commit is contained in:
2 files changed
+25
-7
No files matched your search
@@ -173,6 +173,11 @@ class QuestBook(SignalMixin):
|
||||
return self._quests[-1]
|
||||
return None
|
||||
|
||||
def restore(self, act: int, quests: list[str]) -> None:
|
||||
"""Set the act and quest log wholesale, as when importing a save."""
|
||||
self._act = act
|
||||
self._quests = list(quests)
|
||||
|
||||
def increment_act(self) -> None:
|
||||
self._act += 1
|
||||
self.emit("start_act", self._act)
|
||||
@@ -210,6 +215,14 @@ class Inventory(SignalMixin):
|
||||
def __getitem__(self, idx: int) -> InventoryItem:
|
||||
return self._items[idx]
|
||||
|
||||
def restore(self, gold: int, items: list[InventoryItem]) -> None:
|
||||
"""Set the gold and items wholesale, as when importing a save.
|
||||
|
||||
The encumbrance bar is left alone, so callers can restore it too.
|
||||
"""
|
||||
self._gold = gold
|
||||
self._items = list(items)
|
||||
|
||||
def add_gold(self, quantity: int) -> None:
|
||||
logger.info(
|
||||
"%s %s",
|
||||
@@ -294,6 +307,10 @@ class SpellBook(SignalMixin):
|
||||
def __len__(self) -> int:
|
||||
return len(self._spells)
|
||||
|
||||
def restore(self, spells: list[Spell]) -> None:
|
||||
"""Set the spells wholesale, as when importing a save."""
|
||||
self._spells = list(spells)
|
||||
|
||||
def add(self, spell_name: str, level: int) -> None:
|
||||
for spell in self._spells:
|
||||
if spell.name == spell_name:
|
||||
|
||||
Reference in new issue
Block a user