adaptation of the functionalities to Blockly package

This commit is contained in:
Delucse
2020-07-23 15:42:01 +02:00
parent d1d7a447bc
commit c2405de04a
11 changed files with 254 additions and 73 deletions
+3
View File
@@ -1,5 +1,8 @@
export const NEW_CODE = 'NEW_CODE';
export const CHANGE_WORKSPACE = 'CHANGE_WORKSPACE';
export const NEW_WORKSPACE = 'NEW_WORKSPACE';
export const CREATE_BLOCK = 'CREATE_BLOCK';
export const MOVE_BLOCK = 'MOVE_BLOCK';
export const CHANGE_BLOCK = 'CHANGE_BLOCK';
export const DELETE_BLOCK = 'DELETE_BLOCK';
export const CLEAR_STATS = 'CLEAR_STATS';
+43 -8
View File
@@ -1,28 +1,61 @@
import { NEW_WORKSPACE, CREATE_BLOCK, CHANGE_BLOCK, DELETE_BLOCK, CLEAR_STATS } from './types';
import { NEW_CODE, CHANGE_WORKSPACE, NEW_WORKSPACE, CREATE_BLOCK, MOVE_BLOCK, CHANGE_BLOCK, DELETE_BLOCK, CLEAR_STATS } from './types';
import * as Blockly from 'blockly/core';
export const workspaceChange = () => (dispatch) => {
dispatch({
type: CHANGE_WORKSPACE
})
}
export const initWorkspace = (workspace) => (dispatch) => {
dispatch({
type: NEW_WORKSPACE,
payload: workspace
});
}
export const onChangeWorkspace = (event) => (dispatch, getState) => {
var oldWorkspace = getState().workspace.new; // stored 'new workspace' is from now on old
var newWorkspace = window.Ardublockly.workspace;
const workspace = Blockly.getMainWorkspace();
dispatch({
type: NEW_WORKSPACE,
payload: {new: newWorkspace, old: oldWorkspace}
payload: workspace
});
dispatch({
type: CHANGE_WORKSPACE,
})
var code = getState().workspace.code;
code.arduino = Blockly.Arduino.workspaceToCode(workspace);
var xmlDom = Blockly.Xml.workspaceToDom(workspace);
code.xml = Blockly.Xml.domToPrettyText(xmlDom);
dispatch({
type: NEW_CODE,
payload: code
});
console.log(event.type);
var stats = getState().workspace.stats;
if (event.type === window.Blockly.Events.CREATE){
if (event.type === Blockly.Events.BLOCK_CREATE){
stats.create += event.ids.length;
dispatch({
type: CREATE_BLOCK,
payload: stats
});
}
else if (event.type === window.Blockly.Events.CHANGE){
else if (event.type === Blockly.Events.BLOCK_MOVE){
stats.move += 1;
dispatch({
type: MOVE_BLOCK,
payload: stats
});
}
else if (event.type === Blockly.Events.BLOCK_CHANGE){
stats.change += 1;
dispatch({
type: CHANGE_BLOCK,
payload: stats
});
}
else if (event.type === window.Blockly.Events.DELETE){
else if (event.type === Blockly.Events.BLOCK_DELETE){
if(stats.create > 0){
stats.delete += event.ids.length;
dispatch({
@@ -37,7 +70,8 @@ export const clearStats = () => (dispatch) => {
var stats = {
create: 0,
change: 0,
delete: 0
delete: 0,
move: 0
};
dispatch({
type: CLEAR_STATS,
@@ -45,6 +79,7 @@ export const clearStats = () => (dispatch) => {
});
};
export const setWorkspace = (workspace) => (dispatch, getState) => {
dispatch({
type: NEW_WORKSPACE,