MapComplete/src/Customizations/AllKnownLayouts.ts

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

62 lines
2 KiB
TypeScript
Raw Normal View History

import known_themes from "../assets/generated/known_themes.json"
import LayoutConfig from "../Models/ThemeConfig/LayoutConfig"
import favourite from "../assets/generated/layers/favourite.json"
2022-01-18 20:18:12 +01:00
import { LayoutConfigJson } from "../Models/ThemeConfig/Json/LayoutConfigJson"
import { AllSharedLayers } from "./AllSharedLayers"
import Constants from "../Models/Constants"
/**
* Somewhat of a dictionary, which lazily parses needed themes
*/
export class AllKnownLayoutsLazy {
private readonly raw: Map<string, LayoutConfigJson> = new Map()
private readonly dict: Map<string, LayoutConfig> = new Map()
constructor(includeFavouriteLayer = true) {
for (const layoutConfigJson of known_themes["themes"]) {
for (const layerId of Constants.added_by_default) {
2023-12-02 03:19:50 +01:00
if (layerId === "favourite" && favourite.id) {
if (includeFavouriteLayer) {
layoutConfigJson.layers.push(favourite)
2022-05-21 01:02:03 +02:00
}
continue
}
const defaultLayer = AllSharedLayers.getSharedLayersConfigs().get(layerId)
if (defaultLayer === undefined) {
console.error("Could not find builtin layer", layerId)
continue
}
layoutConfigJson.layers.push(defaultLayer)
}
this.raw.set(layoutConfigJson.id, layoutConfigJson)
}
}
2021-11-07 16:34:51 +01:00
public getConfig(key: string): LayoutConfigJson {
return this.raw.get(key)
}
public get(key: string): LayoutConfig {
const cached = this.dict.get(key)
if (cached !== undefined) {
return cached
}
const layout = new LayoutConfig(this.getConfig(key))
this.dict.set(key, layout)
return layout
2022-01-26 21:40:38 +01:00
}
public keys() {
return this.raw.keys()
2022-07-11 09:14:26 +02:00
}
public values() {
return Array.from(this.keys()).map((k) => this.get(k))
2021-04-10 03:50:44 +02:00
}
}
2021-04-10 03:50:44 +02:00
export class AllKnownLayouts {
public static allKnownLayouts: AllKnownLayoutsLazy = new AllKnownLayoutsLazy()
2020-07-05 18:59:47 +02:00
}