From d7acb36f39d5ca3f8fcda8535c18313e230e8071 Mon Sep 17 00:00:00 2001 From: Luis Fernando Molina Date: Sun, 5 May 2019 13:05:26 +0200 Subject: [PATCH] Physics distributed --- FloatingSpace/CircularMenu.js | 1 + FloatingSpace/CircularMenuItem.js | 4 +-- FloatingSpace/FloatingLayer.js | 30 ---------------------- FloatingSpace/FloatingObject.js | 41 +++++++++++++++++++++++++------ FloatingSpace/StrategyPart.js | 1 + 5 files changed, 37 insertions(+), 40 deletions(-) diff --git a/FloatingSpace/CircularMenu.js b/FloatingSpace/CircularMenu.js index d1b1ed450..0abe8e308 100644 --- a/FloatingSpace/CircularMenu.js +++ b/FloatingSpace/CircularMenu.js @@ -43,6 +43,7 @@ function newCircularMenu () { menuItem.angle = menuItemInitialValue.angle menuItem.initialize() + menuItem.container.connectToParent(thisObject.container, false, false, true) menuItems.push(menuItem) } diff --git a/FloatingSpace/CircularMenuItem.js b/FloatingSpace/CircularMenuItem.js index 7869f8590..442ab6cb7 100644 --- a/FloatingSpace/CircularMenuItem.js +++ b/FloatingSpace/CircularMenuItem.js @@ -121,8 +121,8 @@ function newCircularMenuItem () { if (thisObject.canDrawIcon === true && thisObject.currentRadius > 1) { let menuPosition = { - x: position.x + thisObject.currentRadius * 3 / 4 * Math.cos(toRadians(thisObject.angle)), - y: position.y - thisObject.currentRadius * 3 / 4 * Math.sin(toRadians(thisObject.angle)) } + x: position.x + thisObject.container.frame.radius * 3 / 4 * Math.cos(toRadians(thisObject.angle)), + y: position.y - thisObject.container.frame.radius * 3 / 4 * Math.sin(toRadians(thisObject.angle)) } browserCanvasContext.drawImage(thisObject.icon, menuPosition.x - thisObject.currentRadius, menuPosition.y - thisObject.currentRadius, thisObject.currentRadius * 2, thisObject.currentRadius * 2) diff --git a/FloatingSpace/FloatingLayer.js b/FloatingSpace/FloatingLayer.js index 8ee181c27..ff6c93287 100644 --- a/FloatingSpace/FloatingLayer.js +++ b/FloatingSpace/FloatingLayer.js @@ -581,36 +581,6 @@ function newFloatingLayer () { floatingObject.currentSpeed.y = -MAX_SPEED } - // The radius also have a target. - - if (Math.abs(floatingObject.container.frame.radius - floatingObject.targetRadius) >= 1) { - if (floatingObject.container.frame.radius < floatingObject.targetRadius) { - floatingObject.container.frame.radius = floatingObject.container.frame.radius + 0.5 - } else { - floatingObject.container.frame.radius = floatingObject.container.frame.radius - 0.5 - } - } - - // The imageSize also have a target. - - if (Math.abs(floatingObject.currentImageSize - floatingObject.targetImageSize) >= 1) { - if (floatingObject.currentImageSize < floatingObject.targetImageSize) { - floatingObject.currentImageSize = floatingObject.currentImageSize + 1 - } else { - floatingObject.currentImageSize = floatingObject.currentImageSize - 1 - } - } - - // The fontSize also have a target. - - if (Math.abs(floatingObject.currentFontSize - floatingObject.targetFontSize) >= 0.2) { - if (floatingObject.currentFontSize < floatingObject.targetFontSize) { - floatingObject.currentFontSize = floatingObject.currentFontSize + 0.2 - } else { - floatingObject.currentFontSize = floatingObject.currentFontSize - 0.2 - } - } - // We let the Floating Object animate the physics loops by itself. floatingObject.physics() diff --git a/FloatingSpace/FloatingObject.js b/FloatingSpace/FloatingObject.js index 81cc7f39e..471ec4acb 100644 --- a/FloatingSpace/FloatingObject.js +++ b/FloatingSpace/FloatingObject.js @@ -124,16 +124,41 @@ function newFloatingObject () { } } - function physics (callBackFunction) { - try { - if (INFO_LOG === true) { logger.write('[INFO] initialize -> Entering function.') } + function physics () { + thisObjectPhysics() + thisObject.underlayingObject.physics() + } - thisObject.underlayingObject.physics() + function thisObjectPhysics () { + // The radius also have a target. - if (callBackFunction !== undefined) { callBackFunction(GLOBAL.DEFAULT_OK_RESPONSE) } - } catch (err) { - if (ERROR_LOG === true) { logger.write('[ERROR] physics -> err= ' + err.stack) } - if (callBackFunction !== undefined) { callBackFunction(GLOBAL.DEFAULT_FAIL_RESPONSE) } + if (Math.abs(thisObject.container.frame.radius - thisObject.targetRadius) >= 1) { + if (thisObject.container.frame.radius < thisObject.targetRadius) { + thisObject.container.frame.radius = thisObject.container.frame.radius + 0.5 + } else { + thisObject.container.frame.radius = thisObject.container.frame.radius - 0.5 + } + thisObject.container.eventHandler.raiseEvent('Dimmensions Changed', event) + } + + // The imageSize also have a target. + + if (Math.abs(thisObject.currentImageSize - thisObject.targetImageSize) >= 1) { + if (thisObject.currentImageSize < thisObject.targetImageSize) { + thisObject.currentImageSize = thisObject.currentImageSize + 1 + } else { + thisObject.currentImageSize = thisObject.currentImageSize - 1 + } + } + + // The fontSize also have a target. + + if (Math.abs(thisObject.currentFontSize - thisObject.targetFontSize) >= 0.2) { + if (thisObject.currentFontSize < thisObject.targetFontSize) { + thisObject.currentFontSize = thisObject.currentFontSize + 0.2 + } else { + thisObject.currentFontSize = thisObject.currentFontSize - 0.2 + } } } diff --git a/FloatingSpace/StrategyPart.js b/FloatingSpace/StrategyPart.js index 03066a88a..7aabdcbd6 100644 --- a/FloatingSpace/StrategyPart.js +++ b/FloatingSpace/StrategyPart.js @@ -240,6 +240,7 @@ function newStrategyPart () { thisObject.menu = newCircularMenu() thisObject.menu.initialize(menuItemsInitialValues) + thisObject.menu.container.connectToParent(thisObject.container, false, false, true) /* Load Part Image */