Update: 添加mixly2-api

This commit is contained in:
王立帮
2024-07-21 10:11:34 +08:00
parent 189de53fb0
commit 4de91b3b01
3 changed files with 64 additions and 0 deletions

View File

@@ -13,6 +13,7 @@ goog.require('Mixly.Title');
goog.require('Mixly.LocalStorage');
goog.require('Mixly.Storage');
goog.require('Mixly.Debug');
goog.require('Mixly.API2');
goog.require('Mixly.Electron.LibManager');
goog.require('Mixly.Electron.File');
goog.require('Mixly.WebSocket.Socket');
@@ -31,6 +32,7 @@ const {
LocalStorage,
Storage,
Debug,
API2,
Electron = {},
Web = {},
WebSocket = {}
@@ -39,6 +41,8 @@ const {
const { LibManager, File } = goog.isElectron? Electron : Web;
const { Socket } = WebSocket;
Mixly.Editor = Mixly.Editor ?? {};
window.addEventListener('load', () => {
const app = new App($('body')[0]);
@@ -98,6 +102,7 @@ Loader.init = () => {
Loader.restoreBlocks(editor);
Mixly.app.removeSkeleton();
window.addEventListener('unload', () => Loader.backupBlocks(editor), false);
API2.init();
}
Loader.restoreBlocks = (editor) => {

View File

@@ -0,0 +1,47 @@
goog.loadJs('common', () => {
goog.require('Blockly');
goog.require('Mixly');
goog.provide('Mixly.API2');
goog.provide('Mixly.Editor');
const { API2, Editor } = Mixly;
const HUES = {
ACTUATOR_HUE: 100,
BLYNK0_HUE: 0,
BLYNK1_HUE: 159,
COMMUNICATE_HUE: 140,
LOOPS_HUE: 120,
DISPLAY_HUE: 180,
ETHERNET_HUE: 0,
FACTORY_HUE: '#777777',
BASE_HUE: 20,
LISTS_HUE: 260,
LOGIC_HUE: 210,
MATH_HUE: 230,
PINS_HUE: 230,
PROCEDURES_HUE: 290,
SCOOP_HUE: 120,
SENSOR_HUE: 40,
SERIAL_HUE: 65,
STORAGE_HUE: 0,
TEXTS_HUE: 160,
TOOLS_HUE: '#555555',
VARIABLES_HUE: 330,
HANDBIT_HUE: 65
};
API2.init = () => {
const workspace = Mixly.app.getWorkspace();
const editorsManager = workspace.getEditorsManager();
const mixEditor = editorsManager.getActive();
const blockPage = mixEditor.getPage('block');
const codePage = mixEditor.getPage('code');
Blockly.mainWorkspace = blockPage.getEditor();
Editor.blockEditor = blockPage.getEditor();
Editor.codeEditor = codePage.getEditor();
Object.assign(Blockly.Msg, HUES);
}
});

View File

@@ -628,6 +628,7 @@
"Mixly.LocalStorage",
"Mixly.Storage",
"Mixly.Debug",
"Mixly.API2",
"Mixly.Electron.LibManager",
"Mixly.Electron.File",
"Mixly.WebSocket.Socket"
@@ -710,6 +711,17 @@
"Mixly"
]
},
{
"path": "/common/mixly2-api.js",
"require": [
"Blockly",
"Mixly"
],
"provide": [
"Mixly.API2",
"Mixly.Editor"
]
},
{
"path": "/common/mjson.js",
"require": [