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