Detaching from chainParent Implemented
This commit is contained in:
1 parent
8b26ccc250
commit
37bd44e928
2 files changed
+33
-2
No files matched your search
@@ -47,6 +47,8 @@ function newStrategyPart () {
|
||||
let isHighlighted
|
||||
let highlightCounter = 0
|
||||
|
||||
let previousDistance
|
||||
let detachFuse = 100
|
||||
return thisObject
|
||||
|
||||
function finalize () {
|
||||
@@ -127,8 +129,8 @@ function newStrategyPart () {
|
||||
}
|
||||
|
||||
if (thisObject.payload.chainParent === undefined) {
|
||||
thisObject.payload.targetPosition.x = canvas.floatingSpace.container.frame.width / 2,
|
||||
thisObject.payload.targetPosition.y = canvas.floatingSpace.container.frame.height / 2
|
||||
thisObject.payload.targetPosition.x = thisObject.payload.position.x,
|
||||
thisObject.payload.targetPosition.y = thisObject.payload.position.y
|
||||
} else {
|
||||
thisObject.payload.targetPosition.x = thisObject.payload.chainParent.payload.position.x
|
||||
thisObject.payload.targetPosition.y = thisObject.payload.chainParent.payload.position.y
|
||||
@@ -136,6 +138,30 @@ function newStrategyPart () {
|
||||
|
||||
iconPhysics()
|
||||
highlightPhisycs()
|
||||
detachingPhysics()
|
||||
}
|
||||
|
||||
function detachingPhysics () {
|
||||
let THRESHOLD
|
||||
if (thisObject.payload.floatingObject.isPinned === true) {
|
||||
THRESHOLD = 1.10
|
||||
} else {
|
||||
THRESHOLD = 2.00
|
||||
}
|
||||
|
||||
detachFuse--
|
||||
if (detachFuse < 0) {
|
||||
detachFuse = 0
|
||||
if (thisObject.payload.chainParent !== undefined) {
|
||||
let distanceToChainParent = Math.sqrt(Math.pow(thisObject.payload.position.x - thisObject.payload.targetPosition.x, 2) + Math.pow(thisObject.payload.position.y - thisObject.payload.targetPosition.y, 2))
|
||||
if (previousDistance !== undefined) {
|
||||
if (distanceToChainParent / previousDistance > 1.25) {
|
||||
canvas.strategySpace.workspace.detachNode(thisObject.payload.node)
|
||||
}
|
||||
}
|
||||
previousDistance = distanceToChainParent
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
function highlightPhisycs () {
|
||||
|
||||
@@ -5,6 +5,7 @@ function newWorkspace () {
|
||||
let thisObject = {
|
||||
tradingSystem: undefined,
|
||||
container: undefined,
|
||||
detachNode: detachNode,
|
||||
getContainer: getContainer,
|
||||
initialize: initialize,
|
||||
finalize: finalize
|
||||
@@ -43,6 +44,10 @@ function newWorkspace () {
|
||||
|
||||
}
|
||||
|
||||
function detachNode (node) {
|
||||
node.payload.chainParent = undefined
|
||||
}
|
||||
|
||||
function createPart (partType, name, node, parentNode, chainParent, title) {
|
||||
let payload = {}
|
||||
if (chainParent === undefined) {
|
||||
|
||||
Reference in new issue
Block a user