Skip to content
Closed
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
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,4 +15,4 @@ WARNING! This is not ready for use and is under heavy development of basic featu
1. Mechanisms aren't limited to init
2. Mechanisms aren't limited to only Robot or Mechanism class
3. No way to specify whether an opmode is auto or teleop
4. Since we changed the "Workspace" terminology to "Project", existing Workspaces are no longer supported. They can be deleted via the browser's Developer Tools - Application tab.
4. Since we changed the "Project" terminology to "Robot", existing Projects are no longer supported. They can be deleted via the browser's Developer Tools - Application tab.
22 changes: 11 additions & 11 deletions public/locales/en/translation.json
Original file line number Diff line number Diff line change
@@ -1,24 +1,24 @@
{
"mechanism_delete": "Delete Project",
"mechanism_rename": "Rename Project",
"mechanism_copy": "Copy Project",
"opmode_delete": "Delete Project",
"opmode_rename": "Rename Project",
"opmode_copy": "Copy Project",
"project_delete": "Delete Project",
"project_rename": "Rename Project",
"project_copy": "Copy Project",
"mechanism_delete": "Delete Robot",
"mechanism_rename": "Rename Robot",
"mechanism_copy": "Copy Robot",
"opmode_delete": "Delete Robot",
"opmode_rename": "Rename Robot",
"opmode_copy": "Copy Robot",
"robot_delete": "Delete Robot",
"robot_rename": "Rename Robot",
"robot_copy": "Copy Robot",
"fail_list_modules": "Failed to load the list of modules.",
"mechanism": "Mechanism",
"opmode": "OpMode",
"class_rule_description": "No spaces are allowed in the name. Each word in the name should start with a capital letter.",
"example_mechanism": "For example: GamePieceShooter",
"example_opmode": "For example: AutoParkAndShoot",
"example_project": "For example: WackyWheelerRobot",
"example_robot": "For example: WackyWheelerRobot",
"addTabDialog": {
"title": "Add Tab",
"newItemPlaceholder": "Add Module",
"search": "Search..."

}
}
}
34 changes: 17 additions & 17 deletions src/App.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ const LAYOUT_BACKGROUND_COLOR = '#0F0';

/**
* Main application component that manages the Blockly interface, code generation,
* project management, and user interface layout.
* robot management, and user interface layout.
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No, this should still be project

*/
const App: React.FC = (): React.JSX.Element => {
const [alertErrorMessage, setAlertErrorMessage] = React.useState('');
Expand All @@ -91,7 +91,7 @@ const App: React.FC = (): React.JSX.Element => {
const [messageApi, contextHolder] = Antd.message.useMessage();
const [generatedCode, setGeneratedCode] = React.useState<string>('');
const [toolboxSettingsModalIsOpen, setToolboxSettingsModalIsOpen] = React.useState(false);
const [project, setProject] = React.useState<commonStorage.Project | null>(null);
const [robot, setRobot] = React.useState<commonStorage.Robot | null>(null);
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

should still be project

const [tabItems, setTabItems] = React.useState<Tabs.TabItem[]>([]);
const [activeTab, setActiveTab] = React.useState('');
const [shownPythonToolboxCategories, setShownPythonToolboxCategories] = React.useState<Set<string>>(new Set());
Expand Down Expand Up @@ -225,25 +225,25 @@ const App: React.FC = (): React.JSX.Element => {
handleToolboxSettingsOk(updatedShownCategories);
};

/** Creates tab items from project data. */
const createTabItemsFromProject = (projectData: commonStorage.Project): Tabs.TabItem[] => {
/** Creates tab items from robot data. */
const createTabItemsFromRobot = (robotData: commonStorage.Robot): Tabs.TabItem[] => {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This should still be project

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

and projectData - throughout this method

const tabs: Tabs.TabItem[] = [
{
key: projectData.modulePath,
key: robotData.modulePath,
title: 'Robot',
type: TabType.ROBOT,
},
];

projectData.mechanisms.forEach((mechanism) => {
robotData.mechanisms.forEach((mechanism) => {
tabs.push({
key: mechanism.modulePath,
title: mechanism.className,
type: TabType.MECHANISM,
});
});

projectData.opModes.forEach((opmode) => {
robotData.opModes.forEach((opmode) => {
tabs.push({
key: opmode.modulePath,
title: opmode.className,
Expand Down Expand Up @@ -327,14 +327,14 @@ const App: React.FC = (): React.JSX.Element => {
}
}, [currentModule, shownPythonToolboxCategories]);

// Update tab items when project changes
// Update tab items when robot changes
React.useEffect(() => {
if (project) {
const tabs = createTabItemsFromProject(project);
if (robot) {
const tabs = createTabItemsFromRobot(robot);
setTabItems(tabs);
setActiveTab(project.modulePath);
setActiveTab(robot.modulePath);
}
}, [project]);
}, [robot]);

const {Sider,Content} = Antd.Layout;

Expand All @@ -359,7 +359,7 @@ const App: React.FC = (): React.JSX.Element => {
<Header
alertErrorMessage={alertErrorMessage}
setAlertErrorMessage={setAlertErrorMessage}
project={project}
robot={robot}
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should still be project

/>
<Antd.Layout
style={{
Expand All @@ -376,8 +376,8 @@ const App: React.FC = (): React.JSX.Element => {
storage={storage}
setAlertErrorMessage={setAlertErrorMessage}
gotoTab={setActiveTab}
project={project}
setProject={setProject}
robot={robot}
setRobot={setRobot}
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should still be project

openWPIToolboxSettings={() => setToolboxSettingsModalIsOpen(true)}
/>
</Sider>
Expand All @@ -389,8 +389,8 @@ const App: React.FC = (): React.JSX.Element => {
setAlertErrorMessage={setAlertErrorMessage}
currentModule={currentModule}
setCurrentModule={changeModule}
project={project}
setProject={setProject}
robot={robot}
setRobot={setRobot}
storage={storage}
/>
<Antd.Layout>
Expand Down
5 changes: 2 additions & 3 deletions src/blocks/mrc_call_python_function.ts
Original file line number Diff line number Diff line change
Expand Up @@ -331,8 +331,7 @@ type CallPythonFunctionExtraState = {
*/
actualFunctionName?: string,
/**
* True if this blocks refers to an exported function (for example, from a
* user's Project).
* True if this blocks refers to an exported function (for example, from the Robot).
*/
exportedFunction?: boolean,
/**
Expand Down Expand Up @@ -679,7 +678,7 @@ export const pythonFromBlock = function(
: block.getFieldValue(FIELD_FUNCTION_NAME);
// Generate the correct code depending on the module type.
switch (generator.getModuleType()) {
case commonStorage.MODULE_TYPE_PROJECT:
case commonStorage.MODULE_TYPE_ROBOT:
case commonStorage.MODULE_TYPE_MECHANISM:
code = 'self.';
break;
Expand Down
3 changes: 1 addition & 2 deletions src/blocks/mrc_get_python_variable.ts
Original file line number Diff line number Diff line change
Expand Up @@ -228,8 +228,7 @@ type GetPythonVariableExtraState = {
*/
actualVariableName?: string,
/**
* True if this blocks refers to an exported variable (for example, from a
* user's Project).
* True if this blocks refers to an exported variable (for example, from the Robot).
*/
exportedVariable?: boolean,
};
Expand Down
3 changes: 1 addition & 2 deletions src/blocks/mrc_set_python_variable.ts
Original file line number Diff line number Diff line change
Expand Up @@ -178,8 +178,7 @@ type SetPythonVariableExtraState = {
*/
actualVariableName?: string,
/**
* True if this blocks refers to an exported variable (for example, from a
* user's Project).
* True if this blocks refers to an exported variable (for example, from the Robot).
*/
exportedVariable?: boolean,
};
Expand Down
66 changes: 33 additions & 33 deletions src/editor/editor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -44,10 +44,10 @@ export class Editor {
private methodsCategory: MethodsCategory;
private eventsCategory: EventsCategory;
private currentModule: commonStorage.Module | null = null;
private modulePath: string = '';
private projectPath: string = '';
private moduleContent: string = '';
private projectContent: string = '';
private currentModulePath: string = '';
private robotPath: string = '';
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

should probably still be projectPath

private currentModuleContent: string = '';
private robotContent: string = '';
private bindedOnChange: any = null;
private toolbox: Blockly.utils.toolbox.ToolboxDefinition = EMPTY_TOOLBOX;

Expand All @@ -73,11 +73,11 @@ export class Editor {

// TODO(lizlooney): As blocks are loaded, determine whether any blocks
// are accessing variable or calling functions thar are defined in another
// blocks file (like a Project) and check whether the variable or function
// blocks file (like the Robot) and check whether the variable or function
// definition has changed. This might happen if the user defines a variable
// or function in the Project, uses the variable or function in the
// or function in the Robot, uses the variable or function in the
// OpMode, and then removes or changes the variable or function in the
// Project.
// Robot.

// TODO(lizlooney): We will need a way to identify which variable or
// function, other than by the variable name or function name, because the
Expand All @@ -88,15 +88,15 @@ export class Editor {
// TODO(lizlooney): Look at blocks with type 'mrc_get_python_variable' or
// 'mrc_set_python_variable', and where block.mrcExportedVariable === true.
// Look at block.mrcImportModule and get the exported blocks for that module.
// (It should be the project and we already have the project content.)
// (It should be the Robot and we already have the Robot content.)
// Check whether block.mrcActualVariableName matches any exportedBlock's
// extraState.actualVariableName. If there is no match, put a warning on the
// block.

// TODO(lizlooney): Look at blocks with type 'mrc_call_python_function' and
// where block.mrcExportedFunction === true.
// Look at block.mrcImportModule and get the exported blocks for that module.
// (It should be the project and we already have the project content.)
// (It should be the Robot and we already have the Robot content.)
// Check whether block.mrcActualFunctionName matches any exportedBlock's
// extraState.actualFunctionName. If there is no match, put a warning on the block.
// If there is a match, check whether
Expand All @@ -123,35 +123,35 @@ export class Editor {
this.eventsCategory.setCurrentModule(currentModule);

if (currentModule) {
this.modulePath = currentModule.modulePath;
this.projectPath = commonStorage.makeProjectPath(currentModule.projectName);
this.currentModulePath = currentModule.modulePath;
this.robotPath = commonStorage.makeRobotPath(currentModule.robotName);
} else {
this.modulePath = '';
this.projectPath = '';
this.currentModulePath = '';
this.robotPath = '';
}
this.moduleContent = '';
this.projectContent = '';
this.currentModuleContent = '';
this.robotContent = '';
this.clearBlocklyWorkspace();

if (currentModule) {
const promises: {[key: string]: Promise<string>} = {}; // key is module path, value is promise of module content.
promises[this.modulePath] = this.storage.fetchModuleContent(this.modulePath);
if (this.projectPath !== this.modulePath) {
// Also fetch the project module content. It contains exported blocks that can be used.
promises[this.projectPath] = this.storage.fetchModuleContent(this.projectPath)
promises[this.currentModulePath] = this.storage.fetchModuleContent(this.currentModulePath);
if (this.robotPath !== this.currentModulePath) {
// Also fetch the robot module content. It contains exported blocks that can be used.
promises[this.robotPath] = this.storage.fetchModuleContent(this.robotPath)
}

const moduleContents: {[key: string]: string} = {}; // key is module path, value is module content
await Promise.all(
Object.entries(promises).map(async ([modulePath, promise]) => {
moduleContents[modulePath] = await promise;
Object.entries(promises).map(async ([currentModulePath, promise]) => {
moduleContents[currentModulePath] = await promise;
})
);
this.moduleContent = moduleContents[this.modulePath];
if (this.projectPath === this.modulePath) {
this.projectContent = this.moduleContent
this.currentModuleContent = moduleContents[this.currentModulePath];
if (this.robotPath === this.currentModulePath) {
this.robotContent = this.currentModuleContent;
} else {
this.projectContent = moduleContents[this.projectPath];
this.robotContent = moduleContents[this.robotPath];
}
this.loadBlocksIntoBlocklyWorkspace();
}
Expand Down Expand Up @@ -179,16 +179,16 @@ export class Editor {
// Add the while-loading listener.
this.bindedOnChange = this.onChangeWhileLoading.bind(this);
this.blocklyWorkspace.addChangeListener(this.bindedOnChange);
const blocksContent = commonStorage.extractBlocksContent(this.moduleContent);
const blocksContent = commonStorage.extractBlocksContent(this.currentModuleContent);
if (blocksContent) {
Blockly.serialization.workspaces.load(JSON.parse(blocksContent), this.blocklyWorkspace);
}
}

public updateToolbox(shownPythonToolboxCategories: Set<string>): void {
if (this.currentModule) {
if (!this.projectContent) {
// The Project content hasn't been fetched yet. Try again in a bit.
if (!this.robotContent) {
// The Robot content hasn't been fetched yet. Try again in a bit.
setTimeout(() => {
this.updateToolbox(shownPythonToolboxCategories)
}, 50);
Expand All @@ -204,13 +204,13 @@ export class Editor {
/*
// This code is helpful for debugging issues where the editor says
// 'Blocks have been modified!'.
if (this.getModuleContent() !== this.moduleContent) {
if (this.getModuleContent() !== this.currentModuleContent) {
console.log('isModified will return true');
console.log('this.getModuleContent() is ' + this.getModuleContent());
console.log('this.moduleContent is ' + this.moduleContent);
console.log('this.currentModuleContent is ' + this.currentModuleContent);
}
*/
return this.getModuleContent() !== this.moduleContent;
return this.getModuleContent() !== this.currentModuleContent;
}

private getModuleContent(): string {
Expand All @@ -229,7 +229,7 @@ export class Editor {

private getComponents(): commonStorage.Component[] {
const components: commonStorage.Component[] = [];
if (this.currentModule?.moduleType === commonStorage.MODULE_TYPE_PROJECT) {
if (this.currentModule?.moduleType === commonStorage.MODULE_TYPE_ROBOT) {
// TODO(lizlooney): Fill the components array.
}
return components;
Expand All @@ -238,7 +238,7 @@ export class Editor {
public async saveBlocks() {
const moduleContent = this.getModuleContent();
try {
await this.storage.saveModule(this.modulePath, moduleContent);
await this.storage.saveModule(this.currentModulePath, moduleContent);
this.moduleContent = moduleContent;
} catch (e) {
throw e;
Expand Down
4 changes: 2 additions & 2 deletions src/editor/generator_context.ts
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ export class GeneratorContext {
if (!this.module) {
throw new Error('getClassName: this.module is null.');
}
if (this.module.moduleType === commonStorage.MODULE_TYPE_PROJECT) {
if (this.module.moduleType === commonStorage.MODULE_TYPE_ROBOT) {
return 'Robot';
}

Expand All @@ -69,7 +69,7 @@ export class GeneratorContext {
if (!this.module) {
throw new Error('getClassParent: this.module is null.');
}
if (this.module.moduleType === commonStorage.MODULE_TYPE_PROJECT) {
if (this.module.moduleType === commonStorage.MODULE_TYPE_ROBOT) {
return 'RobotBase';
}
if (this.module.moduleType === commonStorage.MODULE_TYPE_OPMODE) {
Expand Down
Loading