feat: Implement World Architect

This commit is contained in:
2026-04-12 11:29:06 +05:30
parent 86d9bfa746
commit 079fe3ff22
11 changed files with 431 additions and 443 deletions

View File

@@ -3,6 +3,7 @@ import logging
from entities import Player
from interaction import ask_entity
from time_utils import WorldClock
from world_architect import WorldState
logger = logging.getLogger(__name__)
@@ -15,7 +16,13 @@ def _build_name_lookup(entities):
return name_lookup
def start_game(entities, player_id=None, world_time=None, location="Unknown"):
def start_game(
entities,
player_id=None,
world_time=None,
location="Unknown",
world_state=None,
):
player = None
if player_id:
player = entities.get(player_id)
@@ -37,6 +44,26 @@ def start_game(entities, player_id=None, world_time=None, location="Unknown"):
}
world_clock = WorldClock.from_time_str(world_time)
# Initialize world state if not provided
if world_state is None:
world_state = WorldState()
world_state.world_clock = world_clock
for entity_id, entity in entities.items():
world_state.entities[entity_id] = {
"name": entity.name,
"location": location,
"health": 100,
"status": "calm",
"mood": entity.current_mood,
}
world_state.locations[location.lower().replace(" ", "_")] = {
"name": location,
"description": f"The {location}",
"occupants": len(entities),
"visibility": "clear",
}
current_entity = None
name_lookup = _build_name_lookup(available_entities)
entity_names = "/".join(
@@ -56,7 +83,7 @@ def start_game(entities, player_id=None, world_time=None, location="Unknown"):
if target_name in ["exit", "quit"]:
if current_entity:
current_entity.reflect_and_summarize(world_clock, location)
current_entity.reflect_and_summarize(world_clock, location, world_state)
break
target_key = name_lookup.get(target_name)
@@ -69,9 +96,16 @@ def start_game(entities, player_id=None, world_time=None, location="Unknown"):
logger.info(
"You leave %s and approach %s.", current_entity.name, new_entity.name
)
current_entity.reflect_and_summarize(world_clock, location)
current_entity.reflect_and_summarize(world_clock, location, world_state)
current_entity = new_entity
user_msg = input(f"You to {current_entity.name}: ")
ask_entity(current_entity, player, user_msg, world_clock, location)
ask_entity(
current_entity,
player,
user_msg,
world_clock,
location,
world_state=world_state,
)