Created
October 2, 2016 01:07
-
-
Save demipixel/df31ec580cc360d33a269639492c74e2 to your computer and use it in GitHub Desktop.
Create Factorio blueprint strings for any text you'd like in any material!
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| const Blueprint = require('factorio-blueprint'); | |
| const alphabet = ` | |
| ~AA BBB CCC DDD EEEE FFFF GGG H H IIIII JJJJJ K K L MMM MMM NN N OOO PPP QQQ RRR SSSS TTTTT U U V V W W X X Y Y ZZZZZ ( ) * * * ! ?? | |
| A A B B C D D E F G H H I J K K L M M M N N N O O P P Q Q R R S T U U V V W W X X Y Y Z ( ) *** ! ? | |
| AAAA BBB C D D EEEE FFFF G GGG HHHH I J KK L M M M N N N O O PPP Q Q RRR SSS T U U V V W W W X Y Z ( ) ***** ! ? | |
| A A B B C D D E F G G H H I J J K K L M M N NN O O P Q QQ R R S T U U V V W W W X X Y Z ( ) *** .. ? , | |
| A A BBB CCC DDD EEEE F GGG H H IIIII JJJ K K LLLLL M M N N OOO P QQQQ R R SSSS T UUU V WWW X X Y ZZZZZ ( ) * * * .. ! ? ,~~ | |
| `.trim().replace(/\~/g, ' ').split('\n'); | |
| const letters = {}; | |
| function initLetters() { | |
| let currLetterStart = null; | |
| let hasOnY = false; | |
| for (var x = 0; x < alphabet[0].length; x++) { | |
| hasOnY = false; | |
| for (var y = 0; y < 5; y++) { | |
| const c = alphabet[y][x].toLowerCase(); | |
| if (c == ' ') continue; | |
| hasOnY = true; | |
| if (currLetterStart === null) currLetterStart = x; | |
| if (!letters[c]) letters[c] = []; | |
| if (!letters[c][y]) letters[c][y] = []; | |
| letters[c][y][x-currLetterStart] = true; | |
| } | |
| if (!hasOnY) { | |
| currLetterStart = null; | |
| } | |
| } | |
| } | |
| initLetters(); | |
| function createTextBP(str, material='small-lamp') { | |
| str = str.toLowerCase(); | |
| let bp = new Blueprint() | |
| let currX = 0; | |
| let currY = 0; | |
| for (var i = 0; i < str.length; i++) { // Each letter | |
| let c = str[i]; | |
| if (c == ' ') { currX += 4; continue; } // Space | |
| else if (c == '\n') { currY += 7; currX = 0; continue; } // New line | |
| let hasY = true; | |
| let x = 0; | |
| while (hasY) { // Each x | |
| hasY = false; | |
| for (var y = 0; y < 5; y++) { // Each y | |
| if (!letters[c][y]) continue; | |
| if (letters[c][y][x]) { | |
| hasY = true; | |
| bp.createEntity(material, { x: currX + x, y: currY + y }, 0, true); | |
| } | |
| } | |
| x++; | |
| } | |
| currX += x; | |
| } | |
| return bp; | |
| } | |
| console.log(createTextBP('Example text.\nCurrently not case\nsensitive, supports\n* ( ) . , ! ?').fixCenter().encode()); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment