[tool] ECF <-> JSON

Discussion in 'Empyrion API' started by cmwhee, Mar 30, 2018.

  1. cmwhee

    cmwhee Commander

    Joined:
    Oct 31, 2016
    Messages:
    118
    Likes Received:
    72
    Hey everyone,

    So I wanted to do some work with the config files, but I couldn't load them procedurally. @geostar1024 said that he could use the data in python, so I made a python library for parsing ECF files

    it's available here

    https://github.com/lostinplace/ecf-parser

    the documentation is horrible, but if there's any interest I'll flesh it out better
     
    #1
  2. geostar1024

    geostar1024 Rear Admiral

    Joined:
    Jan 24, 2016
    Messages:
    1,483
    Likes Received:
    2,459
    This looks awesome! And you packaged it so nicely too! I'll let you know when I've gotten a chance to try it out.
     
    #2
    Ephoie likes this.
  3. Ephoie

    Ephoie Captain

    Joined:
    Jan 27, 2018
    Messages:
    329
    Likes Received:
    515
    Like to see where this goes, and am happy to help if i can.
     
    #3
  4. cmwhee

    cmwhee Commander

    Joined:
    Oct 31, 2016
    Messages:
    118
    Likes Received:
    72
    ....I mean, it's done, unless someone has some ideas for what to do with it next.
     
    #4
    Ephoie likes this.
  5. geostar1024

    geostar1024 Rear Admiral

    Joined:
    Jan 24, 2016
    Messages:
    1,483
    Likes Received:
    2,459
    @cmwhee: I've installed your tool, but it only seems to function on the command line; there's apparently no python module available for importing (I get an error trying to do "import ecf_parser"). Have I overlooked something, or was that just how you designed it?
     
    #5
    Ephoie likes this.
  6. cmwhee

    cmwhee Commander

    Joined:
    Oct 31, 2016
    Messages:
    118
    Likes Received:
    72
    there should be several functions available on ecf_parser, have you tried import * from ecf_parser?

    I just tried this on a fresh install and it worked:

    ```
    ~ pip install ecf_parser
    Collecting ecf_parser
    Downloading ecf_parser-0.1.2.tar.gz
    Building wheels for collected packages: ecf-parser
    Running setup.py bdist_wheel for ecf-parser ... done
    Stored in directory: /Users/xxx/Library/Caches/pip/wheels/c0/aa/f6/d28aa8a7d1eed5a44713cf8936f3ed127e1b0d91096b0a6ea4
    Successfully built ecf-parser
    Installing collected packages: ecf-parser
    Successfully installed ecf-parser-0.1.2
    (christopherwheeler-RXuGlzBg) ➜ ~ python
    Python 3.6.5 (default, Mar 30 2018, 06:41:53)
    [GCC 4.2.1 Compatible Apple LLVM 9.0.0 (clang-900.0.39.2)] on darwin
    Type "help", "copyright", "credits" or "license" for more information.
    >>> import ecf_parser
    Traceback (most recent call last):
    File "<stdin>", line 1, in <module>
    File "/Users/xxx/.local/share/virtualenvs/christopherwheeler-RXuGlzBg/lib/python3.6/site-packages/ecf_parser/__init__.py", line 3, in <module>
    import jsonpickle
    ModuleNotFoundError: No module named 'jsonpickle'
    >>>
    (xxx-RXuGlzBg) ➜ ~ pip install jsonpickle
    Collecting jsonpickle
    Downloading jsonpickle-0.9.6.tar.gz (67kB)
    100% |████████████████████████████████| 71kB 3.0MB/s
    Building wheels for collected packages: jsonpickle
    Running setup.py bdist_wheel for jsonpickle ... done
    Stored in directory: /Users/xxx/Library/Caches/pip/wheels/c8/c5/88/0975a9ef0ae87799d3a4ae54244ca8f76eaaf03395f48a5129
    Successfully built jsonpickle
    Installing collected packages: jsonpickle
    Successfully installed jsonpickle-0.9.6
    (christopherwheeler-RXuGlzBg) ➜ ~ python
    Python 3.6.5 (default, Mar 30 2018, 06:41:53)
    [GCC 4.2.1 Compatible Apple LLVM 9.0.0 (clang-900.0.39.2)] on darwin
    Type "help", "copyright", "credits" or "license" for more information.
    >>> import ecf_parser
    >>> ecf_parser.parse_ecf_entry
    <function parse_ecf_entry at 0x10bab1268>
    >>>



    ```

    although apparently it doesn't auto-install jsonpickle, I'll fix that shortly
     
    #6
  7. geostar1024

    geostar1024 Rear Admiral

    Joined:
    Jan 24, 2016
    Messages:
    1,483
    Likes Received:
    2,459
    As it turns out, my system was running python 3.5 and I'd messed up my pip packages environment somehow (so fixed that enroute). With python 3.6, I was able to install ecf_parser (along with jsonpickle), and it imports ok now.
     
    #7
  8. zztong

    zztong Rear Admiral

    Joined:
    Apr 12, 2016
    Messages:
    249
    Likes Received:
    269
    I'm happy to see these ECF tools.

    I've been toying with Python (never having learned it) and thinking of Empyrion and thought ECF files were YAML, but eventually realized they weren't. I found this discussion while searching the boards.

    I had taken a look at RimWorld mods and found many are just changes to the game's XML files. In some cases just a few lines of XSLT. Then I though there must be something like this for Empyrion and that maybe I could use a mod to change the default maximum number of Solar Panels allowed in my Single Player game, rather than change the Config_Example.ecf file.

    Then, perhaps a type of mod could be just ECF changes. When a new game is created, load up the Config_Example.ecf file, loop through the ECF mods in some player determined order, and place the resulting Config.ecf file into the saved game.

    Being a Python newb, I'm not sure what pieces are missing.

    It looks like folks use XSLT on JSON. (Oops, by converting JSON to XML.)
    It looks like the game _doesn't_ use a Config.ecf from the Saves/Games/* folders.
    The format of a mod file might need extra stuff, like a way to identify what version of the game it addresses.
    There'd have to be a way to specify an order to apply the mod files.

    I dunno, just thinking. Tonight I had time to dig and look around.
     
    #8
  9. zaphodikus

    zaphodikus Captain

    Joined:
    Oct 1, 2016
    Messages:
    471
    Likes Received:
    226
    I have a github PR up for cmwhee; to update the tests. Trying to read the code still at this stage.

    You apparently did push a exported JSON file up, but it's currently zero length, may want to look into that. What did and did the library not do? I mean it converts to easier to use json, but what did you do with it at the time Chris?

    Also, the "jsonl" file - your code fails to load it going .ecf => json and then back is borked on my interpreter. I'm no guru on python generators, but the json decoding of agenerator is jsut beyonf my skillz with the language to tell where it is broken.
     
    #9
    Last edited: Mar 7, 2020
  10. cmwhee

    cmwhee Commander

    Joined:
    Oct 31, 2016
    Messages:
    118
    Likes Received:
    72
    Oof, I just noticed this. I haven't paid attention to this in a while.

    I've just recently started getting back into Empyrion in preparation for v12. Let me know if there are any tools you'd like ot see, or if you'd like this one actually finished
     
    #10

Share This Page