From 0fa59211444c0fef5d7ca65f3722c852355c4e22 Mon Sep 17 00:00:00 2001 From: Luis Fernando Molina Date: Tue, 2 Jul 2019 23:36:16 +0200 Subject: [PATCH 1/8] Fixes at Speedometer --- CockpitSpace/Speedometer.js | 2 ++ 1 file changed, 2 insertions(+) diff --git a/CockpitSpace/Speedometer.js b/CockpitSpace/Speedometer.js index b20fc3a09..9d129c778 100644 --- a/CockpitSpace/Speedometer.js +++ b/CockpitSpace/Speedometer.js @@ -89,6 +89,8 @@ function newSpeedometer () { let PROFIT_VALUE_ANGLE = CURRENT_VALUE_ANGLE if (CURRENT_VALUE_ANGLE > INIT_VALUE_ANGLE) { CURRENT_VALUE_ANGLE = INIT_VALUE_ANGLE } + if (CURRENT_VALUE_ANGLE < MIN_VALUE_ANGLE) { CURRENT_VALUE_ANGLE = MIN_VALUE_ANGLE } + if (PROFIT_VALUE_ANGLE > BAR_END_ANGLE) { PROFIT_VALUE_ANGLE = BAR_END_ANGLE } if ( thisObject.params.VALUE > 0 && From abbc95f4df2dfaf2453906274eafc14c72a17570 Mon Sep 17 00:00:00 2001 From: Luis Fernando Molina Date: Wed, 3 Jul 2019 00:53:30 +0200 Subject: [PATCH 2/8] Preventing NaN at Floating Layer --- FloatingSpace/FloatingLayer.js | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/FloatingSpace/FloatingLayer.js b/FloatingSpace/FloatingLayer.js index 7554770fc..8beef9810 100644 --- a/FloatingSpace/FloatingLayer.js +++ b/FloatingSpace/FloatingLayer.js @@ -732,10 +732,10 @@ function newFloatingLayer () { pos2.x = pos2.x - minTD.x * (im2 / (im1 + im2)) pos2.y = pos2.y - minTD.y * (im2 / (im1 + im2)) - if (floatingObject1.positionLocked === false) { + if (floatingObject1.positionLocked === false && isNaN(pos1.x) === false && isNaN(pos1.y) === false) { floatingObject1.container.frame.position = pos1 } - if (floatingObject2.positionLocked === false) { + if (floatingObject2.positionLocked === false && isNaN(pos2.x) === false && isNaN(pos2.y) === false) { floatingObject2.container.frame.position = pos2 } } catch (err) { @@ -743,3 +743,4 @@ function newFloatingLayer () { } } } + From 543dd3da3b944ee724cc0f6c4c7e41d12a175b68 Mon Sep 17 00:00:00 2001 From: Luis Fernando Molina Date: Wed, 3 Jul 2019 09:18:21 +0200 Subject: [PATCH 3/8] Tension Implemented without physics --- FloatingSpace/FloatingLayer.js | 4 +- FloatingSpace/FloatingObject.js | 45 ++- FloatingSpace/StrategyPart.js | 7 +- FloatingSpace/StrategyPartConstructor.js | 326 +++++++++++++++++- .../FunctionLibraries/StringifyNode.js | 3 +- 5 files changed, 360 insertions(+), 25 deletions(-) diff --git a/FloatingSpace/FloatingLayer.js b/FloatingSpace/FloatingLayer.js index 8beef9810..7beca69af 100644 --- a/FloatingSpace/FloatingLayer.js +++ b/FloatingSpace/FloatingLayer.js @@ -203,7 +203,7 @@ function newFloatingLayer () { for (let i = 0; i < invisibleFloatingObjects.length; i++) { let floatingObject = invisibleFloatingObjects[i] - if (floatingObject.isFrozen === false) { + if (floatingObject.isFrozen === false && floatingObject.isTensed === false) { visibleFloatingObjects.push(floatingObject) invisibleFloatingObjects.splice(i, 1) // Delete item from array. return // Only one at the time. @@ -215,7 +215,7 @@ function newFloatingLayer () { for (let i = 0; i < visibleFloatingObjects.length; i++) { let floatingObject = visibleFloatingObjects[i] - if (floatingObject.isFrozen === true) { + if (floatingObject.isFrozen === true || floatingObject.isTensed === true) { invisibleFloatingObjects.push(floatingObject) visibleFloatingObjects.splice(i, 1) // Delete item from array. return // Only one at the time. diff --git a/FloatingSpace/FloatingObject.js b/FloatingSpace/FloatingObject.js index bc9462f71..3cf5f06e3 100644 --- a/FloatingSpace/FloatingObject.js +++ b/FloatingSpace/FloatingObject.js @@ -22,13 +22,16 @@ function newFloatingObject () { targetRadius: 0, // This is the target radius of the floating object with zoom applied. It should be animated until reaching this value. isPinned: false, isFrozen: false, + isTensed: false, frozenManually: false, getPinStatus: getPinStatus, getFreezeStatus: getFreezeStatus, + getTensionStatus: getTensionStatus, nearbyFloatingObjects: [], setPosition: setPosition, pinToggle: pinToggle, freezeToggle: freezeToggle, + tensionToggle: tensionToggle, physics: physics, initializeMass: initializeMass, initializeRadius: initializeRadius, @@ -124,6 +127,10 @@ function newFloatingObject () { return thisObject.isFrozen } + function getTensionStatus () { + return thisObject.isTensed + } + function freezeToggle () { if (thisObject.isFrozen !== true) { thisObject.isFrozen = true @@ -135,10 +142,22 @@ function newFloatingObject () { return thisObject.isFrozen } + function tensionToggle () { + if (thisObject.isTensed !== true) { + thisObject.isTensed = true + thisObject.tensedManually = true + } else { + thisObject.isTensed = false + thisObject.tensedManually = false + } + return thisObject.isTensed + } + function physics () { thisObjectPhysics() thisObject.payload.uiObject.physics() frozenPhysics() + tensionPhysics() } function frozenPhysics () { @@ -150,6 +169,15 @@ function newFloatingObject () { } } + function tensionPhysics () { + if (thisObject.tensedManually === false) { + let parent = thisObject.payload.chainParent + if (parent !== undefined) { + thisObject.isTensed = parent.payload.floatingObject.isTensed + } + } + } + function thisObjectPhysics () { // The radius also have a target. @@ -298,12 +326,21 @@ function newFloatingObject () { } function initializeCurrentPosition (arroundPoint) { - let position + let position = {} if (thisObject.payload.position === undefined) { - position = { - x: Math.floor((Math.random() * (200) - 100)) + arroundPoint.x, - y: Math.floor((Math.random() * (200) - 100)) + arroundPoint.y + if (thisObject.payload.chainParent !== undefined) { + position.x = thisObject.payload.chainParent.payload.position.x + 250 + if (thisObject.payload.node.type === thisObject.payload.chainParent.type) { + position.y = thisObject.payload.chainParent.payload.position.y + } else { + position.y = thisObject.payload.chainParent.payload.position.y + Math.floor((Math.random() * (1000) - 500)) + } + } else { + position = { + x: Math.floor((Math.random() * (200) - 100)) + arroundPoint.x, + y: Math.floor((Math.random() * (200) - 100)) + arroundPoint.y + } } } else { position = { diff --git a/FloatingSpace/StrategyPart.js b/FloatingSpace/StrategyPart.js index 565554632..8391e6e86 100644 --- a/FloatingSpace/StrategyPart.js +++ b/FloatingSpace/StrategyPart.js @@ -592,11 +592,12 @@ function newStrategyPart () { if (thisObject.container.frame.radius > 1) { /* Target Line */ - let LINE_STYLE + let LINE_STYLE = UI_COLOR.TITANIUM_YELLOW + if (thisObject.payload.floatingObject.isTensed === true) { + LINE_STYLE = UI_COLOR.GOLDEN_ORANGE + } if (thisObject.payload.floatingObject.isFrozen === true) { LINE_STYLE = UI_COLOR.TURQUOISE - } else { - LINE_STYLE = UI_COLOR.TITANIUM_YELLOW } browserCanvasContext.beginPath() diff --git a/FloatingSpace/StrategyPartConstructor.js b/FloatingSpace/StrategyPartConstructor.js index a017961cd..eda67cb67 100644 --- a/FloatingSpace/StrategyPartConstructor.js +++ b/FloatingSpace/StrategyPartConstructor.js @@ -51,6 +51,9 @@ function newStrategyPartConstructor () { if (payload.node.savedPayload.floatingObject.isFrozen === true) { floatingObject.freezeToggle() } + if (payload.node.savedPayload.floatingObject.isTensed === true) { + floatingObject.tensionToggle() + } } let strategyPart = newStrategyPart() @@ -67,10 +70,11 @@ function newStrategyPartConstructor () { canvas.strategySpace.workspace.tradingSystem = payload.node } } - payload.node.savedPayload = undefined setFloatingObjectBasicProperties(floatingObject, payload) + payload.node.savedPayload = undefined + floatingLayer.addFloatingObject(floatingObject) return @@ -97,20 +101,6 @@ function newStrategyPartConstructor () { currentRadius: 0, angle: -135 }, - { - action: 'Freeze / Unfreeze', - actionFunction: floatingObject.freezeToggle, - actionStatus: floatingObject.getFreezeStatus, - currentStatus: true, - label: undefined, - visible: false, - iconPathOn: 'broken-link', - iconPathOff: 'targeting', - rawRadius: 8, - targetRadius: 0, - currentRadius: 0, - angle: 135 - }, { action: 'Download Workspace', actionFunction: payload.onMenuItemClick, @@ -143,6 +133,20 @@ function newStrategyPartConstructor () { currentRadius: 0, angle: -135 }, + { + action: 'Tense / Untense', + actionFunction: floatingObject.tensionToggle, + actionStatus: floatingObject.getTensionStatus, + currentStatus: true, + label: undefined, + visible: false, + iconPathOn: 'compass', + iconPathOff: 'headphones', + rawRadius: 8, + targetRadius: 0, + currentRadius: 0, + angle: 180 + }, { action: 'Freeze / Unfreeze', actionFunction: floatingObject.freezeToggle, @@ -254,6 +258,20 @@ function newStrategyPartConstructor () { currentRadius: 0, angle: -135 }, + { + action: 'Tense / Untense', + actionFunction: floatingObject.tensionToggle, + actionStatus: floatingObject.getTensionStatus, + currentStatus: false, + label: undefined, + visible: false, + iconPathOn: 'compass', + iconPathOff: 'headphones', + rawRadius: 8, + targetRadius: 0, + currentRadius: 0, + angle: 180 + }, { action: 'Freeze / Unfreeze', actionFunction: floatingObject.freezeToggle, @@ -324,6 +342,20 @@ function newStrategyPartConstructor () { currentRadius: 0, angle: -135 }, + { + action: 'Tense / Untense', + actionFunction: floatingObject.tensionToggle, + actionStatus: floatingObject.getTensionStatus, + currentStatus: false, + label: undefined, + visible: false, + iconPathOn: 'compass', + iconPathOff: 'headphones', + rawRadius: 8, + targetRadius: 0, + currentRadius: 0, + angle: 180 + }, { action: 'Freeze / Unfreeze', actionFunction: floatingObject.freezeToggle, @@ -395,6 +427,20 @@ function newStrategyPartConstructor () { currentRadius: 0, angle: -135 }, + { + action: 'Tense / Untense', + actionFunction: floatingObject.tensionToggle, + actionStatus: floatingObject.getTensionStatus, + currentStatus: false, + label: undefined, + visible: false, + iconPathOn: 'compass', + iconPathOff: 'headphones', + rawRadius: 8, + targetRadius: 0, + currentRadius: 0, + angle: 180 + }, { action: 'Freeze / Unfreeze', actionFunction: floatingObject.freezeToggle, @@ -465,6 +511,20 @@ function newStrategyPartConstructor () { currentRadius: 0, angle: -135 }, + { + action: 'Tense / Untense', + actionFunction: floatingObject.tensionToggle, + actionStatus: floatingObject.getTensionStatus, + currentStatus: false, + label: undefined, + visible: false, + iconPathOn: 'compass', + iconPathOff: 'headphones', + rawRadius: 8, + targetRadius: 0, + currentRadius: 0, + angle: 180 + }, { action: 'Freeze / Unfreeze', actionFunction: floatingObject.freezeToggle, @@ -548,6 +608,20 @@ function newStrategyPartConstructor () { currentRadius: 0, angle: -135 }, + { + action: 'Tense / Untense', + actionFunction: floatingObject.tensionToggle, + actionStatus: floatingObject.getTensionStatus, + currentStatus: false, + label: undefined, + visible: false, + iconPathOn: 'compass', + iconPathOff: 'headphones', + rawRadius: 8, + targetRadius: 0, + currentRadius: 0, + angle: 180 + }, { action: 'Freeze / Unfreeze', actionFunction: floatingObject.freezeToggle, @@ -618,6 +692,20 @@ function newStrategyPartConstructor () { currentRadius: 0, angle: -135 }, + { + action: 'Tense / Untense', + actionFunction: floatingObject.tensionToggle, + actionStatus: floatingObject.getTensionStatus, + currentStatus: false, + label: undefined, + visible: false, + iconPathOn: 'compass', + iconPathOff: 'headphones', + rawRadius: 8, + targetRadius: 0, + currentRadius: 0, + angle: 180 + }, { action: 'Freeze / Unfreeze', actionFunction: floatingObject.freezeToggle, @@ -688,6 +776,20 @@ function newStrategyPartConstructor () { currentRadius: 0, angle: -135 }, + { + action: 'Tense / Untense', + actionFunction: floatingObject.tensionToggle, + actionStatus: floatingObject.getTensionStatus, + currentStatus: false, + label: undefined, + visible: false, + iconPathOn: 'compass', + iconPathOff: 'headphones', + rawRadius: 8, + targetRadius: 0, + currentRadius: 0, + angle: 180 + }, { action: 'Freeze / Unfreeze', actionFunction: floatingObject.freezeToggle, @@ -746,6 +848,20 @@ function newStrategyPartConstructor () { currentRadius: 0, angle: -135 }, + { + action: 'Tense / Untense', + actionFunction: floatingObject.tensionToggle, + actionStatus: floatingObject.getTensionStatus, + currentStatus: false, + label: undefined, + visible: false, + iconPathOn: 'compass', + iconPathOff: 'headphones', + rawRadius: 8, + targetRadius: 0, + currentRadius: 0, + angle: 180 + }, { action: 'Freeze / Unfreeze', actionFunction: floatingObject.freezeToggle, @@ -817,6 +933,20 @@ function newStrategyPartConstructor () { currentRadius: 0, angle: -135 }, + { + action: 'Tense / Untense', + actionFunction: floatingObject.tensionToggle, + actionStatus: floatingObject.getTensionStatus, + currentStatus: false, + label: undefined, + visible: false, + iconPathOn: 'compass', + iconPathOff: 'headphones', + rawRadius: 8, + targetRadius: 0, + currentRadius: 0, + angle: 180 + }, { action: 'Freeze / Unfreeze', actionFunction: floatingObject.freezeToggle, @@ -888,6 +1018,20 @@ function newStrategyPartConstructor () { currentRadius: 0, angle: -135 }, + { + action: 'Tense / Untense', + actionFunction: floatingObject.tensionToggle, + actionStatus: floatingObject.getTensionStatus, + currentStatus: false, + label: undefined, + visible: false, + iconPathOn: 'compass', + iconPathOff: 'headphones', + rawRadius: 8, + targetRadius: 0, + currentRadius: 0, + angle: 180 + }, { action: 'Freeze / Unfreeze', actionFunction: floatingObject.freezeToggle, @@ -959,6 +1103,20 @@ function newStrategyPartConstructor () { currentRadius: 0, angle: -135 }, + { + action: 'Tense / Untense', + actionFunction: floatingObject.tensionToggle, + actionStatus: floatingObject.getTensionStatus, + currentStatus: false, + label: undefined, + visible: false, + iconPathOn: 'compass', + iconPathOff: 'headphones', + rawRadius: 8, + targetRadius: 0, + currentRadius: 0, + angle: 180 + }, { action: 'Freeze / Unfreeze', actionFunction: floatingObject.freezeToggle, @@ -1030,6 +1188,20 @@ function newStrategyPartConstructor () { currentRadius: 0, angle: -135 }, + { + action: 'Tense / Untense', + actionFunction: floatingObject.tensionToggle, + actionStatus: floatingObject.getTensionStatus, + currentStatus: false, + label: undefined, + visible: false, + iconPathOn: 'compass', + iconPathOff: 'headphones', + rawRadius: 8, + targetRadius: 0, + currentRadius: 0, + angle: 180 + }, { action: 'Freeze / Unfreeze', actionFunction: floatingObject.freezeToggle, @@ -1100,6 +1272,20 @@ function newStrategyPartConstructor () { currentRadius: 0, angle: -135 }, + { + action: 'Tense / Untense', + actionFunction: floatingObject.tensionToggle, + actionStatus: floatingObject.getTensionStatus, + currentStatus: false, + label: undefined, + visible: false, + iconPathOn: 'compass', + iconPathOff: 'headphones', + rawRadius: 8, + targetRadius: 0, + currentRadius: 0, + angle: 180 + }, { action: 'Freeze / Unfreeze', actionFunction: floatingObject.freezeToggle, @@ -1171,6 +1357,20 @@ function newStrategyPartConstructor () { currentRadius: 0, angle: -135 }, + { + action: 'Tense / Untense', + actionFunction: floatingObject.tensionToggle, + actionStatus: floatingObject.getTensionStatus, + currentStatus: false, + label: undefined, + visible: false, + iconPathOn: 'compass', + iconPathOff: 'headphones', + rawRadius: 8, + targetRadius: 0, + currentRadius: 0, + angle: 180 + }, { action: 'Freeze / Unfreeze', actionFunction: floatingObject.freezeToggle, @@ -1242,6 +1442,20 @@ function newStrategyPartConstructor () { currentRadius: 0, angle: -135 }, + { + action: 'Tense / Untense', + actionFunction: floatingObject.tensionToggle, + actionStatus: floatingObject.getTensionStatus, + currentStatus: false, + label: undefined, + visible: false, + iconPathOn: 'compass', + iconPathOff: 'headphones', + rawRadius: 8, + targetRadius: 0, + currentRadius: 0, + angle: 180 + }, { action: 'Freeze / Unfreeze', actionFunction: floatingObject.freezeToggle, @@ -1331,6 +1545,20 @@ function newStrategyPartConstructor () { currentRadius: 0, angle: -135 }, + { + action: 'Tense / Untense', + actionFunction: floatingObject.tensionToggle, + actionStatus: floatingObject.getTensionStatus, + currentStatus: false, + label: undefined, + visible: false, + iconPathOn: 'compass', + iconPathOff: 'headphones', + rawRadius: 8, + targetRadius: 0, + currentRadius: 0, + angle: 180 + }, { action: 'Freeze / Unfreeze', actionFunction: floatingObject.freezeToggle, @@ -1402,6 +1630,20 @@ function newStrategyPartConstructor () { currentRadius: 0, angle: -135 }, + { + action: 'Tense / Untense', + actionFunction: floatingObject.tensionToggle, + actionStatus: floatingObject.getTensionStatus, + currentStatus: false, + label: undefined, + visible: false, + iconPathOn: 'compass', + iconPathOff: 'headphones', + rawRadius: 8, + targetRadius: 0, + currentRadius: 0, + angle: 180 + }, { action: 'Freeze / Unfreeze', actionFunction: floatingObject.freezeToggle, @@ -1473,6 +1715,20 @@ function newStrategyPartConstructor () { currentRadius: 0, angle: -135 }, + { + action: 'Tense / Untense', + actionFunction: floatingObject.tensionToggle, + actionStatus: floatingObject.getTensionStatus, + currentStatus: false, + label: undefined, + visible: false, + iconPathOn: 'compass', + iconPathOff: 'headphones', + rawRadius: 8, + targetRadius: 0, + currentRadius: 0, + angle: 180 + }, { action: 'Freeze / Unfreeze', actionFunction: floatingObject.freezeToggle, @@ -1544,6 +1800,20 @@ function newStrategyPartConstructor () { currentRadius: 0, angle: -135 }, + { + action: 'Tense / Untense', + actionFunction: floatingObject.tensionToggle, + actionStatus: floatingObject.getTensionStatus, + currentStatus: false, + label: undefined, + visible: false, + iconPathOn: 'compass', + iconPathOff: 'headphones', + rawRadius: 8, + targetRadius: 0, + currentRadius: 0, + angle: 180 + }, { action: 'Freeze / Unfreeze', actionFunction: floatingObject.freezeToggle, @@ -1620,6 +1890,20 @@ function newStrategyPartConstructor () { currentRadius: 0, angle: -135 }, + { + action: 'Tense / Untense', + actionFunction: floatingObject.tensionToggle, + actionStatus: floatingObject.getTensionStatus, + currentStatus: false, + label: undefined, + visible: false, + iconPathOn: 'compass', + iconPathOff: 'headphones', + rawRadius: 8, + targetRadius: 0, + currentRadius: 0, + angle: 180 + }, { action: 'Freeze / Unfreeze', actionFunction: floatingObject.freezeToggle, @@ -1804,6 +2088,10 @@ function newStrategyPartConstructor () { floatingObject.initializeFontSize(10) floatingObject.fillStyle = 'rgba(' + UI_COLOR.WHITE + ', 1)' + + if (payload.node.savedPayload === undefined) { + floatingObject.tensionToggle() + } } function level_2 () { @@ -1816,6 +2104,10 @@ function newStrategyPartConstructor () { floatingObject.initializeFontSize(10) floatingObject.fillStyle = 'rgba(' + UI_COLOR.GREEN + ', 1)' + + if (payload.node.savedPayload === undefined) { + floatingObject.tensionToggle() + } } function level_3 () { @@ -1828,6 +2120,10 @@ function newStrategyPartConstructor () { floatingObject.initializeFontSize(10) floatingObject.fillStyle = 'rgba(' + UI_COLOR.RUSTED_RED + ', 1)' + + if (payload.node.savedPayload === undefined) { + floatingObject.tensionToggle() + } } function level_4 () { diff --git a/StrategySpace/Workspace/FunctionLibraries/StringifyNode.js b/StrategySpace/Workspace/FunctionLibraries/StringifyNode.js index c7691e2bb..16638aedb 100644 --- a/StrategySpace/Workspace/FunctionLibraries/StringifyNode.js +++ b/StrategySpace/Workspace/FunctionLibraries/StringifyNode.js @@ -310,7 +310,8 @@ function newStringifyNode () { }, floatingObject: { isPinned: node.payload.floatingObject.isPinned, - isFrozen: (node.payload.floatingObject.isFrozen && node.payload.floatingObject.frozenManually) + isFrozen: (node.payload.floatingObject.isFrozen && node.payload.floatingObject.frozenManually), + isTensed: (node.payload.floatingObject.isTensed && node.payload.floatingObject.tensedManually) }, uiObject: { isRunning: node.payload.uiObject.isRunning From d7bdf280550f8b0419a33dde686ede2c82df3885 Mon Sep 17 00:00:00 2001 From: Luis Fernando Molina Date: Wed, 3 Jul 2019 11:10:23 +0200 Subject: [PATCH 4/8] Node Children Implemented --- FloatingSpace/FloatingObject.js | 9 + .../FunctionLibraries/NodeChildren.js | 350 ++++++++++++++++++ StrategySpace/Workspace/Workspace.js | 12 +- 3 files changed, 366 insertions(+), 5 deletions(-) create mode 100644 StrategySpace/Workspace/FunctionLibraries/NodeChildren.js diff --git a/FloatingSpace/FloatingObject.js b/FloatingSpace/FloatingObject.js index 3cf5f06e3..268ead678 100644 --- a/FloatingSpace/FloatingObject.js +++ b/FloatingSpace/FloatingObject.js @@ -170,12 +170,21 @@ function newFloatingObject () { } function tensionPhysics () { + /* Tension Inheritance */ if (thisObject.tensedManually === false) { let parent = thisObject.payload.chainParent if (parent !== undefined) { thisObject.isTensed = parent.payload.floatingObject.isTensed } } + + /* Tension Effect */ + if (thisObject.isTensed === true) { + let parent = thisObject.payload.chainParent + if (parent !== undefined) { + let distanceToChainParent = Math.sqrt(Math.pow(parent.payload.position.x - thisObject.container.frame.position.x, 2) + Math.pow(parent.payload.position.y - thisObject.container.frame.position.y, 2)) // ... we calculate the distance ... + } + } } function thisObjectPhysics () { diff --git a/StrategySpace/Workspace/FunctionLibraries/NodeChildren.js b/StrategySpace/Workspace/FunctionLibraries/NodeChildren.js new file mode 100644 index 000000000..040df4f64 --- /dev/null +++ b/StrategySpace/Workspace/FunctionLibraries/NodeChildren.js @@ -0,0 +1,350 @@ +function newNodeChildren () { + thisObject = { + childrenCount: childrenCount + } + + return thisObject + + function childrenCount (node) { + switch (node.type) { + + case 'Trading System': { + return countChildrenTradingSystem(node) + } + case 'Parameters': { + return countChildrenParameters(node) + } + case 'Base Asset': { + return countChildrenBaseAsset(node) + } + case 'Strategy': { + return countChildrenStrategy(node) + } + case 'Trigger Stage': { + return countChildrenTriggerStage(node) + } + case 'Open Stage': { + return countChildrenOpenStage(node) + } + case 'Manage Stage': { + return countChildrenManageStage(node) + } + case 'Close Stage': { + return countChildrenCloseStage(node) + } + case 'Position Size': { + return countChildrenPositionSize(node) + } + case 'Initial Definition': { + return countChildrenInitialDefinition(node) + } + case 'Event': { + return countChildrenEvent(node) + } + case 'Managed Item': { + return countChildrenManagedItem(node) + } + case 'Phase': { + return countChildrenPhase(node) + } + case 'Formula': { + return countChildrenFormula(node) + } + case 'Situation': { + return countChildrenSituation(node) + } + case 'Condition': { + return countChildrenCondition(node) + } + case 'Code': { + return countChildrenCode(node) + } + } + } + + function countChildrenTradingSystem (node) { + let response = { + childrenCount: 0, + childIndex: undefined + } + + for (let i = 0; i < node.strategies.length; i++) { + let child = node.strategies[i] + response.childrenCount++ + if (child.id === node.id) { + response.childIndex = response.childrenCount + } + } + + if (node.parameters !== undefined) { + response.childrenCount++ + if (node.parameters.id === node.id) { + response.childIndex = response.childrenCount + } + } + return response + } + + function countChildrenParameters (node) { + let response = { + childrenCount: 0, + childIndex: undefined + } + if (node.baseAsset !== undefined) { + response.childrenCount++ + if (node.baseAsset.id === node.id) { + response.childIndex = response.childrenCount + } + } + return response + } + + function countChildrenBaseAsset (node) { + let response = { + childrenCount: 0, + childIndex: undefined + } + if (node.formula !== undefined) { + response.childrenCount++ + if (node.formula.id === node.id) { + response.childIndex = response.childrenCount + } + } + return response + } + + function countChildrenStrategy (node) { + let response = { + childrenCount: 0, + childIndex: undefined + } + if (node.triggerStage !== undefined) { + response.childrenCount++ + if (node.triggerStage.id === node.id) { + response.childIndex = response.childrenCount + } + } + if (node.openStage !== undefined) { + response.childrenCount++ + if (node.openStage.id === node.id) { + response.childIndex = response.childrenCount + } + } + if (node.manageStage !== undefined) { + response.childrenCount++ + if (node.manageStage.id === node.id) { + response.childIndex = response.childrenCount + } + } + if (node.closeStage !== undefined) { + response.childrenCount++ + if (node.closeStage.id === node.id) { + response.childIndex = response.childrenCount + } + } + return response + } + + function countChildrenTriggerStage (node) { + let response = { + childrenCount: 0, + childIndex: undefined + } + if (node.triggerOn !== undefined) { + response.childrenCount++ + if (node.triggerOn.id === node.id) { + response.childIndex = response.childrenCount + } + } + if (node.triggerOff !== undefined) { + response.childrenCount++ + if (node.triggerOff.id === node.id) { + response.childIndex = response.childrenCount + } + } + if (node.takePosition !== undefined) { + response.childrenCount++ + if (node.takePosition.id === node.id) { + response.childIndex = response.childrenCount + } + } + if (node.positionSize !== undefined) { + response.childrenCount++ + if (node.positionSize.id === node.id) { + response.childIndex = response.childrenCount + } + } + return response + } + + function countChildrenOpenStage (node) { + let response = { + childrenCount: 0, + childIndex: undefined + } + if (node.initialDefinition !== undefined) { + response.childrenCount++ + if (node.initialDefinition.id === node.id) { + response.childIndex = response.childrenCount + } + } + return response + } + + function countChildrenManageStage (node) { + let response = { + childrenCount: 0, + childIndex: undefined + } + if (node.stopLoss !== undefined) { + response.childrenCount++ + if (node.stopLoss.id === node.id) { + response.childIndex = response.childrenCount + } + } + if (node.takeProfit !== undefined) { + response.childrenCount++ + if (node.takeProfit.id === node.id) { + response.childIndex = response.childrenCount + } + } + return response + } + + function countChildrenCloseStage (node) { + let response = { + childrenCount: 0, + childIndex: undefined + } + return response + } + + function countChildrenPositionSize (node) { + let response = { + childrenCount: 0, + childIndex: undefined + } + if (node.formula !== undefined) { + response.childrenCount++ + if (node.formula.id === node.id) { + response.childIndex = response.childrenCount + } + } + return response + } + + function countChildrenInitialDefinition (node) { + let response = { + childrenCount: 0, + childIndex: undefined + } + if (node.stopLoss !== undefined) { + response.childrenCount++ + if (node.stopLoss.id === node.id) { + response.childIndex = response.childrenCount + } + } + if (node.takeProfit !== undefined) { + response.childrenCount++ + if (node.takeProfit.id === node.id) { + response.childIndex = response.childrenCount + } + } + return response + } + + function countChildrenEvent (node) { + let response = { + childrenCount: 0, + childIndex: undefined + } + for (let i = 0; i < node.situations.length; i++) { + let child = node.situations[i] + response.childrenCount++ + if (child.id === node.id) { + response.childIndex = response.childrenCount + } + } + return response + } + + function countChildrenManagedItem (node) { + let response = { + childrenCount: 0, + childIndex: undefined + } + for (let i = 0; i < node.phases.length; i++) { + let child = node.phases[i] + response.childrenCount++ + if (child.id === node.id) { + response.childIndex = response.childrenCount + } + } + return response + } + + function countChildrenPhase (node) { + let response = { + childrenCount: 0, + childIndex: undefined + } + if (node.formula !== undefined) { + response.childrenCount++ + if (node.formula.id === node.id) { + response.childIndex = response.childrenCount + } + } + if (node.nextPhaseEvent !== undefined) { + response.childrenCount++ + if (node.nextPhaseEvent.id === node.id) { + response.childIndex = response.childrenCount + } + } + return response + } + + function countChildrenFormula (node) { + let response = { + childrenCount: 0, + childIndex: undefined + } + return response + } + + function countChildrenSituation (node) { + let response = { + childrenCount: 0, + childIndex: undefined + } + for (let i = 0; i < node.conditions.length; i++) { + let child = node.conditions[i] + response.childrenCount++ + if (child.id === node.id) { + response.childIndex = response.childrenCount + } + } + return response + } + + function countChildrenCondition (node) { + let response = { + childrenCount: 0, + childIndex: undefined + } + if (node.code !== undefined) { + response.childrenCount++ + if (node.code.id === node.id) { + response.childIndex = response.childrenCount + } + } + return response + } + + function countChildrenCode (node) { + let response = { + childrenCount: 0, + childIndex: undefined + } + return response + } +} diff --git a/StrategySpace/Workspace/Workspace.js b/StrategySpace/Workspace/Workspace.js index a8b947318..31da4d66a 100644 --- a/StrategySpace/Workspace/Workspace.js +++ b/StrategySpace/Workspace/Workspace.js @@ -6,6 +6,7 @@ function newWorkspace () { tradingSystem: undefined, container: undefined, enabled: false, + nodeChilren: undefined, onMenuItemClick: onMenuItemClick, getProtocolTradingSystem: getProtocolTradingSystem, physics: physics, @@ -36,11 +37,12 @@ function newWorkspace () { let workspaceNode = {} workspaceNode.rootNodes = [] - functionLibraryAttachDetach = newAttachDetach() - functionLibraryNodeDeleter = newNodeDeleter() - functionLibraryPartsFromNodes = newPartsFromNodes() - functionLibraryProtocolNode = newProtocolNode() - functionLibraryWorkspaceNodes = newStringifyNode() + let functionLibraryAttachDetach = newAttachDetach() + let functionLibraryNodeDeleter = newNodeDeleter() + let functionLibraryPartsFromNodes = newPartsFromNodes() + let functionLibraryProtocolNode = newProtocolNode() + let functionLibraryWorkspaceNodes = newStringifyNode() + thisObject.nodeChilren = newNodeChildren() return thisObject From 73f0188ba96554569e725d3edb4200b8413237b8 Mon Sep 17 00:00:00 2001 From: Luis Fernando Molina Date: Wed, 3 Jul 2019 11:43:43 +0200 Subject: [PATCH 5/8] 2 params --- FloatingSpace/FloatingObject.js | 14 ++ .../FunctionLibraries/NodeChildren.js | 207 ++++++++++-------- .../FunctionLibraries/NodeDeleter.js | 4 +- StrategySpace/Workspace/Workspace.js | 4 +- 4 files changed, 133 insertions(+), 96 deletions(-) diff --git a/FloatingSpace/FloatingObject.js b/FloatingSpace/FloatingObject.js index 268ead678..379e1ff01 100644 --- a/FloatingSpace/FloatingObject.js +++ b/FloatingSpace/FloatingObject.js @@ -183,6 +183,20 @@ function newFloatingObject () { let parent = thisObject.payload.chainParent if (parent !== undefined) { let distanceToChainParent = Math.sqrt(Math.pow(parent.payload.position.x - thisObject.container.frame.position.x, 2) + Math.pow(parent.payload.position.y - thisObject.container.frame.position.y, 2)) // ... we calculate the distance ... + let parentChildren = canvas.strategySpace.workspace.nodeChildren.childrenCount(parent) + let axisCount = parentChildren.childrenCount + let axisIndex = parentChildren.childIndex + + if (parent.payload.chainParent !== undefined) { + axisCount++ + axisIndex++ + } + + let angleStep = 360 / axisCount + let myAngle = axisIndex * axisCount + + thisObject.container.frame.position.x = parent.payload.position.x + distanceToChainParent * Math.cos(toRadians(myAngle)) + thisObject.container.frame.position.y = parent.payload.position.y + distanceToChainParent * Math.sin(toRadians(myAngle)) } } } diff --git a/StrategySpace/Workspace/FunctionLibraries/NodeChildren.js b/StrategySpace/Workspace/FunctionLibraries/NodeChildren.js index 040df4f64..1749c3148 100644 --- a/StrategySpace/Workspace/FunctionLibraries/NodeChildren.js +++ b/StrategySpace/Workspace/FunctionLibraries/NodeChildren.js @@ -5,213 +5,219 @@ function newNodeChildren () { return thisObject - function childrenCount (node) { - switch (node.type) { + function childrenCount (parentNode, childNode) { + switch (parentNode.type) { case 'Trading System': { - return countChildrenTradingSystem(node) + return countChildrenTradingSystem(parentNode, childNode) } case 'Parameters': { - return countChildrenParameters(node) + return countChildrenParameters(parentNode, childNode) } case 'Base Asset': { - return countChildrenBaseAsset(node) + return countChildrenBaseAsset(parentNode, childNode) } case 'Strategy': { - return countChildrenStrategy(node) + return countChildrenStrategy(parentNode, childNode) } case 'Trigger Stage': { - return countChildrenTriggerStage(node) + return countChildrenTriggerStage(parentNode, childNode) } case 'Open Stage': { - return countChildrenOpenStage(node) + return countChildrenOpenStage(parentNode, childNode) } case 'Manage Stage': { - return countChildrenManageStage(node) + return countChildrenManageStage(parentNode, childNode) } case 'Close Stage': { - return countChildrenCloseStage(node) + return countChildrenCloseStage(parentNode, childNode) } case 'Position Size': { - return countChildrenPositionSize(node) + return countChildrenPositionSize(parentNode, childNode) } case 'Initial Definition': { - return countChildrenInitialDefinition(node) + return countChildrenInitialDefinition(parentNode, childNode) } case 'Event': { - return countChildrenEvent(node) + return countChildrenEvent(parentNode, childNode) } - case 'Managed Item': { - return countChildrenManagedItem(node) + case 'Stop': { + return countChildrenStop(parentNode, childNode) + } + case 'Take Profit': { + return countChildrenTakeProfit(parentNode, childNode) } case 'Phase': { - return countChildrenPhase(node) + return countChildrenPhase(parentNode, childNode) } case 'Formula': { - return countChildrenFormula(node) + return countChildrenFormula(parentNode, childNode) } case 'Situation': { - return countChildrenSituation(node) + return countChildrenSituation(parentNode, childNode) } case 'Condition': { - return countChildrenCondition(node) + return countChildrenCondition(parentNode, childNode) } case 'Code': { - return countChildrenCode(node) + return countChildrenCode(parentNode, childNode) + } + default: { + console.log('WARNING this parentNode type is not listed at NodeChildren: ' + parentNode.type) } } } - function countChildrenTradingSystem (node) { + function countChildrenTradingSystem (parentNode, childNode) { let response = { childrenCount: 0, childIndex: undefined } - for (let i = 0; i < node.strategies.length; i++) { - let child = node.strategies[i] + for (let i = 0; i < parentNode.strategies.length; i++) { + let child = parentNode.strategies[i] response.childrenCount++ - if (child.id === node.id) { + if (child.id === childNode.id) { response.childIndex = response.childrenCount } } - if (node.parameters !== undefined) { + if (parentNode.parameters !== undefined) { response.childrenCount++ - if (node.parameters.id === node.id) { + if (parentNode.parameters.id === childNode.id) { response.childIndex = response.childrenCount } } return response } - function countChildrenParameters (node) { + function countChildrenParameters (parentNode, childNode) { let response = { childrenCount: 0, childIndex: undefined } - if (node.baseAsset !== undefined) { + if (parentNode.baseAsset !== undefined) { response.childrenCount++ - if (node.baseAsset.id === node.id) { + if (parentNode.baseAsset.id === childNode.id) { response.childIndex = response.childrenCount } } return response } - function countChildrenBaseAsset (node) { + function countChildrenBaseAsset (parentNode, childNode) { let response = { childrenCount: 0, childIndex: undefined } - if (node.formula !== undefined) { + if (parentNode.formula !== undefined) { response.childrenCount++ - if (node.formula.id === node.id) { + if (parentNode.formula.id === childNode.id) { response.childIndex = response.childrenCount } } return response } - function countChildrenStrategy (node) { + function countChildrenStrategy (parentNode, childNode) { let response = { childrenCount: 0, childIndex: undefined } - if (node.triggerStage !== undefined) { + if (parentNode.triggerStage !== undefined) { response.childrenCount++ - if (node.triggerStage.id === node.id) { + if (parentNode.triggerStage.id === childNode.id) { response.childIndex = response.childrenCount } } - if (node.openStage !== undefined) { + if (parentNode.openStage !== undefined) { response.childrenCount++ - if (node.openStage.id === node.id) { + if (parentNode.openStage.id === childNode.id) { response.childIndex = response.childrenCount } } - if (node.manageStage !== undefined) { + if (parentNode.manageStage !== undefined) { response.childrenCount++ - if (node.manageStage.id === node.id) { + if (parentNode.manageStage.id === childNode.id) { response.childIndex = response.childrenCount } } - if (node.closeStage !== undefined) { + if (parentNode.closeStage !== undefined) { response.childrenCount++ - if (node.closeStage.id === node.id) { + if (parentNode.closeStage.id === childNode.id) { response.childIndex = response.childrenCount } } return response } - function countChildrenTriggerStage (node) { + function countChildrenTriggerStage (parentNode, childNode) { let response = { childrenCount: 0, childIndex: undefined } - if (node.triggerOn !== undefined) { + if (parentNode.triggerOn !== undefined) { response.childrenCount++ - if (node.triggerOn.id === node.id) { + if (parentNode.triggerOn.id === childNode.id) { response.childIndex = response.childrenCount } } - if (node.triggerOff !== undefined) { + if (parentNode.triggerOff !== undefined) { response.childrenCount++ - if (node.triggerOff.id === node.id) { + if (parentNode.triggerOff.id === childNode.id) { response.childIndex = response.childrenCount } } - if (node.takePosition !== undefined) { + if (parentNode.takePosition !== undefined) { response.childrenCount++ - if (node.takePosition.id === node.id) { + if (parentNode.takePosition.id === childNode.id) { response.childIndex = response.childrenCount } } - if (node.positionSize !== undefined) { + if (parentNode.positionSize !== undefined) { response.childrenCount++ - if (node.positionSize.id === node.id) { + if (parentNode.positionSize.id === childNode.id) { response.childIndex = response.childrenCount } } return response } - function countChildrenOpenStage (node) { + function countChildrenOpenStage (parentNode, childNode) { let response = { childrenCount: 0, childIndex: undefined } - if (node.initialDefinition !== undefined) { + if (parentNode.initialDefinition !== undefined) { response.childrenCount++ - if (node.initialDefinition.id === node.id) { + if (parentNode.initialDefinition.id === childNode.id) { response.childIndex = response.childrenCount } } return response } - function countChildrenManageStage (node) { + function countChildrenManageStage (parentNode, childNode) { let response = { childrenCount: 0, childIndex: undefined } - if (node.stopLoss !== undefined) { + if (parentNode.stopLoss !== undefined) { response.childrenCount++ - if (node.stopLoss.id === node.id) { + if (parentNode.stopLoss.id === childNode.id) { response.childIndex = response.childrenCount } } - if (node.takeProfit !== undefined) { + if (parentNode.takeProfit !== undefined) { response.childrenCount++ - if (node.takeProfit.id === node.id) { + if (parentNode.takeProfit.id === childNode.id) { response.childIndex = response.childrenCount } } return response } - function countChildrenCloseStage (node) { + function countChildrenCloseStage (parentNode, childNode) { let response = { childrenCount: 0, childIndex: undefined @@ -219,91 +225,106 @@ function newNodeChildren () { return response } - function countChildrenPositionSize (node) { + function countChildrenPositionSize (parentNode, childNode) { let response = { childrenCount: 0, childIndex: undefined } - if (node.formula !== undefined) { + if (parentNode.formula !== undefined) { response.childrenCount++ - if (node.formula.id === node.id) { + if (parentNode.formula.id === childNode.id) { response.childIndex = response.childrenCount } } return response } - function countChildrenInitialDefinition (node) { + function countChildrenInitialDefinition (parentNode, childNode) { let response = { childrenCount: 0, childIndex: undefined } - if (node.stopLoss !== undefined) { + if (parentNode.stopLoss !== undefined) { response.childrenCount++ - if (node.stopLoss.id === node.id) { + if (parentNode.stopLoss.id === childNode.id) { response.childIndex = response.childrenCount } } - if (node.takeProfit !== undefined) { + if (parentNode.takeProfit !== undefined) { response.childrenCount++ - if (node.takeProfit.id === node.id) { + if (parentNode.takeProfit.id === childNode.id) { response.childIndex = response.childrenCount } } return response } - function countChildrenEvent (node) { + function countChildrenEvent (parentNode, childNode) { let response = { childrenCount: 0, childIndex: undefined } - for (let i = 0; i < node.situations.length; i++) { - let child = node.situations[i] + for (let i = 0; i < parentNode.situations.length; i++) { + let child = parentNode.situations[i] response.childrenCount++ - if (child.id === node.id) { + if (child.id === childNode.id) { response.childIndex = response.childrenCount } } return response } - function countChildrenManagedItem (node) { + function countChildrenStop (parentNode, childNode) { let response = { childrenCount: 0, childIndex: undefined } - for (let i = 0; i < node.phases.length; i++) { - let child = node.phases[i] + for (let i = 0; i < parentNode.phases.length; i++) { + let child = parentNode.phases[i] response.childrenCount++ - if (child.id === node.id) { + if (child.id === childNode.id) { response.childIndex = response.childrenCount } } return response } - function countChildrenPhase (node) { + function countChildrenTakeProfit (parentNode, childNode) { let response = { childrenCount: 0, childIndex: undefined } - if (node.formula !== undefined) { + for (let i = 0; i < parentNode.phases.length; i++) { + let child = parentNode.phases[i] response.childrenCount++ - if (node.formula.id === node.id) { - response.childIndex = response.childrenCount - } - } - if (node.nextPhaseEvent !== undefined) { - response.childrenCount++ - if (node.nextPhaseEvent.id === node.id) { + if (child.id === childNode.id) { response.childIndex = response.childrenCount } } return response } - function countChildrenFormula (node) { + function countChildrenPhase (parentNode, childNode) { + let response = { + childrenCount: 0, + childIndex: undefined + } + if (parentNode.formula !== undefined) { + response.childrenCount++ + if (parentNode.formula.id === childNode.id) { + response.childIndex = response.childrenCount + } + } + if (parentNode.nextPhaseEvent !== undefined) { + response.childrenCount++ + if (parentNode.nextPhaseEvent.id === childNode.id) { + response.childIndex = response.childrenCount + } + } + return response + } + + function countChildrenFormula (parentNode, childNode) { let response = { childrenCount: 0, childIndex: undefined @@ -311,36 +332,36 @@ function newNodeChildren () { return response } - function countChildrenSituation (node) { + function countChildrenSituation (parentNode, childNode) { let response = { childrenCount: 0, childIndex: undefined } - for (let i = 0; i < node.conditions.length; i++) { - let child = node.conditions[i] + for (let i = 0; i < parentNode.conditions.length; i++) { + let child = parentNode.conditions[i] response.childrenCount++ - if (child.id === node.id) { + if (child.id === childNode.id) { response.childIndex = response.childrenCount } } return response } - function countChildrenCondition (node) { + function countChildrenCondition (parentNode, childNode) { let response = { childrenCount: 0, childIndex: undefined } - if (node.code !== undefined) { + if (parentNode.code !== undefined) { response.childrenCount++ - if (node.code.id === node.id) { + if (parentNode.code.id === childNode.id) { response.childIndex = response.childrenCount } } return response } - function countChildrenCode (node) { + function countChildrenCode (parentNode, childNode) { let response = { childrenCount: 0, childIndex: undefined diff --git a/StrategySpace/Workspace/FunctionLibraries/NodeDeleter.js b/StrategySpace/Workspace/FunctionLibraries/NodeDeleter.js index 4b1d23c86..2fce8374a 100644 --- a/StrategySpace/Workspace/FunctionLibraries/NodeDeleter.js +++ b/StrategySpace/Workspace/FunctionLibraries/NodeDeleter.js @@ -99,8 +99,10 @@ function newNodeDeleter () { deleteCode(rootNode, rootNodes) break } - default: + default: { + console.log('WARNING this node type is not listed at NodeDeleter: ' + node.type) + } } } diff --git a/StrategySpace/Workspace/Workspace.js b/StrategySpace/Workspace/Workspace.js index 31da4d66a..7c3463a6e 100644 --- a/StrategySpace/Workspace/Workspace.js +++ b/StrategySpace/Workspace/Workspace.js @@ -6,7 +6,7 @@ function newWorkspace () { tradingSystem: undefined, container: undefined, enabled: false, - nodeChilren: undefined, + nodeChildren: undefined, onMenuItemClick: onMenuItemClick, getProtocolTradingSystem: getProtocolTradingSystem, physics: physics, @@ -42,7 +42,7 @@ function newWorkspace () { let functionLibraryPartsFromNodes = newPartsFromNodes() let functionLibraryProtocolNode = newProtocolNode() let functionLibraryWorkspaceNodes = newStringifyNode() - thisObject.nodeChilren = newNodeChildren() + thisObject.nodeChildren = newNodeChildren() return thisObject From 468ef8d0c612721d570e5defca9c57a34ace0d8d Mon Sep 17 00:00:00 2001 From: Luis Fernando Molina Date: Wed, 3 Jul 2019 11:50:04 +0200 Subject: [PATCH 6/8] Implementation of Parent Children Running --- FloatingSpace/FloatingObject.js | 2 +- .../Workspace/FunctionLibraries/NodeChildren.js | 11 ++++++++++- 2 files changed, 11 insertions(+), 2 deletions(-) diff --git a/FloatingSpace/FloatingObject.js b/FloatingSpace/FloatingObject.js index 379e1ff01..925f4e8b6 100644 --- a/FloatingSpace/FloatingObject.js +++ b/FloatingSpace/FloatingObject.js @@ -183,7 +183,7 @@ function newFloatingObject () { let parent = thisObject.payload.chainParent if (parent !== undefined) { let distanceToChainParent = Math.sqrt(Math.pow(parent.payload.position.x - thisObject.container.frame.position.x, 2) + Math.pow(parent.payload.position.y - thisObject.container.frame.position.y, 2)) // ... we calculate the distance ... - let parentChildren = canvas.strategySpace.workspace.nodeChildren.childrenCount(parent) + let parentChildren = canvas.strategySpace.workspace.nodeChildren.childrenCount(parent, thisObject.payload.node) let axisCount = parentChildren.childrenCount let axisIndex = parentChildren.childIndex diff --git a/StrategySpace/Workspace/FunctionLibraries/NodeChildren.js b/StrategySpace/Workspace/FunctionLibraries/NodeChildren.js index 1749c3148..d346f8a82 100644 --- a/StrategySpace/Workspace/FunctionLibraries/NodeChildren.js +++ b/StrategySpace/Workspace/FunctionLibraries/NodeChildren.js @@ -38,7 +38,16 @@ function newNodeChildren () { case 'Initial Definition': { return countChildrenInitialDefinition(parentNode, childNode) } - case 'Event': { + case 'Next Phase Event': { + return countChildrenEvent(parentNode, childNode) + } + case 'Trigger On Event': { + return countChildrenEvent(parentNode, childNode) + } + case 'Trigger Off Event': { + return countChildrenEvent(parentNode, childNode) + } + case 'Take Position Event': { return countChildrenEvent(parentNode, childNode) } case 'Stop': { From eca3a417640c99e75dc7e58be6896895d3200010 Mon Sep 17 00:00:00 2001 From: Luis Fernando Molina Date: Wed, 3 Jul 2019 14:47:41 +0200 Subject: [PATCH 7/8] Working with Phases Aligned --- FloatingSpace/FloatingLayer.js | 24 ++++++---- FloatingSpace/FloatingObject.js | 46 +++++++++++++------ .../FunctionLibraries/NodeChildren.js | 19 ++++++-- 3 files changed, 60 insertions(+), 29 deletions(-) diff --git a/FloatingSpace/FloatingLayer.js b/FloatingSpace/FloatingLayer.js index 7beca69af..a6677cb0c 100644 --- a/FloatingSpace/FloatingLayer.js +++ b/FloatingSpace/FloatingLayer.js @@ -203,7 +203,7 @@ function newFloatingLayer () { for (let i = 0; i < invisibleFloatingObjects.length; i++) { let floatingObject = invisibleFloatingObjects[i] - if (floatingObject.isFrozen === false && floatingObject.isTensed === false) { + if (floatingObject.isFrozen === false) { visibleFloatingObjects.push(floatingObject) invisibleFloatingObjects.splice(i, 1) // Delete item from array. return // Only one at the time. @@ -215,7 +215,7 @@ function newFloatingLayer () { for (let i = 0; i < visibleFloatingObjects.length; i++) { let floatingObject = visibleFloatingObjects[i] - if (floatingObject.isFrozen === true || floatingObject.isTensed === true) { + if (floatingObject.isFrozen === true) { invisibleFloatingObjects.push(floatingObject) visibleFloatingObjects.splice(i, 1) // Delete item from array. return // Only one at the time. @@ -429,9 +429,10 @@ function newFloatingLayer () { } /* We add the force vector to the speed vector */ - - floatingObject.currentSpeed.x = floatingObject.currentSpeed.x + forceVector.x - floatingObject.currentSpeed.y = floatingObject.currentSpeed.y + forceVector.y + if (isNaN(forceVector.x) === false && isNaN(forceVector.y) === false) { + floatingObject.currentSpeed.x = floatingObject.currentSpeed.x + forceVector.x + floatingObject.currentSpeed.y = floatingObject.currentSpeed.y + forceVector.y + } } } catch (err) { if (ERROR_LOG === true) { logger.write('[ERROR] gravityForce -> err= ' + err.stack) } @@ -490,9 +491,10 @@ function newFloatingLayer () { } /* We substract the force vector to the speed vector of the current floatingObject */ - - floatingObject1.currentSpeed.x = floatingObject1.currentSpeed.x - forceVector.x - floatingObject1.currentSpeed.y = floatingObject1.currentSpeed.y - forceVector.y + if (isNaN(forceVector.x) === false && isNaN(forceVector.y) === false) { + floatingObject1.currentSpeed.x = floatingObject1.currentSpeed.x - forceVector.x + floatingObject1.currentSpeed.y = floatingObject1.currentSpeed.y - forceVector.y + } } } } catch (err) { @@ -608,8 +610,10 @@ function newFloatingLayer () { /* We substract the force vector to the speed vector of the current floatingObject */ - floatingObject1.currentSpeed.x = floatingObject1.currentSpeed.x - forceVector.x - floatingObject1.currentSpeed.y = floatingObject1.currentSpeed.y - forceVector.y + if (isNaN(forceVector.x) === false && isNaN(forceVector.y) === false) { + floatingObject1.currentSpeed.x = floatingObject1.currentSpeed.x - forceVector.x + floatingObject1.currentSpeed.y = floatingObject1.currentSpeed.y - forceVector.y + } } } } catch (err) { diff --git a/FloatingSpace/FloatingObject.js b/FloatingSpace/FloatingObject.js index 925f4e8b6..84db50afb 100644 --- a/FloatingSpace/FloatingObject.js +++ b/FloatingSpace/FloatingObject.js @@ -186,17 +186,36 @@ function newFloatingObject () { let parentChildren = canvas.strategySpace.workspace.nodeChildren.childrenCount(parent, thisObject.payload.node) let axisCount = parentChildren.childrenCount let axisIndex = parentChildren.childIndex + let baseAngle = 0 - if (parent.payload.chainParent !== undefined) { + if (axisIndex === undefined) { + axisCount = 1 + axisIndex = axisCount + } + + if (parent.payload.chainParent !== undefined && parent.payload.angle !== undefined) { axisCount++ axisIndex++ + baseAngle = parent.payload.angle + 180 } let angleStep = 360 / axisCount - let myAngle = axisIndex * axisCount - thisObject.container.frame.position.x = parent.payload.position.x + distanceToChainParent * Math.cos(toRadians(myAngle)) - thisObject.container.frame.position.y = parent.payload.position.y + distanceToChainParent * Math.sin(toRadians(myAngle)) + thisObject.payload.angle = baseAngle + (axisIndex - 1) * angleStep + if (thisObject.payload.angle >= 360) { + thisObject.payload.angle = thisObject.payload.angle - 360 + } + + newPosition = { + x: parent.payload.position.x + distanceToChainParent * Math.cos(toRadians(thisObject.payload.angle)), + y: parent.payload.position.y + distanceToChainParent * Math.sin(toRadians(thisObject.payload.angle)) + } + if (isNaN(newPosition.x) === false) { + thisObject.container.frame.position.x = newPosition.x + } + if (isNaN(newPosition.y) === false) { + thisObject.container.frame.position.y = newPosition.y + } } } } @@ -352,19 +371,15 @@ function newFloatingObject () { let position = {} if (thisObject.payload.position === undefined) { - if (thisObject.payload.chainParent !== undefined) { + /* if (thisObject.payload.chainParent !== undefined) { position.x = thisObject.payload.chainParent.payload.position.x + 250 - if (thisObject.payload.node.type === thisObject.payload.chainParent.type) { - position.y = thisObject.payload.chainParent.payload.position.y - } else { - position.y = thisObject.payload.chainParent.payload.position.y + Math.floor((Math.random() * (1000) - 500)) - } - } else { - position = { - x: Math.floor((Math.random() * (200) - 100)) + arroundPoint.x, - y: Math.floor((Math.random() * (200) - 100)) + arroundPoint.y - } + position.y = thisObject.payload.chainParent.payload.position.y + } else { */ + position = { + x: Math.floor((Math.random() * (200) - 100)) + arroundPoint.x, + y: Math.floor((Math.random() * (200) - 100)) + arroundPoint.y } + // } } else { position = { x: thisObject.payload.position.x, @@ -416,3 +431,4 @@ function newFloatingObject () { function updateRadius () { } } + diff --git a/StrategySpace/Workspace/FunctionLibraries/NodeChildren.js b/StrategySpace/Workspace/FunctionLibraries/NodeChildren.js index d346f8a82..a6525663f 100644 --- a/StrategySpace/Workspace/FunctionLibraries/NodeChildren.js +++ b/StrategySpace/Workspace/FunctionLibraries/NodeChildren.js @@ -290,9 +290,14 @@ function newNodeChildren () { } for (let i = 0; i < parentNode.phases.length; i++) { let child = parentNode.phases[i] - response.childrenCount++ + if (child.id === childNode.id) { - response.childIndex = response.childrenCount + if (childNode.payload.chainParent !== undefined) { + if (childNode.payload.chainParent.id === parentNode.id) { + response.childrenCount++ + response.childIndex = response.childrenCount + } + } } } return response @@ -305,9 +310,14 @@ function newNodeChildren () { } for (let i = 0; i < parentNode.phases.length; i++) { let child = parentNode.phases[i] - response.childrenCount++ + if (child.id === childNode.id) { - response.childIndex = response.childrenCount + if (childNode.payload.chainParent !== undefined) { + if (childNode.payload.chainParent.id === parentNode.id) { + response.childrenCount++ + response.childIndex = response.childrenCount + } + } } } return response @@ -378,3 +388,4 @@ function newNodeChildren () { return response } } + From a3ee6fef20cb21af2bd575af9466621302ff72f5 Mon Sep 17 00:00:00 2001 From: Luis Fernando Molina Date: Wed, 3 Jul 2019 15:34:46 +0200 Subject: [PATCH 8/8] Final tests tensors succeeded --- FloatingSpace/FloatingObject.js | 17 ++--------------- FloatingSpace/StrategyPartConstructor.js | 11 ++++++++--- 2 files changed, 10 insertions(+), 18 deletions(-) diff --git a/FloatingSpace/FloatingObject.js b/FloatingSpace/FloatingObject.js index 84db50afb..0166923c2 100644 --- a/FloatingSpace/FloatingObject.js +++ b/FloatingSpace/FloatingObject.js @@ -170,14 +170,6 @@ function newFloatingObject () { } function tensionPhysics () { - /* Tension Inheritance */ - if (thisObject.tensedManually === false) { - let parent = thisObject.payload.chainParent - if (parent !== undefined) { - thisObject.isTensed = parent.payload.floatingObject.isTensed - } - } - /* Tension Effect */ if (thisObject.isTensed === true) { let parent = thisObject.payload.chainParent @@ -371,15 +363,10 @@ function newFloatingObject () { let position = {} if (thisObject.payload.position === undefined) { - /* if (thisObject.payload.chainParent !== undefined) { - position.x = thisObject.payload.chainParent.payload.position.x + 250 - position.y = thisObject.payload.chainParent.payload.position.y - } else { */ position = { - x: Math.floor((Math.random() * (200) - 100)) + arroundPoint.x, - y: Math.floor((Math.random() * (200) - 100)) + arroundPoint.y + x: Math.floor((Math.random() * (1000) - 500)) + arroundPoint.x, + y: Math.floor((Math.random() * (1000) - 500)) + arroundPoint.y } - // } } else { position = { x: thisObject.payload.position.x, diff --git a/FloatingSpace/StrategyPartConstructor.js b/FloatingSpace/StrategyPartConstructor.js index eda67cb67..3f62702a3 100644 --- a/FloatingSpace/StrategyPartConstructor.js +++ b/FloatingSpace/StrategyPartConstructor.js @@ -1969,7 +1969,7 @@ function newStrategyPartConstructor () { function setFloatingObjectBasicProperties (floatingObject, payload) { const FRICTION = 0.95 - const INITIAL_FRICTION = 0.99 + const INITIAL_FRICTION = 0.97 switch (payload.node.type) { case 'Workspace': { @@ -2045,11 +2045,11 @@ function newStrategyPartConstructor () { break } case 'Next Phase Event': { - level_5() + level_4() break } case 'Situation': { - level_5() + level_4() break } case 'Condition': { @@ -2136,6 +2136,10 @@ function newStrategyPartConstructor () { floatingObject.initializeFontSize(10) floatingObject.fillStyle = 'rgba(' + UI_COLOR.TITANIUM_YELLOW + ', 1)' + + if (payload.node.savedPayload === undefined) { + floatingObject.tensionToggle() + } } function level_5 () { @@ -2174,3 +2178,4 @@ function newStrategyPartConstructor () { payload.uiObject = undefined } } +