forked from MapComplete/MapComplete
Refactoring: move all code files into a src directory
This commit is contained in:
parent
de99f56ca8
commit
e75d2789d2
389 changed files with 0 additions and 12 deletions
62
src/Customizations/AllKnownLayouts.ts
Normal file
62
src/Customizations/AllKnownLayouts.ts
Normal file
|
@ -0,0 +1,62 @@
|
|||
import known_themes from "../assets/generated/known_themes.json"
|
||||
import LayoutConfig from "../Models/ThemeConfig/LayoutConfig"
|
||||
import { LayoutConfigJson } from "../Models/ThemeConfig/Json/LayoutConfigJson"
|
||||
|
||||
/**
|
||||
* Somewhat of a dictionary, which lazily parses needed themes
|
||||
*/
|
||||
export class AllKnownLayoutsLazy {
|
||||
private readonly dict: Map<string, { data: LayoutConfig } | { func: () => LayoutConfig }> =
|
||||
new Map()
|
||||
constructor() {
|
||||
for (const layoutConfigJson of known_themes["themes"]) {
|
||||
this.dict.set(layoutConfigJson.id, {
|
||||
func: () => {
|
||||
const layout = new LayoutConfig(<LayoutConfigJson>layoutConfigJson, true)
|
||||
for (let i = 0; i < layout.layers.length; i++) {
|
||||
let layer = layout.layers[i]
|
||||
if (typeof layer === "string") {
|
||||
throw "Layer " + layer + " was not expanded in " + layout.id
|
||||
}
|
||||
}
|
||||
return layout
|
||||
},
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
public get(key: string): LayoutConfig {
|
||||
const thunk = this.dict.get(key)
|
||||
if (thunk === undefined) {
|
||||
return undefined
|
||||
}
|
||||
if (thunk["data"]) {
|
||||
return thunk["data"]
|
||||
}
|
||||
const layout = thunk["func"]()
|
||||
this.dict.set(key, { data: layout })
|
||||
return layout
|
||||
}
|
||||
|
||||
public keys() {
|
||||
return this.dict.keys()
|
||||
}
|
||||
|
||||
public values() {
|
||||
return Array.from(this.keys()).map((k) => this.get(k))
|
||||
}
|
||||
}
|
||||
|
||||
export class AllKnownLayouts {
|
||||
public static allKnownLayouts: AllKnownLayoutsLazy = new AllKnownLayoutsLazy()
|
||||
|
||||
static AllPublicLayers() {
|
||||
const layers = [].concat(
|
||||
...this.allKnownLayouts
|
||||
.values()
|
||||
.filter((layout) => !layout.hideFromOverview)
|
||||
.map((layout) => layout.layers)
|
||||
)
|
||||
return layers
|
||||
}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue