| 
									
										
										
										
											2023-03-02 05:20:53 +01:00
										 |  |  | import known_themes from "../assets/generated/known_themes.json" | 
					
						
							| 
									
										
										
										
											2022-09-08 21:40:48 +02:00
										 |  |  | import LayoutConfig from "../Models/ThemeConfig/LayoutConfig" | 
					
						
							|  |  |  | import { LayoutConfigJson } from "../Models/ThemeConfig/Json/LayoutConfigJson" | 
					
						
							| 
									
										
										
										
											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 { | 
					
						
							|  |  |  |     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 | 
					
						
							|  |  |  |                         } | 
					
						
							| 
									
										
										
										
											2022-05-21 01:02:03 +02:00
										 |  |  |                     } | 
					
						
							| 
									
										
										
										
											2023-03-02 05:20:53 +01:00
										 |  |  |                     return layout | 
					
						
							|  |  |  |                 }, | 
					
						
							|  |  |  |             }) | 
					
						
							| 
									
										
										
										
											2022-01-14 19:34:00 +01:00
										 |  |  |         } | 
					
						
							|  |  |  |     } | 
					
						
							| 
									
										
										
										
											2021-11-07 16:34:51 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2023-03-02 05:20:53 +01:00
										 |  |  |     public get(key: string): LayoutConfig { | 
					
						
							|  |  |  |         const thunk = this.dict.get(key) | 
					
						
							|  |  |  |         if (thunk === undefined) { | 
					
						
							|  |  |  |             return undefined | 
					
						
							| 
									
										
										
										
											2021-12-05 02:06:14 +01:00
										 |  |  |         } | 
					
						
							| 
									
										
										
										
											2023-03-02 05:20:53 +01:00
										 |  |  |         if (thunk["data"]) { | 
					
						
							|  |  |  |             return thunk["data"] | 
					
						
							| 
									
										
										
										
											2022-01-26 21:40:38 +01:00
										 |  |  |         } | 
					
						
							| 
									
										
										
										
											2023-03-02 05:20:53 +01:00
										 |  |  |         const layout = thunk["func"]() | 
					
						
							|  |  |  |         this.dict.set(key, { data: layout }) | 
					
						
							|  |  |  |         return layout | 
					
						
							| 
									
										
										
										
											2022-01-26 21:40:38 +01:00
										 |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2023-03-02 05:20:53 +01:00
										 |  |  |     public keys() { | 
					
						
							|  |  |  |         return this.dict.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() | 
					
						
							| 
									
										
										
										
											2023-03-24 19:21:15 +01:00
										 |  |  | 
 | 
					
						
							|  |  |  |     static AllPublicLayers() { | 
					
						
							|  |  |  |         const layers = [].concat( | 
					
						
							|  |  |  |             ...this.allKnownLayouts | 
					
						
							|  |  |  |                 .values() | 
					
						
							|  |  |  |                 .filter((layout) => !layout.hideFromOverview) | 
					
						
							|  |  |  |                 .map((layout) => layout.layers) | 
					
						
							|  |  |  |         ) | 
					
						
							|  |  |  |         return layers | 
					
						
							|  |  |  |     } | 
					
						
							| 
									
										
										
										
											2020-07-05 18:59:47 +02:00
										 |  |  | } |