Fix edge bug: add broke flag to match Python for-else behavior

This commit is contained in:
Michael Winter 2026-04-01 18:01:09 +02:00
parent 7259cd67bd
commit 990e59b1d6

View file

@ -352,6 +352,14 @@
'border-width': 0,
}
},
{
selector: 'node[sirenActive = "true"]',
style: {
'border-width': 4,
'border-color': '#ffffff',
'border-opacity': 1,
}
},
{
selector: 'edge',
style: {
@ -462,6 +470,20 @@
})
}).then(r => r.json()).then(data => {
console.log('Playing on', destination + ':', data.frequency.toFixed(2), 'Hz on voice', data.voice);
// If playing on siren, add white circle around node for this voice
if (isShift) {
const nodeColor = node.data('color');
// Find any existing node with same color that has sirenActive and remove it
cy.nodes().forEach(n => {
if (n.data('color') === nodeColor && n.data('sirenActive')) {
n.data('sirenActive', '');
}
});
// Add sirenActive to clicked node
node.data('sirenActive', 'true');
console.log('Added sirenActive to', node.id(), 'color:', nodeColor);
}
}).catch(err => {
console.log('Error playing freq:', err);
});
@ -716,6 +738,7 @@
// Count differences in dims 1, 2, 3
let diffCount = 0;
let diffDim = -1;
let broke = false;
for (let d = 1; d < hs1.length; d++) {
const diff = hs2[d] - hs1[d];
@ -723,12 +746,13 @@
diffCount++;
diffDim = d;
} else if (diff !== 0) {
broke = true;
break; // diff > 1 in this dimension
}
}
// Check if exactly one dimension differs
if (diffCount === 1 && diffDim > 0) {
// Check if exactly one dimension differs AND loop didn't break early
if (!broke && diffCount === 1 && diffDim > 0) {
// Calculate frequency ratio
const diffHs = [];
for (let d = 0; d < hs1.length; d++) {
@ -975,6 +999,8 @@
body: JSON.stringify({ soft: true })
}).then(r => r.json()).then(data => {
console.log('Soft kill sent (20 Hz)');
// Clear all siren circles
cy.nodes().forEach(n => n.removeData('sirenActive'));
}).catch(err => {
console.log('Error sending kill:', err);
});
@ -986,6 +1012,8 @@
body: JSON.stringify({ soft: false })
}).then(r => r.json()).then(data => {
console.log('Hard kill sent (0 Hz)');
// Clear all siren circles
cy.nodes().forEach(n => n.removeData('sirenActive'));
}).catch(err => {
console.log('Error sending kill:', err);
});