Skip to content

Commit 59f93fe

Browse files
committed
Add default blocks for mechanism and workspace
1 parent 7f1470f commit 59f93fe

File tree

3 files changed

+73
-4
lines changed

3 files changed

+73
-4
lines changed

src/modules/mechanism_start.json

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
{
2+
"blocks": {
3+
"languageVersion": 0,
4+
"blocks": [
5+
{
6+
"type": "mrc_class_method_def",
7+
"id": "ElbONc{)s(,UprTW(|1C",
8+
"x": 10,
9+
"y": 10,
10+
"deletable": false,
11+
"extraState": {
12+
"canChangeSignature": false,
13+
"returnType": "None",
14+
"params": [],
15+
"pythonMethodName": "__init__"
16+
},
17+
"fields": {
18+
"NAME": "init"
19+
}
20+
},
21+
{
22+
"type": "mrc_class_method_def",
23+
"id": "wxFAh6eaR1|3fTuV:UAd",
24+
"x": 10,
25+
"y": 200,
26+
"deletable": false,
27+
"extraState": {
28+
"canChangeSignature": false,
29+
"returnType": "None",
30+
"params": []
31+
},
32+
"fields": {
33+
"NAME": "update"
34+
}
35+
}
36+
]
37+
}
38+
}

src/modules/robot_start.json

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
{
2+
"blocks": {
3+
"languageVersion": 0,
4+
"blocks": [
5+
{
6+
"type": "mrc_class_method_def",
7+
"id": "ElbONc{)s(,UprTW(|1C",
8+
"x": 10,
9+
"y": 10,
10+
"deletable": false,
11+
"extraState": {
12+
"canChangeSignature": false,
13+
"returnType": "None",
14+
"params": [],
15+
"pythonMethodName": "__init__"
16+
},
17+
"fields": {
18+
"NAME": "init"
19+
}
20+
}
21+
]
22+
}
23+
}

src/storage/common_storage.ts

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,8 @@ import * as Blockly from 'blockly/core';
2323

2424
import {Block} from "../toolbox/items";
2525
import startingOpModeBlocks from '../modules/opmode_start.json';
26+
import startingMechanismBlocks from '../modules/mechanism_start.json';
27+
import startingRobotBlocks from '../modules/robot_start.json';
2628

2729
import {extendedPythonGenerator} from '../editor/extended_python_generator';
2830

@@ -160,9 +162,15 @@ export function newWorkspaceContent(workspaceName: string): string {
160162
dateModifiedMillis: 0,
161163
};
162164

163-
const pythonCode = '';
164-
const exportedBlocks = '[]';
165-
const blocksContent = '{}';
165+
// Create a headless blockly workspace.
166+
const headlessBlocklyWorkspace = new Blockly.Workspace();
167+
headlessBlocklyWorkspace.options.oneBasedIndex = false;
168+
Blockly.serialization.workspaces.load(startingRobotBlocks, headlessBlocklyWorkspace);
169+
170+
extendedPythonGenerator.setCurrentModule(module);
171+
const pythonCode = extendedPythonGenerator.workspaceToCode(headlessBlocklyWorkspace);
172+
const exportedBlocks = JSON.stringify(extendedPythonGenerator.getExportedBlocks(headlessBlocklyWorkspace));
173+
const blocksContent = JSON.stringify(Blockly.serialization.workspaces.save(headlessBlocklyWorkspace));
166174
return makeModuleContent(module, pythonCode, exportedBlocks, blocksContent);
167175
}
168176

@@ -181,7 +189,7 @@ export function newMechanismContent(workspaceName: string, mechanismName: string
181189
// Create a headless blockly workspace.
182190
const headlessBlocklyWorkspace = new Blockly.Workspace();
183191
headlessBlocklyWorkspace.options.oneBasedIndex = false;
184-
// TODO: Create the blocks for a new mechanism.
192+
Blockly.serialization.workspaces.load(startingMechanismBlocks, headlessBlocklyWorkspace);
185193

186194
extendedPythonGenerator.setCurrentModule(module);
187195
const pythonCode = extendedPythonGenerator.workspaceToCode(headlessBlocklyWorkspace);

0 commit comments

Comments
 (0)