import * as questions from "../assets/tagRenderings/questions.json"; import * as icons from "../assets/tagRenderings/icons.json"; import {Utils} from "../Utils"; import TagRenderingConfig from "../Models/ThemeConfig/TagRenderingConfig"; import {TagRenderingConfigJson} from "../Models/ThemeConfig/Json/TagRenderingConfigJson"; export default class SharedTagRenderings { public static SharedTagRendering: Map = SharedTagRenderings.generatedSharedFields(); public static SharedTagRenderingJson: Map = SharedTagRenderings.generatedSharedFieldsJsons(); public static SharedIcons: Map = SharedTagRenderings.generatedSharedFields(true); private static generatedSharedFields(iconsOnly = false): Map { const configJsons = SharedTagRenderings.generatedSharedFieldsJsons(iconsOnly) const d = new Map() for (const key of Array.from(configJsons.keys())) { try { d.set(key, new TagRenderingConfig(configJsons.get(key), `SharedTagRenderings.${key}`)) } catch (e) { if (!Utils.runningFromConsole) { console.error("BUG: could not parse", key, " from questions.json or icons.json - this error happened during the build step of the SharedTagRenderings", e) } } } return d } private static generatedSharedFieldsJsons(iconsOnly = false): Map { const dict = new Map(); if (!iconsOnly) { for (const key in questions) { if (key === "id") { continue } dict.set(key, questions[key]) } } for (const key in icons) { if (key === "id") { continue } dict.set(key, icons[key]) } dict.forEach((value, key) => { if (key === "id") { return } value.id = value.id ?? key; if(value["builtin"] !== undefined){ if(value["override"] == undefined){ throw "HUH? Why whould you want to reuse a builtin if one doesn't override? In questions.json/"+key } if(typeof value["builtin"] !== "string"){ return; } // This is a really funny situation: we extend another tagRendering! const parent = Utils.Clone(dict.get(value["builtin"])) delete parent.id Utils.Merge(value["override"], parent) delete value["builtin"] delete value["override"] for (const pkey in parent) { value[pkey] = parent[pkey] } } }) return dict; } }