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

Feature request: NBA2kStuff's format & conversion #5

Open
9 tasks done
ak2yny opened this issue Jun 23, 2023 · 0 comments
Open
9 tasks done

Feature request: NBA2kStuff's format & conversion #5

ak2yny opened this issue Jun 23, 2023 · 0 comments

Comments

@ak2yny
Copy link
Contributor

ak2yny commented Jun 23, 2023

The converter by BaconWizard17 can convert NBA2kStuff's xml format to JSON which Xmlb can compile to raven formats (xmlb, etc).
NBA2kStuff's xmlb-compile has its own error logging, but the one from Raven-Formats' Xmlb is better in my opinion. I've been using the converter for all of NBA2kStuff's formats.

The format can exist with an .xml extension (suggested by XMLBCUI), so the detection by extension doesn't work with that added. I added a format detection in my batch for Raven-Formats (QuickBatch), which works like this: JSON begins with {, XML begins with <. I've been using it for a while and it has always worked. The batch does not test for NBA2kStuff's format (which usually begins with XMLB, but I am not certain that this is a rule) so all other formats are assumed to be his format. This is my recommendation. When we check for that first character, we have to exclude bit order marks from the search. I don't know how the read_string(xmlb_file, offset: int) command handles BOM, but I'm sure that this part is a lot easier in Python than CMD.
As for the conversion, I've been using this method to convert for many files and it works: Compile to xmlb, decompile back to desired format. Using current Xmlb creates a file and reads it again, which slows down the process in comparison to read and write from stream. I think that conversion should happen by extension, as JSON and XML formats both make the most sense when using their native extensions. And the conversion would probably need a new argument: -c, --convert. Without the argument, it would compile to xmlb, using the specified extension (e.g. test.xml in xmlb format).

Required additions:

  • -c --convert arguments on line 220
  • On line 236, instead of going to convert, go to...
  • New function with format detection { and <. Reads file, passes 3 arguments: file as stream, format, output path. To convert or compile (decide with new argument args.convert). Convert also needs the argument has_indent (pass it through).
  • Modify compile function from extension to new argument ("xml", "json") on lines 202 and 204. Instead of the file extension [] is not supported error (214), use new function xml2json? (Converter by BaconWizard17), then handle JSON (new function?).
  • Modify decompile function to call new function (root_element2file).
  • New function (root_element2file? > arguments element: ET.Element?, output_path: Path, has_indent: bool) and move all parts of the decompile function except reading the file. New convert function needs this as well.
  • New convert function. I don't understand the ElementTree part, I assume root_element is an ET? This might require new or modified functions.
    • Decides input with received argument.
    • XML 2 ET: ET.fromstring(xml_as_string)
    • JSON 2 ET: data = json.load(json_as_string, object_pairs_hook=parse_json_object_pairs) (I think, not sure about the difference between load and loads) then, from_json_element(data[0]) (possibly make function, to also handle the root amount, see below)
    • NBA2kStuff's format 2 JSON: Use new Converter by BaconWizard17 (then use JSON 2 ET - a new function would really be better)
    • Pass the result (arguments ET.Element?, output path, has_indent) to (root_element2file)
  • New function Converter by BaconWizard17
    • Remove file handling and change the input argument file_name: Path to file
    • Change output from writing file to return JSON.
  • Possibly a new function to handle JSON strings (to ET.Element?) and modify the compile function to use this function as well.
ak2yny added a commit to ak2yny/raven-formats that referenced this issue Jun 23, 2023
New functions as requested in nikita488#5

Tested on various formats of decompiled and compiled herostats.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant