123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354 |
- "use strict";
- Object.defineProperty(exports, "__esModule", {
- value: true
- });
- exports.default = void 0;
- var _react = _interopRequireDefault(require("react"));
- var _Logger = _interopRequireDefault(require("./Logger"));
- var _Types = _interopRequireDefault(require("../modules/Types"));
- require("./ModuleLoader.css");
- var _ModuleUtilities = require("../modules/ModuleUtilities");
- function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
- function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i] != null ? arguments[i] : {}; var ownKeys = Object.keys(source); if (typeof Object.getOwnPropertySymbols === 'function') { ownKeys = ownKeys.concat(Object.getOwnPropertySymbols(source).filter(function (sym) { return Object.getOwnPropertyDescriptor(source, sym).enumerable; })); } ownKeys.forEach(function (key) { _defineProperty(target, key, source[key]); }); } return target; }
- function _defineProperty(obj, key, value) { if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
- function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
- function _defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } }
- function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); return Constructor; }
- var LinkManager =
- /*#__PURE__*/
- function () {
- function LinkManager() {
- _classCallCheck(this, LinkManager);
- this.__disableCore = false;
- this.clean();
- }
- _createClass(LinkManager, [{
- key: "disableCore",
- value: function disableCore() {
- this.__disableCore = true;
- }
- }, {
- key: "clean",
- value: function clean() {
- this.links = {};
- this.reverseLinks = {};
- this.inputs = {};
- this.outputs = {};
- }
- }, {
- key: "_resolve",
- value: function _resolve(output, value) {
- //console.log("Resolve", output, value);
- var pid = output.pid;
- if (pid === "core" && this.__disableCore) return; // find all links
- var links = this.links[pid][output.name]; // find all inputs
- for (var i = 0; i < links.length; i++) {
- var _links$i = links[i],
- _pid = _links$i.pid,
- name = _links$i.name; // resolve
- if (this.inputs[_pid][name]) this.inputs[_pid][name].update(value, '' + output.id + output.name);
- }
- }
- }, {
- key: "addOutputRef",
- value: function addOutputRef(output) {
- output = this.ghostOutputRef(output, false);
- this.outputs[output.pid] = _objectSpread({}, this.outputs[output.pid], _defineProperty({}, output.name, output));
- this.links[output.pid] = _objectSpread(_defineProperty({}, output.name, []), this.links[output.pid]);
- return output;
- }
- }, {
- key: "addInputRef",
- value: function addInputRef(input) {
- input = this.ghostInputRef(input);
- this.inputs[input.pid] = _objectSpread({}, this.inputs[input.pid], _defineProperty({}, input.name, input));
- this.reverseLinks[input.pid] = _objectSpread(_defineProperty({}, input.name, []), this.reverseLinks[input.pid]);
- return input;
- }
- }, {
- key: "ghostInputRef",
- value: function ghostInputRef(input) {
- var self = this;
- return _objectSpread({}, input, {
- value: (0, _ModuleUtilities.Resolver)(input),
- onUpdate: function onUpdate(fn) {
- this._onUpdate = fn;
- },
- update: function update(v, name) {
- if (v === undefined) return;
- this.value = (0, _ModuleUtilities.Resolver)(input, v);
- if (this._onUpdate) this._onUpdate(this.value);
- }
- });
- }
- }, {
- key: "ghostOutputRef",
- value: function ghostOutputRef(output) {
- var muted = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : true;
- var props = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {};
- var self = this;
- return _objectSpread({}, output, {
- set: function set(v) {
- this.value = v;
- if (props[output.name]) props[output.name](this.value);
- if (!muted) self._resolve(this, this.value);
- }
- });
- }
- }, {
- key: "createLink",
- value: function createLink(input, output) {
- // check if they exists
- if (!this.inputs[input.pid] || !this.outputs[output.pid]) return;
- if ((output.pid !== "core" || !this.__disableCore) && this.inputs[input.pid][input.name] && this.outputs[output.pid][output.name]) {
- this.inputs[input.pid][input.name].value = this.outputs[output.pid][output.name].value;
- }
- if (!this.links[output.pid][output.name]) {
- this.links[output.pid][output.name] = [];
- }
- this.links[output.pid][output.name].push({
- pid: input.pid,
- name: input.name
- });
- if (!this.reverseLinks[input.pid][input.name]) {
- this.reverseLinks[input.pid][input.name] = [];
- }
- this.reverseLinks[input.pid][input.name].push({
- pid: output.pid,
- name: output.name
- });
- }
- }, {
- key: "addLink",
- value: function addLink(link) {
- this.createLink(link.input, link.output);
- }
- }, {
- key: "clearLinks",
- value: function clearLinks(arr) {
- for (var i in this.links) {
- if (!arr[i] && i != "core") {
- this.breakLinks(i);
- }
- }
- for (var i in this.reverseLinks) {
- if (!arr[i] && i != "core") {
- this.breakLinks(i);
- }
- }
- }
- }, {
- key: "breakInputLinks",
- value: function breakInputLinks(input) {
- if (!input.pid) return;
- var id = input.pid;
- var rlinks = this.reverseLinks[id];
- var arr = rlinks[input.name];
- for (var index = 0; index < arr.length; index++) {
- var _arr$index = arr[index],
- pid = _arr$index.pid,
- name = _arr$index.name; // resolve
- for (var z = 0; z < this.links[pid][name].length; z++) {
- if (this.links[pid][name][z].pid == id && this.links[pid][name][z].name == input.name) {
- this.links[pid][name].splice(z, 1);
- z = z - 1;
- }
- }
- }
- this.reverseLinks[id][input.name] = [];
- }
- }, {
- key: "breakOutputLinks",
- value: function breakOutputLinks(output) {
- if (!output.pid) return;
- var id = output.pid;
- var rlinks = this.links[id];
- var arr = rlinks[output.name];
- for (var index = 0; index < arr.length; index++) {
- var _arr$index2 = arr[index],
- pid = _arr$index2.pid,
- name = _arr$index2.name; // resolve
- for (var z = 0; z < this.reverseLinks[pid][name].length; z++) {
- if (this.reverseLinks[pid][name][z].pid == id && this.reverseLinks[pid][name][z].name == output.name) {
- this.reverseLinks[pid][name].splice(z, 1);
- z = z - 1;
- }
- }
- }
- this.links[id][output.name] = [];
- }
- }, {
- key: "breakLinks",
- value: function breakLinks(id) {
- for (var name in this.reverseLinks[id]) {
- var arr = this.reverseLinks[id][name];
- for (var index = 0; index < arr.length; index++) {
- var _arr$index3 = arr[index],
- pid = _arr$index3.pid,
- _name = _arr$index3.name; // resolve
- for (var z = 0; z < this.links[pid][_name].length; z++) {
- if (this.links[pid][_name][z].pid == id) {
- this.links[pid][_name].splice(z, 1);
- z = z - 1;
- }
- }
- }
- }
- delete this.reverseLinks[id];
- delete this.links[id];
- delete this.inputs[id];
- delete this.outputs[id];
- }
- }, {
- key: "rename",
- value: function rename(oldid, newid) {
- for (var name in this.reverseLinks[oldid]) {
- var arr = this.reverseLinks[oldid][name];
- for (var index = 0; index < arr.length; index++) {
- var _arr$index4 = arr[index],
- pid = _arr$index4.pid,
- _name2 = _arr$index4.name; // resolve
- for (var z = 0; z < this.links[pid][_name2].length; z++) {
- if (this.links[pid][_name2][z].pid == oldid) {
- this.links[pid][_name2][z].pid = newid;
- }
- }
- }
- }
- this.reverseLinks[newid] = this.reverseLinks[oldid]; // NEED TO BE HERE
- for (var name in this.links[oldid]) {
- var _arr = this.links[oldid][name];
- for (var index = 0; index < _arr.length; index++) {
- var _arr$index5 = _arr[index],
- pid = _arr$index5.pid,
- _name3 = _arr$index5.name; // resolve
- for (var z = 0; z < this.reverseLinks[pid][_name3].length; z++) {
- if (this.reverseLinks[pid][_name3][z].pid == oldid) {
- this.reverseLinks[pid][_name3][z].pid = newid;
- }
- }
- }
- }
- this.links[newid] = this.links[oldid];
- this.inputs[newid] = this.inputs[oldid];
- this.outputs[newid] = this.outputs[oldid];
- delete this.inputs[oldid];
- delete this.outputs[oldid];
- delete this.reverseLinks[oldid];
- delete this.links[oldid];
- }
- }, {
- key: "connect",
- value: function connect(input, output) {
- this.createLink(input, output);
- }
- }, {
- key: "getOutputConnections",
- value: function getOutputConnections(output) {
- return this.links[output.pid][output.name];
- }
- }, {
- key: "getInputConnections",
- value: function getInputConnections(input) {
- return this.reverseLinks[input.pid][input.name];
- }
- }, {
- key: "isReady",
- value: function isReady(mod) {
- for (var i = 0; i < mod.inputs.length; i++) {
- if (!this.inputs[mod.id][mod.inputs[i].name]) {
- return false;
- }
- }
- for (var i = 0; i < mod.outputs.length; i++) {
- if (!this.outputs[mod.id][mod.outputs[i].name]) {
- return false;
- }
- } // maybe check more here!
- return true;
- }
- }, {
- key: "selectOutput",
- value: function selectOutput(output) {
- this.__selectedOutput = output;
- }
- }, {
- key: "connectSelected",
- value: function connectSelected(input) {
- if (this.__selectedOutput) this.createLink(input, this.__selectedOutput);
- }
- }, {
- key: "export",
- value: function _export() {
- var links = [];
- for (var i in this.links) {
- for (var j in this.links[i]) {
- if (this.links[i][j].length) {
- for (var z in this.links[i][j]) {
- var temp = {
- output: {
- name: j,
- pid: i
- },
- input: this.links[i][j][z]
- };
- links.push(temp);
- }
- }
- }
- }
- return links;
- }
- }]);
- return LinkManager;
- }();
- var _default = LinkManager;
- exports.default = _default;
|