From 4de91b3b0124cda3800ec1c3417b2878472b4c12 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E7=8E=8B=E7=AB=8B=E5=B8=AE?= <3294713004@qq.com> Date: Sun, 21 Jul 2024 10:11:34 +0800 Subject: [PATCH] =?UTF-8?q?Update:=20=E6=B7=BB=E5=8A=A0mixly2-api?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- common/modules/mixly-modules/common/loader.js | 5 ++ .../mixly-modules/common/mixly2-api.js | 47 +++++++++++++++++++ common/modules/mixly-modules/deps.json | 12 +++++ 3 files changed, 64 insertions(+) create mode 100644 common/modules/mixly-modules/common/mixly2-api.js diff --git a/common/modules/mixly-modules/common/loader.js b/common/modules/mixly-modules/common/loader.js index a4a5c2f9..db0a88bb 100644 --- a/common/modules/mixly-modules/common/loader.js +++ b/common/modules/mixly-modules/common/loader.js @@ -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) => { diff --git a/common/modules/mixly-modules/common/mixly2-api.js b/common/modules/mixly-modules/common/mixly2-api.js new file mode 100644 index 00000000..92d8ee79 --- /dev/null +++ b/common/modules/mixly-modules/common/mixly2-api.js @@ -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); +} + +}); \ No newline at end of file diff --git a/common/modules/mixly-modules/deps.json b/common/modules/mixly-modules/deps.json index 4d4836b5..05625cb7 100644 --- a/common/modules/mixly-modules/deps.json +++ b/common/modules/mixly-modules/deps.json @@ -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": [