diff --git a/assets/converters.py b/assets/converters.py index 5651872..95d2799 100644 --- a/assets/converters.py +++ b/assets/converters.py @@ -47,7 +47,10 @@ def convert(input: str, output: str, params: dict, target): convert_dialog(input, output, params, target) return 0 -def convert_map(input, output, params, target): +def convert_map(input: str, output: str, params: dict, target): + """ + Convert a map. + """ if VERBOSE: print(f"INFO: Converting map {input} -> {output}") input_map = Map(input) dialog_file = "" @@ -75,6 +78,7 @@ def convert_map(input, output, params, target): dialog_file = input_map.get_property("dialogFile") if VERBOSE: print(f"INFO: Dialog file: {dialog_file}.") except Exception as e: + # Show a simple error message on failure. sys.stderr.write(f"ERROR: Failed to get the dialog file.\n" + f" Error message: {e}\n") sys.exit(1) @@ -86,6 +90,7 @@ def convert_map(input, output, params, target): map_y = int(input_map.get_property("mapY")) if VERBOSE: print(f"INFO: Map position: ({map_x}, {map_y}).") except Exception as e: + # Show a simple error message on failure. sys.stderr.write(f"ERROR: Failed to get the map position.\n" + f" Error message: {e}\n") sys.exit(1) @@ -99,6 +104,7 @@ def convert_map(input, output, params, target): for i in dialog_data["dialogs"]: dialog_ids.append(i["ID"]) except Exception as e: + # Show a simple error message on failure. sys.stderr.write(f"ERROR: Failed to get informations about dialogs.\n" + f" Error message: {e}\n") sys.exit(1) @@ -108,6 +114,7 @@ def convert_map(input, output, params, target): if VERBOSE: print("INFO: Getting the outdoor tileset") outdoor_tileset = input_map.get_tileset_by_firstgid(1) except Exception as e: + # Show a simple error message on failure. sys.stderr.write(f"ERROR: Failed to get the outdoor tileset.\n" + f" Error message: {e}\n") sys.exit(1) @@ -117,6 +124,7 @@ def convert_map(input, output, params, target): if VERBOSE: print("INFO: Getting the walkable tileset") walkable_tileset = input_map.get_tileset_by_firstgid(409) except Exception as e: + # Show a simple error message on failure. sys.stderr.write(f"ERROR: Failed to get the walkable tileset.\n" + f" Error message: {e}\n") sys.exit(1) @@ -136,6 +144,7 @@ def convert_map(input, output, params, target): raise Exception("Bad layer size!") if VERBOSE: print("INFO: Layer data has the right size.") except Exception as e: + # Show a simple error message on failure. sys.stderr.write(f"ERROR: Failed to get the background layer.\n" + f" Error message: {e}\n") sys.exit(1) @@ -151,6 +160,7 @@ def convert_map(input, output, params, target): raise Exception("Bad layer size!") if VERBOSE: print("INFO: Layer data has the right size.") except Exception as e: + # Show a simple error message on failure. sys.stderr.write(f"ERROR: Failed to get the foreground layer.\n" + f" Error message: {e}\n") sys.exit(1) @@ -166,6 +176,7 @@ def convert_map(input, output, params, target): raise Exception("Bad layer size!") if VERBOSE: print("INFO: Layer data has the right size.") except Exception as e: + # Show a simple error message on failure. sys.stderr.write(f"ERROR: Failed to get the walkable layer.\n" + f" Error message: {e}\n") sys.exit(1) @@ -216,6 +227,7 @@ def convert_map(input, output, params, target): } signs[object.id] = data except Exception as e: + # Show a simple error message on failure. sys.stderr.write(f"ERROR: Failed to get the extra data.\n" + f" Error message: {e}\n") sys.exit(1) @@ -230,6 +242,7 @@ def convert_map(input, output, params, target): tileset_name = os.path.splitext(os.path.basename(outdoor_tileset.source))[0] map_struct += fxconv.ref(f"img_{tileset_name}") + # Store the walkable layer walkable_data = bytes() for i in walkable_layer: if i < 0: i = 0 @@ -240,6 +253,7 @@ def convert_map(input, output, params, target): map_struct += fxconv.u32(len(npcs)) npc_struct = fxconv.Structure() for i in npcs.values(): + # Convert currentpos to a fixed point value. npc_struct += fxconv.u32((i["position"][0]+i["path"][0])< {output}") + + # Load the JSON dialog file. dialog_data = None try: with open(input, "r") as file: @@ -313,9 +337,12 @@ def convert_dialog(input, output, params, target): sys.stderr.write(f"ERROR: Failed parse json.\n" + f" Error message: {e}\n") sys.exit(1) + + # Create the dialog struct dialog_struct = fxconv.Structure() try: for i in dialog_data["dialogs"]: + # Create a dialog structure for each dialog. dialog_id = i["ID"] dialog_struct += fxconv.u32(dialog_id) dialog_struct += fxconv.string(i["dialog"]) @@ -330,6 +357,7 @@ def convert_dialog(input, output, params, target): name = os.path.splitext(os.path.basename(input))[0] fxconv.elf(dialog_struct, output, f"__{name}", **target) except Exception as e: + # Show an error message if the conversion fails. sys.stderr.write(f"ERROR: Failed convert dialogs.\n" + f" Error message: {e}\n") sys.exit(1)