Fix: restore loading of custom themes

This commit is contained in:
Pieter Vander Vennet 2023-06-07 17:33:07 +02:00
parent 649ed1f53a
commit bcb2ecf6ab
3 changed files with 47 additions and 8 deletions

View file

@ -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<string, TagRenderingConfigJson> {
const dict = new Map<string, TagRenderingConfigJson>()
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(
<TagRenderingConfigJson>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, <LayerConfigJson>layer)
}
const converState = {
tagRenderings: SharedTagRenderings.SharedTagRenderingJson,
const convertState: DesugaringContext = {
tagRenderings: DetermineLayout.getSharedTagRenderings(),
sharedLayers: knownLayersDict,
publicLayers: new Set<string>(),
}
@ -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 <a href="${link}">link</a>...`).AttachTo(
"centermessage"
"maindiv"
)
try {

View file

@ -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"

View file

@ -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")
})