Final touch-ups I think (for tonight at least)

This commit is contained in:
oitsjustjose 2023-03-24 22:45:30 -05:00
commit eafb3c2742
2 changed files with 10 additions and 7 deletions

View file

@ -34,7 +34,7 @@ class Advancement:
return f"{self.__namespace}:{self.__idmp[dep]}" return f"{self.__namespace}:{self.__idmp[dep]}"
return f"{self.__namespace}:root" return f"{self.__namespace}:root"
def get_title(self) -> Union[str, Dict[str, Any]]: def get_title(self) -> Dict[str, Any]:
""" """
Attempts to get the title of a self.__quest. Attempts to get the title of a self.__quest.
Returns the self.__quest ID as fallback Returns the self.__quest ID as fallback
@ -43,17 +43,17 @@ class Advancement:
try: # some titles are json colored try: # some titles are json colored
return json.loads(self.__quest["title"].replace('\\"', '"')) return json.loads(self.__quest["title"].replace('\\"', '"'))
except json.decoder.JSONDecodeError: except json.decoder.JSONDecodeError:
return self.__quest["title"] return {"text": self.__quest["title"]}
else: # attempt to salvage name by fancifying the unloc name else: # attempt to salvage name by fancifying the unloc name
for task in self.__quest["tasks"]: for task in self.__quest["tasks"]:
if "item" in task and isinstance(task["item"], str): if "item" in task and isinstance(task["item"], str):
name = task["item"].split(":")[1].split("_") name = task["item"].split(":")[1].split("_")
name = " ".join(map(lambda x: x[0].upper() + x[1:], name)) name = " ".join(map(lambda x: x[0].upper() + x[1:], name))
return name return {"text": name}
print( print(
f"{Fore.YELLOW}[i] Failed to detect advancement name from self.__quest {self.__quest['id']}{Fore.RESET}" f"{Fore.YELLOW}[i] Failed to detect advancement name from self.__quest {self.__quest['id']}{Fore.RESET}"
) )
return f"{self.__quest['id']}" return {"text": self.__quest["id"]}
def get_icon_item(self) -> str: def get_icon_item(self) -> str:
""" """
@ -101,11 +101,12 @@ class Advancement:
Returns a string list of individual validation errors Returns a string list of individual validation errors
""" """
ret: List[str] = [] ret: List[str] = []
title = self.get_title()
if self.get_parent() == "minecraft:root": if self.get_parent() == "minecraft:root":
ret.append("Parent could not be determined. Defaulted to 'minecraft:root'") ret.append("Parent could not be determined. Defaulted to 'minecraft:root'")
if self.get_icon_item() == "minecraft:air": if self.get_icon_item() == "minecraft:air":
ret.append("Icon could not be determined. Defaulted to 'minecraft:air") ret.append("Icon could not be determined. Defaulted to 'minecraft:air")
if self.get_title() == self.__quest["id"]: if "text" not in title or title["text"] == self.__quest["id"]:
ret.append( ret.append(
f"Advancement Name could not be determined. Defaulted to '{self.__quest['id']}'" f"Advancement Name could not be determined. Defaulted to '{self.__quest['id']}'"
) )
@ -151,12 +152,12 @@ class Advancement:
"parent": self.get_parent(), "parent": self.get_parent(),
"display": { "display": {
"icon": {"item": self.get_icon_item()}, "icon": {"item": self.get_icon_item()},
"title": {"text": self.get_title()}, "title": self.get_title(),
"description": {"text": self.get_description()}, "description": {"text": self.get_description()},
}, },
"criteria": { "criteria": {
"0": { "0": {
"conditions": {"items": [{"items": [[self.get_criteria()]]}]}, "conditions": {"items": [{"items": [self.get_criteria()]}]},
"trigger": "minecraft:inventory_changed", "trigger": "minecraft:inventory_changed",
} }
}, },

View file

@ -36,6 +36,8 @@ def main(parmesan: CommandlineConfigParser) -> None:
.replace("\\\\\\u00a7", "&") .replace("\\\\\\u00a7", "&")
# Fix \u00a7 -> § # Fix \u00a7 -> §
.replace("\\u00a7", "§") .replace("\\u00a7", "§")
# Fix \\\ -> \
.replace("\\\\\\", "\\")
) )
file_handle.write(data_as_str) file_handle.write(data_as_str)