fix(embed): jangan buang wire tanpa id di elemes:load_circuit
Saved velxio_circuit wires sering berbentuk {start,end} tanpa id/color/
waypoints. Filter lama (w && w.start && w.end && w.id) membuang semua
wire sehingga rangkaian lesson kosong. Relaksasi filter ke start+end saja,
lalu normalisasi id/color/waypoints, dan panggil recalculateAllWirePositions
agar wire ter-render.
This commit is contained in:
parent
bf457e17b8
commit
02ea4e3b86
|
|
@ -92,9 +92,26 @@ class EmbedBridge {
|
|||
|
||||
// Set wires if provided
|
||||
if (data.wires && Array.isArray(data.wires)) {
|
||||
// Filter out null/undefined wires to prevent runtime errors
|
||||
const validWires = data.wires.filter((w) => w && w.start && w.end && w.id) as never[];
|
||||
store.setWires(validWires);
|
||||
// Saved circuits (e.g. Elemes `velxio_circuit`) often ship wires
|
||||
// as bare { start, end } pairs WITHOUT an `id`, `color`, or
|
||||
// `waypoints`. The previous filter required `w.id` and silently
|
||||
// dropped EVERY wire, so lessons with wires appeared empty.
|
||||
// Relax the guard to require only a valid start+end endpoint, and
|
||||
// fill in the fields the store/wire renderer expect.
|
||||
const validWires = data.wires
|
||||
.filter((w) => w && w.start && w.end) as Array<Record<string, any>>;
|
||||
const normalized = validWires.map((w, i) => ({
|
||||
id: w.id || `wire-${Date.now()}-${i}`,
|
||||
start: w.start,
|
||||
end: w.end,
|
||||
color: w.color || '#e74c3c',
|
||||
waypoints: w.waypoints || [],
|
||||
}));
|
||||
store.setWires(normalized as never[]);
|
||||
// Wire endpoints store x/y; recompute them against component/board
|
||||
// pins so the wires actually render (loadExample.ts does the same
|
||||
// after setWires — without this, wires sit at 0,0 and are invisible).
|
||||
useSimulatorStore.getState().recalculateAllWirePositions();
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue