factorio-draftsman icon indicating copy to clipboard operation
factorio-draftsman copied to clipboard

blueprint slots in a book are not round-trip safe

Open ca1f opened this issue 10 months ago • 1 comments

Describe the bug Loading the blueprint string of a book with individual blueprints scattered across multiple slots with gaps between them loses the index of the individual blueprints.

Current Behavior Given the blueprint string

0eNrFUu1ugzAMfBf/DhXQL+BVpgnxYTFrwYlC6FZVvPsIbVeqtlJHkfbTjn3nu8sBctmiNsQ
2zZX6hORw6TSQvI1K90aF4mO7oYoz6Xp2rxESIIs1COCsdtWXUiWyV3xgY6ETQFziNyRB9y4
A2ZIlPOIMxT7lts7R9AP3EQRo1fRLih1jD7RZrAXsIYkX685hDuzJ6FgBOzTNsBBGwWobh9t
oE/tLf3W5xu/EVH1k1EvqRvsPtQX+K+KCK3HzpltjSW3tocTCGio8rSRO8+Eu0kNHon9KO6d
qDrG3MDdKV8fko+kyw3ub3hC/gKywtMP07MhT/2j4SK2uTFZiqmXG7FT1nqG1xFWvmVspfzl
Pk9558imO0HGU6PKwpi2cIWOqE/T1wN8YlvPY0v0Axx62Ww==

Screenshot_20240424_191735

and processing the blueprint string with the following snippet:

import sys
import functools

import draftsman.blueprintable


data = b"".join(iter(functools.partial(sys.stdin.buffer.read, 1024), b""))

bp = draftsman.blueprintable.get_blueprintable_from_string(data)

print(bp.to_string())

will pack the individual blueprints in the book together, making them lose their original positioning in the original blueprint string:

Screenshot_20240424_193536

Expected behavior When loading a blueprint string of a book into a draftsman.blueprintable.BlueprintBook instance and converting the result back to a blueprint string should preserve the position of individual blueprints within the given blueprint book.

Please also include the following: Draftsman version: factorio-draftsman==1.1.1 Python version: CPython 3.12.2

ca1f avatar Apr 24 '24 17:04 ca1f

I'm probably just going to lump this fix into 2.0, as it will hopefully inspire me to release 2.0 already for the love of god.

redruin1 avatar Apr 25 '24 22:04 redruin1