UNPKG

lingo3d

Version:

Lingo3D is a React/Vue 3d game development framework that ships with a complete visual editor

60 lines 2.66 kB
import { omit } from "@lincode/utils"; import nonSerializedProperties from "../api/serializer/nonSerializedProperties"; import { spawnNodeDefaults, spawnNodeSchema } from "../interface/ISpawnNode"; import Connector, { findConnected } from "./Connector"; import GameGraphChild from "./GameGraphChild"; import { managerConnectorsMap } from "../collections/managerConnectorsMap"; import { serializeAppendable } from "../api/serializer/serialize"; import { createObjectWithoutTemplatePtr } from "../pointers/createObjectWithoutTemplatePtr"; const spawnConnectors = (connectors, connectedUUIDs) => { for (const { from, to, fromProp, toProp, xyz } of connectors) { const connector = Object.assign(new Connector(), { from: connectedUUIDs.get(from), fromProp, to: connectedUUIDs.get(to), toProp, xyz }); connector.$ghost(); } }; const spawnCached = (cache, patch) => { const { data, connectors } = cache; const connectedUUIDs = new Map(); for (const [connected, type, properties] of data) { const manager = Object.assign(createObjectWithoutTemplatePtr[0](type), properties, patch.get(connected.uuid)); manager.disableBehavior(true, true, false); connectedUUIDs.set(connected.uuid, manager.uuid); } spawnConnectors(connectors, connectedUUIDs); }; class SpawnNode extends GameGraphChild { static componentName = "spawnNode"; static defaults = spawnNodeDefaults; static schema = spawnNodeSchema; static includeKeys = ["spawn"]; cache; patch = new Map(); spawn() { if (this.cache) return spawnCached(this.cache, this.patch); this.cache = { data: [], connectors: new Set() }; const { data, connectors } = this.cache; const connectedUUIDs = new Map(); for (const connected of findConnected(this)) { for (const connector of managerConnectorsMap.get(connected) ?? []) connectors.add(connector); const node = serializeAppendable(connected); if (node.type === "template") continue; const properties = omit(node, nonSerializedProperties); const manager = Object.assign(createObjectWithoutTemplatePtr[0](node.type), properties, this.patch.get(connected.uuid)); manager.disableBehavior(true, true, false); connectedUUIDs.set(connected.uuid, manager.uuid); data.push([connected, node.type, properties]); } spawnConnectors(connectors, connectedUUIDs); } } export default SpawnNode; //# sourceMappingURL=SpawnNode.js.map