diff --git a/FloatingSpace/StrategyPartConstructor.js b/FloatingSpace/StrategyPartConstructor.js index 55d8e1342..f010175d2 100644 --- a/FloatingSpace/StrategyPartConstructor.js +++ b/FloatingSpace/StrategyPartConstructor.js @@ -346,7 +346,7 @@ function newStrategyPartConstructor () { rawRadius: 8, targetRadius: 0, currentRadius: 0, - angle: 40, + angle: -60, dontShowAtFullscreen: true }, { @@ -360,7 +360,7 @@ function newStrategyPartConstructor () { rawRadius: 8, targetRadius: 0, currentRadius: 0, - angle: 0 + angle: -20 }, { action: 'Delete Phase', @@ -372,7 +372,19 @@ function newStrategyPartConstructor () { rawRadius: 8, targetRadius: 0, currentRadius: 0, - angle: -40 + angle: 20 + }, + { + action: 'Download', + actionFunction: payload.onMenuItemClick, + label: 'Download', + visible: false, + iconPathOn: 'upload', + iconPathOff: 'upload', + rawRadius: 8, + targetRadius: 0, + currentRadius: 0, + angle: 60 }] break } @@ -402,7 +414,7 @@ function newStrategyPartConstructor () { rawRadius: 8, targetRadius: 0, currentRadius: 0, - angle: 20 + angle: -40 }, { action: 'Delete Situation', @@ -414,7 +426,19 @@ function newStrategyPartConstructor () { rawRadius: 8, targetRadius: 0, currentRadius: 0, - angle: -20 + angle: 0 + }, + { + action: 'Download', + actionFunction: payload.onMenuItemClick, + label: 'Download', + visible: false, + iconPathOn: 'upload', + iconPathOff: 'upload', + rawRadius: 8, + targetRadius: 0, + currentRadius: 0, + angle: 40 }] break } @@ -448,7 +472,7 @@ function newStrategyPartConstructor () { rawRadius: 8, targetRadius: 0, currentRadius: 0, - angle: 20, + angle: -40, dontShowAtFullscreen: true }, { @@ -461,7 +485,19 @@ function newStrategyPartConstructor () { rawRadius: 8, targetRadius: 0, currentRadius: 0, - angle: -20 + angle: 0 + }, + { + action: 'Download', + actionFunction: payload.onMenuItemClick, + label: 'Download', + visible: false, + iconPathOn: 'upload', + iconPathOff: 'upload', + rawRadius: 8, + targetRadius: 0, + currentRadius: 0, + angle: 40 }] break } diff --git a/StrategySpace/Workspace.js b/StrategySpace/Workspace.js index 4d2780a16..911470e55 100644 --- a/StrategySpace/Workspace.js +++ b/StrategySpace/Workspace.js @@ -269,6 +269,13 @@ function newWorkspace () { case 'Edit Code': + break + case 'Download': + + let text = JSON.stringify(getProtocolNode(payload.node)) + let fileName = payload.node.type + '.' + payload.node.name + '.json' + download(fileName, text) + break case 'Add Phase': { @@ -407,4 +414,59 @@ function newWorkspace () { node.payload = undefined node.cleaned = true } + + function download (filename, text) { + let element = document.createElement('a') + element.setAttribute('href', 'data:text/plain;charset=utf-8,' + encodeURIComponent(text)) + element.setAttribute('download', filename) + element.style.display = 'none' + document.body.appendChild(element) + element.click() + document.body.removeChild(element) + } + + function getProtocolNode (node) { + switch (node.type) { + case 'Condition': + { + let condition = { + type: node.type, + name: node.name, + code: node.code + } + return condition + break + } + case 'Situation': { + let situation = { + type: node.type, + name: node.name, + conditions: [] + } + + for (let m = 0; m < node.conditions.length; m++) { + let condition = getProtocolNode(node.conditions[m]) + situation.conditions.push(condition) + } + return situation + break + } + case 'Phase': { + let phase = { + type: node.type, + subType: node.subType, + name: node.name, + code: node.code, + situations: [] + } + + for (let m = 0; m < node.situations.length; m++) { + let situation = getProtocolNode(node.situations[m]) + phase.situations.push(situation) + } + return phase + break + } + } + } }