|
| 1 | +# mx2json |
| 2 | + |
| 3 | +Create a JSON representation of a Machinations Google Doc |
| 4 | + |
| 5 | +> ⚠️ This is WIP. You’ll need quite a few things for this: |
| 6 | +> 1. A Google Docs API Key with `spreadsheets.readonly` permissions |
| 7 | +> 2. The ID of your Google Sheet |
| 8 | +> 3. use 1 & 2 to create the API URL to your Google Doc, something like `https://sheets.googleapis.com/v4/spreadsheets/18J84rwqwC9AuyabZAK9d4JM6cUZn8jBnhZoT0NHMTp8/values/A%3AZ?key=…` |
| 9 | +4. `curl` this, optionally store the result in a file |
| 10 | + |
| 11 | +## CLI |
| 12 | + |
| 13 | +`mx2json` always reads from `stdin`. Use the pipe (`|`) or redirect (`<`) operators. |
| 14 | + |
| 15 | +##### Read from a file |
| 16 | +`$ mx2json < curl https://....`<br/> |
| 17 | + |
| 18 | +##### Read from a URL |
| 19 | +`$ curl https://.... | mx2json` |
| 20 | + |
| 21 | +## API |
| 22 | + |
| 23 | +`mx2json(doc, toJson)` |
| 24 | + |
| 25 | +**`doc`** is the Machinations Google Sheet, either in JSON or already parsed Object. |
| 26 | + |
| 27 | +**`toJson`** `boolean` or `function`. Set to `true` to get a JSON. Pass a `function`, to get the return value of that function. |
| 28 | + |
| 29 | +```js |
| 30 | +const mx2object = require('mx2json') |
| 31 | +const model = mx2object(myDoc) |
| 32 | +const json = mx2object(myDoc, true) |
| 33 | +const custom = mx2object(mDoc, doc => /* whatever */) |
| 34 | +``` |
| 35 | + |
| 36 | +# Example Result |
| 37 | + |
| 38 | +```json |
| 39 | +{ |
| 40 | + "diagramProperties": { |
| 41 | + "name": "Untitled", |
| 42 | + "url": "https://my.machinations.io/diagram/22179", |
| 43 | + "owner": "Andreas Pizsa", |
| 44 | + "creationDate": "10/22/2019", |
| 45 | + "lastChange": "10/31/2019", |
| 46 | + "timeInterval": 1, |
| 47 | + "timeStepsLimit": 100, |
| 48 | + "numberOfRunsBatch": 10, |
| 49 | + "numberOfRunsTotal": 20 |
| 50 | + }, |
| 51 | + "globalVariables": [ |
| 52 | + { |
| 53 | + "id": 1, |
| 54 | + "name": "Dice", |
| 55 | + "value": "D6" |
| 56 | + }, |
| 57 | + { |
| 58 | + "id": 2, |
| 59 | + "name": "Skill" |
| 60 | + }, |
| 61 | + { |
| 62 | + "id": 3, |
| 63 | + "name": "Multiplayer" |
| 64 | + }, |
| 65 | + { |
| 66 | + "id": 4, |
| 67 | + "name": "Strategy" |
| 68 | + } |
| 69 | + ], |
| 70 | + "pools": [ |
| 71 | + { |
| 72 | + "id": 11, |
| 73 | + "label": "", |
| 74 | + "geometry": "{\"_attributes\":{\"x\":\"360\",\"y\":\"110\",\"width\":\"60\",\"height\":\"60\",\"TRANSLATE_CONTROL_POINTS\":\"1\",\"relative\":\"0\",\"as\":\"geometry\"},\"mxPoint\":{\"_attributes\":{\"x\":\"0\",\"y\":\"40\",\"as\":\"offset\"}}}", |
| 75 | + "style": "shape=pool-shape;whiteSpace=wrap;html=1;strokeWidth=2;aspect=fixed;resizable=0;fontSize=16;fontColor=#000000;strokeColor=#000000;", |
| 76 | + "activation": "passive", |
| 77 | + "activationMode": "pull-any", |
| 78 | + "resources": 10, |
| 79 | + "resourcesColor": "Black", |
| 80 | + "capacityLimit": -1, |
| 81 | + "capacityDisplay": 25, |
| 82 | + "overflow": "block", |
| 83 | + "showInChart": 0 |
| 84 | + }, |
| 85 | + { |
| 86 | + "id": 15, |
| 87 | + "label": "", |
| 88 | + "geometry": "{\"_attributes\":{\"x\":\"150\",\"y\":\"110\",\"width\":\"60\",\"height\":\"60\",\"TRANSLATE_CONTROL_POINTS\":\"1\",\"relative\":\"0\",\"as\":\"geometry\"},\"mxPoint\":{\"_attributes\":{\"x\":\"0\",\"y\":\"40\",\"as\":\"offset\"}}}", |
| 89 | + "style": "shape=pool-shape;whiteSpace=wrap;html=1;strokeWidth=2;aspect=fixed;resizable=0;fontSize=16;fontColor=#000000;strokeColor=#000000;", |
| 90 | + "activation": "interactive", |
| 91 | + "activationMode": "push-any", |
| 92 | + "resources": 5, |
| 93 | + "resourcesColor": "Black", |
| 94 | + "capacityLimit": -1, |
| 95 | + "capacityDisplay": 25, |
| 96 | + "overflow": "block", |
| 97 | + "showInChart": 0 |
| 98 | + } |
| 99 | + ], |
| 100 | + "resourceConnections": [ |
| 101 | + { |
| 102 | + "id": 14, |
| 103 | + "label": 1, |
| 104 | + "geometry": "{\"_attributes\":{\"x\":\"0\",\"y\":\"0\",\"width\":\"60\",\"height\":\"60\",\"relative\":\"1\",\"TRANSLATE_CONTROL_POINTS\":\"1\",\"as\":\"geometry\"},\"mxPoint\":[{\"_attributes\":{\"x\":\"240\",\"y\":\"148.33333333333337\",\"as\":\"sourcePoint\"}},{\"_attributes\":{\"x\":\"324.8528137423857\",\"y\":\"150\",\"as\":\"targetPoint\"}},{\"_attributes\":{\"x\":\"20\",\"y\":\"10\",\"as\":\"offset\"}}]}", |
| 105 | + "style": "shape=resource-connection;endArrow=classic;html=1;strokeWidth=2;fontSize=16;fontColor=#000000;strokeColor=#000000;", |
| 106 | + "source": 15, |
| 107 | + "target": 11, |
| 108 | + "transfer": "interval-based", |
| 109 | + "colorCoding": 0, |
| 110 | + "colorCodingColor": "Orange", |
| 111 | + "shuffleSource": 0, |
| 112 | + "limitsMinimum": -9999, |
| 113 | + "limitsMaximum": 9999 |
| 114 | + } |
| 115 | + ], |
| 116 | + "stateConnections": [ |
| 117 | + { |
| 118 | + "id": 16, |
| 119 | + "label": ">0", |
| 120 | + "geometry": "{\"_attributes\":{\"x\":\"0\",\"y\":\"0\",\"width\":\"60\",\"height\":\"60\",\"relative\":\"1\",\"TRANSLATE_CONTROL_POINTS\":\"1\",\"as\":\"geometry\"},\"mxPoint\":[{\"_attributes\":{\"x\":\"420\",\"y\":\"200\",\"as\":\"sourcePoint\"}},{\"_attributes\":{\"x\":\"504.8528137423857\",\"y\":\"140\",\"as\":\"targetPoint\"}},{\"_attributes\":{\"x\":\"20\",\"y\":\"10\",\"as\":\"offset\"}}],\"Array\":{\"_attributes\":{\"as\":\"points\"},\"mxPoint\":{\"_attributes\":{\"x\":\"350\",\"y\":\"290\"}}}}", |
| 121 | + "style": "shape=state-connection;endArrow=classic;dashed=1;dashPattern=4 3;html=1;strokeWidth=2;fontSize=16;fontColor=#000000;strokeColor=#000000;", |
| 122 | + "source": 11, |
| 123 | + "target": 14, |
| 124 | + "colorCoding": 0, |
| 125 | + "colorCodingColor": "Black" |
| 126 | + } |
| 127 | + ] |
| 128 | +} |
| 129 | +``` |
0 commit comments