@needle-tools/engine
Version:
Needle Engine is a web-based runtime for 3D apps. It runs on your machine for development with great integrations into editors like Unity or Blender - and can be deployed onto any device! It is flexible, extensible and networking and XR are built-in.
56 lines • 1.64 kB
JavaScript
import { getParam } from "./engine_utils.js";
const debug = getParam("debugtypes");
class _TypeStore {
_types = new Map();
constructor() {
if (debug)
console.warn("TypeStore: Created", this);
}
/**
* add a type to the store
*/
add(key, type) {
if (debug)
console.warn("ADD TYPE", key);
const existing = this._types.get(key);
if (!existing)
this._types.set(key, type);
else {
if (debug) {
if (existing !== type) {
console.warn("Type name exists multiple times in your project and may lead to runtime errors:", key);
}
}
}
}
/**
* @returns the type for the given key if registered
*/
get(key) {
return this._types.get(key) || null;
}
/**
* @returns the key/name for the given type if registered
*/
getKey(type) {
for (const [key, value] of this._types) {
if (value === type)
return key;
}
return null;
}
}
export const $BuiltInTypeFlag = Symbol("BuiltInType");
export const TypeStore = new _TypeStore();
/**
* add to a class declaration to automatically register it to the TypeStore (required for HMR right now)
*
* `@registerType`
*
* `export class MyType extends Behaviour { ... }`
*/
export const registerType = function (constructor) {
if (!TypeStore.get(constructor.name))
TypeStore.add(constructor.name, constructor);
};
//# sourceMappingURL=engine_typestore.js.map