Files
logic-gates/js/state.js
Jose Luis 9ec3367253 feat: drag selection box to select, move, and delete multiple gates
Click and drag on empty space to draw a selection rectangle. Gates
inside the box get selected (cyan dashed outline). Drag any selected
gate to move all of them together. Delete/Backspace removes all
selected gates and their connections. Escape clears the selection.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-03-20 04:47:34 +01:00

55 lines
1.5 KiB
JavaScript

// Shared application state — single source of truth
export const state = {
// Circuit
gates: [],
connections: [],
nextId: 1,
// Interaction
placingGate: null,
dragging: null,
dragOffset: { x: 0, y: 0 },
connecting: null,
hoveredGate: null,
hoveredPort: null,
mouseX: 0,
mouseY: 0,
// Camera (pan/zoom)
camX: 0,
camY: 0,
zoom: 1,
// Waveform
waveformVisible: false,
waveformHeight: 220,
recording: true,
waveData: {}, // { gateId: [{ t, value }] }
timeStep: 0,
waveZoom: 20, // pixels per time step
waveScroll: 0,
resizingWave: false,
// Simulation
simRunning: false,
simInterval: null,
simSpeed: 500, // ms per tick
// Puzzle/Components
customComponents: {}, // { id -> component definition }
// Component Editor
componentEditorActive: false,
savedMainCircuit: null, // { gates, connections, nextId } saved before entering editor
componentEditorName: '',
editingComponentId: null, // ID of component being edited (null = new component)
// Bus cutting (shift+drag)
busCutting: null, // { startX, startY, endX, endY } in world coords, or null
// Multi-selection
selectedGates: [], // array of gate IDs currently selected
selectionBox: null, // { startX, startY, endX, endY } in world coords while dragging
multiDrag: null // { startX, startY, origins: [{id, x, y}] } while dragging selected gates
};