From bcb2ecf6ab6c372cd41dd79780b027c79cb4a49e Mon Sep 17 00:00:00 2001 From: Pieter Vander Vennet Date: Wed, 7 Jun 2023 17:33:07 +0200 Subject: [PATCH] Fix: restore loading of custom themes --- Logic/DetermineLayout.ts | 51 ++++++++++++++++++++++++++++++++----- UI/SpecialVisualizations.ts | 2 +- index.ts | 2 ++ 3 files changed, 47 insertions(+), 8 deletions(-) diff --git a/Logic/DetermineLayout.ts b/Logic/DetermineLayout.ts index d2dc46175..3b0e11ae6 100644 --- a/Logic/DetermineLayout.ts +++ b/Logic/DetermineLayout.ts @@ -20,9 +20,14 @@ import { FixImages } from "../Models/ThemeConfig/Conversion/FixImages" import Svg from "../Svg" import { DoesImageExist, - PrevalidateTheme, + PrevalidateTheme, ValidateTagRenderings, ValidateThemeAndLayers, } from "../Models/ThemeConfig/Conversion/Validation" +import {DesugaringContext, Each, On} from "../Models/ThemeConfig/Conversion/Conversion"; +import {PrepareLayer, RewriteSpecial} from "../Models/ThemeConfig/Conversion/PrepareLayer"; +import {AllSharedLayers} from "../Customizations/AllSharedLayers"; +import {TagRenderingConfigJson} from "../Models/ThemeConfig/Json/TagRenderingConfigJson"; +import questions from "../assets/tagRenderings/questions.json"; export default class DetermineLayout { private static readonly _knownImages = new Set(Array.from(licenses).map((l) => l.path)) @@ -64,7 +69,7 @@ export default class DetermineLayout { ).data const layout = AllKnownLayouts.allKnownLayouts.get(layoutId?.toLowerCase()) if (layout === undefined) { - throw "No layout with name " + layoutId + " exists" + throw "No builtin map theme with name " + layoutId + " exists" } return layout } @@ -146,9 +151,41 @@ export default class DetermineLayout { : undefined, ]) .SetClass("flex flex-col clickable") - .AttachTo("centermessage") + .AttachTo("maindiv") } + private static getSharedTagRenderings(): Map { + const dict = new Map() + + const prep = new RewriteSpecial() + const validator = new ValidateTagRenderings() + for (const key in questions) { + if (key === "id") { + continue + } + questions[key].id = key + questions[key]["source"] = "shared-questions" + const config = prep.convertStrict( + questions[key], + "questions.json:" + key + ) + delete config["#"] + validator.convertStrict( + config, + "generate-layer-overview:tagRenderings/questions.json:" + key + ) + dict.set(key, config) + } + + dict.forEach((value, key) => { + if (key === "id") { + return + } + value.id = value.id ?? key + }) + + return dict + } private static prepCustomTheme(json: any, sourceUrl?: string, forceId?: string): LayoutConfig { if (json.layers === undefined && json.tagRenderings !== undefined) { const iconTr = json.mapRendering.map((mr) => mr.icon).find((icon) => icon !== undefined) @@ -170,8 +207,8 @@ export default class DetermineLayout { const layer = known_layers.layers[key] knownLayersDict.set(layer.id, layer) } - const converState = { - tagRenderings: SharedTagRenderings.SharedTagRenderingJson, + const convertState: DesugaringContext = { + tagRenderings: DetermineLayout.getSharedTagRenderings(), sharedLayers: knownLayersDict, publicLayers: new Set(), } @@ -183,7 +220,7 @@ export default class DetermineLayout { "While fixing the images" ) json.enableNoteImports = json.enableNoteImports ?? false - json = new PrepareTheme(converState).convertStrict(json, "While preparing a dynamic theme") + json = new PrepareTheme(convertState).convertStrict(json, "While preparing a dynamic theme") console.log("The layoutconfig is ", json) json.id = forceId ?? json.id @@ -214,7 +251,7 @@ export default class DetermineLayout { console.log("Downloading map theme from ", link) new FixedUiElement(`Downloading the theme from the link...`).AttachTo( - "centermessage" + "maindiv" ) try { diff --git a/UI/SpecialVisualizations.ts b/UI/SpecialVisualizations.ts index 1f20fab08..acca94c50 100644 --- a/UI/SpecialVisualizations.ts +++ b/UI/SpecialVisualizations.ts @@ -310,7 +310,7 @@ export default class SpecialVisualizations { if (template["type"] !== undefined) { console.trace( - "Got a non-expanded template while constructing the specification:", + "Got a non-expanded template while constructing the specification, it still has a 'special-key':", template ) throw "Got a non-expanded template while constructing the specification" diff --git a/index.ts b/index.ts index 5fd61e9ac..8777911b0 100644 --- a/index.ts +++ b/index.ts @@ -3,6 +3,7 @@ import DetermineLayout from "./Logic/DetermineLayout" import ThemeViewState from "./Models/ThemeViewState" import SvelteUIElement from "./UI/Base/SvelteUIElement" import ThemeViewGUI from "./UI/ThemeViewGUI.svelte" +import {FixedUiElement} from "./UI/Base/FixedUiElement"; // Miscelleanous Utils.DisableLongPresses() @@ -16,4 +17,5 @@ DetermineLayout.GetLayout() }) .catch((err) => { console.error("Error while initializing: ", err, err.stack) + new FixedUiElement(err).SetClass("block alert").AttachTo("maindiv") })