Visual Scripting Modules moved in from Foundations
This commit is contained in:
1 parent
cd44cc0d72
commit
1f4fee8904
19 files changed
+109
-100
No files matched your search
@@ -0,0 +1,89 @@
|
||||
function newVisualScriptingUtilitiesHierarchy() {
|
||||
let thisObject = {
|
||||
getHiriarchyMap: getHiriarchyMap,
|
||||
getHiriarchyHead: getHiriarchyHead,
|
||||
getNodeNameTypePath: getNodeNameTypePath
|
||||
}
|
||||
|
||||
return thisObject
|
||||
|
||||
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 schemaDocument = getSchemaDocument(node)
|
||||
if (schemaDocument === undefined) { return }
|
||||
|
||||
if (schemaDocument.childrenNodesProperties !== 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 < schemaDocument.childrenNodesProperties.length; i++) {
|
||||
let property = schemaDocument.childrenNodesProperties[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)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
function getNodeNameTypePath(initialNode) {
|
||||
let pathArray = []
|
||||
stepBackwards(initialNode)
|
||||
return pathArray
|
||||
|
||||
function stepBackwards(node) {
|
||||
if (node === undefined) { return }
|
||||
if (node.payload === undefined) { return }
|
||||
pathArray.unshift([node.name, node.type, node.project, node.id])
|
||||
if (node.payload.parentNode === undefined) {
|
||||
return
|
||||
} else {
|
||||
stepBackwards(node.payload.parentNode)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,33 @@
|
||||
function newVisualScriptingUtilitiesLoadSaveFrame() {
|
||||
let thisObject = {
|
||||
saveFrame: saveFrame,
|
||||
loadFrame: loadFrame
|
||||
}
|
||||
|
||||
return thisObject
|
||||
|
||||
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
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,104 @@
|
||||
function newVisualScriptingUtilitiesMeshes() {
|
||||
let thisObject = {
|
||||
findNodeInNodeMesh: findNodeInNodeMesh
|
||||
}
|
||||
|
||||
return thisObject
|
||||
|
||||
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 schemaDocument = getSchemaDocument(startingNode)
|
||||
if (schemaDocument === 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 (schemaDocument.childrenNodesProperties !== undefined) {
|
||||
for (let i = 0; i < schemaDocument.childrenNodesProperties.length; i++) {
|
||||
let property = schemaDocument.childrenNodesProperties[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)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,390 @@
|
||||
function newVisualScriptingUtilitiesNodeChildren() {
|
||||
let thisObject = {
|
||||
isMissingChildrenById: isMissingChildrenById,
|
||||
isMissingChildrenByType: isMissingChildrenByType,
|
||||
findChildReferencingThisNode: findChildReferencingThisNode,
|
||||
findChildByType: findChildByType,
|
||||
findChildByCodeName: findChildByCodeName,
|
||||
findOrCreateChildWithReference: findOrCreateChildWithReference,
|
||||
findAndRecreateChildWithReference: findAndRecreateChildWithReference,
|
||||
findChildIndexAtParentNode: findChildIndexAtParentNode,
|
||||
isMissingChildrenByName: isMissingChildrenByName
|
||||
}
|
||||
|
||||
return thisObject
|
||||
|
||||
function isMissingChildrenById(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 schemaDocument = getSchemaDocument(startingNode)
|
||||
if (schemaDocument === undefined) { return }
|
||||
|
||||
/* We scan through this node children */
|
||||
if (schemaDocument.childrenNodesProperties !== undefined) {
|
||||
for (let i = 0; i < schemaDocument.childrenNodesProperties.length; i++) {
|
||||
let property = schemaDocument.childrenNodesProperties[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 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 schemaDocument = getSchemaDocument(startingNode)
|
||||
if (schemaDocument === undefined) { return }
|
||||
|
||||
/* We scan through this node children */
|
||||
if (schemaDocument.childrenNodesProperties !== undefined) {
|
||||
for (let i = 0; i < schemaDocument.childrenNodesProperties.length; i++) {
|
||||
let property = schemaDocument.childrenNodesProperties[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
|
||||
}
|
||||
}
|
||||
|
||||
function isMissingChildrenByType(startingNode, nodeType) {
|
||||
/*
|
||||
This functioin scan all the children of a node and returns true or false
|
||||
depending if the node has a children with a certain type.
|
||||
*/
|
||||
if (startingNode === undefined) { return }
|
||||
|
||||
let schemaDocument = getSchemaDocument(startingNode)
|
||||
if (schemaDocument === undefined) { return }
|
||||
|
||||
/* We scan through this node children */
|
||||
if (schemaDocument.childrenNodesProperties !== undefined) {
|
||||
for (let i = 0; i < schemaDocument.childrenNodesProperties.length; i++) {
|
||||
let property = schemaDocument.childrenNodesProperties[i]
|
||||
|
||||
switch (property.type) {
|
||||
case 'node': {
|
||||
let child = startingNode[property.name]
|
||||
if (child !== undefined) {
|
||||
if (child.type === nodeType) {
|
||||
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.type === nodeType) {
|
||||
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 schemaDocument = getSchemaDocument(startingNode)
|
||||
if (schemaDocument === undefined) { return }
|
||||
|
||||
/* We scan through this node children */
|
||||
if (schemaDocument.childrenNodesProperties !== undefined) {
|
||||
for (let i = 0; i < schemaDocument.childrenNodesProperties.length; i++) {
|
||||
let property = schemaDocument.childrenNodesProperties[i]
|
||||
|
||||
switch (property.type) {
|
||||
case 'node': {
|
||||
let child = startingNode[property.name]
|
||||
if (child === undefined) { continue }
|
||||
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
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
function findChildByType(startingNode, nodeType) {
|
||||
/*
|
||||
This functioin scan all the children of a node and returns the child
|
||||
that has a type as specified via parameter.
|
||||
*/
|
||||
if (startingNode === undefined) { return }
|
||||
if (nodeType === undefined) { return }
|
||||
|
||||
let schemaDocument = getSchemaDocument(startingNode)
|
||||
if (schemaDocument === undefined) { return }
|
||||
|
||||
/* We scan through this node children */
|
||||
if (schemaDocument.childrenNodesProperties !== undefined) {
|
||||
for (let i = 0; i < schemaDocument.childrenNodesProperties.length; i++) {
|
||||
let property = schemaDocument.childrenNodesProperties[i]
|
||||
|
||||
switch (property.type) {
|
||||
case 'node': {
|
||||
let child = startingNode[property.name]
|
||||
if (child === undefined) { continue }
|
||||
if (child.payload !== undefined) {
|
||||
if (child.type === nodeType) {
|
||||
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.type === nodeType) {
|
||||
return arrayItem
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
break
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
function findChildByCodeName(startingNode, checkCodeName) {
|
||||
/*
|
||||
This functioin scan all the children of a node and returns the child
|
||||
that has a codeName as specified via parameter.
|
||||
*/
|
||||
if (startingNode === undefined) { return }
|
||||
if (checkCodeName === undefined) { return }
|
||||
|
||||
let schemaDocument = getSchemaDocument(startingNode)
|
||||
if (schemaDocument === undefined) { return }
|
||||
|
||||
/* We scan through this node children */
|
||||
if (schemaDocument.childrenNodesProperties !== undefined) {
|
||||
for (let i = 0; i < schemaDocument.childrenNodesProperties.length; i++) {
|
||||
let property = schemaDocument.childrenNodesProperties[i]
|
||||
|
||||
switch (property.type) {
|
||||
case 'node': {
|
||||
let child = startingNode[property.name]
|
||||
if (child === undefined) { continue }
|
||||
if (child.payload !== undefined) {
|
||||
let codeName = UI.projects.foundations.utilities.nodeConfig.loadConfigProperty(child.payload, 'codeName')
|
||||
if (codeName !== undefined) {
|
||||
if (codeName === checkCodeName) {
|
||||
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) {
|
||||
let codeName = UI.projects.foundations.utilities.nodeConfig.loadConfigProperty(arrayItem.payload, 'codeName')
|
||||
if (codeName !== undefined) {
|
||||
if (codeName === checkCodeName) {
|
||||
return arrayItem
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
break
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
function findOrCreateChildWithReference(startingNode, childType, referencedNode) {
|
||||
/*
|
||||
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 (isMissingChildrenById(startingNode, referencedNode, true) === true) {
|
||||
child = UI.projects.foundations.functionLibraries.uiObjectsFromNodes.addUIObject(startingNode, childType)
|
||||
UI.projects.foundations.functionLibraries.attachDetach.referenceAttachNode(child, referencedNode)
|
||||
} else {
|
||||
child = findChildReferencingThisNode(startingNode, referencedNode)
|
||||
}
|
||||
return child
|
||||
}
|
||||
|
||||
function findAndRecreateChildWithReference(startingNode, childType, referencedNode, rootNodes) {
|
||||
/*
|
||||
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) {
|
||||
UI.projects.foundations.functionLibraries.nodeDeleter.deleteUIObject(child, rootNodes)
|
||||
}
|
||||
child = UI.projects.foundations.functionLibraries.uiObjectsFromNodes.addUIObject(startingNode, childType)
|
||||
UI.projects.foundations.functionLibraries.attachDetach.referenceAttachNode(child, 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 schemaDocument = getSchemaDocument(parentNode)
|
||||
if (schemaDocument === undefined) { return }
|
||||
|
||||
/* We scan through this parent node children */
|
||||
if (schemaDocument.childrenNodesProperties !== undefined) {
|
||||
for (let i = 0; i < schemaDocument.childrenNodesProperties.length; i++) {
|
||||
let property = schemaDocument.childrenNodesProperties[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
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,27 @@
|
||||
function newVisualScriptingUtilitiesNodeConfig() {
|
||||
let thisObject = {
|
||||
saveConfigProperty: saveConfigProperty,
|
||||
loadConfigProperty: loadConfigProperty
|
||||
}
|
||||
|
||||
return thisObject
|
||||
|
||||
function saveConfigProperty(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 loadConfigProperty(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.
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user