Start making serializable components
This commit is contained in:
@@ -1,3 +1,13 @@
|
||||
import { EverythingRegistry } from "../everything_registry.ts";
|
||||
|
||||
EverythingRegistry.add_registry("components");
|
||||
|
||||
export abstract class Component {
|
||||
__component = true;
|
||||
}
|
||||
|
||||
export abstract class SerializableComponent extends Component {
|
||||
abstract serialize(): unknown;
|
||||
// right, this is static you cant do this,,
|
||||
// abstract deserialize<T>(data: unknown): T;
|
||||
}
|
||||
|
||||
@@ -0,0 +1,15 @@
|
||||
export class EverythingRegistry {
|
||||
static #registries = new Map<string, Map<string, unknown>>();
|
||||
|
||||
static add_registry(name: string) {
|
||||
this.#registries.set(name, new Map());
|
||||
}
|
||||
|
||||
static register<T>(registry_name: string, key: string, value: T) {
|
||||
this.#registries.get(registry_name)?.set(key, value);
|
||||
}
|
||||
|
||||
static get<T>(registry_name: string, key: string): T {
|
||||
return this.#registries.get(registry_name)?.get(key) as T;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user