From eafb3c2742a9efbc55860b3fdad4c3312b7a2bb9 Mon Sep 17 00:00:00 2001 From: oitsjustjose Date: Fri, 24 Mar 2023 22:45:30 -0500 Subject: [PATCH] Final touch-ups I think (for tonight at least) --- src/advancement.py | 15 ++++++++------- src/main.py | 2 ++ 2 files changed, 10 insertions(+), 7 deletions(-) diff --git a/src/advancement.py b/src/advancement.py index 3892df3..1b50593 100644 --- a/src/advancement.py +++ b/src/advancement.py @@ -34,7 +34,7 @@ class Advancement: return f"{self.__namespace}:{self.__idmp[dep]}" 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. Returns the self.__quest ID as fallback @@ -43,17 +43,17 @@ class Advancement: try: # some titles are json colored return json.loads(self.__quest["title"].replace('\\"', '"')) except json.decoder.JSONDecodeError: - return self.__quest["title"] + return {"text": self.__quest["title"]} else: # attempt to salvage name by fancifying the unloc name for task in self.__quest["tasks"]: if "item" in task and isinstance(task["item"], str): name = task["item"].split(":")[1].split("_") name = " ".join(map(lambda x: x[0].upper() + x[1:], name)) - return name + return {"text": name} print( 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: """ @@ -101,11 +101,12 @@ class Advancement: Returns a string list of individual validation errors """ ret: List[str] = [] + title = self.get_title() if self.get_parent() == "minecraft:root": ret.append("Parent could not be determined. Defaulted to 'minecraft:root'") if self.get_icon_item() == "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( f"Advancement Name could not be determined. Defaulted to '{self.__quest['id']}'" ) @@ -151,12 +152,12 @@ class Advancement: "parent": self.get_parent(), "display": { "icon": {"item": self.get_icon_item()}, - "title": {"text": self.get_title()}, + "title": self.get_title(), "description": {"text": self.get_description()}, }, "criteria": { "0": { - "conditions": {"items": [{"items": [[self.get_criteria()]]}]}, + "conditions": {"items": [{"items": [self.get_criteria()]}]}, "trigger": "minecraft:inventory_changed", } }, diff --git a/src/main.py b/src/main.py index 67b96b0..7a2f36d 100644 --- a/src/main.py +++ b/src/main.py @@ -36,6 +36,8 @@ def main(parmesan: CommandlineConfigParser) -> None: .replace("\\\\\\u00a7", "&") # Fix \u00a7 -> § .replace("\\u00a7", "§") + # Fix \\\ -> \ + .replace("\\\\\\", "\\") ) file_handle.write(data_as_str)