refactor: bus terminals with single-sided pins only
BUS_IN has input pins only (left side), BUS_OUT has output pins only (right side). No internal connections between them — BUS_OUT reads values directly from its paired BUS_IN via busPairId. The bus cable between them is purely visual, representing the grouped signal bundle. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
47
js/gates.js
47
js/gates.js
@@ -11,7 +11,8 @@ export function gateInputCount(type) {
|
||||
const component = state.customComponents?.[componentId];
|
||||
return component ? component.inputCount : 0;
|
||||
}
|
||||
if (type.startsWith('BUS:')) return parseInt(type.substring(4)) || 0;
|
||||
if (type.startsWith('BUS_IN:')) return parseInt(type.substring(7)) || 0;
|
||||
if (type.startsWith('BUS_OUT:')) return 0;
|
||||
return baseGateInputCount(type);
|
||||
}
|
||||
|
||||
@@ -21,12 +22,23 @@ export function gateOutputCount(type) {
|
||||
const component = state.customComponents?.[componentId];
|
||||
return component ? component.outputCount : 0;
|
||||
}
|
||||
if (type.startsWith('BUS:')) return parseInt(type.substring(4)) || 0;
|
||||
if (type.startsWith('BUS_IN:')) return 0;
|
||||
if (type.startsWith('BUS_OUT:')) return parseInt(type.substring(8)) || 0;
|
||||
return baseGateOutputCount(type);
|
||||
}
|
||||
|
||||
function isBusType(type) {
|
||||
return type.startsWith('BUS_IN:') || type.startsWith('BUS_OUT:');
|
||||
}
|
||||
|
||||
function getBusSize(type) {
|
||||
if (type.startsWith('BUS_IN:')) return parseInt(type.substring(7)) || 1;
|
||||
if (type.startsWith('BUS_OUT:')) return parseInt(type.substring(8)) || 1;
|
||||
return 1;
|
||||
}
|
||||
|
||||
export function getComponentWidth(gate) {
|
||||
if (gate.type.startsWith('BUS:')) return 30;
|
||||
if (isBusType(gate.type)) return 30;
|
||||
if (gate.type.startsWith('COMPONENT:')) {
|
||||
const count = Math.max(gate.component?.inputCount || 1, gate.component?.outputCount || 1);
|
||||
return Math.max(120, (count + 1) * 25);
|
||||
@@ -35,8 +47,8 @@ export function getComponentWidth(gate) {
|
||||
}
|
||||
|
||||
export function getComponentHeight(gate) {
|
||||
if (gate.type.startsWith('BUS:')) {
|
||||
const n = parseInt(gate.type.substring(4)) || 1;
|
||||
if (isBusType(gate.type)) {
|
||||
const n = getBusSize(gate.type);
|
||||
return Math.max(40, (n + 1) * 22);
|
||||
}
|
||||
if (gate.type.startsWith('COMPONENT:')) {
|
||||
@@ -49,7 +61,7 @@ export function getComponentHeight(gate) {
|
||||
export function getInputPorts(gate) {
|
||||
const count = gateInputCount(gate.type);
|
||||
const ports = [];
|
||||
const isDynamic = gate.type.startsWith('COMPONENT:') || gate.type.startsWith('BUS:');
|
||||
const isDynamic = gate.type.startsWith('COMPONENT:') || isBusType(gate.type);
|
||||
const gateHeight = isDynamic ? getComponentHeight(gate) : GATE_H;
|
||||
|
||||
for (let i = 0; i < count; i++) {
|
||||
@@ -62,7 +74,7 @@ export function getInputPorts(gate) {
|
||||
export function getOutputPorts(gate) {
|
||||
const count = gateOutputCount(gate.type);
|
||||
const ports = [];
|
||||
const isDynamic = gate.type.startsWith('COMPONENT:') || gate.type.startsWith('BUS:');
|
||||
const isDynamic = gate.type.startsWith('COMPONENT:') || isBusType(gate.type);
|
||||
const gateWidth = isDynamic ? getComponentWidth(gate) : GATE_W;
|
||||
const gateHeight = isDynamic ? getComponentHeight(gate) : GATE_H;
|
||||
|
||||
@@ -112,10 +124,21 @@ function computeGate(gate) {
|
||||
return outputs[0] || 0;
|
||||
}
|
||||
|
||||
// BUS: pass-through, each input maps to corresponding output
|
||||
if (gate.type.startsWith('BUS:')) {
|
||||
gate.outputValues = [...inputs];
|
||||
return inputs[0] || 0;
|
||||
// BUS_IN: collect input values and store them for the paired BUS_OUT
|
||||
if (gate.type.startsWith('BUS_IN:')) {
|
||||
gate.busValues = [...inputs];
|
||||
gate.value = inputs[0] || 0;
|
||||
return gate.value;
|
||||
}
|
||||
|
||||
// BUS_OUT: read values from paired BUS_IN terminal
|
||||
if (gate.type.startsWith('BUS_OUT:')) {
|
||||
const pair = state.gates.find(g => g.id === gate.busPairId);
|
||||
if (pair && pair.busValues) {
|
||||
gate.outputValues = [...pair.busValues];
|
||||
gate.value = gate.outputValues[0] || 0;
|
||||
}
|
||||
return gate.value || 0;
|
||||
}
|
||||
|
||||
switch (gate.type) {
|
||||
@@ -181,7 +204,7 @@ setEvaluateAll(evaluateAll);
|
||||
|
||||
export function findGateAt(x, y) {
|
||||
return state.gates.find(g => {
|
||||
const isDynamic = g.type.startsWith('COMPONENT:') || g.type.startsWith('BUS:');
|
||||
const isDynamic = g.type.startsWith('COMPONENT:') || isBusType(g.type);
|
||||
const w = isDynamic ? getComponentWidth(g) : GATE_W;
|
||||
const h = isDynamic ? getComponentHeight(g) : GATE_H;
|
||||
return x >= g.x && x <= g.x + w && y >= g.y && y <= g.y + h;
|
||||
|
||||
Reference in New Issue
Block a user