|
1 | 1 | const EXAMPLE_SETTINGS = [
|
2 | 2 | ["how to use: https://github.com/piebro/factorio-blueprint-visualizer/blob/master/draw_setting_documentation.md"],
|
3 | 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}], |
| 4 | + ["tiles", {'fill': '#420217', 'stroke': '#f3ffbd', 'stroke-width': 0.15}, {'deny': [], 'scale': 0.7}], |
5 | 5 |
|
6 | 6 | ["pipes", {'stroke': '#c84c09'}],
|
7 | 7 | ["underground-pipes", {'stroke': '#c84c09'}],
|
@@ -259,6 +259,66 @@ const RANDOM_SETTING_LIST = [
|
259 | 259 | ]
|
260 | 260 | ];
|
261 | 261 |
|
| 262 | + |
| 263 | + |
| 264 | +const SVG_SETTINGS = { |
| 265 | + 'fill': 'none', 'fill-opacity': 1, 'stroke': 'none', 'stroke-linecap': 'round', 'stroke-width': 0.3, 'stroke-opacity': 1 |
| 266 | +}; |
| 267 | +const OTHER_SETTINGS_BBOX = {'scale': 0.85, 'rx': 0.1, 'ry': 0.1}; |
| 268 | +const OTHER_SETTINGS_TILES = {'scale': 0.85}; |
| 269 | +// buildingGenericTerms |
| 270 | +// artificialTilesSortedByLayer |
| 271 | + |
| 272 | +// 1. get all generic terms and do 1-6 bboxes with different colors. Look that |
| 273 | + |
| 274 | +function getRandomSettings() { |
| 275 | + let settings = []; |
| 276 | + const SETTING_NAMES = ["belts", "underground-belts", "pipes", "underground-pipes", "heat-pipes", "inserters", "rails", "power-lines", "green-wire-lines", "red-wire-lines"]; |
| 277 | +// "bbox", |
| 278 | + settings.push(["default settings", {'background': 'none', 'stroke': 'none', 'stroke-linecap': 'round', 'stroke-width': 0.3}, {'scale': 0.85, 'rx': 0.1, 'ry': 0.1}]) |
| 279 | + |
| 280 | + if (Math.random() < 0.8) { |
| 281 | + settings.push(["tiles", {'fill': 'none', 'stroke': 'none', 'stroke-width': 0.15}, {'deny': [], 'scale': 0.7}]) |
| 282 | + } |
| 283 | + |
| 284 | + const temp_settings = []; |
| 285 | + const sampleSettings = shuffleArray([...SETTING_NAMES]).slice(0, 3); |
| 286 | + for (const settingName of sampleSettings) { |
| 287 | + temp_settings.push([settingName, {}]); |
| 288 | + } |
| 289 | + |
| 290 | + // Add 0-4 random bbox settings |
| 291 | + const bboxCount = Math.floor(Math.random() * 5); // Random number 0-4 |
| 292 | + const genericBuildingTerms = Object.keys(buildingGenericTerms); |
| 293 | + const buildingTerms = Object.keys(entityNameToProperties); |
| 294 | + const allTerms = [...genericBuildingTerms, ...genericBuildingTerms, ...buildingTerms]; |
| 295 | + |
| 296 | + for (let i = 0; i < bboxCount; i++) { |
| 297 | + const buildingTermCount = Math.floor(Math.random() * 5) + 1; |
| 298 | + const group = shuffleArray([...allTerms]).slice(0, buildingTermCount); |
| 299 | + const bboxGroupType = Math.random() < 0.8 ? "allow" : "deny"; |
| 300 | + temp_settings.push(["bbox", {[bboxGroupType]: group, 'fill': 'none'}]); |
| 301 | + } |
| 302 | + |
| 303 | + settings = [...settings, ...temp_settings]; |
| 304 | + |
| 305 | + // Replace any "none" values with incrementing hex colors |
| 306 | + let noneColorCounter = 0; |
| 307 | + for (let s of settings) { |
| 308 | + if (typeof s[1] === 'object' && s[1] !== null) { |
| 309 | + for (let key of ['stroke', 'fill', 'background']) { |
| 310 | + if (key in s[1] && s[1][key] === 'none') { |
| 311 | + const hexColor = '#' + noneColorCounter.toString(16).padStart(6, '0'); |
| 312 | + s[1][key] = hexColor; |
| 313 | + noneColorCounter++; |
| 314 | + } |
| 315 | + } |
| 316 | + } |
| 317 | + } |
| 318 | + |
| 319 | + return settingsChangeColors(settings, 10, true); |
| 320 | +} |
| 321 | + |
262 | 322 | function deepCopy(obj) {
|
263 | 323 | return JSON.parse(JSON.stringify(obj));
|
264 | 324 | }
|
@@ -322,38 +382,38 @@ function settingsChangeColors(settings, colorCount = null, changeBackground = tr
|
322 | 382 | return settings;
|
323 | 383 | }
|
324 | 384 |
|
325 |
| -function getRandomSettings() { |
326 |
| - let settings = deepCopy(RANDOM_SETTING_LIST[Math.floor(Math.random() * RANDOM_SETTING_LIST.length)]); |
| 385 | +// function getRandomSettings() { |
| 386 | +// let settings = deepCopy(RANDOM_SETTING_LIST[Math.floor(Math.random() * RANDOM_SETTING_LIST.length)]); |
327 | 387 |
|
328 |
| - if (Math.random() < 0.4) { |
329 |
| - const additionalSettings = RANDOM_SETTING_LIST[Math.floor(Math.random() * RANDOM_SETTING_LIST.length)]; |
330 |
| - settings = [...settings, ...additionalSettings]; |
331 |
| - settings = settingsChangeColors(settings); |
332 |
| - } |
| 388 | +// if (Math.random() < 0.4) { |
| 389 | +// const additionalSettings = RANDOM_SETTING_LIST[Math.floor(Math.random() * RANDOM_SETTING_LIST.length)]; |
| 390 | +// settings = [...settings, ...additionalSettings]; |
| 391 | +// settings = settingsChangeColors(settings); |
| 392 | +// } |
333 | 393 |
|
334 |
| - if (Math.random() < 0.3) { |
335 |
| - const additionalSettings = RANDOM_SETTING_LIST[Math.floor(Math.random() * RANDOM_SETTING_LIST.length)]; |
336 |
| - settings = [...settings, ...additionalSettings]; |
337 |
| - if (settings.length > 8) { |
338 |
| - const indices = [0, 1, ...shuffleArray([...Array(settings.length).keys()].slice(2)).slice(0, settings.length - 4)]; |
339 |
| - settings = settings.filter((_, i) => indices.includes(i)); |
340 |
| - } |
341 |
| - settings = settingsChangeColors(settings); |
342 |
| - } |
| 394 | +// if (Math.random() < 0.3) { |
| 395 | +// const additionalSettings = RANDOM_SETTING_LIST[Math.floor(Math.random() * RANDOM_SETTING_LIST.length)]; |
| 396 | +// settings = [...settings, ...additionalSettings]; |
| 397 | +// if (settings.length > 8) { |
| 398 | +// const indices = [0, 1, ...shuffleArray([...Array(settings.length).keys()].slice(2)).slice(0, settings.length - 4)]; |
| 399 | +// settings = settings.filter((_, i) => indices.includes(i)); |
| 400 | +// } |
| 401 | +// settings = settingsChangeColors(settings); |
| 402 | +// } |
343 | 403 |
|
344 |
| - if (Math.random() < 0.8) { |
345 |
| - settings = settingsChangeColors(settings, Math.floor(Math.random() * 10) + 2); |
346 |
| - } |
| 404 | +// if (Math.random() < 0.8) { |
| 405 | +// settings = settingsChangeColors(settings, Math.floor(Math.random() * 10) + 2); |
| 406 | +// } |
347 | 407 |
|
348 |
| - if (Math.random() < 0.5) { |
349 |
| - settings = settingsChangeProperty(settings, "stroke-width", v => v * (Math.random() * 1.5 + 0.5)); |
350 |
| - } |
| 408 | +// if (Math.random() < 0.5) { |
| 409 | +// settings = settingsChangeProperty(settings, "stroke-width", v => v * (Math.random() * 1.5 + 0.5)); |
| 410 | +// } |
351 | 411 |
|
352 |
| - if (Math.random() < 0.5) { |
353 |
| - settings = settingsChangeProperty(settings, "bbox-scale", v => v * (Math.random() * 0.3 + 0.7)); |
354 |
| - } |
355 |
| - return settings; |
356 |
| -} |
| 412 | +// if (Math.random() < 0.5) { |
| 413 | +// settings = settingsChangeProperty(settings, "bbox-scale", v => v * (Math.random() * 0.3 + 0.7)); |
| 414 | +// } |
| 415 | +// return settings; |
| 416 | +// } |
357 | 417 |
|
358 | 418 | function shuffleArray(array) {
|
359 | 419 | for (let i = array.length - 1; i > 0; i--) {
|
|
0 commit comments