From f06f27834ea39a2933cd442734401f86af6c9d1d Mon Sep 17 00:00:00 2001 From: Luis Fernando Molina Date: Wed, 22 May 2019 13:55:40 +0200 Subject: [PATCH] Attaching Working with Bugs --- FloatingSpace/StrategyPart.js | 39 ++++++++++++++++++++++++++++++++++- 1 file changed, 38 insertions(+), 1 deletion(-) diff --git a/FloatingSpace/StrategyPart.js b/FloatingSpace/StrategyPart.js index fd65783a1..ba43c3691 100644 --- a/FloatingSpace/StrategyPart.js +++ b/FloatingSpace/StrategyPart.js @@ -56,6 +56,9 @@ function newStrategyPart () { let availableToAttachCounter = 0 let isAvailableToAttach + let isAttaching = false + let attachToNode + return thisObject function finalize () { @@ -79,6 +82,7 @@ function newStrategyPart () { } icon = undefined + attachToNode = undefined } function initialize (payload, menuItemsInitialValues) { @@ -177,6 +181,9 @@ function newStrategyPart () { break } let foundCompatible = false + attachToNode = undefined + isAttaching = false + for (let i = 0; i < nearbyFloatingObjects.length; i++) { let nearby = nearbyFloatingObjects[i] let distance = nearby[0] @@ -186,6 +193,8 @@ function newStrategyPart () { if (foundCompatible === false) { if (distance < thisObject.container.frame.radius * 1.5 + floatingObject.container.frame.radius * 1.5) { nearbyNode.payload.uiObject.getReadyToAttach() + isAttaching = true + attachToNode = nearbyNode foundCompatible = true } } @@ -268,6 +277,35 @@ function newStrategyPart () { if (thisObject.codeEditor !== undefined) { thisObject.codeEditor.deactivate() } + + if (isAttaching === true) { + switch (thisObject.payload.node.type) { + case 'Strategy': { + thisObject.payload.parentNode = attachToNode + thisObject.payload.chainParent = attachToNode + thisObject.payload.parentNode.strategies.push(thisObject.payload.node) + } + break + case 'Phase': { + thisObject.payload.parentNode = attachToNode + thisObject.payload.chainParent = attachToNode + thisObject.payload.parentNode.phases.push(thisObject.payload.node) + } + break + case 'Situation': { + thisObject.payload.parentNode = attachToNode + thisObject.payload.chainParent = attachToNode + thisObject.payload.parentNode.situations.push(thisObject.payload.node) + } + break + case 'Condition': { + thisObject.payload.parentNode = attachToNode + thisObject.payload.chainParent = attachToNode + thisObject.payload.parentNode.conditions.push(thisObject.payload.node) + } + break + } + } } function onDisplace (event) { @@ -571,4 +609,3 @@ function newStrategyPart () { } } } -