Generating Blueprints by Coding

Enhance your gameplay with these tools. This category is also the right place for tools useful for modders.
Mod databases, calculators, cheatsheets, multiplayer, scripts, libs and other useful stuff that is not strictly in-game mods.
User avatar
DemiPixel
Long Handed Inserter
Long Handed Inserter
Posts: 72
Joined: Mon Mar 21, 2016 7:27 am
Contact:

Generating Blueprints by Coding

Post by DemiPixel »

If you've ever done a lot of combinator stuff, you know it can be tedious to do by hand. I wrote a node.js library to make it very easy to import/export blueprints, and modify or just read them! Here's a video where I've taken advantage of the ability to interact with things outside of Factorio...

https://www.youtube.com/watch?v=Kry8lbrHjeY << Watch or else

For the above link:
I downloaded the video, shrunk and cropped it to 60x60, then ran (in an img/ folder)

Code: Select all

ffmpeg -i ../video.mp4 -r 20 %d.png
(20 = 20 fps)
Script to Generate the Screen
Script to Generate the Video Data

The library is called factorio-blueprint

Don't know where to start? Try playing with this or see if you can figure out what it does to start with!
Last edited by DemiPixel on Wed Jul 20, 2016 6:41 pm, edited 2 times in total.
delassa
Burner Inserter
Burner Inserter
Posts: 13
Joined: Mon Jun 29, 2015 6:35 pm
Contact:

Re: Generating Blueprints by Coding

Post by delassa »

Ok I must say that is the first time I have ever been rick rolled and enjoyed it, that is fantastic man.
dee-
Filter Inserter
Filter Inserter
Posts: 416
Joined: Mon Jan 19, 2015 9:21 am
Contact:

Re: Generating Blueprints by Coding

Post by dee- »

Sadly not accessible for Germany.
Unfortunately, this video is not available in your country because it could contain music from SME, for which we could not agree on conditions of use with GEMA.
User avatar
DemiPixel
Long Handed Inserter
Long Handed Inserter
Posts: 72
Joined: Mon Mar 21, 2016 7:27 am
Contact:

Re: Generating Blueprints by Coding

Post by DemiPixel »

delassa wrote:Ok I must say that is the first time I have ever been rick rolled and enjoyed it, that is fantastic man.
Well, my hope is that this library could be used to generate tedious, repeated things such as RAM for a computer or whatnot.
Amegatron
Long Handed Inserter
Long Handed Inserter
Posts: 59
Joined: Sun Mar 06, 2016 4:12 am
Contact:

Re: Generating Blueprints by Coding

Post by Amegatron »

Nice library. Though I'm not goot at JS, i wrote a simple code to generate somthing like ROM. Also I noticed some strange things. For example, the generated blueprint has an incorrect preview in game: my combinators are spaced incorrectly in preview and wires are floating in the air :) But the actual placement is correct though. See the screenshot:
Image
Also I could not understand the units I should specify when creating an entity. I thought 1 is 1 tile in game, but as I saw in your example, 0.5 can also be used.
Here is my code
Also I think it would be nice to specify entity's direction when creating :)
nonstickfrypan
Long Handed Inserter
Long Handed Inserter
Posts: 53
Joined: Fri Apr 15, 2016 9:02 am
Contact:

Re: Generating Blueprints by Coding

Post by nonstickfrypan »

My 256 character 8x8 VGA font (viewtopic.php?f=8&t=28570) was not constructed by hand :) I wrote some "throwaway" C to create a blueprint for me.

Image
Also I think it would be nice to specify entity's direction when creating :)
Umm, you can? (direction=)
User avatar
DemiPixel
Long Handed Inserter
Long Handed Inserter
Posts: 72
Joined: Mon Mar 21, 2016 7:27 am
Contact:

Re: Generating Blueprints by Coding

Post by DemiPixel »

Amegatron wrote:Nice library. Though I'm not goot at JS, i wrote a simple code to generate somthing like ROM. Also I noticed some strange things. For example, the generated blueprint has an incorrect preview in game: my combinators are spaced incorrectly in preview and wires are floating in the air :) But the actual placement is correct though. See the screenshot:
Image
Also I could not understand the units I should specify when creating an entity. I thought 1 is 1 tile in game, but as I saw in your example, 0.5 can also be used.
Here is my code
Also I think it would be nice to specify entity's direction when creating :)

Code: Select all

bp.createEntity(bla)
  .setCondition(bla2)
  .setDirection(2)
As for the offset, that's an issue I've had as well and have been trying to figure it out. A temporary solution is to use blueprint string's "fixer" button which will fix a blueprint if you click a few times with it. (Is this still in the latest version of Blueprint String?)

Not sure how to fix it yet, unfortunately :/
Amegatron
Long Handed Inserter
Long Handed Inserter
Posts: 59
Joined: Sun Mar 06, 2016 4:12 am
Contact:

Re: Generating Blueprints by Coding

Post by Amegatron »

DemiPixel wrote:

Code: Select all

bp.createEntity(bla)
  .setCondition(bla2)
  .setDirection(2)
As for the offset, that's an issue I've had as well and have been trying to figure it out. A temporary solution is to use blueprint string's "fixer" button which will fix a blueprint if you click a few times with it. (Is this still in the latest version of Blueprint String?)

Not sure how to fix it yet, unfortunately :/
Thanks for feedback. I'll check blueprint "fixer" as soon as I get to Factorio. As for direction - i meant an argument to "createEntity" method so it is created right in the needed direction (in most cases without direction I have to say "true" to "allowOverlap" for combinators and later specify their direction). In your example I suppose entity is first created, then rotated.
nonstickfrypan
Long Handed Inserter
Long Handed Inserter
Posts: 53
Joined: Fri Apr 15, 2016 9:02 am
Contact:

Re: Generating Blueprints by Coding

Post by nonstickfrypan »

DemiPixel wrote:
As for the offset, that's an issue I've had as well and have been trying to figure it out. A temporary solution is to use blueprint string's "fixer" button which will fix a blueprint if you click a few times with it. (Is this still in the latest version of Blueprint String?)

Not sure how to fix it yet, unfortunately :/
Interesting. I have this in my code:

Code: Select all

	// Hack: a) Next item is a decider and the width/pos seems relative to the right-hand side of the entity.
	//       b) Adding the constant combinator has already increased the x position by 1, but to account for
	//          observation (a) another 0.5 has to be added before a decider can be added (deciders are 1.5 wide)
	//
So I obviously ran across a similar issue. Not really sure if my conclusions were correct though... it was weird

Edit: attached is the C code. It's a horrible mess. It's badly written. It's not generic. It's not a library (it was intended to do one thing only and that was make the font "ROM" and some lamps); it was written in about 30 minutes a throwaway code for the specific purpose of encoding the font data... so it's pretty useless but maybe it can help somebody.
Attachments
fontthingy.zip
(9.05 KiB) Downloaded 219 times
User avatar
DemiPixel
Long Handed Inserter
Long Handed Inserter
Posts: 72
Joined: Mon Mar 21, 2016 7:27 am
Contact:

Re: Generating Blueprints by Coding

Post by DemiPixel »

Amegatron wrote: Thanks for feedback. I'll check blueprint "fixer" as soon as I get to Factorio. As for direction - i meant an argument to "createEntity" method so it is created right in the needed direction (in most cases without direction I have to say "true" to "allowOverlap" for combinators and later specify their direction). In your example I suppose entity is first created, then rotated.
I see, because of overlap. Interesting... Perhaps I'll change the arguments to (name, position, opt) and include "direction" in the opt. You are correct.
nonstickfrypan wrote:Interesting. I have this in my code:

Code: Select all

	// Hack: a) Next item is a decider and the width/pos seems relative to the right-hand side of the entity.
	//       b) Adding the constant combinator has already increased the x position by 1, but to account for
	//          observation (a) another 0.5 has to be added before a decider can be added (deciders are 1.5 wide)
	//
So I obviously ran across a similar issue. Not really sure if my conclusions were correct though... it was weird

Edit: attached is the C code. It's a horrible mess. It's badly written. It's not generic. It's not a library (it was intended to do one thing only and that was make the font "ROM" and some lamps); it was written in about 30 minutes a throwaway code for the specific purpose of encoding the font data... so it's pretty useless but maybe it can help somebody.
I change the position of the center. I believe if this is off by half a tile, it screws everything up (or something like that). Still not sure.

https://github.com/demipixel/factorio-b ... ex.js#L100
nonstickfrypan
Long Handed Inserter
Long Handed Inserter
Posts: 53
Joined: Fri Apr 15, 2016 9:02 am
Contact:

Re: Generating Blueprints by Coding

Post by nonstickfrypan »

DemiPixel wrote: I change the position of the center. I believe if this is off by half a tile, it screws everything up (or something like that). Still not sure.
That makes some sense and may be correct. I'm not sure either... I'll have to experiment some more! :)
User avatar
ssilk
Global Moderator
Global Moderator
Posts: 12889
Joined: Tue Apr 16, 2013 10:35 pm
Contact:

Re: Generating Blueprints by Coding

Post by ssilk »

When I click on the video I see
Unfortunately, this video is not available in your country because it could contain music from SME, for which we could not agree on conditions of use with GEMA.
Well, I know how to go around such restrictions, but as moderator I need to ask, if you can upload it again without music?
Cool suggestion: Eatable MOUSE-pointers.
Have you used the Advanced Search today?
Need help, question? FAQ - Wiki - Forum help
I still like small signatures...
nonstickfrypan
Long Handed Inserter
Long Handed Inserter
Posts: 53
Joined: Fri Apr 15, 2016 9:02 am
Contact:

Re: Generating Blueprints by Coding

Post by nonstickfrypan »

ssilk wrote:When I click on the video I see
Unfortunately, this video is not available in your country because it could contain music from SME, for which we could not agree on conditions of use with GEMA.
Well, I know how to go around such restrictions, but as moderator I need to ask, if you can upload it again without music?
And, perhaps, put a link to the video of the factorio action in BOLD because I suspect many people see this thread and don't actually realise the link is there or worth clicking on; and it IS worth clicking on
User avatar
ssilk
Global Moderator
Global Moderator
Posts: 12889
Joined: Tue Apr 16, 2013 10:35 pm
Contact:

Re: Generating Blueprints by Coding

Post by ssilk »

I moved this to tools.
Cool suggestion: Eatable MOUSE-pointers.
Have you used the Advanced Search today?
Need help, question? FAQ - Wiki - Forum help
I still like small signatures...
nonstickfrypan
Long Handed Inserter
Long Handed Inserter
Posts: 53
Joined: Fri Apr 15, 2016 9:02 am
Contact:

Re: Generating Blueprints by Coding

Post by nonstickfrypan »

I would be nice if more people did this. I might start expanding my hacky blueprint generator code.
Post Reply

Return to “Tools”