Skip to content

Commit

Permalink
Merge branch 'develop'
Browse files Browse the repository at this point in the history
  • Loading branch information
zhengyangliu committed Jun 19, 2024
2 parents 7704a8b + e59e190 commit 8bbbb8e
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 44 deletions.
26 changes: 13 additions & 13 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -56,10 +56,10 @@
"minilog": "3.1.0",
"monaco-editor": "^0.15.1",
"omggif": "1.0.9",
"openblock-blocks": "0.1.0-prerelease.20230529180648",
"openblock-blocks": "0.1.0-prerelease.20240616014658",
"openblock-l10n": "^3.15.20240615153110",
"openblock-save-svg-as-png": "^1.4.18",
"openblock-vm": "^0.2.0-prerelease.20230719104943",
"openblock-vm": "^0.2.0-prerelease.20240618095638",
"papaparse": "5.3.0",
"postcss-import": "^12.0.0",
"postcss-loader": "^3.0.0",
Expand Down
42 changes: 13 additions & 29 deletions src/lib/libraries/devices/index.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -562,6 +562,7 @@ const analysisRealDeviceId = deviceId => {
if (deviceId.indexOf('_') !== -1) {
return deviceId.split('_')[1];
}
return deviceId;
};

/**
Expand All @@ -575,41 +576,24 @@ const makeDeviceLibrary = (deviceList = null) => {
let regeneratedDeviceData = [];

if (deviceList) {
if (deviceList[0].isOrdered) { // External resources customize the device arrangement
regeneratedDeviceData.push(deviceData[0]);
} else {
deviceList = deviceData.concat(deviceList);
}

deviceList.forEach(dev => {
// Check if this is a build-in device.
const matchedDevice = deviceData.find(item => dev.deviceId === item.deviceId);
const realDeviceId = analysisRealDeviceId(dev.deviceId);
const matchedDevice = deviceData.find(item => realDeviceId === item.deviceId);
if (matchedDevice) {
// processing the device which just select only one type
if (matchedDevice.deviceId.indexOf('arduino') !== -1 ||
matchedDevice.deviceId.indexOf('microPython') !== -1) {

const deviceId = matchedDevice.deviceId;
const deviceType = matchedDevice.type;

let parentId = deviceId.replace(deviceType, '');
parentId = parentId.replace(parentId[0], parentId[0].toLowerCase());
if (!deviceList.find(item => item.deviceId === parentId)) {
matchedDevice.hide = false;
matchedDevice.typeList = [deviceType];
}
if (realDeviceId !== dev.deviceId) {
return regeneratedDeviceData.push(defaults({}, dev, {hide: false}, matchedDevice));
}
return regeneratedDeviceData.push(matchedDevice);
}

// This is a third party device. Try to parse it's parent deivce.
const realDeviceId = analysisRealDeviceId(dev.deviceId);
if (realDeviceId) {
const parentDevice = deviceData.find(item => realDeviceId === item.deviceId);
if (parentDevice) {
return regeneratedDeviceData.push(defaults({}, dev, {hide: false}, parentDevice));
}
log.warn('Cannot find the parent device of this device:', dev.deviceId);
return;
}
return regeneratedDeviceData.push(defaults({}, dev, {hide: false}));
log.warn('Unable to find the corresponding built-in device:', dev.deviceId);
return;
});

regeneratedDeviceData.unshift(deviceData[0]); // add unselect deive in the head.
} else {
regeneratedDeviceData = deviceData;
}
Expand Down

0 comments on commit 8bbbb8e

Please sign in to comment.