Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 1 addition & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
3. No way to specify whether an opmode is auto or teleop
9 changes: 6 additions & 3 deletions src/editor/extended_python_generator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 "";
}
Expand All @@ -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);

Expand Down
38 changes: 38 additions & 0 deletions src/modules/mechanism_start.json
Original file line number Diff line number Diff line change
@@ -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"
}
}
]
}
}
23 changes: 23 additions & 0 deletions src/modules/robot_start.json
Original file line number Diff line number Diff line change
@@ -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"
}
}
]
}
}
16 changes: 12 additions & 4 deletions src/storage/common_storage.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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';

Expand Down Expand Up @@ -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);
}

Expand All @@ -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);
Expand Down