Skip to content

Commit

Permalink
Merge pull request #35 from mmacy/treasure-and-char-work-2
Browse files Browse the repository at this point in the history
Treasure and character work (part 2 of n)
  • Loading branch information
mmacy committed Jan 21, 2024
2 parents 82a20ab + 4cfe214 commit 2224104
Show file tree
Hide file tree
Showing 6 changed files with 449 additions and 481 deletions.
703 changes: 355 additions & 348 deletions osrgame/poetry.lock

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion osrlib/osrlib/dice_roller.py
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ def roll_dice(notation: str, modifier: int = 0, drop_lowest: bool = False):
# We need to support calls that pass in a specific value in order to guarantee that
# the "roll" returns that value. You might do this in scenarios like specifying a
# set number of monsters in an encounter or number of gold pieces in a reward. This
# also enables unit tests need a consistent roll results for their test cases.
# also enables unit tests that need a consistent roll results for their test cases.
num_sides = int(notation)
return DiceRoll(1, num_sides, num_sides, 0, num_sides, [num_sides])
except ValueError:
Expand Down
5 changes: 4 additions & 1 deletion osrlib/osrlib/dungeon_master.py
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,10 @@ def start_session(self):
if self.adventure is None:
raise ValueError("There is no active adventure. Call set_active_adventure() with a valid adventure before calling start_session().")

self.client = OpenAI()
try:
self.client = OpenAI()
except e:
logger.critical(f"Error initializing OpenAI client: {e}")

if not self.adventure.is_started:
self.adventure.start_adventure()
Expand Down
45 changes: 2 additions & 43 deletions osrlib/osrlib/game_manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,31 +31,13 @@ def format(self, record):
logger.addHandler(last_message_handler)


class StorageType(Enum):
JSON = "json"
YAML = "yaml"
TOML = "toml"


class GameManager:
"""The GameManager class provides facilities for working with parties and their adventures. It's the main API entry point for the game.
Access the GameManager singleton via the `game_manager.game_manager` module-level variable.
Example:
>>> from osrlib import game_manager, adventure
>>> gm = game_manager.game_manager
>>> gm.parties.append(Party("The B-Team"))
>>> search_for_the_unknown = adventure.Adventure("Search for the Unknown")
>>> gm.start_adventure(search_for_the_unknown, gm.parties[0])
"""The GameManager class provides facilities for working with parties and their adventures.
Attributes:
parties (list): A list of the available parties.
adventures (list): A list of the available adventures.
"""

def __init__(
self,
parties: list = [],
Expand All @@ -65,28 +47,5 @@ def __init__(
self.adventures = adventures
self.parties = parties
logger.debug(
f"GameManager initialized. There are {len(self.adventures)} adventures available."
f"GameManager initialized."
)

def save_game(self, storage_type: StorageType = StorageType.JSON):
"""Save the game state to persistent storage in the given format.
Args:
storage_type (StorageType): The format to use for saving the game state.
"""
logger.debug(
f"Saving the game to persistent storage in {storage_type} format..."
)
if storage_type == StorageType.JSON:
with open("game_manager.json", "w") as f:
json.dump({"parties": self.parties, "adventures": self.adventures}, f)
else:
warnings.warn(f"Storage type {storage_type} not yet supported.")

def load_game(self):
"""Load the game state from disk."""
warnings.warn("Game LOAD is not yet implemented.", UserWarning)


game_manager = GameManager()
"""This module-level variable is the main API entry point for the game - use it instead of instantiating a new GameManager."""
Loading

0 comments on commit 2224104

Please sign in to comment.