mapcomplete/Customizations/SharedTagRenderings.ts

45 lines
1.9 KiB
TypeScript
Raw Normal View History

import * as questions from "../assets/tagRenderings/questions.json";
import * as icons from "../assets/tagRenderings/icons.json";
2021-07-04 20:36:19 +02:00
import {Utils} from "../Utils";
import TagRenderingConfig from "../Models/ThemeConfig/TagRenderingConfig";
import {TagRenderingConfigJson} from "../Models/ThemeConfig/Json/TagRenderingConfigJson";
2020-10-27 01:01:34 +01:00
export default class SharedTagRenderings {
public static SharedTagRendering: Map<string, TagRenderingConfig> = SharedTagRenderings.generatedSharedFields();
public static SharedTagRenderingJson: Map<string, TagRenderingConfigJson> = SharedTagRenderings.generatedSharedFieldsJsons();
public static SharedIcons: Map<string, TagRenderingConfig> = SharedTagRenderings.generatedSharedFields(true);
2020-10-27 01:01:34 +01:00
private static generatedSharedFields(iconsOnly = false): Map<string, TagRenderingConfig> {
const configJsons = SharedTagRenderings.generatedSharedFieldsJsons(iconsOnly)
const d = new Map<string, TagRenderingConfig>()
for (const key of Array.from(configJsons.keys())) {
2020-10-27 01:01:34 +01:00
try {
d.set(key, new TagRenderingConfig(configJsons.get(key), `SharedTagRenderings.${key}`))
2020-10-27 01:01:34 +01:00
} catch (e) {
if (!Utils.runningFromConsole) {
2021-07-04 20:36:19 +02:00
console.error("BUG: could not parse", key, " from questions.json or icons.json - this error happened during the build step of the SharedTagRenderings", e)
}
2020-10-27 01:01:34 +01:00
}
}
return d
}
private static generatedSharedFieldsJsons(iconsOnly = false): Map<string, TagRenderingConfigJson> {
const dict = new Map<string, TagRenderingConfigJson>();
if (!iconsOnly) {
for (const key in questions) {
dict.set(key, <TagRenderingConfigJson>questions[key])
}
}
for (const key in icons) {
dict.set(key, <TagRenderingConfigJson>icons[key])
}
2020-10-27 01:01:34 +01:00
return dict;
}
}