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:
+14
-1
@@ -73,6 +73,11 @@ export function serializeInterface(iface: Interface): string {
|
|||||||
if (sv.unit) attrs.push(`unit="${xmlEsc(sv.unit)}"`);
|
if (sv.unit) attrs.push(`unit="${xmlEsc(sv.unit)}"`);
|
||||||
if (sv.low !== undefined) attrs.push(`low="${sv.low}"`);
|
if (sv.low !== undefined) attrs.push(`low="${sv.low}"`);
|
||||||
if (sv.high !== undefined) attrs.push(`high="${sv.high}"`);
|
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(' ')}/>`);
|
lines.push(` <statevar ${attrs.join(' ')}/>`);
|
||||||
}
|
}
|
||||||
if (iface.logic && (iface.logic.nodes.length > 0 || iface.logic.wires.length > 0)) {
|
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 low = el.getAttribute('low');
|
||||||
const high = el.getAttribute('high');
|
const high = el.getAttribute('high');
|
||||||
const unit = el.getAttribute('unit');
|
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({
|
statevars.push({
|
||||||
name,
|
name,
|
||||||
type: type === 'bool' || type === 'string' ? type : 'number',
|
type: svType,
|
||||||
initial: el.getAttribute('initial') ?? '',
|
initial: el.getAttribute('initial') ?? '',
|
||||||
...(unit ? { unit } : {}),
|
...(unit ? { unit } : {}),
|
||||||
...(low !== null ? { low: parseFloat(low) } : {}),
|
...(low !== null ? { low: parseFloat(low) } : {}),
|
||||||
...(high !== null ? { high: parseFloat(high) } : {}),
|
...(high !== null ? { high: parseFloat(high) } : {}),
|
||||||
|
...(elem ? { elem: elem as StateVar['elem'] } : {}),
|
||||||
|
...(sizing ? { sizing: sizing as StateVar['sizing'] } : {}),
|
||||||
|
...(capacityAttr !== null ? { capacity: Number(capacityAttr) } : {}),
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user