diff --git a/Canvas.js b/Canvas.js index 2fc49d162..0187d907d 100644 --- a/Canvas.js +++ b/Canvas.js @@ -106,6 +106,7 @@ function newCanvas() { let projectInstance = UI.projects[projectDefinition.propertyName] projectInstance.spaces = {} projectInstance.events = {} + projectInstance.utilities = {} projectInstance.events.onMouseWheelMap = new Map() projectInstance.events.onMouseOverMap = new Map() @@ -117,6 +118,7 @@ function newCanvas() { let spaceDefinitionMap = new Map() /* Space Instantiation */ + if (projectDefinition.spaces === undefined) {continue} for (let j = 0; j < projectDefinition.spaces.length; j++) { let spaceDefinition = projectDefinition.spaces[j] projectInstance.spaces[spaceDefinition.propertyName] = eval(spaceDefinition.functionName + '()') @@ -167,8 +169,18 @@ function newCanvas() { thisObject.animation.addCallBackFunction(spaceDefinition.name + ' ' + 'Draw', spaceInstance.draw) } } + + /* Set up Utilities of this Project */ + if (projectDefinition.utilities === undefined) {continue} + for (let j = 0; j < projectDefinition.utilities.length; j++) { + let utilityDefinition = projectDefinition.utilities[j] + + projectInstance.utilities[utilityDefinition.propertyName] = eval(utilityDefinition.functionName + '()') + } } + console.log(UI) + return thisObject.animation.start() } catch (err) { diff --git a/Utilities/Branches.js b/Utilities/Branches.js deleted file mode 100644 index 8aa46d4db..000000000 --- a/Utilities/Branches.js +++ /dev/null @@ -1,57 +0,0 @@ -function nodeBranchToArray(node, nodeType) { - /* - This function scans a node branch for a certain node type and - return an array of with all the nodes of that type found. - */ - if (node === undefined) { return } - if (nodeType === undefined) { return } - let resultArray = [] - scanNodeBranch(node, nodeType) - return resultArray - - function scanNodeBranch(startingNode) { - if (startingNode === undefined) { return } - - let nodeDefinition = getNodeDefinition(startingNode) - if (nodeDefinition === undefined) { return } - - if (startingNode.type === nodeType) { - resultArray.push(startingNode) - return - } - - if (nodeDefinition.properties === undefined) { return } - let lastNodePropertyName - for (let i = 0; i < nodeDefinition.properties.length; i++) { - let property = nodeDefinition.properties[i] - if (lastNodePropertyName === property.name) { continue } // Some nodes have a single property por multiple child node types. We need to check repeated properties only once so as no to duplicate results. - switch (property.type) { - case 'node': { - scanNodeBranch(startingNode[property.name]) - lastNodePropertyName = property.name - } - break - case 'array': { - let startingNodePropertyArray = startingNode[property.name] - for (let m = 0; m < startingNodePropertyArray.length; m++) { - scanNodeBranch(startingNodePropertyArray[m]) - } - break - } - } - } - } -} - -function findInBranch(startingNode, nodeType, errorNode, connectedViaPayload) { - /* - This function finds a node in a brach and reports an error if it could not be found. - */ - let nodeFound = findNodeInNodeMesh(startingNode, nodeType, undefined, connectedViaPayload, true, false, false) - if (nodeFound === undefined) { - errorNode.payload.uiObject.setErrorMessage('Could not find ' + nodeType + ' at ' + startingNode.type + ' ' + startingNode.name) - return - } else { - return nodeFound - } -} diff --git a/Utilities/Clipboard.js b/Utilities/Clipboard.js deleted file mode 100644 index d6af25c88..000000000 --- a/Utilities/Clipboard.js +++ /dev/null @@ -1,35 +0,0 @@ -function fallbackCopyTextToClipboard(text) { - var textArea = document.createElement("textarea"); - textArea.value = text; - - // Avoid scrolling to bottom - textArea.style.top = "0"; - textArea.style.left = "0"; - textArea.style.position = "fixed"; - - document.body.appendChild(textArea); - textArea.focus(); - textArea.select(); - - try { - var successful = document.execCommand('copy'); - var msg = successful ? 'successful' : 'unsuccessful'; - //console.log('Fallback: Copying text command was ' + msg); - } catch (err) { - console.error('Fallback: Oops, unable to copy', err); - } - - document.body.removeChild(textArea); -} - -function copyTextToClipboard(text) { - if (!navigator.clipboard) { - fallbackCopyTextToClipboard(text); - return; - } - navigator.clipboard.writeText(text).then(function() { - //console.log('Async: Copying to clipboard was successful!'); - }, function(err) { - console.error('Async: Could not copy text: ', err); - }); -} \ No newline at end of file diff --git a/Utilities/CoordinateTransformations.js b/Utilities/CoordinateTransformations.js deleted file mode 100644 index 923cb9e72..000000000 --- a/Utilities/CoordinateTransformations.js +++ /dev/null @@ -1,17 +0,0 @@ -function transformThisPoint(point, container) { - /* We make the point relative to the current frame */ - - point = container.frame.frameThisPoint(point) - - /* We pass this point through the UI.projects.superalgos.spaces.chartingSpace.viewport lends, meaning we apply the UI.projects.superalgos.spaces.chartingSpace.viewport zoom and displacement. */ - - point = UI.projects.superalgos.spaces.chartingSpace.viewport.transformThisPoint(point) - return point -} - -function unTransformThisPoint(point, container) { - point = UI.projects.superalgos.spaces.chartingSpace.viewport.unTransformThisPoint(point) - - point = container.frame.unframeThisPoint(point) - return point -} diff --git a/Utilities/DateRateTransformations.js b/Utilities/DateRateTransformations.js deleted file mode 100644 index 4829787ed..000000000 --- a/Utilities/DateRateTransformations.js +++ /dev/null @@ -1,53 +0,0 @@ -function getDateFromPointAtBrowserCanvas(point, container, coordinateSystem) { - point = unTransformThisPoint(point, container) - point = coordinateSystem.unInverseTransform(point, container.frame.height) - - let date = new Date(point.x) - - return date -} - -function getDateFromPointAtChartsSpace(point, container, coordinateSystem) { - point = container.frame.unframeThisPoint(point) - point = coordinateSystem.unInverseTransform(point, container.frame.height) - - let date = new Date(point.x) - - return date -} - -function getDateFromPointAtContainer(point, container, coordinateSystem) { - point = coordinateSystem.unInverseTransform(point, container.frame.height) - - let date = new Date(point.x) - - return date -} - -function getRateFromPointAtBrowserCanvas(point, container, coordinateSystem) { - point = unTransformThisPoint(point, container) - point = coordinateSystem.unInverseTransform(point, container.frame.height) - - return point.y -} - -function getRateFromPointAtChartingSpace(point, container, coordinateSystem) { - point = container.frame.unframeThisPoint(point) - point = coordinateSystem.unInverseTransform(point, container.frame.height) - - return point.y -} - -function getRateFromPointAtContainer(point, container, coordinateSystem) { - point = coordinateSystem.unInverseTransform(point, container.frame.height) - - return point.y -} - -function getMilisecondsFromPoint(point, container, coordinateSystem) { - point = unTransformThisPoint(point, container) - point = coordinateSystem.unInverseTransform(point, container.frame.height) - - return point.x -} - diff --git a/Utilities/Dates.js b/Utilities/Dates.js deleted file mode 100644 index 9102d52ba..000000000 --- a/Utilities/Dates.js +++ /dev/null @@ -1,13 +0,0 @@ -function formatDate(date) { - var d = new Date(date), - month = '' + (d.getMonth() + 1), - day = '' + d.getDate(), - year = d.getFullYear(); - - if (month.length < 2) - month = '0' + month; - if (day.length < 2) - day = '0' + day; - - return [year, month, day].join('-'); -} \ No newline at end of file diff --git a/Utilities/Download.js b/Utilities/Download.js deleted file mode 100644 index b6007dac2..000000000 --- a/Utilities/Download.js +++ /dev/null @@ -1,58 +0,0 @@ -function downloadText(filename, text) { - let element = document.createElement('a') - element.setAttribute('href', 'data:text/plain;charset=utf-8,' + encodeURIComponent(text)) - element.setAttribute('download', filename) - element.style.display = 'none' - document.body.appendChild(element) - element.click() - document.body.removeChild(element) -} - -function downloadCanvas(filename, canvasToUse) { - let data = canvasToUse.toDataURL('image/png', 1) - /* Change MIME type to trick the browser to downlaod the file instead of displaying it */ - data = data.replace(/^data:image\/[^;]*/, 'data:application/octet-stream') - - /* In addition to 's "download" attribute, you can define HTTP-style headers */ - data = data.replace(/^data:application\/octet-stream/, 'data:application/octet-stream;headers=Content-Disposition%3A%20attachment%3B%20filename=' + filename + '.png') - - let element = document.createElement('a') - element.setAttribute('href', data) - element.setAttribute('download', filename + '.PNG') - element.style.display = 'none' - document.body.appendChild(element) - element.click() - document.body.removeChild(element) -}; - -function downloadPanorama(filename) { - let INITIAL_WIDTH = 800 - let FINAL_WIDTH = browserCanvas.width - INITIAL_WIDTH - - if (ARE_WE_RECORDING_A_MARKET_PANORAMA === false) { - /* We start recording the panorame. */ - ARE_WE_RECORDING_A_MARKET_PANORAMA = true - marketPanoramaCanvas = document.createElement('canvas') - marketPanoramaCanvas.width = INITIAL_WIDTH * 50 - marketPanoramaCanvas.height = browserCanvas.height - marketPanoramaCanvas.getContext('2d').drawImage(browserCanvas, 0, 0, INITIAL_WIDTH, browserCanvas.height, 0, 0, INITIAL_WIDTH, browserCanvas.height) - CURRENT_PANORAMA_POSITION = INITIAL_WIDTH - } else { - /* We stop recording and download the resulting image. */ - ARE_WE_RECORDING_A_MARKET_PANORAMA = false - marketPanoramaCanvas.getContext('2d').drawImage(browserCanvas, browserCanvas.width - FINAL_WIDTH, 0, FINAL_WIDTH, browserCanvas.height, CURRENT_PANORAMA_POSITION, 0, FINAL_WIDTH, browserCanvas.height) - let finalResultCanvas = document.createElement('canvas') - finalResultCanvas.width = CURRENT_PANORAMA_POSITION + FINAL_WIDTH - finalResultCanvas.height = browserCanvas.height - finalResultCanvas.getContext('2d').drawImage(marketPanoramaCanvas, 0, 0, finalResultCanvas.width, browserCanvas.height, 0, 0, finalResultCanvas.width, browserCanvas.height) - downloadCanvas(filename, finalResultCanvas) - marketPanoramaCanvas = undefined - } -} - -function addToMarketPanorama() { - let SECTION_WIDTH = 80 * 2 - let INITIAL_POSITION = 800 - SECTION_WIDTH - marketPanoramaCanvas.getContext('2d').drawImage(browserCanvas, INITIAL_POSITION, 0, SECTION_WIDTH, browserCanvas.height, CURRENT_PANORAMA_POSITION, 0, SECTION_WIDTH, browserCanvas.height) - CURRENT_PANORAMA_POSITION = CURRENT_PANORAMA_POSITION + SECTION_WIDTH -} diff --git a/Utilities/DrawPrint.js b/Utilities/DrawPrint.js deleted file mode 100644 index 37dad6bb4..000000000 --- a/Utilities/DrawPrint.js +++ /dev/null @@ -1,221 +0,0 @@ -function roundedCornersBackground(params) { - if (params.xOffset === undefined) { params.xOffset = 0 } - borderPoint1 = { - x: params.cornerRadius + params.xOffset, - y: params.cornerRadius - } - - borderPoint2 = { - x: params.container.frame.width - params.cornerRadius, - y: params.cornerRadius - } - - borderPoint3 = { - x: params.container.frame.width - params.cornerRadius, - y: params.container.frame.height - params.cornerRadius - } - - borderPoint4 = { - x: params.cornerRadius + params.xOffset, - y: params.container.frame.height - params.cornerRadius - } - - /* Now the transformations. */ - - if (params.coordinateSystem !== undefined) { // For instance Candles would use this - borderPoint1 = params.coordinateSystem.transformThisPoint(borderPoint1) - borderPoint2 = params.coordinateSystem.transformThisPoint(borderPoint2) - borderPoint3 = params.coordinateSystem.transformThisPoint(borderPoint3) - borderPoint4 = params.coordinateSystem.transformThisPoint(borderPoint4) - } else { - if (params.outsideViewPort === true) { // If the element is not affected by zoom - borderPoint1 = transformThisPoint(borderPoint1, params.container) - borderPoint2 = transformThisPoint(borderPoint2, params.container) - borderPoint3 = transformThisPoint(borderPoint3, params.container) - borderPoint4 = transformThisPoint(borderPoint4, params.container) - } else { // For instance Panels use this - borderPoint1 = params.container.frame.frameThisPoint(borderPoint1) - borderPoint2 = params.container.frame.frameThisPoint(borderPoint2) - borderPoint3 = params.container.frame.frameThisPoint(borderPoint3) - borderPoint4 = params.container.frame.frameThisPoint(borderPoint4) - } - } - - if (params.fitFunction !== undefined) { - borderPoint1 = params.fitFunction(borderPoint1) - borderPoint2 = params.fitFunction(borderPoint2) - borderPoint3 = params.fitFunction(borderPoint3) - borderPoint4 = params.fitFunction(borderPoint4) - } - - browserCanvasContext.setLineDash([0, 0]) - - /* Shadow */ - - if (params.castShadow === true) { - let SHADOW_OFFSET = 2 - - browserCanvasContext.beginPath() - - browserCanvasContext.arc(borderPoint1.x + SHADOW_OFFSET, borderPoint1.y + SHADOW_OFFSET, params.cornerRadius, 1.0 * Math.PI, 1.5 * Math.PI) - browserCanvasContext.lineTo(borderPoint2.x + SHADOW_OFFSET, borderPoint2.y - params.cornerRadius + SHADOW_OFFSET) - browserCanvasContext.arc(borderPoint2.x + SHADOW_OFFSET, borderPoint2.y + SHADOW_OFFSET, params.cornerRadius, 1.5 * Math.PI, 2.0 * Math.PI) - browserCanvasContext.lineTo(borderPoint3.x + params.cornerRadius + SHADOW_OFFSET, borderPoint3.y + SHADOW_OFFSET) - browserCanvasContext.arc(borderPoint3.x + SHADOW_OFFSET, borderPoint3.y + SHADOW_OFFSET, params.cornerRadius, 0 * Math.PI, 0.5 * Math.PI) - browserCanvasContext.lineTo(borderPoint4.x + SHADOW_OFFSET, borderPoint4.y + params.cornerRadius + SHADOW_OFFSET) - browserCanvasContext.arc(borderPoint4.x + SHADOW_OFFSET, borderPoint4.y + SHADOW_OFFSET, params.cornerRadius, 0.5 * Math.PI, 1.0 * Math.PI) - browserCanvasContext.lineTo(borderPoint1.x - params.cornerRadius + SHADOW_OFFSET, borderPoint1.y + SHADOW_OFFSET) - - browserCanvasContext.closePath() - - browserCanvasContext.lineWidth = 10 - browserCanvasContext.strokeStyle = 'rgba(' + UI_COLOR.BLACK + ', ' + 0.01 + ')' - browserCanvasContext.stroke() - - browserCanvasContext.lineWidth = 5 - browserCanvasContext.strokeStyle = 'rgba(' + UI_COLOR.BLACK + ', ' + 0.01 + ')' - browserCanvasContext.stroke() - - browserCanvasContext.lineWidth = 1 - browserCanvasContext.strokeStyle = 'rgba(' + UI_COLOR.BLACK + ', ' + 0.15 + ')' - browserCanvasContext.stroke() - } - - /* Background */ - - browserCanvasContext.beginPath() - - browserCanvasContext.arc(borderPoint1.x, borderPoint1.y, params.cornerRadius, 1.0 * Math.PI, 1.5 * Math.PI) - browserCanvasContext.lineTo(borderPoint2.x, borderPoint2.y - params.cornerRadius) - browserCanvasContext.arc(borderPoint2.x, borderPoint2.y, params.cornerRadius, 1.5 * Math.PI, 2.0 * Math.PI) - browserCanvasContext.lineTo(borderPoint3.x + params.cornerRadius, borderPoint3.y) - browserCanvasContext.arc(borderPoint3.x, borderPoint3.y, params.cornerRadius, 0 * Math.PI, 0.5 * Math.PI) - browserCanvasContext.lineTo(borderPoint4.x, borderPoint4.y + params.cornerRadius) - browserCanvasContext.arc(borderPoint4.x, borderPoint4.y, params.cornerRadius, 0.5 * Math.PI, 1.0 * Math.PI) - browserCanvasContext.lineTo(borderPoint1.x - params.cornerRadius, borderPoint1.y) - - browserCanvasContext.closePath() - - browserCanvasContext.fillStyle = 'rgba(' + params.backgroundColor + ', ' + params.opacity + ')' - - browserCanvasContext.fill() - - browserCanvasContext.lineWidth = params.lineWidth - browserCanvasContext.strokeStyle = 'rgba(' + params.borderColor + ', ' + params.opacity + ')' - browserCanvasContext.stroke() -} - -function drawLabel(label, xFactor, yFactor, xOffset, yOffset, fontSize, container, fontColor, noFrameX, noFrameY, opacity) { - if (label === undefined) { return } - if (fontColor === undefined) { fontColor = UI_COLOR.WHITE } - let fontOffset = label.length * fontSize * FONT_ASPECT_RATIO + 10 - if (opacity === undefined) { opacity = 1 } - - let labelPoint = { - x: container.frame.width * xFactor + xOffset - fontOffset / 2, - y: container.frame.height * yFactor + yOffset - } - - labelPoint = container.frame.frameThisPoint(labelPoint) - - if (noFrameX !== undefined) { - labelPoint.x = noFrameX + xOffset - } - - if (noFrameY !== undefined) { - labelPoint.y = noFrameY + yOffset - } - - browserCanvasContext.font = fontSize + 'px ' + UI_FONT.PRIMARY - browserCanvasContext.fillStyle = 'rgba(' + fontColor + ', ' + opacity + ')' - - browserCanvasContext.fillText(label, labelPoint.x, labelPoint.y) -} - -function drawIcon(icon, xFactor, yFactor, xOffset, yOffset, imageSize, container) { - if (icon !== undefined) { - if (icon.canDrawIcon === true) { - let imagePosition = { - x: container.frame.width * xFactor + xOffset - imageSize / 2, - y: container.frame.height * yFactor + yOffset - imageSize / 2 - } - - imagePosition = container.frame.frameThisPoint(imagePosition) - - browserCanvasContext.drawImage( - icon, imagePosition.x, - imagePosition.y, - imageSize, - imageSize) - } - } -} - -function drawContainerBackground(container, color, opacity, fitFunction) { - let fromPoint = { - x: 0, - y: 0 - } - - let toPoint = { - x: container.frame.width, - y: container.frame.height - } - - fromPoint = transformThisPoint(fromPoint, container) - toPoint = transformThisPoint(toPoint, container) - - fromPoint = fitFunction(fromPoint) - toPoint = fitFunction(toPoint) - - browserCanvasContext.beginPath() - browserCanvasContext.rect(fromPoint.x, fromPoint.y, toPoint.x - fromPoint.x, toPoint.y - fromPoint.y) - browserCanvasContext.fillStyle = 'rgba(' + color + ', ' + opacity + ')' - browserCanvasContext.closePath() - browserCanvasContext.fill() -} - -function printLabel(labelToPrint, x, y, opacity, fontSize, color, center, container, fitFunction, noDecimals, fixedDecimals) { - if (labelToPrint === undefined) { return } - let labelPoint - if (color === undefined) { color = UI_COLOR.DARK } - if (fontSize === undefined) { fontSize = 10 }; - - browserCanvasContext.font = fontSize + 'px ' + UI_FONT.PRIMARY - let label = labelToPrint - if (isNaN(label) === false && label !== '') { - if (fixedDecimals !== true) { - label = dynamicDecimals(labelToPrint) - } - label = label.toLocaleString() - if (noDecimals === true) { - label = Math.trunc(label) - } - } - - let xOffset = label.length / 2 * fontSize * FONT_ASPECT_RATIO - - if (center === true) { - labelPoint = { - x: x - xOffset, - y: y - } - } else { - labelPoint = { - x: x, - y: y - } - } - - if (container !== undefined) { - labelPoint = container.frame.frameThisPoint(labelPoint) - } - - if (fitFunction !== undefined) { - labelPoint = fitFunction(labelPoint) - } - - browserCanvasContext.fillStyle = 'rgba(' + color + ', ' + opacity + ')' - browserCanvasContext.fillText(label, labelPoint.x, labelPoint.y) -} - diff --git a/Utilities/Folders.js b/Utilities/Folders.js deleted file mode 100644 index 38cc08666..000000000 --- a/Utilities/Folders.js +++ /dev/null @@ -1,93 +0,0 @@ - - -function asymetricalFolderStructureCloning( - originNode, - destinationNode, - originObjectsArrayPropertyName, - originFoldersArrayPropertyName, - destinationFoldersArrayPropertyName, - clonedObjectType, - destinationFolderType, - originObjectArrayPropertyName, - functionLibraryUiObjectsFromNodes -) { - /* - This function will scan one branch of the workspace, and recreate - a similar structure in some other place, based on the parameters - sent to the function is what types of nodes are going to be mapped - into which other types. - */ - if (originNode === undefined) { return } - if (destinationNode === undefined) { return } - - /* Now we go down through all the children of the origin node, recreating at the destination node the same children structure*/ - let nodeDefinition = getNodeDefinition(originNode) - if (nodeDefinition === undefined) { return } - - if (nodeDefinition.properties !== undefined) { - for (let i = 0; i < nodeDefinition.properties.length; i++) { - let property = nodeDefinition.properties[i] - - switch (property.name) { - case originObjectsArrayPropertyName: { - let originNodePropertyArray = originNode[property.name] - for (let m = 0; m < originNodePropertyArray.length; m++) { - let originObject = originNodePropertyArray[m] - if (originObjectArrayPropertyName === undefined) { - /* - In this first Use Case, we are going to connect each orgin object clone - to its origin object counter part. - */ - let clonedObject = functionLibraryUiObjectsFromNodes.addUIObject(destinationNode, clonedObjectType) - clonedObject.payload.referenceParent = originObject - } else { - /* - In this second Use Case, we are going to connect an inner object that is - inside the origin object at an array. We recognize we have to do this - because we did receive this array proeprty name. - */ - let originObjectArray = originObject[originObjectArrayPropertyName] - for (let n = 0; n < originObjectArray.length; n++) { - let originObjectArrayItem = originObjectArray[n] - let clonedObject = functionLibraryUiObjectsFromNodes.addUIObject(destinationNode, clonedObjectType) - clonedObject.payload.referenceParent = originObjectArrayItem - } - } - } - break - } - case originFoldersArrayPropertyName: { - let originNodePropertyArray = originNode[property.name] - let destinationNodePropertyArray = destinationNode[destinationFoldersArrayPropertyName] - for (let m = 0; m < originNodePropertyArray.length; m++) { - let originFolder = originNodePropertyArray[m] - let found = false - let destinationFolder - for (let n = 0; n < destinationNodePropertyArray.length; n++) { - destinationFolder = destinationNodePropertyArray[n] - if (originFolder.name === destinationFolder.name) { - found = true - } - } - if (found === false) { - destinationFolder = functionLibraryUiObjectsFromNodes.addUIObject(destinationNode, destinationFolderType) - destinationFolder.name = originFolder.name - } - asymetricalFolderStructureCloning( - originFolder, - destinationFolder, - originObjectsArrayPropertyName, - originFoldersArrayPropertyName, - destinationFoldersArrayPropertyName, - clonedObjectType, - destinationFolderType, - originObjectArrayPropertyName, - functionLibraryUiObjectsFromNodes - ) - } - break - } - } - } - } -} diff --git a/Utilities/Hiriarchy.js b/Utilities/Hiriarchy.js deleted file mode 100644 index f1c0e965c..000000000 --- a/Utilities/Hiriarchy.js +++ /dev/null @@ -1,64 +0,0 @@ - - -function getHiriarchyMap(rootNode) { - /* - This function scans a node hiriatchy recursively and creates a Map by Id of all the nodes of it. - */ - let hiriatchyMap = new Map() - evalNode(rootNode) - return hiriatchyMap - - function evalNode(node) { - if (node === undefined) { return } - - hiriatchyMap.set(node.id, node) - - /* Now we go down through all this node children */ - let nodeDefinition = getNodeDefinition(node) - if (nodeDefinition === undefined) { return } - - if (nodeDefinition.properties !== undefined) { - let previousPropertyName // Since there are cases where there are many properties with the same name,because they can hold nodes of different types but only one at the time, we have to avoind counting each property of those as individual children. - for (let i = 0; i < nodeDefinition.properties.length; i++) { - let property = nodeDefinition.properties[i] - - switch (property.type) { - case 'node': { - if (property.name !== previousPropertyName) { - if (node[property.name] !== undefined) { - evalNode(node[property.name]) - } - previousPropertyName = property.name - } - break - } - case 'array': { - if (node[property.name] !== undefined) { - let nodePropertyArray = node[property.name] - for (let m = 0; m < nodePropertyArray.length; m++) { - evalNode(nodePropertyArray[m]) - } - } - break - } - } - } - } - } -} - -function getHiriarchyHead(initialNode) { - let headNode - stepBackwards(initialNode) - return headNode - - function stepBackwards(node) { - if (node === undefined) {return} - if (node.payload === undefined) {return} - if (node.payload.parentNode === undefined) { - headNode = node - } else { - stepBackwards(node.payload.parentNode) - } - } -} diff --git a/Utilities/LoadSaveFrame.js b/Utilities/LoadSaveFrame.js deleted file mode 100644 index 67fecfbb0..000000000 --- a/Utilities/LoadSaveFrame.js +++ /dev/null @@ -1,24 +0,0 @@ -function saveFrame(payload, frame) { - payload.frame = { - position: { - x: frame.position.x, - y: frame.position.y - }, - width: frame.width, - height: frame.height, - radius: frame.radius - } -} - -function loadFrame(payload, frame) { - if (payload.node.savedPayload !== undefined) { - if (payload.node.savedPayload.frame !== undefined) { - frame.position.x = payload.node.savedPayload.frame.position.x - frame.position.y = payload.node.savedPayload.frame.position.y - frame.width = payload.node.savedPayload.frame.width - frame.height = payload.node.savedPayload.frame.height - frame.radius = payload.node.savedPayload.frame.radius - payload.node.savedPayload.frame = undefined - } - } -} diff --git a/Utilities/LoadSaveTutorial.js b/Utilities/LoadSaveTutorial.js deleted file mode 100644 index 402a3ddf0..000000000 --- a/Utilities/LoadSaveTutorial.js +++ /dev/null @@ -1,18 +0,0 @@ -function saveTutorial(payload, tutorial) { - payload.tutorial = { - status: tutorial.status - } -} - -function loadTutorial(payload, tutorial) { - if (payload.tutorial !== undefined) { - tutorial.status = payload.tutorial.status - return - } - if (payload.node.savedPayload !== undefined) { - if (payload.node.savedPayload.tutorial !== undefined) { - tutorial.status = payload.node.savedPayload.tutorial.status - payload.node.savedPayload.tutorial = undefined - } - } -} diff --git a/Utilities/Menu.js b/Utilities/Menu.js deleted file mode 100644 index 6412faf23..000000000 --- a/Utilities/Menu.js +++ /dev/null @@ -1,14 +0,0 @@ -function menuClickOfNodeArray(nodeArray, action, confirm) { - for (let j=0; j < nodeArray.length; j++) { - let node = nodeArray[j] - menuClick(node, action, confirm) - } -} - -function menuClick(node, action, confirm) { - let menu = node.payload.uiObject.menu - menu.internalClick(action) - if (confirm === true) { - menu.internalClick(action) - } -} \ No newline at end of file diff --git a/Utilities/Meshes.js b/Utilities/Meshes.js deleted file mode 100644 index fbc659f17..000000000 --- a/Utilities/Meshes.js +++ /dev/null @@ -1,88 +0,0 @@ -function findNodeInNodeMesh(node, nodeType, nodeName, connectedViaPayload, findInChildren, findInParents, findInReferenceParents) { - /* - This function scans a node mesh for a certain node type and - returns the first instance found. Please specify either nodeType - or nodeName. - */ - const MAX_DEPTH = 100 - let nodeFound - scanNodeMesh(node, 0) - return nodeFound - - function scanNodeMesh(startingNode, depth) { - if (startingNode === undefined) { return } - if (connectedViaPayload === true) { - if (startingNode.payload === undefined) { return } - } - if (nodeFound !== undefined) { return } - if (depth >= MAX_DEPTH) {return} - - let nodeDefinition = getNodeDefinition(startingNode) - if (nodeDefinition === undefined) { return } - - if (nodeType !== undefined) { - if (startingNode.type === nodeType) { - nodeFound = startingNode - return - } - } - - if (nodeName !== undefined) { - if (startingNode.name === nodeName) { - nodeFound = startingNode - return - } - } - - /* We scan through this node children */ - if (findInChildren === true) { - if (nodeDefinition.properties !== undefined) { - for (let i = 0; i < nodeDefinition.properties.length; i++) { - let property = nodeDefinition.properties[i] - - switch (property.type) { - case 'node': { - scanNodeMesh(startingNode[property.name], depth + 1) - } - break - case 'array': { - let startingNodePropertyArray = startingNode[property.name] - if (startingNodePropertyArray !== undefined) { - for (let m = 0; m < startingNodePropertyArray.length; m++) { - scanNodeMesh(startingNodePropertyArray[m], depth + 1) - } - } - break - } - } - } - } - } - - /* We scan parents nodes. */ - if (findInParents === true) { - if (connectedViaPayload === true) { - if (startingNode.payload.parentNode !== undefined) { - scanNodeMesh(startingNode.payload.parentNode, depth + 1) - } - } else { - if (startingNode.parentNode !== undefined) { - scanNodeMesh(startingNode.parentNode, depth + 1) - } - } - } - - /* We scan reference parents too. */ - if (findInReferenceParents === true) { - if (connectedViaPayload === true) { - if (startingNode.payload.referenceParent !== undefined) { - scanNodeMesh(startingNode.payload.referenceParent, depth + 1) - } - } else { - if (startingNode.referenceParent !== undefined) { - scanNodeMesh(startingNode.referenceParent, depth + 1) - } - } - } - } -} \ No newline at end of file diff --git a/Utilities/NodeChildren.js b/Utilities/NodeChildren.js deleted file mode 100644 index f1a000446..000000000 --- a/Utilities/NodeChildren.js +++ /dev/null @@ -1,231 +0,0 @@ -function isMissingChildren(startingNode, checkNode, checkReferenceParent) { - /* - This functioin scan all the children of a node and returns true or false - depending if the checkNode is a missing children. - */ - if (startingNode === undefined) { return } - if (checkNode === undefined) { return } - - let nodeDefinition = getNodeDefinition(startingNode) - if (nodeDefinition === undefined) { return } - - /* We scan through this node children */ - if (nodeDefinition.properties !== undefined) { - for (let i = 0; i < nodeDefinition.properties.length; i++) { - let property = nodeDefinition.properties[i] - - switch (property.type) { - case 'node': { - let child = startingNode[property.name] - if (child === undefined) { continue } - if (checkReferenceParent !== true) { - if (child.id === checkNode.id) { - return false - } - } else { - if (child.payload !== undefined) { - if (child.payload.referenceParent !== undefined) { - if (child.payload.referenceParent.id === checkNode.id) { - return false - } - } - } - } - } - break - case 'array': { - let startingNodePropertyArray = startingNode[property.name] - if (startingNodePropertyArray !== undefined) { - for (let m = 0; m < startingNodePropertyArray.length; m++) { - let arrayItem = startingNodePropertyArray[m] - if (checkReferenceParent !== true) { - if (arrayItem.id === checkNode.id) { - return false - } - } else { - if (arrayItem.payload !== undefined) { - if (arrayItem.payload.referenceParent !== undefined) { - if (arrayItem.payload.referenceParent.id === checkNode.id) { - return false - } - } - } - } - } - } - break - } - } - } - return true - } -} - -function findChildReferencingThisNode(startingNode, checkNode) { - /* - This functioin scan all the children of a node and returns the child - that is referencing the checkNode. - */ - if (startingNode === undefined) { return } - if (checkNode === undefined) { return } - - let nodeDefinition = getNodeDefinition(startingNode) - if (nodeDefinition === undefined) { return } - - /* We scan through this node children */ - if (nodeDefinition.properties !== undefined) { - for (let i = 0; i < nodeDefinition.properties.length; i++) { - let property = nodeDefinition.properties[i] - - switch (property.type) { - case 'node': { - let child = startingNode[property.name] - - if (child.payload !== undefined) { - if (child.payload.referenceParent !== undefined) { - if (child.payload.referenceParent.id === checkNode.id) { - return child - } - } - } - } - break - case 'array': { - let startingNodePropertyArray = startingNode[property.name] - if (startingNodePropertyArray !== undefined) { - for (let m = 0; m < startingNodePropertyArray.length; m++) { - let arrayItem = startingNodePropertyArray[m] - - if (arrayItem.payload !== undefined) { - if (arrayItem.payload.referenceParent !== undefined) { - if (arrayItem.payload.referenceParent.id === checkNode.id) { - return arrayItem - } - } - } - } - } - break - } - } - } - return true - } -} - -function findOrCreateChildWithReference(startingNode, childType, referencedNode, functionLibraryUiObjectsFromNodes) { - /* - This function find the child node of starting node that references - refereced node. If there is none, then it creates a child and stablish - the referecen. - */ - let child - if (isMissingChildren(startingNode, referencedNode, true) === true) { - child = functionLibraryUiObjectsFromNodes.addUIObject(startingNode, childType) - child.payload.referenceParent = referencedNode - } else { - child = findChildReferencingThisNode(startingNode, referencedNode) - } - return child -} - -function findAndRecreateChildWithReference(startingNode, childType, referencedNode, rootNodes, functionLibraryUiObjectsFromNodes, functionLibraryNodeDeleter) { - /* - This function finds the child of the starting node that references - the reference node and if found it deletes it. Existing or not - it creates it again with the child type specified. - */ - let child - child = findChildReferencingThisNode(startingNode, referencedNode) - if (child !== undefined) { - functionLibraryNodeDeleter.deleteUIObject(child, rootNodes) - } - child = functionLibraryUiObjectsFromNodes.addUIObject(startingNode, childType) - child.payload.referenceParent = referencedNode - return child -} - -function findChildIndexAtParentNode(startingNode) { - /* - This functioin scan all the children of a node's parent and returns the child - index at the node property array that contains it. - */ - if (startingNode === undefined) { return } - if (startingNode.payload === undefined) { return } - if (startingNode.payload.parentNode === undefined) { return } - - let parentNode = startingNode.payload.parentNode - - let nodeDefinition = getNodeDefinition(parentNode) - if (nodeDefinition === undefined) { return } - - /* We scan through this parent node children */ - if (nodeDefinition.properties !== undefined) { - for (let i = 0; i < nodeDefinition.properties.length; i++) { - let property = nodeDefinition.properties[i] - - switch (property.type) { - case 'node': { - /* We ignore these types of children. */ - } - break - case 'array': { - let startingNodePropertyArray = parentNode[property.name] - if (startingNodePropertyArray !== undefined) { - for (let m = 0; m < startingNodePropertyArray.length; m++) { - let arrayItem = startingNodePropertyArray[m] - - if (arrayItem.id === startingNode.id) { - return m - } - } - } - break - } - } - } - } -} - -function isMissingChildrenByName(startingNode, nodeName) { - /* - This functioin scan all the children of a node and returns true or false - depending if the node has a children with a certain name. - */ - if (startingNode === undefined) { return } - - let nodeDefinition = getNodeDefinition(startingNode) - if (nodeDefinition === undefined) { return } - - /* We scan through this node children */ - if (nodeDefinition.properties !== undefined) { - for (let i = 0; i < nodeDefinition.properties.length; i++) { - let property = nodeDefinition.properties[i] - - switch (property.type) { - case 'node': { - let child = startingNode[property.name] - if (child !== undefined) { - if (child.name === nodeName) { - return false - } - } - } - break - case 'array': { - let startingNodePropertyArray = startingNode[property.name] - if (startingNodePropertyArray !== undefined) { - for (let m = 0; m < startingNodePropertyArray.length; m++) { - let arrayItem = startingNodePropertyArray[m] - if (arrayItem.name === nodeName) { - return false - } - } - } - break - } - } - } - return true - } -} \ No newline at end of file diff --git a/Utilities/NodeConfig.js b/Utilities/NodeConfig.js deleted file mode 100644 index f33cc2754..000000000 --- a/Utilities/NodeConfig.js +++ /dev/null @@ -1,18 +0,0 @@ -function savePropertyAtNodeConfig(payload, propertyName, value) { - try { - let config = JSON.parse(payload.node.config) - config[propertyName] = value - payload.node.config = JSON.stringify(config, null, 4) - } catch (err) { - // we ignore errors here since most likely they will be parsing errors. - } -} - -function loadPropertyFromNodeConfig(payload, propertyName) { - try { - let config = JSON.parse(payload.node.config) - return config[propertyName] - } catch (err) { - // we ignore errors here since most likely they will be parsing errors. - } -}