Page 1 of 1

Generating Blueprints by Coding

Posted: Sat Jun 25, 2016 3:23 am
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!

Re: Generating Blueprints by Coding

Posted: Fri Jul 01, 2016 10:57 pm
by delassa
Ok I must say that is the first time I have ever been rick rolled and enjoyed it, that is fantastic man.

Re: Generating Blueprints by Coding

Posted: Sat Jul 02, 2016 9:42 am
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.

Re: Generating Blueprints by Coding

Posted: Tue Jul 05, 2016 7:38 pm
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.

Re: Generating Blueprints by Coding

Posted: Sun Jul 17, 2016 2:02 pm
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 :)

Re: Generating Blueprints by Coding

Posted: Mon Jul 18, 2016 6:47 am
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=)

Re: Generating Blueprints by Coding

Posted: Mon Jul 18, 2016 5:11 pm
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 :/

Re: Generating Blueprints by Coding

Posted: Mon Jul 18, 2016 6:00 pm
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.

Re: Generating Blueprints by Coding

Posted: Mon Jul 18, 2016 6:12 pm
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.

Re: Generating Blueprints by Coding

Posted: Mon Jul 18, 2016 10:09 pm
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

Re: Generating Blueprints by Coding

Posted: Tue Jul 19, 2016 10:37 am
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! :)

Re: Generating Blueprints by Coding

Posted: Tue Jul 19, 2016 11:38 am
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?

Re: Generating Blueprints by Coding

Posted: Wed Jul 20, 2016 8:31 am
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

Re: Generating Blueprints by Coding

Posted: Thu Sep 15, 2016 11:17 am
by ssilk
I moved this to tools.

Re: Generating Blueprints by Coding

Posted: Thu Sep 15, 2016 1:59 pm
by nonstickfrypan
I would be nice if more people did this. I might start expanding my hacky blueprint generator code.