I want to convert blueprint strings like this:
0eNqdm91u20YQhV+l4LUUcH+51H2eIJdBEMg26xKgSIGiihqG3z1U3NZCwhW/oytDsvXpzO7OjHxm9Vo8dOfmOLb9VOxei/Zx6E/F7utrcWqf+313eW56OTbFrmin5lBsin5/uDyaxn1/Og7jtH1ouql42xRt/9T8U+zM22b1xadp6Jvtn+ex3z82V6+1b982RdNP7dQ27yp+Pnj53p8PD804w3PvvymOw2l+2dBf3nRGbetN8TL/iDP9qR2bx/ff2Yu6X6CWQysMdRyaMNRzaMDQwKERQyOHOgytONRjaOJQswj1C9CaQy1WakpMNRzKU4pvlOEpJYTPU4offsNTih8pw1OKFxTDU4qnqeEpxeup4SnFS5/hKXXJE1r6y0xPWqjSn/49Ve5TeFtCfSRS25+acZqfzHalsF5CrMXS4po0R6RVXNpH0pwO+67bNt3852P7uD0OXZNvRn5RXMBxurU4I4nT8zgrLM2sSdPbTADHtyYBWxyww+mwFq/7yIbz/NlufB6H+Wcm4nI54M3/Hx774/nyEfP3d7EgfsPDd9q5Lm8ca+fpUq6dahdAkI4HGdU2uqyqEjbYr2zwcJ5yO5y0LblVaVxNt2StoPoSbEnEW+INFbbWhDxJiMSFiQlhbmWE90KDtEDcR150Q/+8/Ws/n8On7Q124uwodEzCq35ZyG5/OOYbpV1cv6TGG7m+WmU7zA6l0JUJz6haDWdboaESnkP7Xt7Y9uB5jyOK1KwRgo28UREcy5lbKRPUlBFOoZoxvFhEobsQnJovvARHod0QHMsWcytdopctQgPsLMEk+08ewUZVbAmglayVUJPskpIFqGWbFFCrUtUKFqAyqlQCtbKjS+J3sqVLqLL7TBZAdp8JVHefSfy6/UyoSdVKFqBWpQJoKmULA8SfjGyVE6pVtZIFcKpUAvWqqU/C51nFm1WKolISfSUKJcykTjRI8LU60QDQuhSVguhrIwolTKtaRiR4p05eCNSLSkn0QRRKmFGdEJHgK3VCRKBJVEqir0WhJRmOluooyxCqUWdZiGpFrWgBnCgVQb08ILPL1qQpA/f/zDIhyiOxrJjqPvMwIyxxuzBDqBWDcJlxdT9AMggzNCPP5XKLfXUdQHIXM8Ic9xMzBC/P9bKhhfvMyIywyO3HDKFSJ3jZyJJgXWbE1Ni6XAbw8fzaEbTmLtszI8tiozMDcIK1mUH4u6zNDCyok7HsOse7bNGMrAoboRlAUgdr2bjqu0zUZVmuxLZpBmAUozTDsLwd+2WCcK0kQ7jvIolbhgXeFzJyouoaeHJtreJFPaMryZcpvHyXwjherZdlXk3FhesTy5vpDS6xGTHq/6x+fT5hrubh9NKD1+88GO/vufSQWciAa2hmISMuVhlAddclgkw4SZ2YBHIJVB5DEGqQxxCIalTHHFHlQQSiOtWHRlSvWuaIGtTiv/xJIUTVJUbqKtF8RVDVKUVQ1Skl0FiKHhyCGrFFIKgVvS0EdaIJh6Be9IsQNIjOFoJG9e73b9Rvm/evIO2uvu60Kbr9TJmf+7wfu5c/vhxmZNs/z7/4uxlPP18ZU2VNcrF0c3P7AeCWj3g=
to Lua files, like this:
local ce = entity.surface.create_entity
local fN = entity.force
local center = entity.position
ce{name = "express-transport-belt", position = {center.x + (-1), center.y + (-5)}, force = fN}
ce{name = "express-transport-belt", position = {center.x + (-2), center.y + (-5)}, force = fN}
ce{name = "express-transport-belt", position = {center.x + (1), center.y + (-5)}, force = fN}
ce{name = "express-transport-belt", position = {center.x + (0), center.y + (-5)}, force = fN}
ce{name = "express-splitter", position = {center.x + (-1.5), center.y + (-4)}, force = fN}
ce{name = "express-underground-belt", position = {center.x + (-1), center.y + (-3)}, force = fN,type = "output"}
ce{name = "express-transport-belt", position = {center.x + (-2), center.y + (-3)}, force = fN}
ce{name = "express-splitter", position = {center.x + (0.5), center.y + (-4)}, force = fN}
ce{name = "express-transport-belt", position = {center.x + (1), center.y + (-3)}, force = fN}
ce{name = "express-underground-belt", position = {center.x + (0), center.y + (-3)}, force = fN,type = "output"}
ce{name = "express-transport-belt", position = {center.x + (-1), center.y + (-2)}, force = fN,direction = 6}
ce{name = "express-splitter", position = {center.x + (-0.5), center.y + (-1)}, force = fN}
ce{name = "express-transport-belt", position = {center.x + (-2), center.y + (-2)}, force = fN}
ce{name = "express-transport-belt", position = {center.x + (1), center.y + (-2)}, force = fN}
ce{name = "express-transport-belt", position = {center.x + (0), center.y + (-2)}, force = fN,direction = 2}
ce{name = "express-transport-belt", position = {center.x + (-1), center.y + (0)}, force = fN}
ce{name = "express-underground-belt", position = {center.x + (-1), center.y + (1)}, force = fN}
ce{name = "express-transport-belt", position = {center.x + (-2), center.y + (1)}, force = fN}
ce{name = "express-transport-belt", position = {center.x + (-2), center.y + (0)}, force = fN,direction = 2}
ce{name = "express-transport-belt", position = {center.x + (1), center.y + (0)}, force = fN,direction = 6}
ce{name = "express-transport-belt", position = {center.x + (1), center.y + (1)}, force = fN}
ce{name = "express-underground-belt", position = {center.x + (0), center.y + (1)}, force = fN}
ce{name = "express-transport-belt", position = {center.x + (0), center.y + (0)}, force = fN}
ce{name = "express-splitter", position = {center.x + (-0.5), center.y + (2)}, force = fN}
ce{name = "express-splitter", position = {center.x + (-1.5), center.y + (3)}, force = fN}
ce{name = "express-transport-belt", position = {center.x + (-2), center.y + (2)}, force = fN}
ce{name = "express-transport-belt", position = {center.x + (1), center.y + (2)}, force = fN}
ce{name = "express-splitter", position = {center.x + (0.5), center.y + (3)}, force = fN}
ce{name = "express-transport-belt", position = {center.x + (-1), center.y + (4)}, force = fN}
ce{name = "express-transport-belt", position = {center.x + (-2), center.y + (4)}, force = fN}
ce{name = "express-transport-belt", position = {center.x + (1), center.y + (4)}, force = fN}
ce{name = "express-transport-belt", position = {center.x + (0), center.y + (4)}, force = fN}
Is there a easy way?
Is there any Blueprint String to Lua converter?
- DellAquila
- Inserter
- Posts: 48
- Joined: Fri Mar 16, 2018 2:54 pm
- Contact:
Re: Is there any Blueprint String to Lua converter?
I recognize that code
If you wanna maintain the ruins mod, just tell me and I'll make it happen. I should also be able to get you the tool that was used to generate the files.
If you wanna maintain the ruins mod, just tell me and I'll make it happen. I should also be able to get you the tool that was used to generate the files.
I'm an admin over at https://wiki.factorio.com. Feel free to contact me if there's anything wrong (or right) with it.
Re: Is there any Blueprint String to Lua converter?
Enter it here http://www.txtwizard.net/compression without the 0 at the start and select deflate.
You'll get a json with all this info.
After copying it into this http://jsonprettyprint.com/ you get a nice looking format like this:
You'll get a json with all this info.
After copying it into this http://jsonprettyprint.com/ you get a nice looking format like this:
JSON
- DellAquila
- Inserter
- Posts: 48
- Joined: Fri Mar 16, 2018 2:54 pm
- Contact:
Re: Is there any Blueprint String to Lua converter?
Bika!!! I love your mod!!! XD I'm learning a lot from it... I'm making this Balancers mod, and i use some of the ruins code to facilitate XD Actually, your code make it possible!
https://mods.factorio.com/mod/Balancers
Its about put some "composite items", like a ruin, when put one object.... Instead of using blueprints, you can make balancers in a assembling machine and put it in your factory....
Is there an easy way to a noob convert the blueprints to composite items in that way?
Steinios, that helps a lot, i'm getting this json code from https://factorioprints.com/, but in your way i think its quickly....
https://mods.factorio.com/mod/Balancers
Its about put some "composite items", like a ruin, when put one object.... Instead of using blueprints, you can make balancers in a assembling machine and put it in your factory....
Is there an easy way to a noob convert the blueprints to composite items in that way?
Steinios, that helps a lot, i'm getting this json code from https://factorioprints.com/, but in your way i think its quickly....
- eradicator
- Smart Inserter
- Posts: 5211
- Joined: Tue Jul 12, 2016 9:03 am
- Contact:
Re: Is there any Blueprint String to Lua converter?
What about using LuaItemStack.build_blueprint() directly? Or just looping over the decompressed bp table. Converting a nice table into a block of hard to edit text doesn't sound like a good solution to me :P.
Ok...i'm way too bored and wrote some code to directly spawn in a blueprint from string (using a blueprint-on-the-ground to decode the string :P). Conveniently calling create_entity has the same format as the blueprint has, and it simply ignores superflous things like entity_index. Though it will need further work if you want circuit connections...
(You can remove the deepcopy if you don't plan on storing the decoded table of entities...)
Ok...i'm way too bored and wrote some code to directly spawn in a blueprint from string (using a blueprint-on-the-ground to decode the string :P). Conveniently calling create_entity has the same format as the blueprint has, and it simply ignores superflous things like entity_index. Though it will need further work if you want circuit connections...
Code: Select all
/c
--[[FUNCTION DEFINITION]]
local function build_blueprint_from_string(bp_string,surface,offset,force)
local bp_entity = surface.create_entity{name='item-on-ground',position=offset,stack='blueprint'}
bp_entity.stack.import_stack(bp_string)
local bp_entities = bp_entity.stack.get_blueprint_entities()
bp_entity.destroy()
for _,entity in pairs(util.table.deepcopy(bp_entities)) do
entity.position = {entity.position.x + offset.x, entity.position.y + offset.y}
entity.force = force
surface.create_entity(entity)
end
end
--[[FUNCTION CALL]]
local bp_string = "0eNqVlu9qg0AQxN9lP1/A2zuN8VVKKZoc5SA5RS+lIfju1QRKabbpzifx389ldgbnSt3xHIYxpkzNleK+TxM1L1ea4ntqj+u1fBkCNRRzOJGh1J7Wszy2aRr6MW+6cMw0G4rpED6psfOroZByzDHcSbeTy1s6n7owLg/8xTA09NPyWp/Wry6oTWnoshzcQj/EMezv93g2D1DWQ50a6vRQr4Z6PdSKUC9ASz2U1ZNWauj3oAJlq6b4J5QaNo2VMDsYwxLGFvAS7f9LtBamsoLK6BpF5axDMbJyevu7Z9PoDc+i/pLfbYXOxgoo7H9ZNzgAsm5wAAoJw7D/FfZn2P6FAoq6X5SNUfPLqqHeV3iWS5Cp0awCw1Uo5kRjoDEMnAkxWrxDu8Ov2FdSdSjQ7qCBwgnRQBntDhooGhhxM86Dpnn4HS5V9FZbmx8t19BHGKf76PWWbe2qwvl5/gIqEqz8"
--[[use a surface suitable for your usecase...]]
local first_available_surface
for _,surface in pairs(game.surfaces) do first_available_surface = surface break end
--[[offset from the surface center, i.e. position on the surface]]
local offset = {x = 10, y = 10}
local force = 'player'
build_blueprint_from_string(bp_string,first_available_surface,offset,force)
-
- Filter Inserter
- Posts: 302
- Joined: Fri Mar 18, 2016 4:34 pm
- Contact:
Re: Is there any Blueprint String to Lua converter?
Or you could just build_blueprint{} and then revive() each of the returned entities...
- eradicator
- Smart Inserter
- Posts: 5211
- Joined: Tue Jul 12, 2016 9:03 am
- Contact:
Re: Is there any Blueprint String to Lua converter?
justarandomgeek wrote:Or you could just build_blueprint{} and then revive() each of the returned entities...
Edit: Semi-removed incorrect information, see below posts.
Last edited by eradicator on Sat Jun 02, 2018 9:33 am, edited 1 time in total.
-
- Filter Inserter
- Posts: 302
- Joined: Fri Mar 18, 2016 4:34 pm
- Contact:
Re: Is there any Blueprint String to Lua converter?
Build_blueprint *returns* all the ghosts.eradicator wrote:The problem with that (as i just discussed something similar in another thread) is that there is as far as i know no easy way to get a handle of all the ghosts you just created. So depending on how you try to approximate you might accidentially revive an unrelated ghost that was a) also in the general area, or b) built in the same tick. Also build_blueprint can fail creating a ghost if it doesn't fit (trees, rocks, other stuff in the way), while create_entity will generally succeed even for things like pumps over land, or assemblers over water.justarandomgeek wrote:Or you could just build_blueprint{} and then revive() each of the returned entities...
- eradicator
- Smart Inserter
- Posts: 5211
- Joined: Tue Jul 12, 2016 9:03 am
- Contact:
Re: Is there any Blueprint String to Lua converter?
Hrng. I was hoping it would do that. But the API doc didn't list any return value. That still leaves the problem of ghosts not being placed because of unsuitable terrain though.justarandomgeek wrote:Build_blueprint *returns* all the ghosts.