Created
September 16, 2020 09:23
-
-
Save Bilka2/e06c5f10cf7bc74d45c210c50f1443ef to your computer and use it in GitHub Desktop.
Decode a Factorio blueprint string, change some of it and reencode it
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import json | |
import zlib | |
import base64 | |
original_bp_string = '0eNp9j80OgjAQhN9lzq0RFNC+ijGGnw1uQhdCi5GQvrstXjx5m9mfb2c3NMNC08ziYTZwO4qDuW1w3Es9pJpfJ4IBe7JQkNomVztHthlYem3r9slCOkdQYOnoDZOFuwKJZ8/05e1mfchiG5rjwH+SwjS6uDxKShCB+nQoFNYoskOR7sQ0LvWmeeyW1vMr0rWNeiB9gslDSrBnNj8vKrxodjs2v2Tn6nytyio7lkUZwgd0Blhx' | |
bp_json = json.loads(zlib.decompress(base64.b64decode(original_bp_string[1:])).decode('utf8')) | |
# there is one entity in the blueprint, it's an assembler with a item request for 2 prod-3 modules and no recipe set | |
# for the fields of the blueprint json see https://wiki.factorio.com/Blueprint_string_format | |
bp_json['blueprint']['entities'][0]['items'] = {'copper-plate': 200} # overwrites existing item request | |
bp_json['blueprint']['entities'][0]['recipe'] = 'copper-cable' # creates new key/value pair | |
changed_bp_string = '0' + base64.b64encode(zlib.compress(bytes(json.dumps(bp_json), 'utf8'))).decode('utf8') | |
print(changed_bp_string) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment