Recovering Object State from local storage implemented
This commit is contained in:
1 parent
ca26eddbf0
commit
57df515f60
5 files changed
+61
-35
No files matched your search
@@ -82,6 +82,9 @@ function newCanvas () {
|
||||
|
||||
/* Instantiate all the children spaces of Canvas object */
|
||||
|
||||
thisObject.floatingSpace = newFloatingSpace()
|
||||
thisObject.floatingSpace.initialize()
|
||||
|
||||
thisObject.topSpace = newTopSpace()
|
||||
await thisObject.topSpace.initialize()
|
||||
|
||||
@@ -94,9 +97,6 @@ function newCanvas () {
|
||||
thisObject.panelsSpace = newPanelsSpace()
|
||||
thisObject.panelsSpace.initialize()
|
||||
|
||||
thisObject.floatingSpace = newFloatingSpace()
|
||||
thisObject.floatingSpace.initialize()
|
||||
|
||||
thisObject.chartSpace = newChartSpace()
|
||||
thisObject.chartSpace.initialize(onCharSpaceInitialized)
|
||||
|
||||
@@ -706,4 +706,3 @@ function newCanvas () {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -21,6 +21,7 @@ function newFloatingObject () {
|
||||
targetRadius: 0, // This is the target radius of the floating object with zoom applied. It should be animated until reaching this value.
|
||||
isPinned: false,
|
||||
nearbyFloatingObjects: [],
|
||||
setPosition: setPosition,
|
||||
pinToggle: pinToggle,
|
||||
physics: physics,
|
||||
initializeMass: initializeMass,
|
||||
@@ -267,8 +268,10 @@ function newFloatingObject () {
|
||||
y: Math.floor((Math.random() * (200) - 100)) + arroundPoint.y
|
||||
}
|
||||
|
||||
// thisObject.container.frame.position = thisObject.container.frame.frameThisPoint(position)
|
||||
setPosition(position)
|
||||
}
|
||||
|
||||
function setPosition (position) {
|
||||
thisObject.container.frame.position.x = position.x
|
||||
thisObject.container.frame.position.y = position.y
|
||||
|
||||
@@ -309,4 +312,3 @@ function newFloatingObject () {
|
||||
function updateRadius () {
|
||||
}
|
||||
}
|
||||
|
||||
@@ -36,6 +36,19 @@ function newStrategyPartConstructor () {
|
||||
floatingObject.initialize('Strategy Part', payload)
|
||||
payload.floatingObject = floatingObject
|
||||
|
||||
if (payload.node.savedPayload !== undefined) {
|
||||
position = {
|
||||
x: payload.node.savedPayload.position.x,
|
||||
y: payload.node.savedPayload.position.y
|
||||
}
|
||||
floatingObject.setPosition(position)
|
||||
payload.node.savedPayload.position = undefined
|
||||
if (payload.node.savedPayload.floatingObject.isPinned === true) {
|
||||
floatingObject.pinToggle()
|
||||
}
|
||||
payload.node.savedPayload = undefined
|
||||
}
|
||||
|
||||
let strategyPart = newStrategyPart()
|
||||
strategyPart.fitFunction = canvas.floatingSpace.fitIntoVisibleArea
|
||||
strategyPart.isVisibleFunction = canvas.floatingSpace.isThisPointVisible
|
||||
|
||||
+16
-18
@@ -8,7 +8,6 @@ function newStrategySpace () {
|
||||
iconCollection: undefined,
|
||||
iconByPartType: undefined,
|
||||
workspace: undefined,
|
||||
isDeployed: false,
|
||||
isInitialized: false,
|
||||
physics: physics,
|
||||
draw: draw,
|
||||
@@ -30,16 +29,24 @@ function newStrategySpace () {
|
||||
return thisObject
|
||||
|
||||
async function initialize () {
|
||||
thisObject.strategizerGateway = newStrategizerGateway()
|
||||
|
||||
thisObject.strategizerGateway.initialize()
|
||||
await thisObject.strategizerGateway.loadFromStrategyzer()
|
||||
|
||||
loadIconCollection()
|
||||
buildIconByPartTypeMap()
|
||||
|
||||
if (thisObject.strategizerGateway.strategizerData !== undefined) {
|
||||
thisObject.strategizerGateway = newStrategizerGateway()
|
||||
thisObject.strategizerGateway.initialize()
|
||||
|
||||
let savedWorkspace = window.localStorage.getItem('workspace')
|
||||
if (savedWorkspace === null) {
|
||||
await thisObject.strategizerGateway.loadFromStrategyzer()
|
||||
if (thisObject.strategizerGateway.strategizerData !== undefined) {
|
||||
thisObject.isInitialized = true
|
||||
thisObject.workspace = newWorkspace()
|
||||
thisObject.workspace.initialize(thisObject.strategizerGateway.strategizerData)
|
||||
}
|
||||
} else {
|
||||
thisObject.isInitialized = true
|
||||
thisObject.workspace = newWorkspace()
|
||||
thisObject.workspace.initialize()
|
||||
}
|
||||
}
|
||||
|
||||
@@ -140,25 +147,15 @@ function newStrategySpace () {
|
||||
}
|
||||
|
||||
function physics () {
|
||||
if (visible !== true) { return }
|
||||
thisObject.workspace.physics()
|
||||
}
|
||||
|
||||
function makeVisible () {
|
||||
if (thisObject.isDeployed !== true) {
|
||||
deploydTradingSystem()
|
||||
}
|
||||
canvas.floatingSpace.makeVisible()
|
||||
visible = true
|
||||
}
|
||||
|
||||
function deploydTradingSystem () {
|
||||
thisObject.workspace = newWorkspace()
|
||||
if (thisObject.strategizerGateway.strategizerData !== undefined) {
|
||||
thisObject.workspace.initialize(thisObject.strategizerGateway.strategizerData)
|
||||
thisObject.isDeployed = true
|
||||
}
|
||||
}
|
||||
|
||||
function makeInvisible () {
|
||||
visible = false
|
||||
}
|
||||
@@ -185,3 +182,4 @@ function newStrategySpace () {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
+25
-11
@@ -42,12 +42,16 @@ function newWorkspace () {
|
||||
}
|
||||
|
||||
function initialize (tradingSystem) {
|
||||
thisObject.tradingSystem = {
|
||||
id: tradingSystem.id,
|
||||
strategies: tradingSystem.subStrategies
|
||||
let savedWorkspace = window.localStorage.getItem('workspace')
|
||||
if (savedWorkspace === null) {
|
||||
thisObject.tradingSystem = {
|
||||
id: tradingSystem.id,
|
||||
strategies: tradingSystem.subStrategies
|
||||
}
|
||||
} else {
|
||||
thisObject.tradingSystem = JSON.parse(savedWorkspace)
|
||||
}
|
||||
generateStrategyParts()
|
||||
|
||||
rootNodes.set(thisObject.tradingSystem.id, thisObject.tradingSystem)
|
||||
}
|
||||
|
||||
@@ -62,7 +66,7 @@ function newWorkspace () {
|
||||
function saveRootNode (value, key, map) {
|
||||
workspaceNode = getWorkspaceNode(value)
|
||||
let textToSave = JSON.stringify(workspaceNode)
|
||||
window.localStorage.setItem('nodeValue', textToSave)
|
||||
window.localStorage.setItem('workspace', textToSave)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -340,15 +344,24 @@ function newWorkspace () {
|
||||
|
||||
function createPart (partType, name, node, parentNode, chainParent, title) {
|
||||
let payload = {}
|
||||
if (chainParent === undefined) {
|
||||
|
||||
if (node.savedPayload !== undefined) {
|
||||
payload.targetPosition = {
|
||||
x: spawnPosition.x,
|
||||
y: spawnPosition.y
|
||||
x: node.savedPayload.targetPosition.x,
|
||||
y: node.savedPayload.targetPosition.y
|
||||
}
|
||||
node.savedPayload.targetPosition = undefined
|
||||
} else {
|
||||
payload.targetPosition = {
|
||||
x: chainParent.payload.position.x,
|
||||
y: chainParent.payload.position.y
|
||||
if (chainParent === undefined) {
|
||||
payload.targetPosition = {
|
||||
x: spawnPosition.x,
|
||||
y: spawnPosition.y
|
||||
}
|
||||
} else {
|
||||
payload.targetPosition = {
|
||||
x: chainParent.payload.position.x,
|
||||
y: chainParent.payload.position.y
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1059,5 +1072,6 @@ function newWorkspace () {
|
||||
|
||||
}
|
||||
}
|
||||
return savedPayload
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user