diff --git a/README.md b/README.md index 601316a0..9ccb42bf 100644 --- a/README.md +++ b/README.md @@ -14,9 +14,4 @@ WARNING! This is not ready for use and is under heavy development of basic featu ## Known Issues 1. Mechanisms aren't limited to init 2. Mechanisms aren't limited to only Robot or Mechanism class -3. There is no default Robot class -4. No way to specify whether an opmode is auto or teleop -5. Workspace can have blocks -6. No Robot workspace yet -7. No Mechanism workspace yet -8. Something weird is going on with currentModule getting unset \ No newline at end of file +3. No way to specify whether an opmode is auto or teleop diff --git a/src/editor/extended_python_generator.ts b/src/editor/extended_python_generator.ts index 3c67be97..bddddccc 100644 --- a/src/editor/extended_python_generator.ts +++ b/src/editor/extended_python_generator.ts @@ -161,13 +161,13 @@ export class ExtendedPythonGenerator extends PythonGenerator { classParentFromModuleType(moduleType : string) : string{ if(moduleType == commonStorage.MODULE_TYPE_WORKSPACE){ - return "Robot"; + return "RobotBase"; } if(moduleType == commonStorage.MODULE_TYPE_OPMODE){ return "OpMode"; } if(moduleType == commonStorage.MODULE_TYPE_MECHANISM){ - return "OpMode"; + return "Mechanism"; } return ""; } @@ -176,7 +176,10 @@ export class ExtendedPythonGenerator extends PythonGenerator { if (!this.currentModule) { return super.finish(code); } - let className = this.currentModule.moduleName; + let className = 'Robot'; // Default for Workspace + if (this.currentModule.moduleType != commonStorage.MODULE_TYPE_WORKSPACE){ + className = this.currentModule.moduleName; + } let classParent = this.classParentFromModuleType(this.currentModule.moduleType); this.addImport(classParent); diff --git a/src/modules/mechanism_start.json b/src/modules/mechanism_start.json new file mode 100644 index 00000000..87cc9057 --- /dev/null +++ b/src/modules/mechanism_start.json @@ -0,0 +1,38 @@ +{ + "blocks": { + "languageVersion": 0, + "blocks": [ + { + "type": "mrc_class_method_def", + "id": "ElbONc{)s(,UprTW(|1C", + "x": 10, + "y": 10, + "deletable": false, + "extraState": { + "canChangeSignature": false, + "returnType": "None", + "params": [], + "pythonMethodName": "__init__" + }, + "fields": { + "NAME": "init" + } + }, + { + "type": "mrc_class_method_def", + "id": "wxFAh6eaR1|3fTuV:UAd", + "x": 10, + "y": 200, + "deletable": false, + "extraState": { + "canChangeSignature": false, + "returnType": "None", + "params": [] + }, + "fields": { + "NAME": "update" + } + } + ] + } +} \ No newline at end of file diff --git a/src/modules/robot_start.json b/src/modules/robot_start.json new file mode 100644 index 00000000..0f5391af --- /dev/null +++ b/src/modules/robot_start.json @@ -0,0 +1,23 @@ +{ + "blocks": { + "languageVersion": 0, + "blocks": [ + { + "type": "mrc_class_method_def", + "id": "ElbONc{)s(,UprTW(|1C", + "x": 10, + "y": 10, + "deletable": false, + "extraState": { + "canChangeSignature": false, + "returnType": "None", + "params": [], + "pythonMethodName": "__init__" + }, + "fields": { + "NAME": "init" + } + } + ] + } +} \ No newline at end of file diff --git a/src/storage/common_storage.ts b/src/storage/common_storage.ts index 28851cab..0389b88d 100644 --- a/src/storage/common_storage.ts +++ b/src/storage/common_storage.ts @@ -23,6 +23,8 @@ import * as Blockly from 'blockly/core'; import {Block} from "../toolbox/items"; import startingOpModeBlocks from '../modules/opmode_start.json'; +import startingMechanismBlocks from '../modules/mechanism_start.json'; +import startingRobotBlocks from '../modules/robot_start.json'; import {extendedPythonGenerator} from '../editor/extended_python_generator'; @@ -160,9 +162,15 @@ export function newWorkspaceContent(workspaceName: string): string { dateModifiedMillis: 0, }; - const pythonCode = ''; - const exportedBlocks = '[]'; - const blocksContent = '{}'; + // Create a headless blockly workspace. + const headlessBlocklyWorkspace = new Blockly.Workspace(); + headlessBlocklyWorkspace.options.oneBasedIndex = false; + Blockly.serialization.workspaces.load(startingRobotBlocks, headlessBlocklyWorkspace); + + extendedPythonGenerator.setCurrentModule(module); + const pythonCode = extendedPythonGenerator.workspaceToCode(headlessBlocklyWorkspace); + const exportedBlocks = JSON.stringify(extendedPythonGenerator.getExportedBlocks(headlessBlocklyWorkspace)); + const blocksContent = JSON.stringify(Blockly.serialization.workspaces.save(headlessBlocklyWorkspace)); return makeModuleContent(module, pythonCode, exportedBlocks, blocksContent); } @@ -181,7 +189,7 @@ export function newMechanismContent(workspaceName: string, mechanismName: string // Create a headless blockly workspace. const headlessBlocklyWorkspace = new Blockly.Workspace(); headlessBlocklyWorkspace.options.oneBasedIndex = false; - // TODO: Create the blocks for a new mechanism. + Blockly.serialization.workspaces.load(startingMechanismBlocks, headlessBlocklyWorkspace); extendedPythonGenerator.setCurrentModule(module); const pythonCode = extendedPythonGenerator.workspaceToCode(headlessBlocklyWorkspace);