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

Add more utility for lmlsb edit and dump #133

Closed
wants to merge 13 commits into from

Conversation

dreamsavior
Copy link

Resolves #126

lmlsb edit

  • Added capability to insert certain parameters without prompt
  • Added capability to edit based on the list of parameters in JSON format
Usage: lmlsb edit [OPTIONS] LSB_FILE [LINE_NUMBER]

  Edit the specified command within an LSB file.

  Only specific command types and specific fields can be edited.

  The original LSB file will be backed up to <lsb_file>.bak

  WARNING: This command should only be used by advanced users familiar with
  the LiveMaker engine. Improper use of this command may cause undefined
  behavior (or a complete crash) in the LiveMaker engine during runtime.

  Note: Setting empty fields to improper data types may cause undefined
  behavior in the LiveMaker engine. When editing a field, the data type of the
  new value is assumed to be the same as the original data type.

  Batch mode:
  You can batch edit several line and paramaters with JSON file.
  The format of JSON file is as follow:
  {
      "36" : {
          "modified": true,
          "params": {
              "PR_LEFT": "20",
              "PR_TOP": "12"
          }
      }
  }

  You can generate the JSON via "lmlsb.exe dump" command with JSON mode.

  Example:
      - To edit line 33 with prompt:
      lmlsb.exe edit 00000001.lsb 33

      - To set the value of PR_LEFT parameter on line 33 to 20:
      lmlsb.exe edit 00000001.lsb 33 -p '{\"PR_LEFT\": 20}'

      - To import back the value from lmlsb dump:
      lmlsb.exe edit 00000001.lsb -b 00000001.json

Options:
  -p, --param TEXT  Parameter in JSON format.
  -b, --batch TEXT  Edit with parameter with JSON formatted file.
  --help            Show this message and exit.

lmlsb dump

  • Add option to dump into JSON formatted data that supports lmlsb edit
Usage: lmlsb dump [OPTIONS] INPUT_FILE...

  Dump the contents of the specified LSB file(s) to stdout in a human-readable
  format.

  MODE:
  text
      The full LSB will be output as human-readable text.

  xml
      The full LSB file will be output as an XML document.

  lines
      only text lines will be output.

  json
      The output will be a JSON-formatted LSB command (JSON will always be in UTF-8 format).
      You can edit the JSON and import it back using the lmlsb edit command.
      Use "jsonfull" option if you want to output all line.
      Note:   - Don't forget to set the "modified" flag to true for each line you edit.
              - This mode will only output the editable lines.

  jsonfull
      Will output the complete line instead of only editable lines


  Example:
      lmlsb.exe dump 00000001.lsb -m json -o 00000001.json

Options:
  -m, --mode [text|xml|lines|json|jsonfull]
                                  Output mode (defaults to text)
  -e, --encoding [cp932|utf-8]    Output text encoding (defaults to utf-8).
  -o, --output-file FILE          Output file. If unspecified, output will be
                                  dumped to stdout.
  --help                          Show this message and exit.

@codecov-commenter
Copy link

codecov-commenter commented Mar 12, 2024

Codecov Report

Attention: Patch coverage is 5.63380% with 134 lines in your changes are missing coverage. Please review.

Project coverage is 48.07%. Comparing base (04c8f5b) to head (808a6e7).

Files Patch % Lines
src/livemaker/cli/lmlsb.py 5.63% 134 Missing ⚠️

❗ Your organization needs to install the Codecov GitHub app to enable full functionality.

Additional details and impacted files
@@            Coverage Diff             @@
##           master     #133      +/-   ##
==========================================
- Coverage   49.04%   48.07%   -0.97%     
==========================================
  Files          23       23              
  Lines        5548     5672     +124     
==========================================
+ Hits         2721     2727       +6     
- Misses       2827     2945     +118     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

Copy link
Owner

@pmrowla pmrowla left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the PR! I've added a couple comments on coding style issues.

In general I'll have to think about whether or not to merge this, as I'm not sure about adding another data/serialization format to the dump output.

XML is already supported as a dump format, and I get that JSON can be easier to work with then XML, but one of the reasons for using XML here (and in the original tool pylm is forked from) is that the XML format gives a much more accurate representation of the original LiveMaker editor format (when you make a game in LM, the project files are stored as XML).

I think for addressing #126 it would be sufficient to have a simple command-line based workflow that just takes something like -p/--param PR_LEFT=20.

Being able to parse a file to set multiple lines/fields at once would be nice to have, but I think ideally we should be parsing XML (which would also enable parsing of actual/original LM project files)

One question I have is whether or not you added JSON here to facilitate something in translator++?

.gitignore Outdated
Comment on lines 103 to 105


deploy.bat
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This looks like a change that's specific to your workspace?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes it is.

src/livemaker/cli/lmlsb.py Outdated Show resolved Hide resolved
src/livemaker/cli/lmlsb.py Outdated Show resolved Hide resolved
@@ -150,9 +152,59 @@ def validate(input_file):
print(f" script mismatch, {len(orig_bytes)} {len(new_bytes)}")


def _dump_json(lsb, pylm, jsonmode):
jsonData = {}
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please use snake_case for variable names so that your changes match the rest of the code base

(as noted in the contributing docs, the code base generally follows PEP8 Python standards with the exception of code that is intended to directly mirror original LiveMaker engine Pascal naming conventions)

dreamsavior and others added 2 commits March 13, 2024 13:10
Co-authored-by: Peter Rowlands (변기호) <[email protected]>
Co-authored-by: Peter Rowlands (변기호) <[email protected]>
@dreamsavior
Copy link
Author

@pmrowla
Thank you for your insightful feedback.

In addressing the need for inputting values without manual intervention, several considerations emerged during the development process:

  • Ensuring the edit command could accept parameters without needing human input was crucial for automation. This is the main issue that lead to this PR.
  • Recognizing that multiple parameters might be involved, I pondered the most efficient way to transfer these values from CLI parameters to lmlsb.
  • I also grappled with the need to edit multiple lines simultaneously, seeking a method more efficient than invoking the lmlsb edit command individually for each line. This led me to explore batch mode editing via an external file, recognizing that CLI arguments might not suffice due to potential size limitations.
  • Recognizing the potential complexity of using an external file, I saw the importance of providing an easy way to create or edit templates. Thus, I introduced a new method in lmlsb dump to generate a ready-to-use template for the edit command.

After much trial and consideration, I found that JSON format offered the most logical solution for my use case. I prefer it over the original XML format due to its efficiency and compatibility with other applications. And yes, to answer your question, I've already integrated this feature for Translator++.

Thank you again for your feedback. I'll make sure to address your suggestions as I continue to refine the implementation.

@pmrowla
Copy link
Owner

pmrowla commented Mar 13, 2024

One thing to note would be that when pylivemaker is installed you can just use it as a library, so any scripts and utilties you need for translator++ purposes can be kept separate and just import livemaker as needed (they don't necessarily need to be added back into the pylm CLI)

@dreamsavior
Copy link
Author

Thank you for the hint @pmrowla

@pmrowla
Copy link
Owner

pmrowla commented May 27, 2024

Thanks again for this PR. I'm closing this for now as it's not something I have the time to maintain in pylm, and since it seems like this can be handled within translator++. But I'm open to revisiting this in the future if needed.

@pmrowla pmrowla closed this May 27, 2024
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

Successfully merging this pull request may close these issues.

lmlsb edit: support setting values from command line flags
3 participants