From d76bcf0b8acac80a7782918b600a29288a6fcc1c Mon Sep 17 00:00:00 2001 From: Sean Sube Date: Sat, 22 Jun 2024 18:10:47 -0500 Subject: [PATCH] make core systems optional, format logic labels as templates --- .gitignore | 1 + README.md | 2 +- taleweave/main.py | 6 ------ taleweave/systems/core/action.py | 2 +- taleweave/systems/core/planning.py | 2 +- taleweave/systems/generic/logic.py | 7 +++++-- 6 files changed, 9 insertions(+), 11 deletions(-) diff --git a/.gitignore b/.gitignore index 99417be..99c5c8c 100644 --- a/.gitignore +++ b/.gitignore @@ -5,5 +5,6 @@ venv/ client/node_modules/ client/out/ taleweave/custom_* +taleweave/systems/custom/ .coverage coverage.* diff --git a/README.md b/README.md index e98f171..8b26b5a 100644 --- a/README.md +++ b/README.md @@ -75,7 +75,7 @@ TaleWeave AI has game systems for: | Core | Life Sim | RPG | Environment | Generic | | -------- | --------------- | ------ | ----------- | ------- | -| Acting | Hunger & Thirst | Health | Humidity | Logic | +| Acting | Hunger & Thirst | Health | Moisture | Logic | | Planning | Hygiene | Quests | Temperature | | | Summary | Mood | | Time of day | | | | Sleeping | | Weather | | diff --git a/taleweave/main.py b/taleweave/main.py index 69e4f5f..6fe6f28 100644 --- a/taleweave/main.py +++ b/taleweave/main.py @@ -60,8 +60,6 @@ if True: from taleweave.models.prompt import PromptLibrary from taleweave.plugins import load_plugin from taleweave.state import save_world_state - from taleweave.systems.core.action import init_action - from taleweave.systems.core.planning import init_planning def int_or_inf(value: str) -> float | int: @@ -269,10 +267,6 @@ def main(): # set up the game systems systems: List[GameSystem] = [] - systems.extend(init_planning()) - systems.extend(init_action()) - - # load extra systems from plugins for system_name in args.systems or []: logger.info(f"loading systems from {system_name}") module_systems = load_plugin(system_name) diff --git a/taleweave/systems/core/action.py b/taleweave/systems/core/action.py index 611283e..c4e7809 100644 --- a/taleweave/systems/core/action.py +++ b/taleweave/systems/core/action.py @@ -195,7 +195,7 @@ def simulate_action(world: World, turn: int, data: Any | None = None): logger.exception(f"error during action for character {character.name}") -def init_action(): +def init(): return [ GameSystem( ACTION_SYSTEM_NAME, initialize=initialize_action, simulate=simulate_action diff --git a/taleweave/systems/core/planning.py b/taleweave/systems/core/planning.py index e5d6c25..8001bf5 100644 --- a/taleweave/systems/core/planning.py +++ b/taleweave/systems/core/planning.py @@ -191,7 +191,7 @@ def simulate_planning(world: World, turn: int, data: Any | None = None): ) -def init_planning(): +def init(): # TODO: add format method that renders the recent notes and upcoming events return [ GameSystem( diff --git a/taleweave/systems/generic/logic.py b/taleweave/systems/generic/logic.py index 142d868..e38ce61 100644 --- a/taleweave/systems/generic/logic.py +++ b/taleweave/systems/generic/logic.py @@ -11,6 +11,7 @@ from yaml import Loader, load from taleweave.game_system import FormatPerspective, GameSystem from taleweave.models.entity import Attributes, World, WorldEntity, dataclass from taleweave.plugins import get_plugin_function +from taleweave.utils.template import format_str logger = getLogger(__name__) @@ -158,9 +159,11 @@ def format_logic( for label in rules.labels: if match_logic(entity, label): if perspective == FormatPerspective.SECOND_PERSON and label.backstory: - labels.append(label.backstory) + backstory = format_str(label.backstory, entity=entity) + labels.append(backstory) elif perspective == FormatPerspective.THIRD_PERSON and label.description: - labels.append(label.description) + description = format_str(label.description, entity=entity) + labels.append(description) else: logger.debug("label has no relevant description: %s", label)