2021-02-26 17:22:24 +01:00
|
|
|
import AllKnownLayers from "./AllKnownLayers";
|
2021-04-10 03:50:44 +02:00
|
|
|
import * as known_themes from "../assets/generated/known_layers_and_themes.json"
|
2021-08-07 23:11:34 +02:00
|
|
|
import LayoutConfig from "../Models/ThemeConfig/LayoutConfig";
|
2021-07-03 22:00:36 +02:00
|
|
|
|
2020-07-05 18:59:47 +02:00
|
|
|
export class AllKnownLayouts {
|
|
|
|
|
2020-09-17 13:13:02 +02:00
|
|
|
|
2021-04-10 03:50:44 +02:00
|
|
|
public static allKnownLayouts: Map<string, LayoutConfig> = AllKnownLayouts.AllLayouts();
|
|
|
|
public static layoutsList: LayoutConfig[] = AllKnownLayouts.GenerateOrderedList(AllKnownLayouts.allKnownLayouts);
|
|
|
|
|
|
|
|
private static GenerateOrderedList(allKnownLayouts: Map<string, LayoutConfig>): LayoutConfig[] {
|
2021-04-22 03:57:50 +02:00
|
|
|
const keys = ["personal", "cyclofix", "hailhydrant", "bookcases", "toilets", "aed"]
|
2021-04-10 03:50:44 +02:00
|
|
|
const list = []
|
|
|
|
for (const key of keys) {
|
|
|
|
list.push(allKnownLayouts.get(key))
|
|
|
|
}
|
|
|
|
allKnownLayouts.forEach((layout, key) => {
|
|
|
|
if (keys.indexOf(key) < 0) {
|
|
|
|
list.push(layout)
|
|
|
|
}
|
|
|
|
})
|
|
|
|
return list;
|
|
|
|
}
|
|
|
|
|
|
|
|
private static AddGhostBikes(layout: LayoutConfig): LayoutConfig {
|
2021-03-21 01:49:08 +01:00
|
|
|
const now = new Date();
|
|
|
|
const m = now.getMonth() + 1;
|
|
|
|
const day = new Date().getDate() + 1;
|
|
|
|
const date = day + "/" + m;
|
|
|
|
if (date === "31/10" || date === "1/11" || date === "2/11") {
|
|
|
|
console.log("The current date is ", date, ", which means we remember our dead")
|
|
|
|
// Around Halloween/Fiesta de muerte/Allerzielen, we remember the dead
|
|
|
|
layout.layers.push(
|
|
|
|
AllKnownLayers.sharedLayers.get("ghost_bike")
|
|
|
|
);
|
2020-07-31 04:58:58 +02:00
|
|
|
|
2021-03-21 01:49:08 +01:00
|
|
|
}
|
|
|
|
return layout;
|
|
|
|
|
|
|
|
}
|
2020-07-25 01:07:02 +02:00
|
|
|
|
2020-11-11 16:23:49 +01:00
|
|
|
private static AllLayouts(): Map<string, LayoutConfig> {
|
2021-04-10 03:50:44 +02:00
|
|
|
const dict: Map<string, LayoutConfig> = new Map();
|
|
|
|
for (const layoutConfigJson of known_themes.themes) {
|
|
|
|
const layout = new LayoutConfig(layoutConfigJson, true)
|
|
|
|
|
|
|
|
if (layout.id === "cyclofix") {
|
|
|
|
AllKnownLayouts.AddGhostBikes(layout)
|
|
|
|
}
|
|
|
|
dict.set(layout.id, layout)
|
|
|
|
|
2020-08-31 02:59:47 +02:00
|
|
|
for (let i = 0; i < layout.layers.length; i++) {
|
|
|
|
let layer = layout.layers[i];
|
|
|
|
if (typeof (layer) === "string") {
|
2021-02-26 17:22:24 +01:00
|
|
|
layer = layout.layers[i] = AllKnownLayers.sharedLayers.get(layer);
|
2021-03-21 01:49:08 +01:00
|
|
|
if (layer === undefined) {
|
2021-02-26 17:22:24 +01:00
|
|
|
console.log("Defined layers are ", AllKnownLayers.sharedLayers.keys())
|
2020-09-11 02:14:16 +02:00
|
|
|
throw `Layer ${layer} was not found or defined - probably a type was made`
|
|
|
|
}
|
2020-08-31 02:59:47 +02:00
|
|
|
}
|
|
|
|
|
2020-07-25 01:07:02 +02:00
|
|
|
}
|
|
|
|
}
|
2021-04-10 03:50:44 +02:00
|
|
|
return dict;
|
2020-07-05 18:59:47 +02:00
|
|
|
}
|
2020-07-15 15:55:08 +02:00
|
|
|
|
2020-07-05 18:59:47 +02:00
|
|
|
}
|