From 8bad7502109307655cfa0faf06dfa1b6568e6e69 Mon Sep 17 00:00:00 2001 From: Luis Fernando Molina Date: Thu, 9 May 2019 09:01:46 +0200 Subject: [PATCH] Big reorg of where things are, departure from Profile Balls and Notes --- FloatingSpace/FloatingLayer.js | 12 +++--- FloatingSpace/FloatingObject.js | 52 ++++++------------------ FloatingSpace/NoteSets.js | 4 +- FloatingSpace/ProfileBall.js | 4 +- FloatingSpace/ProfileBalls.js | 2 +- FloatingSpace/StrategyPart.js | 7 +--- FloatingSpace/StrategyPartConstructor.js | 30 ++++++++++---- FloatingSpace/StrategyPartTitle.js | 7 ++-- PlottersManager.js | 6 +-- Spaces/FloatingSpace.js | 8 ++-- StrategySpace/Strategy.js | 14 +++---- 11 files changed, 64 insertions(+), 82 deletions(-) diff --git a/FloatingSpace/FloatingLayer.js b/FloatingSpace/FloatingLayer.js index d1dc9a1d1..db281d20f 100644 --- a/FloatingSpace/FloatingLayer.js +++ b/FloatingSpace/FloatingLayer.js @@ -22,7 +22,7 @@ function newFloatingLayer () { let thisObject = { addFloatingObject: addFloatingObject, - killFloatingObject: killFloatingObject, + removeFloatingObject: removeFloatingObject, getFloatingObject: getFloatingObject, physics: physics, changeTargetRepulsion: changeTargetRepulsion, @@ -91,7 +91,7 @@ function newFloatingLayer () { invisibleFloatingObjects.push(pFloatingObject) } - function killFloatingObject (pFloatingObjectHandle) { + function removeFloatingObject (pFloatingObjectHandle) { try { /* The floting object to be killed can be either at the visible or the invisible array. What we do here is look for it @@ -121,11 +121,11 @@ function newFloatingLayer () { } } - if (ERROR_LOG === true) { logger.write('[ERROR] killFloatingObject -> Floating Object Not Found.') } - if (ERROR_LOG === true) { logger.write('[ERROR] killFloatingObject -> Floating Object cannot be killed.') } - if (ERROR_LOG === true) { logger.write('[ERROR] killFloatingObject -> pFloatingObjectHandle = ' + pFloatingObjectHandle) } + if (ERROR_LOG === true) { logger.write('[ERROR] removeFloatingObject -> Floating Object Not Found.') } + if (ERROR_LOG === true) { logger.write('[ERROR] removeFloatingObject -> Floating Object cannot be killed.') } + if (ERROR_LOG === true) { logger.write('[ERROR] removeFloatingObject -> pFloatingObjectHandle = ' + pFloatingObjectHandle) } } catch (err) { - if (ERROR_LOG === true) { logger.write('[ERROR] killFloatingObject -> err= ' + err.stack) } + if (ERROR_LOG === true) { logger.write('[ERROR] removeFloatingObject -> err= ' + err.stack) } } } diff --git a/FloatingSpace/FloatingObject.js b/FloatingSpace/FloatingObject.js index d4c27396d..743726606 100644 --- a/FloatingSpace/FloatingObject.js +++ b/FloatingSpace/FloatingObject.js @@ -12,7 +12,6 @@ function newFloatingObject () { isOnFocus: false, payload: undefined, // This is a reference to an object controlled by a Plotter. The plotter can change its internal value and we will see them from here. type: undefined, // Currently there are two types of Floating Objects: Profile Balls, and Notes. - underlayingObject: undefined, currentSpeed: 0, // This is the current speed of the floating object. currentMass: 0, // This is the current mass of the floating object, including its zoom applied. friction: 0, // This is a factor that will ultimatelly desacelerate the floating object. @@ -62,38 +61,11 @@ function newFloatingObject () { thisObject.container.finalize() thisObject.container = undefined thisObject.payload = undefined - thisObject.underlayingObject.finalize() - thisObject.underlayingObject = undefined } - function initialize (pType, floatingLayer) { - switch (pType) { - - case 'Profile Ball': { - thisObject.underlayingObject = newProfileBall() - thisObject.underlayingObject.initialize() - break - } - case 'Note': { - thisObject.underlayingObject = newNote() - thisObject.underlayingObject.initialize() - break - } - - case 'Strategy Part': { - thisObject.underlayingObject = newStrategyPart() - thisObject.underlayingObject.initialize(floatingLayer, thisObject.payload) - thisObject.underlayingObject.container.connectToParent(thisObject.container, false, false, true, true, false, false, true, true) - break - } - default: { - if (ERROR_LOG === true) { logger.write('[ERROR] initialize -> Unsopported type received -> pType = ' + pType) } - callBackFunction(GLOBAL.DEFAULT_FAIL_RESPONSE) - break - } - } - - thisObject.type = pType + function initialize (type, payload) { + thisObject.payload = payload + thisObject.type = type selfMouseOverEventSubscriptionId = thisObject.container.eventHandler.listenToEvent('onMouseOver', onMouseOver) selfMouseClickEventSubscriptionId = thisObject.container.eventHandler.listenToEvent('onMouseClick', onMouseClick) @@ -111,7 +83,7 @@ function newFloatingObject () { function getContainer (point) { let container - container = thisObject.underlayingObject.getContainer(point) + container = thisObject.payload.uiObject.getContainer(point) if (container !== undefined) { return container } if (thisObject.container.frame.isThisPointHere(point, true) === true) { @@ -123,7 +95,7 @@ function newFloatingObject () { function physics () { thisObjectPhysics() - thisObject.underlayingObject.physics() + thisObject.payload.uiObject.physics() } function thisObjectPhysics () { @@ -176,7 +148,7 @@ function newFloatingObject () { thisObject.targetImageSize = thisObject.rawImageSize * 2.0 thisObject.targetFontSize = thisObject.rawFontSize * 2.0 - thisObject.underlayingObject.container.eventHandler.raiseEvent('onFocus', point) + thisObject.payload.uiObject.container.eventHandler.raiseEvent('onFocus', point) thisObject.positionLocked = true @@ -201,7 +173,7 @@ function newFloatingObject () { thisObject.targetImageSize = thisObject.rawImageSize * 1 thisObject.targetFontSize = thisObject.rawFontSize * 1 - thisObject.underlayingObject.container.eventHandler.raiseEvent('onNotFocus') + thisObject.payload.uiObject.container.eventHandler.raiseEvent('onNotFocus') thisObject.positionLocked = false thisObject.isOnFocus = false @@ -213,23 +185,23 @@ function newFloatingObject () { point: pPoint, parent: thisObject } - thisObject.underlayingObject.container.eventHandler.raiseEvent('onMouseClick', event) + thisObject.payload.uiObject.container.eventHandler.raiseEvent('onMouseClick', event) } function drawBackground () { - thisObject.underlayingObject.drawBackground(thisObject) + thisObject.payload.uiObject.drawBackground(thisObject) } function drawMiddleground () { - thisObject.underlayingObject.drawMiddleground(thisObject) + thisObject.payload.uiObject.drawMiddleground(thisObject) } function drawForeground () { - thisObject.underlayingObject.drawForeground(thisObject) + thisObject.payload.uiObject.drawForeground(thisObject) } function drawOnFocus () { - thisObject.underlayingObject.drawOnFocus(thisObject) + thisObject.payload.uiObject.drawOnFocus(thisObject) } function initializeMass (suggestedValue) { diff --git a/FloatingSpace/NoteSets.js b/FloatingSpace/NoteSets.js index e0a5d8093..f61a55c67 100644 --- a/FloatingSpace/NoteSets.js +++ b/FloatingSpace/NoteSets.js @@ -124,7 +124,7 @@ function newNoteSets () { Each time we identify a floatingObject that is not at the raw data anymore, we request the floatinglayer to kill it. */ - floatingLayer.killFloatingObject(floatingNote.floatingHandle) + floatingLayer.removeFloatingObject(floatingNote.floatingHandle) } else { newFloatingNotes.push(floatingNote) @@ -299,7 +299,7 @@ function newNoteSets () { for (let j = 0; j < noteSet.floatingNotes.length; j++) { let floatingNote = noteSet.floatingNotes[j] - floatingLayer.killFloatingObject(floatingNote.floatingHandle) + floatingLayer.removeFloatingObject(floatingNote.floatingHandle) } noteSets.splice(i, 1) // Delete item from array. diff --git a/FloatingSpace/ProfileBall.js b/FloatingSpace/ProfileBall.js index 8328b7b25..c940bfbd1 100644 --- a/FloatingSpace/ProfileBall.js +++ b/FloatingSpace/ProfileBall.js @@ -306,7 +306,7 @@ function newProfileBall () { let label - label = pFloatingObject.payload.profile.upLabel + label = pFloatingObject.payload.profile.subTitle if (label !== undefined) { labelPoint = { @@ -319,7 +319,7 @@ function newProfileBall () { browserCanvasContext.fillText(label, labelPoint.x, labelPoint.y) } - label = pFloatingObject.payload.profile.downLabel + label = pFloatingObject.payload.profile.title if (label !== undefined) { labelPoint = { diff --git a/FloatingSpace/ProfileBalls.js b/FloatingSpace/ProfileBalls.js index 98d4de498..45f53e013 100644 --- a/FloatingSpace/ProfileBalls.js +++ b/FloatingSpace/ProfileBalls.js @@ -56,7 +56,7 @@ function newProfileBalls () { } function destroyProfileBall (pFloatingObjectHandle) { - floatingLayer.killFloatingObject(pFloatingObjectHandle) + floatingLayer.removeFloatingObject(pFloatingObjectHandle) } } diff --git a/FloatingSpace/StrategyPart.js b/FloatingSpace/StrategyPart.js index b70212ae2..888c9292b 100644 --- a/FloatingSpace/StrategyPart.js +++ b/FloatingSpace/StrategyPart.js @@ -32,7 +32,6 @@ function newStrategyPart () { thisObject.container.frame.position.x = 0 thisObject.container.frame.position.y = 0 - let floatingLayer let image let imagePath @@ -60,14 +59,12 @@ function newStrategyPart () { thisObject.codeEditor = undefined } - floatingLayer = undefined image = undefined imagePath = undefined } - function initialize (pFloatingLayer, payload) { + function initialize (payload) { thisObject.payload = payload - floatingLayer = pFloatingLayer let menuItemsInitialValues = [] switch (thisObject.payload.node.type) { @@ -497,7 +494,7 @@ function newStrategyPart () { if (radius > 6) { const MAX_LABEL_LENGTH = 30 - label = params.payload.upLabel + label = params.payload.subTitle label = addIndexNumber(label) if (label !== undefined) { diff --git a/FloatingSpace/StrategyPartConstructor.js b/FloatingSpace/StrategyPartConstructor.js index 93a2c1d85..6b848c628 100644 --- a/FloatingSpace/StrategyPartConstructor.js +++ b/FloatingSpace/StrategyPartConstructor.js @@ -1,13 +1,13 @@ function newStrategyPartConstructor () { - const MODULE_NAME = 'Strategy Parts' + const MODULE_NAME = 'Strategy Part Constructor' const ERROR_LOG = true const logger = newWebDebugLog() logger.fileName = MODULE_NAME let thisObject = { - createNewStrategyPart: createNewStrategyPart, + createStrategyPart: createStrategyPart, destroyStrategyPart: destroyStrategyPart, initialize: initialize, finalize: finalize @@ -20,16 +20,24 @@ function newStrategyPartConstructor () { function finalize () { floatingLayer = undefined + + payload.uiObject.finalize() + payload.uiObject = undefined } function initialize (pFloatingLayer) { floatingLayer = pFloatingLayer } - function createNewStrategyPart (payload) { + function createStrategyPart (payload) { let floatingObject = newFloatingObject() - floatingObject.payload = payload - floatingObject.initialize('Strategy Part', payload.node.type, floatingLayer) + floatingObject.initialize('Strategy Part', payload) + payload.floatingObject = floatingObject + + let strategyPart = newStrategyPart() + strategyPart.initialize(payload) + strategyPart.container.connectToParent(floatingObject.container, false, false, true, true, false, false, true, true) + payload.uiObject = strategyPart const FRICTION = 0.97 @@ -139,10 +147,16 @@ function newStrategyPartConstructor () { floatingLayer.addFloatingObject(floatingObject) - return floatingObject.handle + return } - function destroyStrategyPart (pFloatingObjectHandle) { - floatingLayer.killFloatingObject(pFloatingObjectHandle) + function destroyStrategyPart (payload) { + floatingLayer.removeFloatingObject(payload.floatingObject.handle) + + payload.floatingObject.finalize() + payload.floatingObject = undefined + + payload.uiObject.finalize() + payload.uiObject = undefined } } diff --git a/FloatingSpace/StrategyPartTitle.js b/FloatingSpace/StrategyPartTitle.js index fddf36c15..9428289be 100644 --- a/FloatingSpace/StrategyPartTitle.js +++ b/FloatingSpace/StrategyPartTitle.js @@ -93,8 +93,8 @@ function newStrategyPartTitle () { thisObject.container.frame.position.x = 0 - label.length / 2 * fontSize * FONT_ASPECT_RATIO * 1.2 thisObject.container.frame.position.y = 0 - radius * 1 / 2 - fontSize * FONT_ASPECT_RATIO - 10 - thisObject.container.frame.width = thisObject.container.frame.radius - thisObject.container.frame.height = 20 + // thisObject.container.frame.width = thisObject.container.frame.radius + // thisObject.container.frame.height = 20 } function onFocus () { @@ -149,7 +149,7 @@ function newStrategyPartTitle () { browserCanvasContext.font = fontSize + 'px ' + UI_FONT.PRIMARY - label = params.payload.downLabel + label = params.payload.title if (label !== undefined) { if (label.length > MAX_LABEL_LENGTH) { @@ -168,4 +168,3 @@ function newStrategyPartTitle () { } } } - diff --git a/PlottersManager.js b/PlottersManager.js index d3c00d03f..dd693d6d6 100644 --- a/PlottersManager.js +++ b/PlottersManager.js @@ -285,7 +285,7 @@ function newPlottersManager () { botAvatar.src = window.canvasApp.context.fbProfileImages.get(TEAM + '-' + BOT) - competitionPlotter.plotter.payload[k].profile.downLabel = bot.displayName + competitionPlotter.plotter.payload[k].profile.title = bot.displayName competitionPlotter.plotter.payload[k].profile.imageId = imageId competitionPlotter.plotter.payload[k].profile.botAvatar = botAvatar @@ -525,8 +525,8 @@ function newPlottersManager () { if (productPlotter.plotter.payload !== undefined) { let imageId = pProductCard.bot.devTeam + '.' + pProductCard.bot.profilePicture - productPlotter.plotter.payload.profile.upLabel = pProductCard.product.shortDisplayName - productPlotter.plotter.payload.profile.downLabel = pProductCard.bot.displayName + productPlotter.plotter.payload.profile.subTitle = pProductCard.product.shortDisplayName + productPlotter.plotter.payload.profile.title = pProductCard.bot.displayName productPlotter.plotter.payload.profile.imageId = imageId productPlotter.plotter.payload.profile.botAvatar = pProductCard.bot.avatar diff --git a/Spaces/FloatingSpace.js b/Spaces/FloatingSpace.js index 14ea12a3b..f11be01dd 100644 --- a/Spaces/FloatingSpace.js +++ b/Spaces/FloatingSpace.js @@ -10,7 +10,7 @@ function newFloatingSpace () { let thisObject = { floatingLayer: undefined, // This is the array of floatingObjects being displayed profileBalls: undefined, - strategyParts: undefined, + strategyPartConstructor: undefined, noteSets: undefined, container: undefined, makeVisible: makeVisible, @@ -41,7 +41,7 @@ function newFloatingSpace () { function finalize () { thisObject.floatingLayer.finalize() thisObject.profileBalls.finalize() - thisObject.strategyParts.finalize() + thisObject.strategyPartConstructor.finalize() thisObject.noteSets.finalize() } @@ -55,8 +55,8 @@ function newFloatingSpace () { thisObject.noteSets = newNoteSets() thisObject.noteSets.initialize(thisObject.floatingLayer) - thisObject.strategyParts = newStrategyPartConstructor() - thisObject.strategyParts.initialize(thisObject.floatingLayer) + thisObject.strategyPartConstructor = newStrategyPartConstructor() + thisObject.strategyPartConstructor.initialize(thisObject.floatingLayer) thisObject.container.eventHandler.listenToEvent('onMouseWheel', onMouseWheel) } diff --git a/StrategySpace/Strategy.js b/StrategySpace/Strategy.js index 2567cbc9d..5ca65a714 100644 --- a/StrategySpace/Strategy.js +++ b/StrategySpace/Strategy.js @@ -52,13 +52,13 @@ function newStrategy () { } if (title !== undefined) { - payload.upLabel = title + payload.subTitle = title } else { - payload.upLabel = partType + payload.subTitle = partType } payload.visible = true - payload.downLabel = name + payload.title = name payload.node = node payload.parentNode = parentNode payload.chainParent = chainParent @@ -69,11 +69,11 @@ function newStrategy () { } node.payload = payload node.type = partType - node.handle = canvas.floatingSpace.strategyParts.createNewStrategyPart(payload) + canvas.floatingSpace.strategyPartConstructor.createStrategyPart(payload) } function destroyPart (node) { - canvas.floatingSpace.strategyParts.destroyStrategyPart(node.handle) + canvas.floatingSpace.strategyPartConstructor.destroyStrategyPart(payload) } function generateStrategyParts () { @@ -379,8 +379,8 @@ function newStrategy () { node.payload.targetPosition.x = undefined node.payload.targetPosition.y = undefined node.payload.visible = undefined - node.payload.upLabel = undefined - node.payload.downLabel = undefined + node.payload.subTitle = undefined + node.payload.title = undefined node.payload.node = undefined node.payload.parentNode = undefined node.payload.chainParent = undefined