diff --git a/Container.js b/Container.js index cacb0bec1..5d743b388 100644 --- a/Container.js +++ b/Container.js @@ -33,11 +33,11 @@ function newContainer () { } } - function initialize (pName) { + function initialize (pName, pType) { thisObject.name = pName thisObject.frame = newFrame() - thisObject.frame.initialize() + thisObject.frame.initialize(pType) thisObject.frame.containerName = pName thisObject.frame.container = thisObject diff --git a/FloatingSpace/FloatingLayer.js b/FloatingSpace/FloatingLayer.js index a541d5dca..c2a07b07d 100644 --- a/FloatingSpace/FloatingLayer.js +++ b/FloatingSpace/FloatingLayer.js @@ -30,6 +30,7 @@ function newFloatingLayer () { isInside: isInside, isInsideFloatingObject: isInsideFloatingObject, changeTargetRepulsion: changeTargetRepulsion, + getContainer: getContainer, initialize: initialize, finalize: finalize } @@ -85,6 +86,18 @@ function newFloatingLayer () { /* We dont need to initialize anything right now. */ } + function getContainer (point) { + let container + + for (let i = 0; i < visibleFloatingObjects.length; i++) { + let floatingObject = visibleFloatingObjects[i] + container = floatingObject.getContainer(point) + if (container !== undefined) { return container } + } + + return container + } + function addFloatingObject (pFloatingObject, callBackFunction) { /* As you can see here, even though the floating objects are created outside this layer, its creator it is not supossed to keep diff --git a/FloatingSpace/FloatingObject.js b/FloatingSpace/FloatingObject.js index 903f05d3d..357547743 100644 --- a/FloatingSpace/FloatingObject.js +++ b/FloatingSpace/FloatingObject.js @@ -54,11 +54,21 @@ function newFloatingObject () { linkedObject: undefined, // This is a reference to the object that this floating object is representing. linkedObjectType: '', // Since there might be floating objects for different types of objects, here we store the type of object we are linking to. - container: undefined, // This is a pointer to the object where the floating object belongs to. + getContainer: getContainer, + container: undefined, initialize: initialize } + thisObject.container = newContainer() + thisObject.container.name = MODULE_NAME + thisObject.container.initialize('Circle') + thisObject.container.isClickeable = true + thisObject.container.isDraggeable = false + thisObject.container.frame.radius = 0 + thisObject.container.frame.position.x = 0 + thisObject.container.frame.position.y = 0 + thisObject.eventHandler = newEventHandler() return thisObject @@ -110,6 +120,19 @@ function newFloatingObject () { } } + function getContainer (point) { + let container + + container = thisObject.underlayingObject.getContainer(point) + if (container !== undefined) { return container } + + if (thisObject.container.frame.isThisPointHere(point, true) === true) { + return thisObject.container + } else { + return undefined + } + } + function physicsLoop (callBackFunction) { try { if (INFO_LOG === true) { logger.write('[INFO] initialize -> Entering function.') } diff --git a/FloatingSpace/Note.js b/FloatingSpace/Note.js index 26e76668d..3a1aa4ead 100644 --- a/FloatingSpace/Note.js +++ b/FloatingSpace/Note.js @@ -1,23 +1,44 @@  function newNote () { - let thisObject = { + const MODULE_NAME = 'Note' + let thisObject = { + container: undefined, physicsLoop: physicsLoop, onMouseOver: onMouseOver, onMouseClick: onMouseClick, onMouseNotOver: onMouseNotOver, drawBackground: drawBackground, drawForeground: drawForeground, + getContainer: getContainer, initialize: initialize - } + thisObject.container = newContainer() + thisObject.container.name = MODULE_NAME + thisObject.container.initialize('Circle') + thisObject.container.isClickeable = true + thisObject.container.isDraggeable = false + thisObject.container.frame.radius = 0 + thisObject.container.frame.position.x = 0 + thisObject.container.frame.position.y = 0 + return thisObject function initialize () { } + function getContainer (point) { + let container + + if (thisObject.container.frame.isThisPointHere(point, true) === true) { + return thisObject.container + } else { + return undefined + } + } + function physicsLoop () { } diff --git a/FloatingSpace/ProfileBall.js b/FloatingSpace/ProfileBall.js index 2e0c52f8f..3a2c6c22e 100644 --- a/FloatingSpace/ProfileBall.js +++ b/FloatingSpace/ProfileBall.js @@ -1,17 +1,28 @@ function newProfileBall () { - let thisObject = { + const MODULE_NAME = 'Profile Ball' + let thisObject = { + container: undefined, physicsLoop: physicsLoop, onMouseOver: onMouseOver, onMouseClick: onMouseClick, onMouseNotOver: onMouseNotOver, drawBackground: drawBackground, drawForeground: drawForeground, + getContainer: getContainer, initialize: initialize - } + thisObject.container = newContainer() + thisObject.container.name = MODULE_NAME + thisObject.container.initialize('Circle') + thisObject.container.isClickeable = true + thisObject.container.isDraggeable = false + thisObject.container.frame.radius = 0 + thisObject.container.frame.position.x = 0 + thisObject.container.frame.position.y = 0 + let ballStringMenu = [ { visible: false, @@ -79,6 +90,16 @@ function newProfileBall () { } } + function getContainer (point) { + let container + + if (thisObject.container.frame.isThisPointHere(point, true) === true) { + return thisObject.container + } else { + return undefined + } + } + function physicsLoop () { // The menuItems also have a target. diff --git a/FloatingSpace/StrategyPart.js b/FloatingSpace/StrategyPart.js index 12842d9ba..44a20db78 100644 --- a/FloatingSpace/StrategyPart.js +++ b/FloatingSpace/StrategyPart.js @@ -1,19 +1,30 @@ function newStrategyPart () { + const MODULE_NAME = 'Strategy Part' + let thisObject = { type: undefined, + container: undefined, physicsLoop: physicsLoop, onMouseOver: onMouseOver, onMouseClick: onMouseClick, onMouseNotOver: onMouseNotOver, drawBackground: drawBackground, drawForeground: drawForeground, + getContainer: getContainer, initialize: initialize - } - let ballStringMenu = [] + thisObject.container = newContainer() + thisObject.container.name = MODULE_NAME + thisObject.container.initialize('Circle') + thisObject.container.isClickeable = true + thisObject.container.isDraggeable = false + thisObject.container.frame.radius = 0 + thisObject.container.frame.position.x = 0 + thisObject.container.frame.position.y = 0 + let ballStringMenu = [] let floatingLayer let isMouseOver = false let image @@ -263,6 +274,16 @@ function newStrategyPart () { } } + function getContainer (point) { + let container + + if (thisObject.container.frame.isThisPointHere(point, true) === true) { + return thisObject.container + } else { + return undefined + } + } + function physicsLoop () { // The menuItems also have a target. diff --git a/Spaces/FloatingSpace.js b/Spaces/FloatingSpace.js index 810ca77b6..632666043 100644 --- a/Spaces/FloatingSpace.js +++ b/Spaces/FloatingSpace.js @@ -12,6 +12,7 @@ function newFloatingSpace () { profileBalls: undefined, strategyParts: undefined, noteSets: undefined, + getContainer: getContainer, initialize: initialize, finalize: finalize } @@ -38,5 +39,14 @@ function newFloatingSpace () { thisObject.strategyParts = newStrategyParts() thisObject.strategyParts.initialize(thisObject.floatingLayer) } + + function getContainer (point) { + let container + + container = thisObject.floatingLayer.getContainer(point) + if (container !== undefined) { return container } + + return container + } }