Page 1 of 1

blueprint string viewer

Posted: Fri Dec 16, 2016 10:22 am
by Skandragon
A while back, someone posted about an online blueprint string viewer. AFAIK, that is no longer available. Am I wrong, and if so, what is the URL?

I have started writing one, but it's going to be tedious to get right; before I go too far down this rabbit hole, I want to make sure I'm not repeating efforts someone else has done.

Right now, a sample of my "red circuit pod" is here: http://www.flame.org/~explorer/factorio ... t-pod.html The intent is not to render just like it is in game, but to show it more like a building floor plan, and use simple boxes and such. Eventually, I'll annotate things like requester boxes with what they request, filter inserters with their list, things connected to networks or wires, etc with their parameters.

The blueprint string this is rendered from:

Code: Select all

H4sIAAAAAAAA/91VzW7bMAx+lSBnC3DcbpdOz2IoEpMQkyVNorMWht99dKP1z80ibwXaLpcgEcnvhyJl/Mp6reyqlQM4QkJIchic6kCuVUrQbS26veiUPqAD
cbWugk8c5p0cbqW4ru6kaMYqgsYwpZijchqM0Bh1j7Qeq1xspxIJdAkiQXxRpZmqXI2VQa5z/29Tae8oettu4aCO6KMcrN9jItQtH5mcvMOYqE24d8rKge4m
DkjQrassYc6HsxMpR7Kppw//7oKKihhi/e107phFS759QHRAP338Lin2MD5I+n0s9AFYXIQfPX/P1G2yunze7tBy0GQzOgO3cpO5gmXY6N1UMLNlMj0z/VIz
5im4ycHBqnvorYpPopZyexdqf7gJ84vw9TNchMuD8oZz0jyz51zDA3PCI4gQ/RHN63eyKerJCXXzbDoXKK85u34Urn0IEIVWWwuPolOnrBVWdWGe/JTmIpEL
NM6NbYrTNq/3o3B5Ft2JDgz2nThNIasPns2bN6ku7+eZdl4GKseZwSzxptiaS0LfbFoWDMt//ZJ9oNeiftnf679fFOeXzBkz6jIv8r5jlQT/+FB/IOdnk1W8
Lj/P4z5WOBVhjxcB54Zw/k0E6qNbtTfgzC+qlKFJaQsAAA==

Re: blueprint string viewer

Posted: Tue Dec 20, 2016 2:07 am
by aober93
Might be useful if implemented with the blueprint share sites. The users often post blueprints, but no picture.

Re: blueprint string viewer

Posted: Tue Dec 20, 2016 6:15 am
by Skandragon
aober93 wrote:Might be useful if implemented with the blueprint share sites. The users often post blueprints, but no picture.
That's the plan.

Well, sort of. I think my ultimate plan is to provide a blueprint management site, although I do see some hints that 0.15 will have loading and saving of them more integrated.

Things like, "give me a blueprint book that has oil processing and rail intersections set" or "take this blueprint and lower the logistic limits for the inserters from 200k to 10k"

Re: blueprint string viewer

Posted: Wed Dec 21, 2016 3:43 pm
by sniderthanyou
I love the idea! Do you intend to keep the source private, or would you consider hosting it on GitHub to allow others to contribute?

Re: blueprint string viewer

Posted: Wed Dec 21, 2016 10:38 pm
by Skandragon
sniderthanyou wrote:I love the idea! Do you intend to keep the source private, or would you consider hosting it on GitHub to allow others to contribute?
Right now it's private mostly because it's in its infancy. However, if you are offering to help contribute... I'm interested in that, and plans can change. What I have now is more of a proof of concept -- it's got some pretty major hacking behind it.

First, a Ruby script to uncompress the BASE64 encoded data. Then a Lua script to output the data as JSON. Then a Ruby script to generate SVG. Lots of moving parts.

Re: blueprint string viewer

Posted: Mon Dec 26, 2016 2:34 am
by aober93
How do you read the blueprint string anyway. It begins with H4sIAAAAAA what does that mean?

Re: blueprint string viewer

Posted: Mon Dec 26, 2016 3:17 am
by Yoyobuae
aober93 wrote:How do you read the blueprint string anyway. It begins with H4sIAAAAAA what does that mean?
It's BASE64 encoded and GZipped. Once those two are undone you get something like:

Code: Select all

do local _={entities={{name="constant-combinator",position={x=-3,y=-1},direction=2,control_behavior={filters={{signal={type="virtual",name="signal-black"},count=-3,index=1},{signal={type="item",name="copper-plate"},count=-4,index=2},{signal={type="item",name="iron-plate"},count=-4,index=3}}},connections={["1"]={red={{entity_id=2,circuit_id=1}}}}},{name="decider-combinator",position={x=-1.5,y=-1},direction=2,control_behavior={decider_conditions={first_signal={type="virtual",name="signal-each"},constant=0,comparator=">",output_signal={type="item",name="copper-plate"},copy_count_from_input=true}},connections={["1"]={red={{entity_id=1}},green={{entity_id=3,circuit_id=1}}},["2"]={green={{entity_id=3,circuit_id=2}}}}},{name="decider-combinator",position={x=-1.5,y=0},direction=2,control_behavior={decider_conditions={first_signal={type="virtual",name="signal-each"},constant=4,comparator="<",output_signal={type="virtual",name="signal-each"},copy_count_from_input=true}},connections={["1"]={green={{entity_id=3,circuit_id=2},{entity_id=2,circuit_id=1}}},["2"]={green={{entity_id=3,circuit_id=1},{entity_id=2,circuit_id=2},{entity_id=4,circuit_id=1}}}}},{name="decider-combinator",position={x=0.5,y=0},direction=2,control_behavior={decider_conditions={first_signal={type="virtual",name="signal-anything"},constant=3,comparator=">",output_signal={type="virtual",name="signal-black"},copy_count_from_input=false}},connections={["1"]={green={{entity_id=3,circuit_id=2}}},["2"]={green={{entity_id=5,circuit_id=1}}}}},{name="decider-combinator",position={x=2.5,y=0},direction=2,control_behavior={decider_conditions={first_signal={type="virtual",name="signal-black"},constant=2,comparator="<",output_signal={type="virtual",name="signal-black"},copy_count_from_input=true}},connections={["1"]={green={{entity_id=4,circuit_id=2},{entity_id=5,circuit_id=2}}},["2"]={green={{entity_id=5,circuit_id=1}}}}}},icons={{signal={type="item",name="decider-combinator"},index=1}}};return _;end

Re: blueprint string viewer

Posted: Mon Dec 26, 2016 1:05 pm
by ssilk
Moved from Show Your Creations to Tools.

Re: blueprint string viewer

Posted: Tue Dec 27, 2016 6:07 pm
by Skandragon
It's BASE64 encoded and GZipped.
Technically, I think it's just Deflated, as it does not have a gzip header from what I can tell.

Re: blueprint string viewer

Posted: Tue Dec 27, 2016 6:18 pm
by Yoyobuae
Skandragon wrote:
It's BASE64 encoded and GZipped.
Technically, I think it's just Deflated, as it does not have a gzip header from what I can tell.
Weill I just asked the file utility on Linux and it said it was gzip:

Code: Select all

$ cat blueprint.txt | base64 -d | file -
/dev/stdin: gzip compressed data
And piping it to zcat instead produced the output above. :D

Re: blueprint string viewer

Posted: Tue Apr 18, 2017 1:48 pm
by SyncViews
Did you get anywhere further with this?
Been playing with some concepts for a blueprint viewer/tool in Javascript/Rails.

Re: blueprint string viewer

Posted: Mon May 01, 2017 9:57 pm
by shockr
SyncViews wrote:Did you get anywhere further with this?
Been playing with some concepts for a blueprint viewer/tool in Javascript/Rails.
So have I, with the new 0.15 patch the internal blueprint string format is "<version:1char><base64+zlib:rest>"


Decode it:

Code: Select all

cat blueprint.b64 | tail -c +2 | base64 -d | zlib-flate  -uncompress
Pretty print it:

Code: Select all

cat blueprint.b64 | tail -c +2 | base64 -d | zlib-flate  -uncompress | python -m json.tool

Re: blueprint string viewer

Posted: Tue May 02, 2017 8:20 pm
by SyncViews
Yep the new JSON based format is a lot better, was able to fully implement in my webapp once I found a pure JavaScript deflate library. There are still some potential issues, but hopefully no one is expecting to put an entire factory in one in practice (I was able to fairly easily get something that used over a GB of memory for that decompressed JSON as well as poor CPU performance for inflate/deflate and JSON parsing).

Internal format is just a JSON representation of the Lua API's in a simple wrapper (for anyone porting existing logic, there is an extra '{"blueprint": {...}}' wrapper layer, and it uses "label" for the Blueprint name/label).
Only thing I am not 100% sure on is how "version" is encoded.

Re: blueprint string viewer

Posted: Wed May 03, 2017 5:14 pm
by cid0rz
Hum I 'm having some problems decoding new strings in python. In the past I did:
being todecodestr a read from an openfile of a blueprint:

Code: Select all

decoded_data = base64.decodestring(todecodestr)
    tempfile = StringIO.StringIO(decoded_data)
    decompressed = gzip.GzipFile(fileobj=tempfile)
    mydata = decompressed.read()
and from:

Code: Select all

H4sIAAAAAAAA/52TUW7bMAyGrxLodfJQJ2hfCu0GPUEwGIpEJwRkyaDpLIGhu1dS6m5Jk66p32zyJ///s2TDwgWj3aJREx97UGLjRugJPQtpNWs1gWdkhEFNk9dd6tCE
vOuA0VQmdBv0mgMJ2Ych9QWvpoN6+Pkoj6qqo7RIYMrnpTTBMwXXbGCn9xhITX9HNaloiz4tapEGbgbceu1mX3skHrUT8mTiVKxAm52IefLA2rN6kKEH0mWh+CFkGLkf
7xkVyzB/8pysrEUtfquJwKb8BcWxQZvDIJkRubwk0ZYA/FlLfdES5Vos86z/tNYxP/INtgWDFugm6apOoBPueIXum/abaP/skOGcbTLRa8omlPh1F9yXMqg/Ji+j56al
0DXok1q12g1wg/pHUqt/OF7+k08ozhluYswUz07r0xWeLToGyhfhPn4psVpJ9BYOxdcXsy4/5okSTRFdOEibunn99esZ3/fLT7RXTtsszIfc6Q24THOuwkF3vUsp4zMB
j+QXzTN4+wr96fJnVgQAAA==
got:

Code: Select all

do local _={type="blueprint",data={entities={{name="arithmetic-combinator",position={x=0.5,y=-1},direction=2,control_behavior={arithmetic_conditions={first_signal={type="virtual",name="signal-each"},constant=0,operation="+",output_signal={type="virtual",name="signal-each"}}},connections={["1"]={red={{entity_id=2,circuit_id=2}},green={{entity_id=1,circuit_id=2}}},["2"]={green={{entity_id=1,circuit_id=1}}}}},{name="decider-combinator",position={x=-1,y=0.5},control_behavior={decider_conditions={first_signal={type="virtual",name="signal-white"},constant=0,comparator=">",output_signal={type="virtual",name="signal-M"},copy_count_from_input=false}},connections={["1"]={green={{entity_id=3}}},["2"]={red={{entity_id=1,circuit_id=1}}}}},{name="constant-combinator",position={x=1,y=1},direction=6,control_behavior={filters={{signal={type="virtual",name="signal-white"},count=3,index=1}}},connections={["1"]={green={{entity_id=2,circuit_id=1}}}}}},icons={{signal={type="item",name="arithmetic-combinator"},index=1},{signal={type="item",name="decider-combinator"},index=2}},label="combinatorexample"}};return _;end
now the new blueprints:

Code: Select all

0eNrtWNmumzAQ/Rc/wxV2IAtS+wv9gKpCBCbJSGCQMWlRxL93DO1tmsU15EbqQ16ieJv1zBybE9sWLdQKpWbxiWFWyYbFX0+swb1MCzOnuxpYzFBDyTwm09KMcsgwB+VnVblFmepKsd5jKHP4wWLee/8UYBTpVOrbEkT/zWMgNWqE0Z5h0CWyLbegSIXNEo/VVUNHK2nUkzg/eIs81tEfQTpyVJCNq8IzhmhVFckWDukR6TQd+SUzobV8kNOY2R2qRidXfh1R6ZZm3i0ad/hfjD8NGBnuh74fKEzmILlTp2pwJ2afaF/V6rqdoB6OoDp9QLkfxdUdudNKnexUVSYoSRiLtWqhH5alHGMyeMrNj4L8PPJIIwpihiprUQ9DbrK0VwDyciPlj6QKNzFmc28gc5FjYQXLdZLFnxTfSuoOCw3qDrod8tGaEuGTQL5LG+2jbECR5jMpPg+Cc6zfycDN0PKrHNwM3uLdiBJybEsfChKvMPPrqoDr6PExeAt3MHDhlsZwXqkGr0r9yEr1/lreuBbyclohW7XcA0g0s5fzF0IeQEhoRwh3RcjKihBuR0johpDlLCYInkkEizMimNS/Q7f+vZpHfvyZPotJ5KdSLD6I8yK3mK3nNZLXnfCRPuJMJTywdoqNvVNc3jbuYWAzDwMvLnkEA2s7l4TOEOFWiIR2iKzdyIQHs1rrU58V0Vw2WbtVBeezfH4qm4Rzfd44+iwmtYLxASTeov7Ztf87A3RDuajnz/9nPdtf84sh/lTSA/3HZx+UPEa2NUOIl2EowvVixQXv+59LY1qv
give me incorrect padding error. I tried padding in the end with = till length divisible by 4 but still does not decode, any hint where the problem can be? So you say the changed the description format inside the blueprint to json? then once decoded sure there is a library to replace my parser ^^

Re: blueprint string viewer

Posted: Wed May 03, 2017 7:47 pm
by SyncViews
You need to strip that leading zero (likely a format version number).

Code: Select all

0eNrtWNmumzAQ/Rc/wxV2IAtS...
eNrtWNmumzAQ/Rc/wxV2IAtS...

Re: blueprint string viewer

Posted: Wed May 03, 2017 9:37 pm
by cid0rz
Thank you! Now i got it with:

Code: Select all

    todecodestr = bprintfile.read()
    todecodestr = todecodestr[1:]
    bprintfile.close()

    decoded_data = base64.b64decode(todecodestr)
    mydata=zlib.decompress(decoded_data)
didn't notice the 0 :!: