A pair of helper scripts for Factorio blueprint (string) parsing.
Factorio blueprint strings are base64-encoded and zlib compressed JSON. There is a leading 0
which prefixes the blueprint string. Consider:
0eNp9j80KwjAQhN9lzmmhbWI0ryIibV0kkD+SVCwl725TL548zjLzzeyGySwUonYZaoOevUtQ1w1JP91o6i2vgaCgM1kwuNFWlexoTEOG5hz13ARvCIVBuwe9obpyYyCXddb0xR1ivbvFThR3w18QQ/Bpz3pX+ytvkLIVDCtUM/ChFaUWHIvUzwMML4rpiPXnjstLL4XgXMhTKR9Exkxi
The preceeding is a base64 encoded blueprint string for a single Small electric pole
with no connections or anything else going on.
Stripping the leading 0
we have the real base64 blob:
0eNp9j80KwjAQhN9lzmmhbWI0ryIibV0kkD+SVCwl725TL548zjLzzeyGySwUonYZaoOevUtQ1w1JP91o6i2vgaCgM1kwuNFWlexoTEOG5hz13ARvCIVBuwe9obpyYyCXddb0xR1ivbvFThR3w18QQ/Bpz3pX+ytvkLIVDCtUM/ChFaUWHIvUzwMML4rpiPXnjstLL4XgXMhTKR9Exkxi
Using bpstring-to-json.rb
as: ./bpstring-to-json.rb sample.txt sample-decoded.json
we get the JSON representation of the blueprint (here it has been "prettified:"
{
"blueprint": {
"icons": [
{
"signal": {
"type": "item",
"name": "small-electric-pole"
},
"index": 1
}
],
"entities": [
{
"entity_number": 1,
"name": "small-electric-pole",
"position": {
"x": 1377.5,
"y": -343.5
}
}
],
"item": "blueprint",
"version": 281479275544576
}
}
This is very handy but complex blueprints can be extremely large which can make counting entities tricky. Enter component-counter.rb
.
Counting entities can be done with component-counter.rb sample-decoded.json
:
small-electric-pole: 1
Total entities: 1
For a more complex blueprint:
assembling-machine-1: 4
assembling-machine-2: 124
chemical-plant: 2
fast-inserter: 33
inserter: 237
long-handed-inserter: 75
medium-electric-pole: 7
pipe: 2
pipe-to-ground: 1
small-electric-pole: 146
splitter: 1
transport-belt: 936
underground-belt: 55
Total entities: 1623