Skip to content

Commit a6e0bc7

Browse files
committed
added better example settings and a btn to change the color palette
1 parent 4231c76 commit a6e0bc7

File tree

4 files changed

+42
-40
lines changed

4 files changed

+42
-40
lines changed

README.md

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ I love the game Factorio and I really like the look of factories after growing f
77

88
All factorio buildings and tiles with their bounding boxes and belt, pipe, rail, inserter, wire and electricity connections can be visualized. Everything is drawn in vector graphics (SVG) to be able to view it in any resolution.
99

10-
Use the [online demo](https://piebro.github.io/factorio-blueprint-visualizer/) to visualize your own blueprints.
10+
Use the [online demo](https://piebro.github.io/factorio-blueprint-visualizer/) to visualize your own blueprints. With the latest update, only Blueprints from Factorio 2.0 and later work correctly.
1111

1212
## Examples
1313

@@ -22,17 +22,16 @@ Use the [online demo](https://piebro.github.io/factorio-blueprint-visualizer/) t
2222

2323
The last three blueprints are by Josh Ventura and can be found [here](https://factorioprints.com/user/6QrnfqXIffQcWgHC6Xs4uHv1BGg2).
2424

25-
## Usage
26-
27-
<!-- TODO: add a few screenshots to visualize a new blueprint? or some text how this generally works? -->
25+
## Updates <!-- TODO add date -->
2826

29-
### Drawing Settings
27+
- Factorio 2.0 and Factorio: Space Age are supported. <!-- TODO: test if I can past older blueprint in factotio 2.0 and export them again to update them -->
28+
- Portet everything to Javascript for simplicity and performance.
29+
- Added ability to modify drawing settings.
3030

31-
To visualize a blueprint you need drawing settings that define what is drawn, in which order and in what kind of style. Drawing settings are a list of option that are executed one after the other. You can decide which bounding box to draw with an allow or deny list of building names. You can also draw connected `belt`, `underground-belts`, `pipes`, `underground-pipes`, `inserter`, `rail`, `electricity`, `red-circuits` and `green-circuits`.
32-
33-
Furthermore, you can define the style of each drawing command or set a new default drawing style. You can use `fill`, `stroke`, `stroke-width`, `stroke-linecap`, `stroke-opacity`, `fill-opacity`, `bbox-scale`, `bbox-rx` and `bbox-ry` as properties and every SVG tag should also work.
31+
## Usage
3432

35-
Every visualization has the used drawing settings and blueprint saved with it, so you can check out the drawing settings of the examples blueprints inspiration.
33+
<!-- TODO: add a few screenshots to visualize a new blueprint? or some text how this generally works? -->
34+
<!-- add link to draw_setting_documenation.md -->
3635

3736
### Text to Image
3837

blueprintVisualizer.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -203,10 +203,13 @@ function drawBlueprint(blueprint, settings, svgWidthInMm = 300, aspectRatio = nu
203203
}
204204
}
205205
const dwg = getSVG(blueprint.bboxWidth, blueprint.bboxHeight, background, metadataStr, svgWidthInMm, aspectRatio);
206+
let currentDefaultOtherSettings = {};
206207

207208
for (let [settingName, svgSettings, otherSettings] of settings) {
209+
otherSettings = {...currentDefaultOtherSettings, ...otherSettings};
208210
if (settingName === "default settings") {
209211
appendGroup(dwg, svgSettings);
212+
currentDefaultOtherSettings = otherSettings;
210213
continue;
211214
} else if (settingName === "bbox") {
212215
drawEntitiesBbox(dwg, blueprint.entities, blueprint.posOffset, svgSettings, otherSettings, "bbox_size");

drawingSettings.js

Lines changed: 24 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,24 @@
11
const EXAMPLE_SETTINGS = [
2-
['how to use: https://github.com/piebro/factorio-blueprint-visualizer/blob/master/draw_setting_documentation.md'],
3-
['default settings', {'background': '#a2aebb', 'stroke': '#3f88c5', 'stroke-linecap': 'round', 'stroke-width': 0.3}],
4-
['tiles', {'fill': '#a2fffb', 'stroke-width': 0.1}, {'allow': ['landfill'], 'size': 0.7}],
5-
['tiles', {'fill': '#a2aefb', 'stroke-width': 0.1}, {'deny': ['landfill'], 'size': 0.7}],
6-
['bbox', {'fill': '#ff0000', 'stroke': 'none'}, {'deny': ["pipes", "underground-pipes", "belts", "underground-belts"], 'scale': 0.75, 'rx': 0.1, 'ry': 0.1}],
7-
// ['bbox-selection', {'fill': '#00ff00', 'stroke': 'none'}, {'scale': 1}],
8-
// ['bbox-collision', {'fill': '#0000ff', 'stroke': 'none'}, {'scale': 1}],
9-
10-
['pipes', {'stroke': '#ff0000'}],
11-
['underground-pipes', {'stroke': '#ff0000'}],
12-
['belts', {'stroke': '#00ff00'}],
13-
['underground-belts', {'stroke': '#00ff00'}],
14-
['heat-pipes', {'stroke': '#ff0000'}],
15-
['power-lines', {'stroke': '#ff0000'}],
16-
// ['green-wire-lines', {'stroke': '#ff0000'}],
17-
// ['red-wire-lines', {'stroke': '#ff0000'}],
18-
['inserters', {'stroke': '#ff0000', 'stroke-width': 0.1}],
19-
['rails', {'stroke': '#ff0000'}],
20-
];
2+
["how to use: https://github.com/piebro/factorio-blueprint-visualizer/blob/master/draw_setting_documentation.md"],
3+
["default settings", {'background': '#a2aebb', 'stroke': 'none', 'stroke-linecap': 'round', 'stroke-width': 0.3}, {'scale': 0.85, 'rx': 0.1, 'ry': 0.1}],
4+
["tiles", {'fill': '#420217', 'stroke': '#f3ffbd', 'stroke-width': 0.15}, {'deny': [], 'size': 0.7}],
5+
6+
["pipes", {'stroke': '#c84c09'}],
7+
["underground-pipes", {'stroke': '#c84c09'}],
8+
["belts", {'stroke': '#f3ffbd'}],
9+
["underground-belts", {'stroke': '#f3ffbd'}],
10+
["inserters", {'stroke': '#f3ffbd'}],
11+
12+
["bbox", {'fill': '#247ba0'}, {'deny': ["pipe", "pipe-to-ground", "belt", "inserter", "solar-panel", "accumulator", "asteroid-collector", "cargo-bay", "space-platform-hub", "thruster"]}],
13+
["bbox", {'fill': '#ff1654'}, {'allow': ["solar-panel"]}],
14+
["bbox", {'fill': '#436436'}, {'allow': ["accumulator"]}],
15+
["bbox", {'fill': '#70c1b3'}, {'allow': ["cargo-bay"]}],
16+
["bbox", {'fill': '#b2dbbf'}, {'allow': ["asteroid-collector", "thruster", "space-platform-hub"]}],
17+
18+
["heat-pipes", {'stroke': '#b2dbbf'}],
19+
["power-lines", {'stroke': '#70c1b3'}],
20+
["rails", {'stroke': '#faa275'}],
21+
]
2122

2223
const PREDEFINED_COLOR_PALETTES = [
2324
[
@@ -276,19 +277,12 @@ function settingsChangeProperty(settings, propertyName, changeFunc) {
276277
function settingsChangeColors(settings, colorCount = null, changeBackground = true) {
277278
settings = deepCopy(settings);
278279
const originalColors = {};
279-
const keysThatHaveAColor = ["stroke", "fill"];
280+
let keysThatHaveAColor = ["stroke", "fill"];
281+
if (changeBackground) {
282+
keysThatHaveAColor.push("background");
283+
}
280284

281285
for (let s of settings) {
282-
// Handle background color
283-
if (changeBackground && s[0] === "background") {
284-
if (!(s[1] in originalColors)) {
285-
originalColors[s[1]] = [[s, 1]];
286-
} else {
287-
originalColors[s[1]].push([s, 1]);
288-
}
289-
continue;
290-
}
291-
292286
// Only check for stroke/fill if s[1] is an object and not null
293287
if (typeof s[1] === 'object' && s[1] !== null) {
294288
for (let key of keysThatHaveAColor) {

index.html

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -130,7 +130,7 @@
130130

131131
function newBlueprintString(blueprintString){
132132
[currentBlueprintNames, currentBlueprintJsons] = getBlueprintList(blueprintString);
133-
currentBlueprint = processBlueprint(currentBlueprintJsons[2])
133+
currentBlueprint = processBlueprint(currentBlueprintJsons[0])
134134

135135
getCurrentBlueprintEntityCount(currentBlueprint)
136136

@@ -204,6 +204,12 @@
204204

205205
newBlueprintString(START_EXAMPLE_BLUEPRINT);
206206
showBlueprint();
207+
208+
// Add click handler for random color palette button
209+
document.getElementById("randomColorPalletBtn").onclick = () => {
210+
settingsList[currentSettingIndex] = settingsChangeColors(settingsList[currentSettingIndex], null, true);
211+
showBlueprint();
212+
};
207213
}
208214

209215
function showBlueprint(){

0 commit comments

Comments
 (0)