Skip to content

Commit

Permalink
fixed some things for import
Browse files Browse the repository at this point in the history
  • Loading branch information
Unreal-Dan committed Feb 5, 2025
1 parent d1a6625 commit 395a01c
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 8 deletions.
17 changes: 11 additions & 6 deletions js/ModesPanel.js
Original file line number Diff line number Diff line change
Expand Up @@ -442,10 +442,10 @@ export default class ModesPanel extends Panel {
modeData.num_leds = 1; // Default case
})();
this.lightshow.setLedCount(modeData.num_leds);
const modeCount = this.lightshow.vortex.numModes();
let curSel;
if (addNew) {
curSel = this.lightshow.vortex.engine().modes().curModeIndex();
let modeCount = this.lightshow.vortex.numModes();
// check the mode count against max
const device = this.editor.devicePanel.selectedDevice;
const maxModes = this.getMaxModes(device)
Expand Down Expand Up @@ -476,13 +476,17 @@ export default class ModesPanel extends Panel {
return;
}
patterns.forEach((pat, index) => {
if (!pat.colorset) {
Notification.failure("Invalid pattern data");
const patData = pat.data;
if (!patData) {
return;
}
if (!patData.colorset) {
Notification.failure("Invalid pattern data: " + JSON.stringify(pat));
return;
}

const set = new this.lightshow.vortexLib.Colorset();
pat.colorset.forEach(hexCode => {
patData.colorset.forEach(hexCode => {
const normalizedHex = hexCode.replace('0x', '#');
const result = /^#?([a-f\d]{2})([a-f\d]{2})([a-f\d]{2})$/i.exec(normalizedHex);
if (result) {
Expand All @@ -494,9 +498,9 @@ export default class ModesPanel extends Panel {
}
});

const patID = this.lightshow.vortexLib.intToPatternID(pat.pattern_id);
const patID = this.lightshow.vortexLib.intToPatternID(patData.pattern_id);
const args = new this.lightshow.vortexLib.PatternArgs();
pat.args.forEach(arg => args.addArgs(arg));
patData.args.forEach(arg => args.addArgs(arg));
// TODO: Have to fetch cur each time some reason... Use after free I guess
cur = this.lightshow.vortex.engine().modes().curMode();
cur.setPattern(patID, index, args, set);
Expand All @@ -515,6 +519,7 @@ export default class ModesPanel extends Panel {
this.refreshModeList();
this.editor.ledSelectPanel.renderLedIndicators(initialDevice);
this.editor.ledSelectPanel.handleLedSelectionChange();
this.selectMode(addNew ? modeCount : curSel);
this.refreshPatternControlPanel();
this.refresh();
Notification.success("Successfully imported mode");
Expand Down
4 changes: 2 additions & 2 deletions js/VortexEditor.js
Original file line number Diff line number Diff line change
Expand Up @@ -229,15 +229,15 @@ export default class VortexEditor {

if (type === 'mode') {
try {
this.modesPanel.importModeFromData(modeJson, true);
this.modesPanel.importModeFromData(modeJson, false);
console.log('Mode loaded successfully via postMessage');
} catch (error) {
console.error('Error loading mode via postMessage:', error);
}
}
if (type === 'pattern') {
try {
this.modesPanel.importPatternFromData(modeJson, true);
this.modesPanel.importPatternFromData(modeJson, false);
console.log('Mode loaded successfully via postMessage');
} catch (error) {
console.error('Error loading pattern via postMessage:', error);
Expand Down

0 comments on commit 395a01c

Please sign in to comment.