//=============================================== // Imports //=============================================== import { ModuleLoader } from "../loaders/ModuleLoader"; import type { Command } from "./types/Command"; import type { Button } from "./types/Button"; import type { Module } from "./types/Module"; import type { Event } from "./types/Event"; export type CacheMap = Map; //=============================================== // ModuleManager Implementation //=============================================== export class ModuleManager { private cache = new Map>(); // Module Loading //============================== async loadModules(path: string) { const moduleLoader = new ModuleLoader(path); const modules = (await moduleLoader.collect()).getJSON(); for (const module of modules) { await this.prepareModule(module); } } async prepareModule(module: Module) { for (const exp of module.exports) { const loader = new exp.loader(exp.source); const data = (await loader.collect()).getJSON(); for (const item of data) { this.set(loader.id, (item as any).id, item); } } } // Core API //============================== set(type: string, id: string, value: T) { if (!this.cache.has(type)) this.cache.set(type, new Map()); (this.cache.get(type) as CacheMap).set(id, value); } get(type: string, id: string): T | undefined { return (this.cache.get(type) as CacheMap)?.get(id); } getAll(type: string): CacheMap { return (this.cache.get(type) as CacheMap) ?? new Map(); } // Typed Accessors //============================== get modules(): CacheMap { return this.getAll("module"); } get commands(): CacheMap { return this.getAll("command"); } get buttons(): CacheMap