redruin1 / factorio-draftsman

A complete, well-tested, and up-to-date module to manipulate Factorio blueprint strings. Compatible with mods.
MIT License
114 stars 19 forks source link

Updates to support 2.x. #123

Open jmgurney opened 2 weeks ago

jmgurney commented 2 weeks ago

Describe the bug

Initial import of a 2.0 blueprint causes an error. (Specific version is 2.0.14 build 79988)

It appears that the type key is no longer required on the signals in icons.

It also appears that the direction has now double, that is, it supports NNE/SSW type directions, so EAST is now 4, SOUTH 8, and WEST is 12.

Both of these are documented on the factorio wiki: https://wiki.factorio.com/Blueprint_string_format#SignalID_object

Current Behavior

Load the following blueprint:

0eNp9jsEKgzAQRP9lzlGwmlbzK6UUtUtZSDZiYqlI/r3RHnrrcYd5b3bDYBeaZpYIs4FHLwHmuiHwU3q7Z9I7gkFwvbUFWRrjzGMxeUtICiwPesNU6aZAEjkyfQXHsd5lcQPNuaD+iRQmHzLrZV/MvkupFdaMVaVOu5sjuQz/vlV40RwOQp9PXdN1uqnrtq3alD4FdUcL

Then try to make a blueprint out of it:

>>> blueprint = Blueprint(bp_string)
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/Users/jmg/git/cnidetobp/p/lib/python3.10/site-packages/draftsman/utils.py", line 858, in inner
    result = func(*args, **kwargs)
  File "/Users/jmg/git/cnidetobp/p/lib/python3.10/site-packages/draftsman/classes/blueprint.py", line 140, in __init__
    super(Blueprint, self).__init__(
  File "/Users/jmg/git/cnidetobp/p/lib/python3.10/site-packages/draftsman/utils.py", line 858, in inner
    result = func(*args, **kwargs)
  File "/Users/jmg/git/cnidetobp/p/lib/python3.10/site-packages/draftsman/classes/blueprintable.py", line 48, in __init__
    self.load_from_string(init_data)
  File "/Users/jmg/git/cnidetobp/p/lib/python3.10/site-packages/draftsman/utils.py", line 858, in inner
    result = func(*args, **kwargs)
  File "/Users/jmg/git/cnidetobp/p/lib/python3.10/site-packages/draftsman/classes/blueprintable.py", line 87, in load_from_string
    self.setup(**root[self._root_item])
  File "/Users/jmg/git/cnidetobp/p/lib/python3.10/site-packages/draftsman/utils.py", line 858, in inner
    result = func(*args, **kwargs)
  File "/Users/jmg/git/cnidetobp/p/lib/python3.10/site-packages/draftsman/classes/blueprint.py", line 156, in setup
    self.icons = kwargs.pop("icons", None)
  File "/Users/jmg/git/cnidetobp/p/lib/python3.10/site-packages/draftsman/classes/blueprintable.py", line 257, in icons
    six.raise_from(DataFormatError(e), None)
  File "<string>", line 3, in raise_from
draftsman.error.DataFormatError: Or([Schema({'index': And(Use(<class 'int'>), <function <lambda> at 0x103154700>), 'signal': Schema(And(Use(<function normalize_signal_id at 0x1031544c0>), {Optional('name'): <class 'str'>, 'type': <class 'str'>}))})], None) did not validate [{'signal': {'name': 'assembling-machine-2'}, 'index': 1}, {'signal': {'name': 'transport-belt'}, 'index': 2}]
Or(Schema({'index': And(Use(<class 'int'>), <function <lambda> at 0x103154700>), 'signal': Schema(And(Use(<function normalize_signal_id at 0x1031544c0>), {Optional('name'): <class 'str'>, 'type': <class 'str'>}))})) did not validate {'signal': {'name': 'assembling-machine-2'}, 'index': 1}
Key 'signal' error:
Missing key: 'type'
None does not match [{'signal': {'name': 'assembling-machine-2'}, 'index': 1}, {'signal': {'name': 'transport-belt'}, 'index': 2}]

Expected behavior

I expect that a valid blueprint not raise an exception

Additional context

This is from a 2.0 factorio:

>>> hex(blueprint_dict['blueprint']['version'])
'0x20000000e0002'

Please also include the following: Draftsman version: 1.1.1 Python version: 3.10.14

redruin1 commented 2 weeks ago

Thanks for the report. I'm currently actively working on the 2.0 branch, since there are some major structural changes (both on my end and the games end) that are best left for a major release. Large swaths of the string format have changed, so I'm afraid this might take a couple of weeks to properly get it to feature completeness with the game itself. (For example, I've currently rewritten how Draftsman extracts its data, since there are now multiple "official" configurations that it has to anticipate.)

Feel free to suggest the first things I should work on, if you have a particular preference.

ewjake commented 2 weeks ago

I personally want the lamps updated first, since they now have much more options for colors than previously. Want to make my own image to lamp blueprint code as a side project.

jmgurney commented 2 weeks ago

The direction issue is of low importance for me. I was going to try to use the library to layout circuits which is highest priority for me.

SilverFolfy commented 2 weeks ago

I personally want the lamps updated first, since they now have much more options for colors than previously. Want to make my own image to lamp blueprint code as a side project.

This please, I'm also trying to do that right now (load image with python "pillow", iterate over the pixels and create blueprint with lamps from those pixels' RGB colors). I've gotten to the point where I have all the code for this ready, but draftsman does not allow me to set the "color" attribute to a lamp in a blueprint object.

ewjake commented 2 weeks ago

Yeah I ended up just raw dogging the json to output mine. Works pretty damn well tho! I did basically the exact same thing with Pillow. I just have to get the power pole placement to be smarter but the colors are about what you'd expect from lamps. Looks way better than old programs did with the limited colors tho!

Looking forward to when this gets updated so I can try new stuff!