| 
									
										
										
										
											2021-09-26 18:21:29 +02:00
										 |  |  | /* | 
					
						
							|  |  |  |  * This script reads all theme and layer files and reformats them inplace | 
					
						
							|  |  |  |  * Use with caution, make a commit beforehand! | 
					
						
							|  |  |  |  */ | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | import ScriptUtils from "./ScriptUtils"; | 
					
						
							| 
									
										
										
										
											2021-10-19 02:31:32 +02:00
										 |  |  | import {writeFileSync} from "fs"; | 
					
						
							| 
									
										
										
										
											2021-09-26 19:56:40 +02:00
										 |  |  | import {LayerConfigJson} from "../Models/ThemeConfig/Json/LayerConfigJson"; | 
					
						
							| 
									
										
										
										
											2021-10-20 02:01:27 +02:00
										 |  |  | import LineRenderingConfigJson from "../Models/ThemeConfig/Json/LineRenderingConfigJson"; | 
					
						
							| 
									
										
										
										
											2021-09-26 18:21:29 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-09-26 19:56:40 +02:00
										 |  |  | /** | 
					
						
							|  |  |  |  * In place fix | 
					
						
							|  |  |  |  */ | 
					
						
							| 
									
										
										
										
											2021-10-19 02:31:32 +02:00
										 |  |  | function fixLayerConfig(config: LayerConfigJson): void { | 
					
						
							| 
									
										
										
										
											2021-10-22 01:07:32 +02:00
										 |  |  |     if(config["overpassTags"]){ | 
					
						
							|  |  |  |         config.source.osmTags = config["overpassTags"] | 
					
						
							|  |  |  |         delete config["overpassTags"] | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  |      | 
					
						
							| 
									
										
										
										
											2021-10-19 02:31:32 +02:00
										 |  |  |     if (config.tagRenderings !== undefined) { | 
					
						
							|  |  |  |         for (const tagRendering of config.tagRenderings) { | 
					
						
							|  |  |  |             if (tagRendering["#"] !== undefined) { | 
					
						
							|  |  |  |                 tagRendering["id"] = tagRendering["#"] | 
					
						
							|  |  |  |                 delete tagRendering["#"] | 
					
						
							|  |  |  |             } | 
					
						
							|  |  |  |             if (tagRendering["id"] === undefined) { | 
					
						
							|  |  |  |                 if (tagRendering["freeform"]?.key !== undefined) { | 
					
						
							|  |  |  |                     tagRendering["id"] = config.id + "-" + tagRendering["freeform"]["key"] | 
					
						
							|  |  |  |                 } | 
					
						
							|  |  |  |             } | 
					
						
							|  |  |  |         } | 
					
						
							| 
									
										
										
										
											2021-09-26 19:59:51 +02:00
										 |  |  |     } | 
					
						
							| 
									
										
										
										
											2021-10-21 21:41:45 +02:00
										 |  |  | 
 | 
					
						
							|  |  |  |     if (config.mapRendering === undefined || true) { | 
					
						
							| 
									
										
										
										
											2021-10-19 02:31:32 +02:00
										 |  |  |         // This is a legacy format, lets create a pointRendering
 | 
					
						
							| 
									
										
										
										
											2021-10-21 21:41:45 +02:00
										 |  |  |         let location: ("point" | "centroid")[] = ["point"] | 
					
						
							|  |  |  |         let wayHandling: number = config["wayHandling"] ?? 0 | 
					
						
							|  |  |  |         if (wayHandling === 2) { | 
					
						
							| 
									
										
										
										
											2021-10-19 02:31:32 +02:00
										 |  |  |             location = ["point", "centroid"] | 
					
						
							| 
									
										
										
										
											2021-09-26 18:21:29 +02:00
										 |  |  |         } | 
					
						
							| 
									
										
										
										
											2021-10-19 02:31:32 +02:00
										 |  |  |         config.mapRendering = [ | 
					
						
							|  |  |  |             { | 
					
						
							|  |  |  |                 icon: config["icon"], | 
					
						
							| 
									
										
										
										
											2021-10-21 21:41:45 +02:00
										 |  |  |                 iconBadges: config["iconOverlays"], | 
					
						
							| 
									
										
										
										
											2021-10-19 02:31:32 +02:00
										 |  |  |                 label: config["label"], | 
					
						
							|  |  |  |                 iconSize: config["iconSize"], | 
					
						
							|  |  |  |                 location, | 
					
						
							|  |  |  |                 rotation: config["rotation"] | 
					
						
							| 
									
										
										
										
											2021-09-26 18:21:29 +02:00
										 |  |  |             } | 
					
						
							| 
									
										
										
										
											2021-10-19 02:31:32 +02:00
										 |  |  |         ] | 
					
						
							| 
									
										
										
										
											2021-10-21 21:41:45 +02:00
										 |  |  | 
 | 
					
						
							|  |  |  |         if (wayHandling !== 1) { | 
					
						
							| 
									
										
										
										
											2021-10-20 02:01:27 +02:00
										 |  |  |             const lineRenderConfig = <LineRenderingConfigJson>{ | 
					
						
							|  |  |  |                 color: config["color"], | 
					
						
							|  |  |  |                 width: config["width"], | 
					
						
							|  |  |  |                 dashArray: config["dashArray"] | 
					
						
							|  |  |  |             } | 
					
						
							| 
									
										
										
										
											2021-10-21 21:41:45 +02:00
										 |  |  |             if (Object.keys(lineRenderConfig).length > 0) { | 
					
						
							| 
									
										
										
										
											2021-10-20 02:01:27 +02:00
										 |  |  |                 config.mapRendering.push(lineRenderConfig) | 
					
						
							|  |  |  |             } | 
					
						
							|  |  |  |         } | 
					
						
							| 
									
										
										
										
											2021-10-21 21:41:45 +02:00
										 |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-10-20 02:01:27 +02:00
										 |  |  |         /*delete config["color"] | 
					
						
							|  |  |  |         delete config["width"] | 
					
						
							|  |  |  |         delete config["dashArray"] | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         delete config["icon"] | 
					
						
							|  |  |  |         delete config["iconOverlays"] | 
					
						
							|  |  |  |         delete config["label"] | 
					
						
							|  |  |  |         delete config["iconSize"] | 
					
						
							|  |  |  |         delete config["rotation"] | 
					
						
							| 
									
										
										
										
											2021-10-21 21:41:45 +02:00
										 |  |  |          delete config["wayHandling"] | 
					
						
							| 
									
										
										
										
											2021-10-20 02:01:27 +02:00
										 |  |  |         */ | 
					
						
							| 
									
										
										
										
											2021-10-21 21:41:45 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-09-26 18:21:29 +02:00
										 |  |  |     } | 
					
						
							| 
									
										
										
										
											2021-10-21 21:41:45 +02:00
										 |  |  | 
 | 
					
						
							|  |  |  |     for (const mapRenderingElement of config.mapRendering) { | 
					
						
							|  |  |  |         if (mapRenderingElement["iconOverlays"] !== undefined) { | 
					
						
							|  |  |  |             mapRenderingElement["iconBadges"] = mapRenderingElement["iconOverlays"] | 
					
						
							|  |  |  |         } | 
					
						
							|  |  |  |         for (const overlay of mapRenderingElement["iconBadges"] ?? []) { | 
					
						
							|  |  |  |             if (overlay["badge"] !== true) { | 
					
						
							|  |  |  |                 console.log("Warning: non-overlay element for ", config.id) | 
					
						
							|  |  |  |             } | 
					
						
							|  |  |  |             delete overlay["badge"] | 
					
						
							|  |  |  |         } | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-09-26 19:56:40 +02:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | const layerFiles = ScriptUtils.getLayerFiles(); | 
					
						
							|  |  |  | for (const layerFile of layerFiles) { | 
					
						
							|  |  |  |     fixLayerConfig(layerFile.parsed) | 
					
						
							| 
									
										
										
										
											2021-09-26 18:21:29 +02:00
										 |  |  |     writeFileSync(layerFile.path, JSON.stringify(layerFile.parsed, null, "    ")) | 
					
						
							| 
									
										
										
										
											2021-09-26 19:56:40 +02:00
										 |  |  | } | 
					
						
							| 
									
										
										
										
											2021-09-26 19:59:51 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-09-26 19:56:40 +02:00
										 |  |  | const themeFiles = ScriptUtils.getThemeFiles() | 
					
						
							|  |  |  | for (const themeFile of themeFiles) { | 
					
						
							| 
									
										
										
										
											2021-09-26 19:58:11 +02:00
										 |  |  |     for (const layerConfig of themeFile.parsed.layers ?? []) { | 
					
						
							| 
									
										
										
										
											2021-10-19 02:31:32 +02:00
										 |  |  |         if (typeof layerConfig === "string" || layerConfig["builtin"] !== undefined) { | 
					
						
							| 
									
										
										
										
											2021-09-26 19:56:40 +02:00
										 |  |  |             continue | 
					
						
							|  |  |  |         } | 
					
						
							|  |  |  |         // @ts-ignore
 | 
					
						
							|  |  |  |         fixLayerConfig(layerConfig) | 
					
						
							|  |  |  |     } | 
					
						
							| 
									
										
										
										
											2021-10-21 21:41:45 +02:00
										 |  |  | 
 | 
					
						
							|  |  |  |     if (themeFile.parsed["roamingRenderings"] !== undefined && themeFile.parsed["roamingRenderings"].length == 0) { | 
					
						
							| 
									
										
										
										
											2021-10-19 02:03:52 +02:00
										 |  |  |         delete themeFile.parsed["roamingRenderings"] | 
					
						
							|  |  |  |     } | 
					
						
							| 
									
										
										
										
											2021-10-21 21:41:45 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-09-26 19:59:51 +02:00
										 |  |  |     writeFileSync(themeFile.path, JSON.stringify(themeFile.parsed, null, "  ")) | 
					
						
							| 
									
										
										
										
											2021-09-26 19:58:11 +02:00
										 |  |  | } | 
					
						
							| 
									
										
										
										
											2021-10-19 02:03:52 +02:00
										 |  |  | //*/
 |