Simplifying Code
This commit is contained in:
1 parent
29a349b50d
commit
297d2d500f
5 files changed
+164
-197
No files matched your search
@@ -1,8 +1,6 @@
|
||||
|
||||
function newFloatingObject () {
|
||||
const MODULE_NAME = 'Floating Object'
|
||||
const INFO_LOG = false
|
||||
const INTENSIVE_LOG = false
|
||||
const ERROR_LOG = true
|
||||
|
||||
const logger = newWebDebugLog()
|
||||
@@ -47,50 +45,41 @@ function newFloatingObject () {
|
||||
|
||||
return thisObject
|
||||
|
||||
function initialize (pType, pSubType, floatingLayer, callBackFunction) {
|
||||
try {
|
||||
if (INFO_LOG === true) { logger.write('[INFO] initialize -> Entering function.') }
|
||||
function initialize (pType, pSubType, floatingLayer) {
|
||||
switch (pType) {
|
||||
|
||||
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, pSubType, 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
|
||||
}
|
||||
case 'Profile Ball': {
|
||||
thisObject.underlayingObject = newProfileBall()
|
||||
thisObject.underlayingObject.initialize()
|
||||
break
|
||||
}
|
||||
case 'Note': {
|
||||
thisObject.underlayingObject = newNote()
|
||||
thisObject.underlayingObject.initialize()
|
||||
break
|
||||
}
|
||||
|
||||
thisObject.type = pType
|
||||
case 'Strategy Part': {
|
||||
thisObject.underlayingObject = newStrategyPart()
|
||||
thisObject.underlayingObject.initialize(floatingLayer, pSubType, 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.container.eventHandler.listenToEvent('onMouseOver', onMouseOver)
|
||||
thisObject.container.eventHandler.listenToEvent('onMouseClick', onMouseClick)
|
||||
thisObject.type = pType
|
||||
|
||||
thisObject.container.eventHandler.listenToEvent('onMouseOver', onMouseOver)
|
||||
thisObject.container.eventHandler.listenToEvent('onMouseClick', onMouseClick)
|
||||
|
||||
/* To consider that this object lost the focus, we monitor the space for 2 key events */
|
||||
canvas.floatingSpace.container.eventHandler.listenToEvent('onMouseOver', mouseOverFlotingSpace)
|
||||
canvas.floatingSpace.container.eventHandler.listenToEvent('onFocusAquired', someoneAquiredFocus)
|
||||
|
||||
if (callBackFunction !== undefined) { callBackFunction(GLOBAL.DEFAULT_OK_RESPONSE) }
|
||||
} catch (err) {
|
||||
if (ERROR_LOG === true) { logger.write('[ERROR] initialize -> err= ' + err.stack) }
|
||||
if (callBackFunction !== undefined) { callBackFunction(GLOBAL.DEFAULT_FAIL_RESPONSE) }
|
||||
}
|
||||
canvas.floatingSpace.container.eventHandler.listenToEvent('onMouseOver', mouseOverFlotingSpace)
|
||||
canvas.floatingSpace.container.eventHandler.listenToEvent('onFocusAquired', someoneAquiredFocus)
|
||||
}
|
||||
|
||||
function getContainer (point) {
|
||||
@@ -279,13 +268,8 @@ function newFloatingObject () {
|
||||
|
||||
function updateMass () {
|
||||
|
||||
// thisObject.currentMass = thisObject.rawMass + thisObject.rawMass * thisObject.container.zoom.incrementM * thisObject.container.zoom.levelM;
|
||||
|
||||
}
|
||||
|
||||
function updateRadius () {
|
||||
|
||||
// thisObject.targetRadius = thisObject.rawRadius + thisObject.rawRadius * thisObject.container.zoom.incrementR * thisObject.container.zoom.levelR;
|
||||
|
||||
}
|
||||
}
|
||||
+19
-23
@@ -225,21 +225,18 @@ function newNoteSets () {
|
||||
*/
|
||||
|
||||
let floatingObject = newFloatingObject()
|
||||
floatingObject.initialize('Note', '', floatingLayer, onInitialized)
|
||||
floatingObject.initialize('Note', '', floatingLayer)
|
||||
|
||||
function onInitialized (err) {
|
||||
if (INFO_LOG === true) { logger.write('[INFO] createNoteSet -> onNotesChanged -> Add new Notes -> onInitialized -> Entering function.') }
|
||||
floatingObject.payload = noteSet.payload
|
||||
floatingObject.payloadNoteIndex = i
|
||||
floatingObject.payloadImageId = noteSet.imageId
|
||||
|
||||
floatingObject.payload = noteSet.payload
|
||||
floatingObject.payloadNoteIndex = i
|
||||
floatingObject.payloadImageId = noteSet.imageId
|
||||
floatingObject.friction = 0.995
|
||||
|
||||
floatingObject.friction = 0.995
|
||||
|
||||
floatingObject.initializeMass(200)
|
||||
floatingObject.initializeMass(200)
|
||||
|
||||
// let bodyText = pNewNotes[i].body;
|
||||
let radius
|
||||
let radius
|
||||
|
||||
/*
|
||||
if (bodyText.length < 100) {
|
||||
@@ -248,27 +245,26 @@ function newNoteSets () {
|
||||
radius = bodyText.length;
|
||||
}
|
||||
*/
|
||||
radius = 50
|
||||
radius = 50
|
||||
|
||||
floatingObject.initializeRadius(radius)
|
||||
floatingObject.initializeImageSize(15)
|
||||
floatingObject.initializeRadius(radius)
|
||||
floatingObject.initializeImageSize(15)
|
||||
|
||||
floatingObject.fillStyle = 'rgba(' + UI_COLOR.WHITE + ', 0.5)'
|
||||
floatingObject.labelStrokeStyle = 'rgba(60, 60, 60, 0.50)'
|
||||
floatingObject.fillStyle = 'rgba(' + UI_COLOR.WHITE + ', 0.5)'
|
||||
floatingObject.labelStrokeStyle = 'rgba(60, 60, 60, 0.50)'
|
||||
|
||||
floatingLayer.addFloatingObject(floatingObject)
|
||||
floatingLayer.addFloatingObject(floatingObject)
|
||||
|
||||
if (INFO_LOG === true) { logger.write('[INFO] createNoteSet -> onNotesChanged -> Add new Notes -> onInitialized -> New Note added to Layer.') }
|
||||
if (INFO_LOG === true) { logger.write('[INFO] createNoteSet -> onNotesChanged -> Add new Notes -> onInitialized -> New Note added to Layer.') }
|
||||
|
||||
plotterNote.floatingHandle = floatingObject.handle
|
||||
plotterNote.floatingHandle = floatingObject.handle
|
||||
|
||||
if (INFO_LOG === true) { logger.write('[INFO] createNoteSet -> onNotesChanged -> Add new Notes -> plotterNote.floatingHandle = ' + plotterNote.floatingHandle) }
|
||||
if (INFO_LOG === true) { logger.write('[INFO] createNoteSet -> onNotesChanged -> Add new Notes -> plotterNote.floatingHandle = ' + plotterNote.floatingHandle) }
|
||||
|
||||
newFloatingNotes.push(plotterNote)
|
||||
newFloatingNotes.push(plotterNote)
|
||||
|
||||
if (INFO_LOG === true) { logger.write('[INFO] createNoteSet -> onNotesChanged -> Add new Notes -> onInitialized -> Added to newFloatingNotes.') }
|
||||
if (INFO_LOG === true) { logger.write('[INFO] createNoteSet -> onNotesChanged -> Add new Notes -> onInitialized -> newFloatingNotes.length = ' + newFloatingNotes.length) }
|
||||
}
|
||||
if (INFO_LOG === true) { logger.write('[INFO] createNoteSet -> onNotesChanged -> Add new Notes -> onInitialized -> Added to newFloatingNotes.') }
|
||||
if (INFO_LOG === true) { logger.write('[INFO] createNoteSet -> onNotesChanged -> Add new Notes -> onInitialized -> newFloatingNotes.length = ' + newFloatingNotes.length) }
|
||||
} else {
|
||||
newFloatingNotes.push(floatingNote)
|
||||
|
||||
|
||||
@@ -36,25 +36,23 @@ function newProfileBalls () {
|
||||
|
||||
function createNewProfileBall (pPayload, callBackFunction) {
|
||||
let floatingObject = newFloatingObject()
|
||||
floatingObject.initialize('Profile Ball', '', floatingLayer, onInitialized)
|
||||
floatingObject.initialize('Profile Ball', '', floatingLayer)
|
||||
|
||||
function onInitialized (err) {
|
||||
floatingObject.payload = pPayload
|
||||
floatingObject.payload = pPayload
|
||||
|
||||
floatingObject.friction = 0.995
|
||||
floatingObject.friction = 0.995
|
||||
|
||||
floatingObject.initializeMass(100)
|
||||
floatingObject.initializeRadius(30)
|
||||
floatingObject.initializeImageSize(50)
|
||||
floatingObject.initializeFontSize(10)
|
||||
floatingObject.initializeMass(100)
|
||||
floatingObject.initializeRadius(30)
|
||||
floatingObject.initializeImageSize(50)
|
||||
floatingObject.initializeFontSize(10)
|
||||
|
||||
floatingObject.fillStyle = 'rgba(' + UI_COLOR.WHITE + ', 0.5)'
|
||||
floatingObject.labelStrokeStyle = 'rgba(60, 60, 60, 0.50)'
|
||||
floatingObject.fillStyle = 'rgba(' + UI_COLOR.WHITE + ', 0.5)'
|
||||
floatingObject.labelStrokeStyle = 'rgba(60, 60, 60, 0.50)'
|
||||
|
||||
floatingLayer.addFloatingObject(floatingObject)
|
||||
floatingLayer.addFloatingObject(floatingObject)
|
||||
|
||||
callBackFunction(GLOBAL.DEFAULT_OK_RESPONSE, floatingObject.handle)
|
||||
}
|
||||
callBackFunction(GLOBAL.DEFAULT_OK_RESPONSE, floatingObject.handle)
|
||||
}
|
||||
|
||||
function destroyProfileBall (pFloatingObjectHandle) {
|
||||
|
||||
+104
-111
@@ -5,12 +5,6 @@ function newStrategyParts () {
|
||||
const logger = newWebDebugLog()
|
||||
logger.fileName = MODULE_NAME
|
||||
|
||||
/*
|
||||
|
||||
This object deals with Strategy Parts, a type of Floating Object that shows together with other parts a graphical representation of a strategy.
|
||||
|
||||
*/
|
||||
|
||||
let thisObject = {
|
||||
|
||||
createNewStrategyPart: createNewStrategyPart,
|
||||
@@ -33,122 +27,121 @@ function newStrategyParts () {
|
||||
floatingLayer = pFloatingLayer
|
||||
}
|
||||
|
||||
function createNewStrategyPart (type, pPayload, callBackFunction) {
|
||||
function createNewStrategyPart (type, pPayload) {
|
||||
let floatingObject = newFloatingObject()
|
||||
floatingObject.payload = pPayload
|
||||
floatingObject.initialize('Strategy Part', type, floatingLayer, onInitialized)
|
||||
floatingObject.underlayingObject.type = type
|
||||
floatingObject.initialize('Strategy Part', type, floatingLayer)
|
||||
floatingObject.underlayingObject.type = type // after initialize
|
||||
|
||||
function onInitialized (err) {
|
||||
const FRICTION = 0.97
|
||||
const FRICTION = 0.97
|
||||
|
||||
switch (type) {
|
||||
case 'Strategy': {
|
||||
level_1()
|
||||
break
|
||||
}
|
||||
case 'Strategy Entry': {
|
||||
level_2()
|
||||
break
|
||||
}
|
||||
case 'Strategy Exit': {
|
||||
level_2()
|
||||
break
|
||||
}
|
||||
case 'Trade Entry': {
|
||||
level_2()
|
||||
break
|
||||
}
|
||||
case 'Trade Exit': {
|
||||
level_2()
|
||||
break
|
||||
}
|
||||
case 'Stop': {
|
||||
level_2()
|
||||
break
|
||||
}
|
||||
case 'Take Profit': {
|
||||
level_2()
|
||||
break
|
||||
}
|
||||
case 'Phase': {
|
||||
level_3()
|
||||
break
|
||||
}
|
||||
case 'Situation': {
|
||||
level_4()
|
||||
break
|
||||
}
|
||||
case 'Condition': {
|
||||
level_5()
|
||||
break
|
||||
}
|
||||
default: {
|
||||
if (ERROR_LOG === true) { logger.write('[ERROR] initialize -> Part Type not Recognized -> type = ' + type) }
|
||||
}
|
||||
switch (type) {
|
||||
case 'Strategy': {
|
||||
level_1()
|
||||
break
|
||||
}
|
||||
|
||||
function level_1 () {
|
||||
floatingObject.friction = FRICTION
|
||||
|
||||
floatingObject.initializeMass(100)
|
||||
floatingObject.initializeRadius(45)
|
||||
floatingObject.initializeImageSize(80)
|
||||
floatingObject.initializeFontSize(10)
|
||||
|
||||
floatingObject.fillStyle = 'rgba(' + UI_COLOR.WHITE + ', 1)'
|
||||
case 'Strategy Entry': {
|
||||
level_2()
|
||||
break
|
||||
}
|
||||
|
||||
function level_2 () {
|
||||
floatingObject.friction = FRICTION
|
||||
|
||||
floatingObject.initializeMass(50)
|
||||
floatingObject.initializeRadius(40)
|
||||
floatingObject.initializeImageSize(70)
|
||||
floatingObject.initializeFontSize(10)
|
||||
|
||||
floatingObject.fillStyle = 'rgba(' + UI_COLOR.GREEN + ', 1)'
|
||||
case 'Strategy Exit': {
|
||||
level_2()
|
||||
break
|
||||
}
|
||||
|
||||
function level_3 () {
|
||||
floatingObject.friction = FRICTION
|
||||
|
||||
floatingObject.initializeMass(10)
|
||||
floatingObject.initializeRadius(35)
|
||||
floatingObject.initializeImageSize(60)
|
||||
floatingObject.initializeFontSize(10)
|
||||
|
||||
floatingObject.fillStyle = 'rgba(' + UI_COLOR.RUSTED_RED + ', 1)'
|
||||
case 'Trade Entry': {
|
||||
level_2()
|
||||
break
|
||||
}
|
||||
|
||||
function level_4 () {
|
||||
floatingObject.friction = FRICTION
|
||||
|
||||
floatingObject.initializeMass(10)
|
||||
floatingObject.initializeRadius(30)
|
||||
floatingObject.initializeImageSize(50)
|
||||
floatingObject.initializeFontSize(10)
|
||||
|
||||
floatingObject.fillStyle = 'rgba(' + UI_COLOR.TITANIUM_YELLOW + ', 1)'
|
||||
case 'Trade Exit': {
|
||||
level_2()
|
||||
break
|
||||
}
|
||||
|
||||
function level_5 () {
|
||||
floatingObject.friction = FRICTION
|
||||
|
||||
floatingObject.initializeMass(10)
|
||||
floatingObject.initializeRadius(25)
|
||||
floatingObject.initializeImageSize(30)
|
||||
floatingObject.initializeFontSize(10)
|
||||
|
||||
floatingObject.fillStyle = 'rgba(' + UI_COLOR.RED + ', 1)'
|
||||
case 'Stop': {
|
||||
level_2()
|
||||
break
|
||||
}
|
||||
case 'Take Profit': {
|
||||
level_2()
|
||||
break
|
||||
}
|
||||
case 'Phase': {
|
||||
level_3()
|
||||
break
|
||||
}
|
||||
case 'Situation': {
|
||||
level_4()
|
||||
break
|
||||
}
|
||||
case 'Condition': {
|
||||
level_5()
|
||||
break
|
||||
}
|
||||
default: {
|
||||
if (ERROR_LOG === true) { logger.write('[ERROR] initialize -> Part Type not Recognized -> type = ' + type) }
|
||||
return
|
||||
}
|
||||
|
||||
floatingObject.labelStrokeStyle = 'rgba(' + UI_COLOR.WHITE + ', 1)'
|
||||
|
||||
floatingLayer.addFloatingObject(floatingObject)
|
||||
|
||||
callBackFunction(GLOBAL.CUSTOM_OK_RESPONSE, floatingObject.handle)
|
||||
}
|
||||
|
||||
function level_1 () {
|
||||
floatingObject.friction = FRICTION
|
||||
|
||||
floatingObject.initializeMass(100)
|
||||
floatingObject.initializeRadius(45)
|
||||
floatingObject.initializeImageSize(80)
|
||||
floatingObject.initializeFontSize(10)
|
||||
|
||||
floatingObject.fillStyle = 'rgba(' + UI_COLOR.WHITE + ', 1)'
|
||||
}
|
||||
|
||||
function level_2 () {
|
||||
floatingObject.friction = FRICTION
|
||||
|
||||
floatingObject.initializeMass(50)
|
||||
floatingObject.initializeRadius(40)
|
||||
floatingObject.initializeImageSize(70)
|
||||
floatingObject.initializeFontSize(10)
|
||||
|
||||
floatingObject.fillStyle = 'rgba(' + UI_COLOR.GREEN + ', 1)'
|
||||
}
|
||||
|
||||
function level_3 () {
|
||||
floatingObject.friction = FRICTION
|
||||
|
||||
floatingObject.initializeMass(10)
|
||||
floatingObject.initializeRadius(35)
|
||||
floatingObject.initializeImageSize(60)
|
||||
floatingObject.initializeFontSize(10)
|
||||
|
||||
floatingObject.fillStyle = 'rgba(' + UI_COLOR.RUSTED_RED + ', 1)'
|
||||
}
|
||||
|
||||
function level_4 () {
|
||||
floatingObject.friction = FRICTION
|
||||
|
||||
floatingObject.initializeMass(10)
|
||||
floatingObject.initializeRadius(30)
|
||||
floatingObject.initializeImageSize(50)
|
||||
floatingObject.initializeFontSize(10)
|
||||
|
||||
floatingObject.fillStyle = 'rgba(' + UI_COLOR.TITANIUM_YELLOW + ', 1)'
|
||||
}
|
||||
|
||||
function level_5 () {
|
||||
floatingObject.friction = FRICTION
|
||||
|
||||
floatingObject.initializeMass(10)
|
||||
floatingObject.initializeRadius(25)
|
||||
floatingObject.initializeImageSize(30)
|
||||
floatingObject.initializeFontSize(10)
|
||||
|
||||
floatingObject.fillStyle = 'rgba(' + UI_COLOR.RED + ', 1)'
|
||||
}
|
||||
|
||||
floatingObject.labelStrokeStyle = 'rgba(' + UI_COLOR.WHITE + ', 1)'
|
||||
|
||||
floatingLayer.addFloatingObject(floatingObject)
|
||||
|
||||
return floatingObject.handle
|
||||
}
|
||||
|
||||
function destroyStrategyPart (pFloatingObjectHandle) {
|
||||
|
||||
@@ -109,11 +109,7 @@ function newStrategyCollectionItem () {
|
||||
payload.parentNode = parentNode
|
||||
payload.onMenuItemClick = onMenuItemClick
|
||||
|
||||
canvas.floatingSpace.strategyParts.createNewStrategyPart(partType, payload, onStrategyPartCreated)
|
||||
|
||||
function onStrategyPartCreated (err, pPartHandle) {
|
||||
node.handle = pPartHandle
|
||||
}
|
||||
node.handle = canvas.floatingSpace.strategyParts.createNewStrategyPart(partType, payload)
|
||||
}
|
||||
|
||||
function destroyPart (node) {
|
||||
|
||||
Reference in new issue
Block a user