-
Notifications
You must be signed in to change notification settings - Fork 8
Changed project to robot. #142
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
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..." | ||
|
||
} | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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. | ||
*/ | ||
const App: React.FC = (): React.JSX.Element => { | ||
const [alertErrorMessage, setAlertErrorMessage] = React.useState(''); | ||
|
@@ -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); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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()); | ||
|
@@ -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[] => { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This should still be project There was a problem hiding this comment. Choose a reason for hiding this commentThe 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, | ||
|
@@ -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; | ||
|
||
|
@@ -359,7 +359,7 @@ const App: React.FC = (): React.JSX.Element => { | |
<Header | ||
alertErrorMessage={alertErrorMessage} | ||
setAlertErrorMessage={setAlertErrorMessage} | ||
project={project} | ||
robot={robot} | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Should still be project |
||
/> | ||
<Antd.Layout | ||
style={{ | ||
|
@@ -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} | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Should still be project |
||
openWPIToolboxSettings={() => setToolboxSettingsModalIsOpen(true)} | ||
/> | ||
</Sider> | ||
|
@@ -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> | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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 = ''; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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; | ||
|
||
|
@@ -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 | ||
|
@@ -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 | ||
|
@@ -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(); | ||
} | ||
|
@@ -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); | ||
|
@@ -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 { | ||
|
@@ -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; | ||
|
@@ -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; | ||
|
There was a problem hiding this comment.
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