found variable BUG fixed

This commit is contained in:
Luis Fernando Molina committed 2018-05-05 10:31:41 +02:00
1 parent 2f62d573db
commit f734af6cc2
3 files changed
+151 -44

No files matched your search

Binary file not shown.
+112 -44
View File
@@ -2,7 +2,7 @@
function newBubbleSets() {
const MODULE_NAME = "Bubble Sets";
const INFO_LOG = false;
const INFO_LOG = true;
const ERROR_LOG = true;
const logger = newDebugLog();
logger.fileName = MODULE_NAME;
@@ -37,6 +37,8 @@ function newBubbleSets() {
function createBubbleSet(pPayload, pEventHandler, callBackFunction) {
if (INFO_LOG === true) { logger.write("[INFO] createBubbleSet -> Entering function."); }
let bubbleSet = {
imageId: pPayload.profile.imageId,
floatingBubbles: [],
@@ -52,32 +54,110 @@ function newBubbleSets() {
function onBubblesChanged(pNewBubbles, pBubbleSetIndex) {
if (INFO_LOG === true) { logger.write("[INFO] createBubbleSet -> onBubblesChanged -> Entering function."); }
if (INFO_LOG === true) { logger.write("[INFO] createBubbleSet -> onBubblesChanged -> pNewBubbles.length = " + pNewBubbles.length); }
if (INFO_LOG === true) { logger.write("[INFO] createBubbleSet -> onBubblesChanged -> pBubbleSetIndex = " + pBubbleSetIndex); }
let bubbleSet = bubbleSets[pBubbleSetIndex];
let found = false;
let newFloatingBubbles;
/* First we add the new bubbles. */
/* First we remove the old bubbles. */
let newFloatingBubbles = []; // We will create a new array of Floating Bubbles as a result of this operation.
if (INFO_LOG === true) { logger.write("[INFO] createBubbleSet -> onBubblesChanged -> Remove old Bubbles."); }
for (let i = 0; i < pNewBubbles.length; i++) {
newFloatingBubbles = []; // We will create a new array of Floating Bubbles as a result of this operation.
let plotterBubble = pNewBubbles[i];
let plotterBubbleKey = plotterBubble.date.toString() + plotterBubble.rate.toString();
let found = false;
for (let j = 0; j < bubbleSet.floatingBubbles.length; j++) {
for (let j = 0; j < bubbleSet.floatingBubbles.length; j++) {
found = false;
let floatingBubble = bubbleSet.floatingBubbles[j];
let floatingBubbleKey = floatingBubble.date.toString() + floatingBubble.rate.toString();
let floatingBubble = bubbleSet.floatingBubbles[j];
let floatingBubbleKey = floatingBubble.date.toString() + floatingBubble.rate.toString();
if (INFO_LOG === true) { logger.write("[INFO] createBubbleSet -> onBubblesChanged -> Remove old Bubbles -> j = " + j); }
for (let i = 0; i < pNewBubbles.length; i++) {
let plotterBubble = pNewBubbles[i];
let plotterBubbleKey = plotterBubble.date.toString() + plotterBubble.rate.toString();
if (INFO_LOG === true) { logger.write("[INFO] createBubbleSet -> onBubblesChanged -> Remove old Bubbles -> i = " + i); }
if (INFO_LOG === true) { logger.write("[INFO] createBubbleSet -> onBubblesChanged -> Remove old Bubbles -> floatingBubbleKey = " + floatingBubbleKey); }
if (INFO_LOG === true) { logger.write("[INFO] createBubbleSet -> onBubblesChanged -> Remove old Bubbles -> plotterBubbleKey = " + plotterBubbleKey); }
if (plotterBubbleKey === floatingBubbleKey) {
found = true;
break;
if (INFO_LOG === true) { logger.write("[INFO] createBubbleSet -> onBubblesChanged -> found = " + found); }
break;
}
}
if (INFO_LOG === true) { logger.write("[INFO] createBubbleSet -> onBubblesChanged -> Remove old Bubbles -> End of For i."); }
if (INFO_LOG === true) { logger.write("[INFO] createBubbleSet -> onBubblesChanged -> Remove old Bubbles -> found = " + found); }
if (found === false) {
floatingLayer.removeFloatingObject(floatingBubble.floatingHandle);
if (INFO_LOG === true) { logger.write("[INFO] createBubbleSet -> onBubblesChanged -> Remove old Bubbles -> floatingBubble.floatingHandle = " + floatingBubble.floatingHandle); }
if (INFO_LOG === true) { logger.write("[INFO] createBubbleSet -> onBubblesChanged -> Remove old Bubbles -> Removed from Layer."); }
} else {
newFloatingBubbles.push(floatingBubble);
if (INFO_LOG === true) { logger.write("[INFO] createBubbleSet -> onBubblesChanged -> Remove old Bubbles -> floatingBubble.floatingHandle = " + floatingBubble.floatingHandle); }
if (INFO_LOG === true) { logger.write("[INFO] createBubbleSet -> onBubblesChanged -> Remove old Bubbles -> Added to newFloatingBubbles."); }
if (INFO_LOG === true) { logger.write("[INFO] createBubbleSet -> onBubblesChanged -> Remove old Bubbles -> newFloatingBubbles.length = " + newFloatingBubbles.length); }
}
}
bubbleSet.floatingBubbles = newFloatingBubbles;
if (INFO_LOG === true) { logger.write("[INFO] createBubbleSet -> onBubblesChanged -> Remove old Bubbles -> bubbleSet.floatingBubbles.length = " + bubbleSet.floatingBubbles.length); }
/* Second we add the new bubbles. */
if (INFO_LOG === true) { logger.write("[INFO] createBubbleSet -> onBubblesChanged -> Add new Bubbles."); }
newFloatingBubbles = []; // We will create a new array of Floating Bubbles as a result of this operation.
for (let i = 0; i < pNewBubbles.length; i++) {
found = false;
let plotterBubble = pNewBubbles[i];
let plotterBubbleKey = plotterBubble.date.toString() + plotterBubble.rate.toString();
let floatingBubble;
let floatingBubbleKey;
if (INFO_LOG === true) { logger.write("[INFO] createBubbleSet -> onBubblesChanged -> Add new Bubbles -> i = " + i); }
for (let j = 0; j < bubbleSet.floatingBubbles.length; j++) {
floatingBubble = bubbleSet.floatingBubbles[j];
floatingBubbleKey = floatingBubble.date.toString() + floatingBubble.rate.toString();
if (INFO_LOG === true) { logger.write("[INFO] createBubbleSet -> onBubblesChanged -> Add new Bubbles -> j = " + j); }
if (INFO_LOG === true) { logger.write("[INFO] createBubbleSet -> onBubblesChanged -> Add new Bubbles -> floatingBubbleKey = " + floatingBubbleKey); }
if (INFO_LOG === true) { logger.write("[INFO] createBubbleSet -> onBubblesChanged -> Add new Bubbles -> plotterBubbleKey = " + plotterBubbleKey); }
if (plotterBubbleKey === floatingBubbleKey) {
found = true;
if (INFO_LOG === true) { logger.write("[INFO] createBubbleSet -> onBubblesChanged -> Add new Bubbles -> found = " + found); }
break;
}
}
if (INFO_LOG === true) { logger.write("[INFO] createBubbleSet -> onBubblesChanged -> Add new Bubbles -> End of For j."); }
if (INFO_LOG === true) { logger.write("[INFO] createBubbleSet -> onBubblesChanged -> Add new Bubbles -> found = " + found); }
if (found === false) {
let floatingObject = newFloatingObject();
@@ -85,7 +165,9 @@ function newBubbleSets() {
function onInitialized(err) {
floatingObject.payload = bubbleSet.payload;
if (INFO_LOG === true) { logger.write("[INFO] createBubbleSet -> onBubblesChanged -> Add new Bubbles -> onInitialized -> Entering function."); }
floatingObject.payload = bubbleSet.payload;
floatingObject.payloadBubbleIndex = i;
floatingObject.payload.profile.imageId = bubbleSet.imageId;
@@ -109,57 +191,43 @@ function newBubbleSets() {
floatingObject.labelStrokeStyle = 'rgba(60, 60, 60, 0.50)';
floatingLayer.addFloatingObject(floatingObject);
if (INFO_LOG === true) { logger.write("[INFO] createBubbleSet -> onBubblesChanged -> Add new Bubbles -> onInitialized -> New Bubble added to Layer."); }
plotterBubble.floatingHandle = floatingObject.handle;
}
if (INFO_LOG === true) { logger.write("[INFO] createBubbleSet -> onBubblesChanged -> Add new Bubbles -> plotterBubble.floatingHandle = " + plotterBubble.floatingHandle); }
}
newFloatingBubbles.push(plotterBubble);
newFloatingBubbles.push(plotterBubble);
}
bubbleSet.floatingBubbles = newFloatingBubbles;
/* Second we remove the old bubbles. */
newFloatingBubbles = []; // We will create a new array of Floating Bubbles as a result of this operation.
found = false;
for (let j = 0; j < bubbleSet.floatingBubbles.length; j++) {
let floatingBubble = bubbleSet.floatingBubbles[j];
let floatingBubbleKey = floatingBubble.date.toString() + floatingBubble.rate.toString();
for (let i = 0; i < pNewBubbles.length; i++) {
let plotterBubble = pNewBubbles[i];
let plotterBubbleKey = plotterBubble.date.toString() + plotterBubble.rate.toString();
if (plotterBubbleKey === floatingBubbleKey) {
found = true;
break;
if (INFO_LOG === true) { logger.write("[INFO] createBubbleSet -> onBubblesChanged -> Add new Bubbles -> onInitialized -> Added to newFloatingBubbles."); }
if (INFO_LOG === true) { logger.write("[INFO] createBubbleSet -> onBubblesChanged -> Add new Bubbles -> onInitialized -> newFloatingBubbles.length = " + newFloatingBubbles.length); }
}
}
if (found === false) {
floatingLayer.removeFloatingObject(floatingBubble.floatingHandle);
} else {
newFloatingBubbles.push(floatingBubble);
if (INFO_LOG === true) { logger.write("[INFO] createBubbleSet -> onBubblesChanged -> Add new Bubbles -> onInitialized -> Old Bubble Kept."); }
if (INFO_LOG === true) { logger.write("[INFO] createBubbleSet -> onBubblesChanged -> Add new Bubbles -> onInitialized -> floatingBubble.floatingHandle = " + floatingBubble.floatingHandle); }
if (INFO_LOG === true) { logger.write("[INFO] createBubbleSet -> onBubblesChanged -> Add new Bubbles -> onInitialized -> Added to newFloatingBubbles."); }
if (INFO_LOG === true) { logger.write("[INFO] createBubbleSet -> onBubblesChanged -> Add new Bubbles -> onInitialized -> newFloatingBubbles.length = " + newFloatingBubbles.length); }
}
}
bubbleSet.floatingBubbles = newFloatingBubbles;
if (INFO_LOG === true) { logger.write("[INFO] createBubbleSet -> onBubblesChanged -> Add new Bubbles -> bubbleSet.floatingBubbles.length = " + bubbleSet.floatingBubbles.length); }
}
}
function destroyBubbleSet(pHandle) {
if (INFO_LOG === true) { logger.write("[INFO] destroyBubbleSet -> Entering function."); }
for (let i = 0; i < bubbleSets.length; i++) {
let bubbleSet = bubbleSets[i];
+39
View File
@@ -1,6 +1,12 @@
function newFloatingLayer() {
const MODULE_NAME = "Floating Layer";
const INFO_LOG = true;
const ERROR_LOG = true;
const logger = newDebugLog();
logger.fileName = MODULE_NAME;
let thisObject = {
floatingObjects: undefined, // This is the array of floatingObjects being displayed
addFloatingObject: addFloatingObject,
@@ -17,6 +23,8 @@ function newFloatingLayer() {
function initialize(callBackFunction) {
if (INFO_LOG === true) { logger.write("[INFO] initialize -> Entering function."); }
thisObject.floatingObjects = []; // We initialize this in order to start the calculations in a clean way.
callBackFunction();
@@ -24,20 +32,34 @@ function newFloatingLayer() {
function addFloatingObject(pFloatingObject) {
if (INFO_LOG === true) { logger.write("[INFO] addFloatingObject -> Entering function."); }
innactiveFloatingObjects.push(pFloatingObject);
if (INFO_LOG === true) { logger.write("[INFO] addFloatingObject -> innactiveFloatingObjects.length = " + innactiveFloatingObjects.length); }
pFloatingObject.handle = Math.floor((Math.random() * 10000000) + 1);
if (INFO_LOG === true) { logger.write("[INFO] addFloatingObject -> pFloatingObject.handle = " + pFloatingObject.handle); }
if (INFO_LOG === true) { logger.write("[INFO] addFloatingObject -> pFloatingObject.type = " + pFloatingObject.type); }
}
function removeFloatingObject(pFloatingObjectHandle) {
if (INFO_LOG === true) { logger.write("[INFO] removeFloatingObject -> Entering function."); }
for (let i = 0; i < innactiveFloatingObjects.length; i++) {
let floatingObject = innactiveFloatingObjects[i];
if (floatingObject.handle === pFloatingObjectHandle) {
innactiveFloatingObjects.splice(i, 1); // Delete item from array.
if (INFO_LOG === true) { logger.write("[INFO] removeFloatingObject -> floatingObject.handle = " + floatingObject.handle); }
if (INFO_LOG === true) { logger.write("[INFO] removeFloatingObject -> Removing floatingObject from innactiveFloatingObjects."); }
if (INFO_LOG === true) { logger.write("[INFO] removeFloatingObject -> innactiveFloatingObjects.length = " + innactiveFloatingObjects.length); }
return;
}
}
@@ -48,6 +70,11 @@ function newFloatingLayer() {
if (floatingObject.handle === pFloatingObjectHandle) {
thisObject.floatingObjects.splice(i, 1); // Delete item from array.
if (INFO_LOG === true) { logger.write("[INFO] removeFloatingObject -> floatingObject.handle = " + floatingObject.handle); }
if (INFO_LOG === true) { logger.write("[INFO] removeFloatingObject -> Removing floatingObject from thisObject.floatingObjects."); }
if (INFO_LOG === true) { logger.write("[INFO] removeFloatingObject -> thisObject.floatingObjects.length = " + thisObject.floatingObjects.length); }
return;
}
}
@@ -222,13 +249,25 @@ function newFloatingLayer() {
if (payload.visible === true) {
if (INFO_LOG === true) { logger.write("[INFO] physicsLoop -> payload.visible = " + payload.visible); }
/* The first time that the floatingObject becomes visible, we need to do this. */
floatingObject.radomizeCurrentPosition(payload.position);
floatingObject.radomizeCurrentSpeed();
thisObject.floatingObjects.push(floatingObject);
if (INFO_LOG === true) { logger.write("[INFO] physicsLoop -> floatingObject.handle = " + floatingObject.handle); }
if (INFO_LOG === true) { logger.write("[INFO] physicsLoop -> floatingObject added to thisObject.floatingObjects"); }
if (INFO_LOG === true) { logger.write("[INFO] physicsLoop -> thisObject.floatingObjects.length = " + thisObject.floatingObjects.length); }
innactiveFloatingObjects.splice(i, 1); // Delete item from array.
if (INFO_LOG === true) { logger.write("[INFO] physicsLoop -> floatingObject.handle = " + floatingObject.handle); }
if (INFO_LOG === true) { logger.write("[INFO] physicsLoop -> floatingObject removed from innactiveFloatingObjects"); }
if (INFO_LOG === true) { logger.write("[INFO] physicsLoop -> innactiveFloatingObjects.length = " + innactiveFloatingObjects.length); }
return; // Only one at the time.
}