Skip to content

Commit 1b66c77

Browse files
committed
Merge branch 'dev' into simulator
Support local device and save data * dev: Set initial board type to simulator Clear page when opening stage Monitor the change of simulator Set initial board type to simulator Save the data of simulator Fix bug that can’t work when demo area appears Fix bug that can’t get information of board Support local device Fix xml of stages Update simulator to support local device
2 parents 07a01a2 + ba4e9e9 commit 1b66c77

141 files changed

Lines changed: 951 additions & 12810 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

code.js

Lines changed: 29 additions & 56 deletions
Original file line numberDiff line numberDiff line change
@@ -1091,46 +1091,45 @@ Code.loadSimulator = function () {
10911091
var resizeTopRightBar = document.querySelector('#simulator-area .resize-bar-top-right');
10921092
var resizeBottomLeftBar = document.querySelector('#simulator-area .resize-bar-bottom-left');
10931093
var resizeBottomRightBar = document.querySelector('#simulator-area .resize-bar-bottom-right');
1094-
var storage = {};
1095-
var MIN_WIDTH = 225;
1094+
var MIN_WIDTH = 345;
10961095
var MIN_HEIGHT = 225;
10971096

1098-
if (localStorage.simulator) {
1099-
try {
1100-
storage = JSON.parse(localStorage.simulator);
1101-
} catch (e) {
1102-
storage = {};
1103-
}
1104-
}
1097+
loadConfig();
11051098

1106-
if (frame.contentWindow.blockly) {
1107-
frameReady();
1108-
} else {
1109-
frame.contentWindow.addEventListener('load', frameReady);
1099+
if ('BlocklySimStorage' in window) {
1100+
// Hook a save function onto unload.
1101+
BlocklySimStorage.backupOnUnload(area, frame);
11101102
}
11111103

1112-
window.addEventListener('unload', function () {
1113-
storage.config = frame.contentWindow.blockly.config();
1114-
storage.opened = area.classList.contains('show');
1115-
storage.isFull = area.classList.contains('full');
1116-
storage.width = area.dataset.width;
1117-
storage.height = area.dataset.height;
1118-
localStorage.simulator = JSON.stringify(storage);
1119-
});
1104+
// 處理 firefox iframe 中,vue 拋錯的問題
1105+
setTimeout(function () {
1106+
area.classList.remove('init');
1107+
}, 1000);
11201108

11211109
Code.bindClick('runButton', function () {
11221110
var xml = Blockly.Xml.workspaceToDom(Code.workspace);
11231111
var deviceIds = [];
1124-
var nodes = xml.querySelectorAll('[name="device_"] [name="TEXT"]');
1112+
var devices = [];
1113+
var boards = xml.querySelectorAll('block[type="board"],block[type="board_ready"]');
1114+
1115+
boards.forEach(function (board) {
1116+
var id = board.querySelector('[name="device_"] [name="TEXT"]').textContent;
1117+
var local = board.querySelector('[name="type_"]').textContent === '5';
11251118

1126-
nodes.forEach(function (node) {
1127-
deviceIds.push(node.textContent);
1119+
devices.push({
1120+
id: id,
1121+
local: local
1122+
});
11281123
});
11291124

1130-
frame.contentWindow.blockly.setDeviceId(deviceIds);
1125+
frame.contentWindow.blockly.setDevice(devices);
11311126
frame.contentWindow.blockly.toggleRunning();
11321127
});
11331128

1129+
Code.bindClick('linkButton', function () {
1130+
BlocklySimStorage.link(area, frame, btn);
1131+
});
1132+
11341133
Code.bindClick(closeBtn, function () {
11351134
area.classList.remove('show', 'full');
11361135
btn.classList.remove('opened');
@@ -1684,38 +1683,12 @@ Code.loadSimulator = function () {
16841683
area.style.width = area.dataset.width || '';
16851684
}
16861685

1687-
function frameReady() {
1688-
var api = frame.contentWindow.blockly;
1689-
1690-
// 寬度的儲存
1691-
storage.width && (area.dataset.width = storage.width);
1692-
storage.height && (area.dataset.height = storage.height);
1693-
1694-
// 語系
1695-
api.lang(Code.getLang());
1696-
1697-
// 之前存檔的回復
1698-
if (storage.config) {
1699-
api.config(storage.config);
1700-
}
1701-
1702-
if (storage.isFull) {
1703-
area.classList.add('full');
1704-
}
1705-
1706-
updateWidth();
1707-
updateHeight();
1708-
1709-
if (storage.opened) {
1710-
area.classList.add('show');
1711-
btn.classList.add('opened');
1686+
function loadConfig() {
1687+
if ('BlocklySimStorage' in window && BlocklySimStorage.isLinkUrl()) {
1688+
BlocklySimStorage.retrieveXml(window.location.hash.substring(1), area, frame, btn);
1689+
} else if ('BlocklySimStorage' in window) {
1690+
BlocklySimStorage.restoreBlocks(area, frame, btn);
17121691
}
1713-
1714-
// 處理 firefox iframe 中,vue 拋錯的問題
1715-
setTimeout(function () {
1716-
area.classList.remove('init');
1717-
}, 1000);
1718-
17191692
}
17201693

17211694
};

components/simulator/.bower.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,11 +26,11 @@
2626
"defiant": "defiant-js#^1.4.0",
2727
"webduino-js": "dist"
2828
},
29-
"_release": "ff496653d1",
29+
"_release": "cd7bd6d578",
3030
"_resolution": {
3131
"type": "branch",
3232
"branch": "blockly",
33-
"commit": "ff496653d16c4d0275b736cf81a37ed56835e3a3"
33+
"commit": "cd7bd6d578c9c190ba27dcab3d3e946bbfd14485"
3434
},
3535
"_source": "https://git.kingkit.codes/webduino/simulator.git",
3636
"_target": "blockly",

components/simulator/dist/bower.json

Lines changed: 0 additions & 29 deletions
This file was deleted.

components/simulator/dist/css/bundle-20170407101439.css renamed to components/simulator/dist/css/bundle-20170519145949.css

File renamed without changes.

components/simulator/dist/css/less/index.less

Lines changed: 0 additions & 117 deletions
This file was deleted.

components/simulator/dist/css/less/sidebar.less

Lines changed: 0 additions & 44 deletions
This file was deleted.

0 commit comments

Comments
 (0)