redruin1 / factorio-draftsman

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

blueprint slots in a book are not round-trip safe #119

Open ca1f opened 4 months ago

ca1f commented 4 months ago

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

redruin1 commented 4 months ago

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.