Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Actor and context data caching #354

Merged
merged 2 commits into from
Aug 14, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions src/conversation/context.py
Original file line number Diff line number Diff line change
Expand Up @@ -118,14 +118,14 @@ def __remove_character(self, npc: Character):
def get_time_group(self) -> str:
return get_time_group(self.__ingame_time)

def update_context(self, location: str, in_game_time: int, custom_ingame_events: list[str], weather: str, custom_context_values: dict[str, Any]):
def update_context(self, location: str | None, in_game_time: int, custom_ingame_events: list[str], weather: str, custom_context_values: dict[str, Any]):
self.__ingame_events.extend(custom_ingame_events)
if weather != self.__weather:
if self.__weather != "":
self.__ingame_events.append(weather)
self.__weather = weather
self.__custom_context_values = custom_context_values
if location != self.__location:
if (location) and (location != self.__location):
self.__location = location
self.__ingame_events.append(f"The location is now {location}.")

Expand Down
2 changes: 1 addition & 1 deletion src/conversation/conversation.py
Original file line number Diff line number Diff line change
Expand Up @@ -162,7 +162,7 @@ def process_player_input(self, player_text: str):
else:
self.__start_generating_npc_sentences()

def update_context(self, location: str, time: int, custom_ingame_events: list[str], weather: str, custom_context_values: dict[str, Any]):
def update_context(self, location: str | None, time: int, custom_ingame_events: list[str], weather: str, custom_context_values: dict[str, Any]):
"""Updates the context with a new set of values

Args:
Expand Down
4 changes: 1 addition & 3 deletions src/game_manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -58,8 +58,6 @@ def continue_conversation(self, input_json: dict[str, Any]) -> dict[str, Any]:
if(not self.__talk ):
return self.error_message("No running conversation at this point")

self.__update_context(input_json) # TODO: check how fast reloading characters each conversation turn is

if input_json.__contains__(comm_consts.KEY_REQUEST_EXTRA_ACTIONS):
extra_actions: list[str] = input_json[comm_consts.KEY_REQUEST_EXTRA_ACTIONS]
if extra_actions.__contains__(comm_consts.ACTION_RELOADCONVERSATION):
Expand Down Expand Up @@ -122,7 +120,7 @@ def __update_context(self, json: dict[str, Any]):
actors_in_json.append(actor)

self.__talk.add_or_update_character(actors_in_json)
location: str = json[comm_consts.KEY_CONTEXT][comm_consts.KEY_CONTEXT_LOCATION]
location: str = json[comm_consts.KEY_CONTEXT].get(comm_consts.KEY_CONTEXT_LOCATION, None)
time: int = json[comm_consts.KEY_CONTEXT][comm_consts.KEY_CONTEXT_TIME]
ingame_events: list[str] = json[comm_consts.KEY_CONTEXT][comm_consts.KEY_CONTEXT_INGAMEEVENTS]
custom_context_values: dict[str, Any] = {}
Expand Down