UNPKG

@polygonjs/polygonjs

Version:

node-based WebGL 3D engine https://polygonjs.com

42 lines (41 loc) 1.35 kB
"use strict"; export class TypedGLDefinitionCollection { constructor(_definitions = []) { this._definitions = _definitions; this._errored = false; } get errored() { return this._errored; } get error_message() { return this._error_message; } uniq() { const definitions_by_name = /* @__PURE__ */ new Map(); const names = []; for (const definition of this._definitions) { if (!this._errored) { const name = definition.name(); const existing = definitions_by_name.get(name); if (existing) { if (existing.data_type != definition.data_type) { this._errored = true; this._error_message = `attempt to create '${definition.name()}' with types '${definition.data_type}' by node '${definition.node.path()}', when there is already an existing with type ${existing.data_type} from node '${existing.node.path()}'`; console.warn("emitting error message:", this._error_message); } } else { definitions_by_name.set(name, definition); names.push(name); } } } const uniq_definitions = []; for (const name of names) { const definition = definitions_by_name.get(name); if (definition) { uniq_definitions.push(definition); } } return uniq_definitions; } }