feat(logic): round-trip array statevar attributes in panel XML

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
Martino Ferrari
2026-06-24 11:12:05 +02:00
parent 8f50bc2498
commit b82e8852b3
+14 -1
View File
@@ -73,6 +73,11 @@ export function serializeInterface(iface: Interface): string {
if (sv.unit) attrs.push(`unit="${xmlEsc(sv.unit)}"`);
if (sv.low !== undefined) attrs.push(`low="${sv.low}"`);
if (sv.high !== undefined) attrs.push(`high="${sv.high}"`);
if (sv.type === 'array') {
if (sv.elem) attrs.push(`elem="${sv.elem}"`);
if (sv.sizing) attrs.push(`sizing="${sv.sizing}"`);
if (sv.capacity !== undefined) attrs.push(`capacity="${sv.capacity}"`);
}
lines.push(` <statevar ${attrs.join(' ')}/>`);
}
if (iface.logic && (iface.logic.nodes.length > 0 || iface.logic.wires.length > 0)) {
@@ -213,13 +218,21 @@ export function parseInterface(xml: string): Interface {
const low = el.getAttribute('low');
const high = el.getAttribute('high');
const unit = el.getAttribute('unit');
const elem = el.getAttribute('elem');
const sizing = el.getAttribute('sizing');
const capacityAttr = el.getAttribute('capacity');
const svType: StateVar['type'] =
type === 'bool' || type === 'string' || type === 'array' ? type : 'number';
statevars.push({
name,
type: type === 'bool' || type === 'string' ? type : 'number',
type: svType,
initial: el.getAttribute('initial') ?? '',
...(unit ? { unit } : {}),
...(low !== null ? { low: parseFloat(low) } : {}),
...(high !== null ? { high: parseFloat(high) } : {}),
...(elem ? { elem: elem as StateVar['elem'] } : {}),
...(sizing ? { sizing: sizing as StateVar['sizing'] } : {}),
...(capacityAttr !== null ? { capacity: Number(capacityAttr) } : {}),
});
}