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

Improvements to character overrides #348

Merged
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
38 changes: 21 additions & 17 deletions src/games/gameable.py
Original file line number Diff line number Diff line change
Expand Up @@ -222,22 +222,26 @@ def __apply_character_overrides(self, overrides_folder: str, character_df_column
full_path_file = os.path.join(overrides_folder,file)
if extension == ".json":
with open(full_path_file) as fp:
content: dict[str, str] = json.load(fp)
name = content.get("name", "")
base_id = content.get("base_id", "")
race = content.get("race", "")
matcher = self._get_matching_df_rows_matcher(base_id, name, race)
if isinstance(matcher, type(None)): #character not in csv, add as new row
row = []
for entry in character_df_column_headers:
value = content.get(entry, "")
row.append(value)
self.character_df.loc[len(self.character_df.index)] = row
else: #character is in csv, update row
for entry in character_df_column_headers:
value = content.get(entry, None)
if value:
self.character_df.loc[matcher, entry] = value
json_object = json.load(fp)
if isinstance(json_object, dict):#Otherwise it is already a list
json_object = [json_object]
for json_content in json_object:
content: dict[str, str] = json_content
name = content.get("name", "")
base_id = content.get("base_id", "")
race = content.get("race", "")
matcher = self._get_matching_df_rows_matcher(base_id, name, race)
if isinstance(matcher, type(None)): #character not in csv, add as new row
row = []
for entry in character_df_column_headers:
value = content.get(entry, "")
row.append(value)
self.character_df.loc[len(self.character_df.index)] = row
else: #character is in csv, update row
for entry in character_df_column_headers:
value = content.get(entry, None)
if value and value != "":
self.character_df.loc[matcher, entry] = value
elif extension == ".csv":
extra_df = self.__get_character_df(full_path_file)
for i in range(extra_df.shape[0]):#for each row in df
Expand All @@ -254,6 +258,6 @@ def __apply_character_overrides(self, overrides_folder: str, character_df_column
else: #character is in csv, update row
for entry in character_df_column_headers:
value = extra_df.iloc[i].get(entry, None)
if value:
if value and not pd.isna(value) and value != "":
self.character_df.loc[matcher, entry] = value