simple-circuit-engine 0.0.13 → 0.0.14
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/AGENTS.md +7 -5
- package/README.md +8 -8
- package/dist/core/index.js +110 -85
- package/dist/core/setup.d.ts +10 -0
- package/dist/core/simulation/behaviors/index.d.ts +10 -0
- package/dist/core/simulation/behaviors/interface/EightInputBehavior.d.ts +9 -0
- package/dist/core/simulation/behaviors/interface/EightLightBehavior.d.ts +9 -0
- package/dist/core/simulation/behaviors/interface/FourInputBehavior.d.ts +9 -0
- package/dist/core/simulation/behaviors/interface/FourLightBehavior.d.ts +9 -0
- package/dist/core/simulation/behaviors/interface/InputBehaviorMixin.d.ts +37 -0
- package/dist/core/simulation/behaviors/interface/LightBehaviorMixin.d.ts +60 -0
- package/dist/core/simulation/behaviors/interface/OneInputBehavior.d.ts +9 -0
- package/dist/core/simulation/behaviors/interface/OneLightBehavior.d.ts +9 -0
- package/dist/core/simulation/behaviors/interface/TwoInputBehavior.d.ts +9 -0
- package/dist/core/simulation/behaviors/interface/TwoLightBehavior.d.ts +9 -0
- package/dist/core/simulation/behaviors/interface/index.d.ts +0 -0
- package/dist/core/simulation/states/index.d.ts +10 -0
- package/dist/core/simulation/states/interface/EightInputState.d.ts +6 -0
- package/dist/core/simulation/states/interface/EightLightState.d.ts +6 -0
- package/dist/core/simulation/states/interface/FourInputState.d.ts +6 -0
- package/dist/core/simulation/states/interface/FourLightState.d.ts +6 -0
- package/dist/core/simulation/states/interface/InputState.d.ts +45 -0
- package/dist/core/simulation/states/interface/LightState.d.ts +54 -0
- package/dist/core/simulation/states/interface/OneInputState.d.ts +6 -0
- package/dist/core/simulation/states/interface/OneLightState.d.ts +6 -0
- package/dist/core/simulation/states/interface/TwoInputState.d.ts +6 -0
- package/dist/core/simulation/states/interface/TwoLightState.d.ts +6 -0
- package/dist/core/simulation/types.d.ts +9 -1
- package/dist/core/topology/Component.d.ts +4 -0
- package/dist/core/topology/ENode.d.ts +7 -2
- package/dist/core/topology/index.d.ts +2 -0
- package/dist/core/topology/networkTraversal.d.ts +50 -0
- package/dist/core/topology/types.d.ts +13 -2
- package/dist/{core-b6Q8w2sn.js → core-HH6iRWtB.js} +1850 -739
- package/dist/core-HH6iRWtB.js.map +1 -0
- package/dist/i18n/index.d.ts +276 -0
- package/dist/i18n/locales/en.json.d.ts +98 -0
- package/dist/i18n/locales/fr.json.d.ts +98 -0
- package/dist/index.js +172 -135
- package/dist/scene/CircuitEngine.d.ts +36 -4
- package/dist/scene/index.d.ts +6 -2
- package/dist/scene/index.js +62 -50
- package/dist/scene/setup.d.ts +10 -0
- package/dist/scene/shared/AbstractCircuitController.d.ts +5 -3
- package/dist/scene/shared/HoverManager.d.ts +15 -0
- package/dist/scene/shared/components/index.d.ts +10 -0
- package/dist/scene/shared/components/interface/EightInputVisualFactory.d.ts +15 -0
- package/dist/scene/shared/components/interface/EightLightVisualFactory.d.ts +15 -0
- package/dist/scene/shared/components/interface/FourInputVisualFactory.d.ts +15 -0
- package/dist/scene/shared/components/interface/FourLightVisualFactory.d.ts +15 -0
- package/dist/scene/shared/components/interface/InputVisualFactoryBase.d.ts +50 -0
- package/dist/scene/shared/components/interface/LightVisualFactoryBase.d.ts +46 -0
- package/dist/scene/shared/components/interface/OneInputVisualFactory.d.ts +15 -0
- package/dist/scene/shared/components/interface/OneLightVisualFactory.d.ts +15 -0
- package/dist/scene/shared/components/interface/TwoInputVisualFactory.d.ts +15 -0
- package/dist/scene/shared/components/interface/TwoLightVisualFactory.d.ts +15 -0
- package/dist/scene/shared/types.d.ts +34 -2
- package/dist/scene/shared/utils/ControlsUtils.d.ts +1 -1
- package/dist/scene/shared/utils/GeometryUtils.d.ts +35 -0
- package/dist/scene/static/CircuitController.d.ts +12 -1
- package/dist/scene/static/tools/BuildTool.d.ts +77 -0
- package/dist/scene/static/tools/MultiWiringPlacement.d.ts +40 -0
- package/dist/scene/widgets/HelpWidget.d.ts +13 -0
- package/dist/scene/widgets/ModeWidget.d.ts +16 -0
- package/dist/scene/widgets/MultiWiringWidget.d.ts +21 -0
- package/dist/scene/{static → widgets}/PinTooltipWidget.d.ts +2 -1
- package/dist/scene/widgets/SimulationPlayerWidget.d.ts +62 -0
- package/dist/scene/widgets/ToolsWidget.d.ts +18 -0
- package/dist/scene/widgets/WidgetsManager.d.ts +65 -0
- package/dist/scene/widgets/assets/icons.d.ts +20 -0
- package/dist/scene/widgets/index.d.ts +9 -0
- package/dist/scene/widgets/styles.d.ts +33 -0
- package/dist/{scene-D4QcWeiq.js → scene-C1xhdw_B.js} +3311 -1478
- package/dist/scene-C1xhdw_B.js.map +1 -0
- package/package.json +2 -2
- package/dist/core-b6Q8w2sn.js.map +0 -1
- package/dist/scene-D4QcWeiq.js.map +0 -1
package/AGENTS.md
CHANGED
|
@@ -35,15 +35,15 @@ registerGatesComponentsFactories(componentsFactoryRegistry); //... other groups
|
|
|
35
35
|
const behaviorRegistry = registerBasicComponentsBehaviors(new BehaviorRegistry());
|
|
36
36
|
registerGatesComponentsBehaviors(behaviorRegistry); //... other groupsof components if needed
|
|
37
37
|
|
|
38
|
+
// Rendering (must exist before engine.initialize — it binds MapControls to the canvas)
|
|
39
|
+
const renderer = new WebGLRenderer();
|
|
40
|
+
|
|
38
41
|
// Instanciate and Initialize CircuitEngine (it creates and uses a new Circuit by default)
|
|
39
42
|
const engine = new CircuitEngine(componentsFactoryRegistry, behaviorRegistry);
|
|
40
43
|
const container = document.getElementById('canvas-container')!;
|
|
41
|
-
engine.initialize(container, engineOptions());
|
|
44
|
+
engine.initialize(container, renderer, engineOptions());
|
|
42
45
|
// set engine circuit to a new empty circuit
|
|
43
46
|
engine.setCircuit(new Circuit(new CircuitOptions()));
|
|
44
|
-
|
|
45
|
-
// Rendering
|
|
46
|
-
const renderer = new WebGLRenderer();
|
|
47
47
|
const width = window.innerWidth,
|
|
48
48
|
height = window.innerHeight;
|
|
49
49
|
renderer.setSize(container.clientWidth, container.clientHeight);
|
|
@@ -121,8 +121,10 @@ animate();
|
|
|
121
121
|
### Initialize Engine
|
|
122
122
|
|
|
123
123
|
```typescript
|
|
124
|
+
const renderer = new WebGLRenderer();
|
|
124
125
|
const engine = new CircuitEngine(factoryRegistry, behaviorRegistry);
|
|
125
|
-
engine.initialize(container, engineOptions());
|
|
126
|
+
engine.initialize(container, renderer, engineOptions());
|
|
127
|
+
container.appendChild(renderer.domElement);
|
|
126
128
|
engine.setCircuit(new Circuit());
|
|
127
129
|
|
|
128
130
|
// Add Component Programmatically
|
package/README.md
CHANGED
|
@@ -44,21 +44,21 @@ const componentsFactoryRegistry = registerBasicComponentsFactories(new GroupedFa
|
|
|
44
44
|
// Create behavior registry with basic components behaviors (for simulation)
|
|
45
45
|
const behaviorRegistry = registerBasicComponentsBehaviors(new BehaviorRegistry());
|
|
46
46
|
|
|
47
|
+
// Create and setup WebGL renderer (must exist before engine.initialize — it binds MapControls to the canvas)
|
|
48
|
+
const renderer = new WebGLRenderer({ antialias: true, alpha: false });
|
|
49
|
+
renderer.setClearColor(0x1a1a2e);
|
|
50
|
+
const container = document.getElementById('canva-container')!;
|
|
51
|
+
renderer.setSize(container.clientWidth, container.clientHeight);
|
|
52
|
+
renderer.setPixelRatio(Math.min(window.devicePixelRatio, 2));
|
|
53
|
+
|
|
47
54
|
// Initialize CircuitEngine
|
|
48
55
|
// It creates THREE.js scene, camera, controls, lights, etc
|
|
49
56
|
// and the interactive controllers (edit and simulation) of simple-circuit-engine
|
|
50
|
-
const container = document.getElementById('canva-container')!;
|
|
51
57
|
const engine = new CircuitEngine(componentsFactoryRegistry, behaviorRegistry);
|
|
52
|
-
engine.initialize(container, engineOptions());
|
|
58
|
+
engine.initialize(container, renderer, engineOptions());
|
|
53
59
|
// set engine circuit to a new empty circuit
|
|
54
60
|
engine.setCircuit(new Circuit(new CircuitOptions()));
|
|
55
61
|
|
|
56
|
-
// Create and setup WebGL renderer
|
|
57
|
-
const renderer = new WebGLRenderer({ antialias: true, alpha: false });
|
|
58
|
-
renderer.setClearColor(0x1a1a2e);
|
|
59
|
-
const width = window.innerWidth, height = window.innerHeight;
|
|
60
|
-
renderer.setSize(container.clientWidth, container.clientHeight);
|
|
61
|
-
renderer.setPixelRatio(Math.min(window.devicePixelRatio, 2));
|
|
62
62
|
// Append renderer to DOM
|
|
63
63
|
container.appendChild(renderer.domElement);
|
|
64
64
|
|
package/dist/core/index.js
CHANGED
|
@@ -1,87 +1,112 @@
|
|
|
1
|
-
import { $ as t, A as
|
|
1
|
+
import { $ as a, $t as e, A as s, At as i, B as o, Bt as r, C as n, Ct as h, D as S, Dt as B, E as v, Et as p, F as g, Ft as u, G as c, Gt as d, H as E, Ht as I, I as L, It as l, J as m, Jt as G, K as T, Kt as C, L as N, Lt as A, M as D, Mt as O, N as y, Nt as R, O as f, Ot as F, P as M, Pt as P, Q as w, Qt as _, R as b, Rt as U, S as X, St as x, T as k, Tt as W, U as z, Ut as H, V as Y, Vt as Q, W as V, Wt as j, X as q, Xt as J, Y as K, Yt as Z, Z as $, Zt as tt, _ as at, _t as et, a as st, at as it, b as ot, bt as rt, c as nt, ct as ht, d as St, dt as Bt, en as vt, et as pt, f as gt, ft as ut, g as ct, gt as dt, h as Et, ht as It, i as Lt, it as lt, j as mt, jt as Gt, k as Tt, kt as Ct, l as Nt, lt as At, m as Dt, mt as Ot, n as yt, nt as Rt, o as ft, ot as Ft, p as Mt, pt as Pt, q as wt, qt as _t, r as bt, rt as Ut, s as Xt, st as xt, t as kt, tn as Wt, tt as zt, u as Ht, ut as Yt, v as Qt, vt as Vt, w as jt, wt as qt, x as Jt, xt as Kt, y as Zt, yt as $t, z as ta, zt as aa } from "../core-HH6iRWtB.js";
|
|
2
2
|
export {
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
3
|
+
r as ALL_LOGIC_FAMILIES,
|
|
4
|
+
Jt as AdderBehavior,
|
|
5
|
+
zt as AdderState,
|
|
6
|
+
Ut as ArithmeticState,
|
|
7
|
+
o as BatteryBehavior,
|
|
8
|
+
Kt as BatteryState,
|
|
9
|
+
E as BehaviorRegistry,
|
|
10
|
+
Q as CIRCUIT_FILE_VERSION,
|
|
11
|
+
I as COMPONENT_TYPE_METADATA,
|
|
12
|
+
_ as CameraOptions,
|
|
13
|
+
Gt as Circuit,
|
|
14
|
+
u as CircuitMetadata,
|
|
15
|
+
l as CircuitOptions,
|
|
16
|
+
st as CircuitRunner,
|
|
17
|
+
y as ClockBehavior,
|
|
18
|
+
Ot as ClockState,
|
|
19
|
+
A as Component,
|
|
20
|
+
x as ComponentState,
|
|
21
|
+
H as ComponentType,
|
|
22
|
+
j as DEFAULT_LOGIC_FAMILY,
|
|
23
|
+
Xt as DirtyTracker,
|
|
24
|
+
M as DoubleThrowSwitchBehavior,
|
|
25
|
+
It as DoubleThrowSwitchState,
|
|
26
|
+
aa as ENode,
|
|
27
|
+
d as ENodeSourceType,
|
|
28
|
+
C as ENodeType,
|
|
29
|
+
ot as EightBitAdderBehavior,
|
|
30
|
+
pt as EightBitAdderState,
|
|
31
|
+
Zt as EightBitOnesComplementBehavior,
|
|
32
|
+
a as EightBitOnesComplementState,
|
|
33
|
+
Dt as EightInputBehavior,
|
|
34
|
+
m as EightInputState,
|
|
35
|
+
Nt as EightLightBehavior,
|
|
36
|
+
z as EightLightState,
|
|
37
|
+
nt as EventQueue,
|
|
38
|
+
Et as FourInputBehavior,
|
|
39
|
+
K as FourInputState,
|
|
40
|
+
Ht as FourLightBehavior,
|
|
41
|
+
V as FourLightState,
|
|
42
|
+
X as HalfAdderBehavior,
|
|
43
|
+
Rt as HalfAdderState,
|
|
44
|
+
Qt as InputBehaviorMixin,
|
|
45
|
+
w as InputState,
|
|
46
|
+
D as InverterBehavior,
|
|
47
|
+
Pt as InverterState,
|
|
48
|
+
Mt as LightBehaviorMixin,
|
|
49
|
+
wt as LightState,
|
|
50
|
+
ta as LightbulbBehavior,
|
|
51
|
+
rt as LightbulbState,
|
|
52
|
+
vt as Memoize,
|
|
53
|
+
Wt as MemoizeExpiring,
|
|
54
|
+
s as Nand4GateBehavior,
|
|
55
|
+
Bt as Nand4GateState,
|
|
56
|
+
Tt as Nand8GateBehavior,
|
|
57
|
+
Yt as Nand8GateState,
|
|
58
|
+
mt as NandGateBehavior,
|
|
59
|
+
ut as NandGateState,
|
|
60
|
+
S as Nor4GateBehavior,
|
|
61
|
+
ht as Nor4GateState,
|
|
62
|
+
v as Nor8GateBehavior,
|
|
63
|
+
xt as Nor8GateState,
|
|
64
|
+
f as NorGateBehavior,
|
|
65
|
+
At as NorGateState,
|
|
66
|
+
at as OneInputBehavior,
|
|
67
|
+
$ as OneInputState,
|
|
68
|
+
gt as OneLightBehavior,
|
|
69
|
+
T as OneLightState,
|
|
70
|
+
Z as Position,
|
|
71
|
+
e as Position3D,
|
|
72
|
+
b as RectangleLEDBehavior,
|
|
73
|
+
Vt as RectangleLEDState,
|
|
74
|
+
N as RelayBehavior,
|
|
75
|
+
et as RelayState,
|
|
76
|
+
G as Rotation,
|
|
77
|
+
W as SIMULATION_SPEED,
|
|
78
|
+
h as SimulationState,
|
|
79
|
+
L as SmallLEDBehavior,
|
|
80
|
+
$t as SmallLEDState,
|
|
81
|
+
ft as StateManager,
|
|
82
|
+
g as SwitchBehavior,
|
|
83
|
+
dt as SwitchState,
|
|
84
|
+
p as TRANSITION_DEFAULTS,
|
|
85
|
+
ct as TwoInputBehavior,
|
|
86
|
+
q as TwoInputState,
|
|
87
|
+
St as TwoLightBehavior,
|
|
88
|
+
c as TwoLightState,
|
|
89
|
+
U as Wire,
|
|
90
|
+
jt as Xor4GateBehavior,
|
|
91
|
+
it as Xor4GateState,
|
|
92
|
+
n as Xor8GateBehavior,
|
|
93
|
+
lt as Xor8GateState,
|
|
94
|
+
k as XorGateBehavior,
|
|
95
|
+
Ft as XorGateState,
|
|
96
|
+
O as classifyGate,
|
|
97
|
+
R as computeGateDelay,
|
|
98
|
+
P as computeTransitionSpan,
|
|
99
|
+
B as findBpsAtLogicDistance,
|
|
100
|
+
F as findBpsAtLogicDistanceWithPath,
|
|
101
|
+
Ct as findPinsReachableFromBp,
|
|
102
|
+
i as findPinsReachableFromBpWithPath,
|
|
103
|
+
J as findPositionBestIndex,
|
|
104
|
+
_t as generateUUID,
|
|
105
|
+
Y as getTransitionSpan,
|
|
106
|
+
kt as registerArithmeticComponentsBehaviors,
|
|
107
|
+
yt as registerBasicComponentsBehaviors,
|
|
108
|
+
bt as registerGatesComponentsBehaviors,
|
|
109
|
+
Lt as registerInterfaceComponentsBehaviors,
|
|
110
|
+
tt as simplifyPositions,
|
|
111
|
+
qt as unionElectricalStates
|
|
87
112
|
};
|
package/dist/core/setup.d.ts
CHANGED
|
@@ -23,3 +23,13 @@ export declare function registerGatesComponentsBehaviors(registry: BehaviorRegis
|
|
|
23
23
|
* @return the input behavior registry for chaining
|
|
24
24
|
*/
|
|
25
25
|
export declare function registerArithmeticComponentsBehaviors(registry: BehaviorRegistry): BehaviorRegistry;
|
|
26
|
+
/**
|
|
27
|
+
* Register all interface component behaviors in the given registry.
|
|
28
|
+
* Interface components are:
|
|
29
|
+
* - inputs: OneInput, TwoInput, FourInput, EightInput
|
|
30
|
+
* - lights: OneLight, TwoLight, FourLight, EightLight
|
|
31
|
+
* @public
|
|
32
|
+
* @param registry
|
|
33
|
+
* @return the input behavior registry for chaining
|
|
34
|
+
*/
|
|
35
|
+
export declare function registerInterfaceComponentsBehaviors(registry: BehaviorRegistry): BehaviorRegistry;
|
|
@@ -26,3 +26,13 @@ export { HalfAdderBehavior } from './arithmetic/HalfAdderBehavior';
|
|
|
26
26
|
export { AdderBehavior } from './arithmetic/AdderBehavior';
|
|
27
27
|
export { EightBitAdderBehavior } from './arithmetic/EightBitAdderBehavior';
|
|
28
28
|
export { EightBitOnesComplementBehavior } from './arithmetic/EightBitOnesComplementBehavior';
|
|
29
|
+
export { InputBehaviorMixin } from './interface/InputBehaviorMixin';
|
|
30
|
+
export { OneInputBehavior } from './interface/OneInputBehavior';
|
|
31
|
+
export { TwoInputBehavior } from './interface/TwoInputBehavior';
|
|
32
|
+
export { FourInputBehavior } from './interface/FourInputBehavior';
|
|
33
|
+
export { EightInputBehavior } from './interface/EightInputBehavior';
|
|
34
|
+
export { LightBehaviorMixin } from './interface/LightBehaviorMixin';
|
|
35
|
+
export { OneLightBehavior } from './interface/OneLightBehavior';
|
|
36
|
+
export { TwoLightBehavior } from './interface/TwoLightBehavior';
|
|
37
|
+
export { FourLightBehavior } from './interface/FourLightBehavior';
|
|
38
|
+
export { EightLightBehavior } from './interface/EightLightBehavior';
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { Component } from '../../../topology/Component';
|
|
2
|
+
import { ComponentState } from '../../states/ComponentState';
|
|
3
|
+
import { IComponentBehavior } from '../types';
|
|
4
|
+
import { InputBehaviorMixin } from './InputBehaviorMixin';
|
|
5
|
+
/** Eight-switch user input. See {@link InputBehaviorMixin}. */
|
|
6
|
+
export declare class EightInputBehavior extends InputBehaviorMixin implements IComponentBehavior {
|
|
7
|
+
constructor();
|
|
8
|
+
createInitialState(component: Component): ComponentState;
|
|
9
|
+
}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { Component } from '../../../topology/Component';
|
|
2
|
+
import { ComponentState } from '../../states/ComponentState';
|
|
3
|
+
import { IComponentBehavior } from '../types';
|
|
4
|
+
import { LightBehaviorMixin } from './LightBehaviorMixin';
|
|
5
|
+
/** Eight-light input mirror. See {@link LightBehaviorMixin}. */
|
|
6
|
+
export declare class EightLightBehavior extends LightBehaviorMixin implements IComponentBehavior {
|
|
7
|
+
constructor();
|
|
8
|
+
createInitialState(component: Component): ComponentState;
|
|
9
|
+
}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { Component } from '../../../topology/Component';
|
|
2
|
+
import { ComponentState } from '../../states/ComponentState';
|
|
3
|
+
import { IComponentBehavior } from '../types';
|
|
4
|
+
import { InputBehaviorMixin } from './InputBehaviorMixin';
|
|
5
|
+
/** Four-switch user input. See {@link InputBehaviorMixin}. */
|
|
6
|
+
export declare class FourInputBehavior extends InputBehaviorMixin implements IComponentBehavior {
|
|
7
|
+
constructor();
|
|
8
|
+
createInitialState(component: Component): ComponentState;
|
|
9
|
+
}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { Component } from '../../../topology/Component';
|
|
2
|
+
import { ComponentState } from '../../states/ComponentState';
|
|
3
|
+
import { IComponentBehavior } from '../types';
|
|
4
|
+
import { LightBehaviorMixin } from './LightBehaviorMixin';
|
|
5
|
+
/** Four-light input mirror. See {@link LightBehaviorMixin}. */
|
|
6
|
+
export declare class FourLightBehavior extends LightBehaviorMixin implements IComponentBehavior {
|
|
7
|
+
constructor();
|
|
8
|
+
createInitialState(component: Component): ComponentState;
|
|
9
|
+
}
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
import { Component } from '../../../topology/Component';
|
|
2
|
+
import { ComponentState } from '../../states/ComponentState';
|
|
3
|
+
import { INodeElectricalState } from '../../states/types';
|
|
4
|
+
import { UUID } from '../../../utils/types';
|
|
5
|
+
import { ENodeSourceType } from '../../../topology/types';
|
|
6
|
+
import { IScheduledEvent, IUserCommand } from '../../types';
|
|
7
|
+
import { IBehaviorResult } from '../types';
|
|
8
|
+
import { ComponentBehaviorMixin } from '../ComponentBehavior';
|
|
9
|
+
/**
|
|
10
|
+
* Factorises the plumbing shared by `OneInput`, `TwoInput`, `FourInput` and
|
|
11
|
+
* `EightInput` behaviors.
|
|
12
|
+
*
|
|
13
|
+
* These components only react to user actions (`toggle_input` commands) — they
|
|
14
|
+
* have no logic inputs. The state encodes the current outputs as a hex value
|
|
15
|
+
* (e.g. `'5'` = `0101` for FourInput); while at least one switch is moving the
|
|
16
|
+
* state literal is `'moving'` and a parameter map tracks each pending switch
|
|
17
|
+
* (`${index}` → `${target}-${startTick}-${endTick}`) plus the actual driving
|
|
18
|
+
* value in `prevState`.
|
|
19
|
+
*
|
|
20
|
+
* Concurrency model:
|
|
21
|
+
* - Toggling a different switch while another is still moving simply adds a
|
|
22
|
+
* new pending entry — both transitions resolve independently. No
|
|
23
|
+
* `shouldCancelPending`.
|
|
24
|
+
* - Toggling the *same* switch a second time is debounced (the second command
|
|
25
|
+
* is silently ignored).
|
|
26
|
+
* - Vcc loss collapses the state to `allLowState` and clears all pending
|
|
27
|
+
* transitions.
|
|
28
|
+
*
|
|
29
|
+
* @public
|
|
30
|
+
*/
|
|
31
|
+
export declare abstract class InputBehaviorMixin extends ComponentBehaviorMixin {
|
|
32
|
+
onPinsChange(component: Component, state: ComponentState, nodeStates: ReadonlyMap<UUID, INodeElectricalState>, targetTick: number): IBehaviorResult;
|
|
33
|
+
onUserCommand(component: Component, state: ComponentState, command: IUserCommand): IBehaviorResult;
|
|
34
|
+
onEventFiring(_component: Component, state: ComponentState, event: IScheduledEvent): IBehaviorResult;
|
|
35
|
+
allowConductivity(component: Component, state: ComponentState, _conductivityType: ENodeSourceType, pinId: string, otherPinId: string): boolean;
|
|
36
|
+
protected noChange(state: ComponentState): IBehaviorResult;
|
|
37
|
+
}
|
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
import { Component } from '../../../topology/Component';
|
|
2
|
+
import { ComponentState } from '../../states/ComponentState';
|
|
3
|
+
import { INodeElectricalState } from '../../states/types';
|
|
4
|
+
import { UUID } from '../../../utils/types';
|
|
5
|
+
import { ENodeSourceType } from '../../../topology/types';
|
|
6
|
+
import { IScheduledEvent } from '../../types';
|
|
7
|
+
import { IBehaviorResult } from '../types';
|
|
8
|
+
import { ComponentBehaviorMixin } from '../ComponentBehavior';
|
|
9
|
+
import { LightState } from '../../states/interface/LightState';
|
|
10
|
+
/**
|
|
11
|
+
* Factorises the plumbing shared by `OneLight`, `TwoLight`, `FourLight` and
|
|
12
|
+
* `EightLight` behaviors.
|
|
13
|
+
*
|
|
14
|
+
* These components mirror their `input-i` pins onto matching `output-i` pins
|
|
15
|
+
* with a per-light `transitionSpan` delay. The state encodes the current
|
|
16
|
+
* outputs as a hex value (e.g. `'5'` = `0101` for FourLight); while at least
|
|
17
|
+
* one light is moving the state literal is `'moving'` and a parameter map
|
|
18
|
+
* tracks each pending light (`${index}` → `${target}-${startTick}-${endTick}`)
|
|
19
|
+
* plus the actual driving value in `prevState`.
|
|
20
|
+
*
|
|
21
|
+
* Guards (run first in `onPinsChange`):
|
|
22
|
+
* - Vcc loss collapses the state to `allLowState` and clears all pending.
|
|
23
|
+
* - Any ill-defined logic input switches the state to `'indeterminate'`.
|
|
24
|
+
*
|
|
25
|
+
* Concurrency model (per-light, independent transitions):
|
|
26
|
+
* - When an input changes, the target output bit is recomputed; if it differs
|
|
27
|
+
* from the currently-driving (or already-pending) target a `lightChanged`
|
|
28
|
+
* event is scheduled with a per-light span.
|
|
29
|
+
* - If the same input toggles while its light is still moving, the symmetric
|
|
30
|
+
* transition pattern shortens the new span to `Math.max(prevEnd - prevStart, 1)`
|
|
31
|
+
* and the in-flight event becomes a no-op (its readyAtTick no longer matches
|
|
32
|
+
* the pending entry).
|
|
33
|
+
* - `shouldCancelPending: false` outside guards — other lights' transitions
|
|
34
|
+
* keep their schedule.
|
|
35
|
+
*
|
|
36
|
+
* @public
|
|
37
|
+
*/
|
|
38
|
+
export declare abstract class LightBehaviorMixin extends ComponentBehaviorMixin {
|
|
39
|
+
onPinsChange(component: Component, state: ComponentState, nodeStates: ReadonlyMap<UUID, INodeElectricalState>, targetTick: number): IBehaviorResult;
|
|
40
|
+
onEventFiring(_component: Component, state: ComponentState, event: IScheduledEvent): IBehaviorResult;
|
|
41
|
+
allowConductivity(component: Component, state: ComponentState, _conductivityType: ENodeSourceType, pinId: string, otherPinId: string): boolean;
|
|
42
|
+
/**
|
|
43
|
+
* On vcc loss: drop all outputs low immediately and clear any pending
|
|
44
|
+
* transitions. Returns `null` when vcc is present so callers can proceed.
|
|
45
|
+
*/
|
|
46
|
+
protected vccGuardBehavior(state: LightState, pinStates: Map<string, INodeElectricalState>, targetTick: number): IBehaviorResult | null;
|
|
47
|
+
/**
|
|
48
|
+
* Scan all logic inputs; if any is ill-defined (both voltage and ground, or
|
|
49
|
+
* neither), switch to `'indeterminate'` immediately and clear any pending
|
|
50
|
+
* transitions. Otherwise returns `null` so the caller can proceed.
|
|
51
|
+
*/
|
|
52
|
+
protected nonLogicInputGuardBehavior(state: LightState, pinStates: Map<string, INodeElectricalState>, targetTick: number): IBehaviorResult | null;
|
|
53
|
+
/**
|
|
54
|
+
* For each logic input, compute the desired output bit and schedule a
|
|
55
|
+
* per-light `lightChanged` event whenever that bit differs from the current
|
|
56
|
+
* effective (or already-pending) target.
|
|
57
|
+
*/
|
|
58
|
+
protected scheduleInputTransitions(component: Component, state: LightState, pinStates: Map<string, INodeElectricalState>, targetTick: number): IBehaviorResult;
|
|
59
|
+
protected noChange(state: ComponentState): IBehaviorResult;
|
|
60
|
+
}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { Component } from '../../../topology/Component';
|
|
2
|
+
import { ComponentState } from '../../states/ComponentState';
|
|
3
|
+
import { IComponentBehavior } from '../types';
|
|
4
|
+
import { InputBehaviorMixin } from './InputBehaviorMixin';
|
|
5
|
+
/** Single-switch user input. See {@link InputBehaviorMixin}. */
|
|
6
|
+
export declare class OneInputBehavior extends InputBehaviorMixin implements IComponentBehavior {
|
|
7
|
+
constructor();
|
|
8
|
+
createInitialState(component: Component): ComponentState;
|
|
9
|
+
}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { Component } from '../../../topology/Component';
|
|
2
|
+
import { ComponentState } from '../../states/ComponentState';
|
|
3
|
+
import { IComponentBehavior } from '../types';
|
|
4
|
+
import { LightBehaviorMixin } from './LightBehaviorMixin';
|
|
5
|
+
/** Single-light input mirror. See {@link LightBehaviorMixin}. */
|
|
6
|
+
export declare class OneLightBehavior extends LightBehaviorMixin implements IComponentBehavior {
|
|
7
|
+
constructor();
|
|
8
|
+
createInitialState(component: Component): ComponentState;
|
|
9
|
+
}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { Component } from '../../../topology/Component';
|
|
2
|
+
import { ComponentState } from '../../states/ComponentState';
|
|
3
|
+
import { IComponentBehavior } from '../types';
|
|
4
|
+
import { InputBehaviorMixin } from './InputBehaviorMixin';
|
|
5
|
+
/** Two-switch user input. See {@link InputBehaviorMixin}. */
|
|
6
|
+
export declare class TwoInputBehavior extends InputBehaviorMixin implements IComponentBehavior {
|
|
7
|
+
constructor();
|
|
8
|
+
createInitialState(component: Component): ComponentState;
|
|
9
|
+
}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { Component } from '../../../topology/Component';
|
|
2
|
+
import { ComponentState } from '../../states/ComponentState';
|
|
3
|
+
import { IComponentBehavior } from '../types';
|
|
4
|
+
import { LightBehaviorMixin } from './LightBehaviorMixin';
|
|
5
|
+
/** Two-light input mirror. See {@link LightBehaviorMixin}. */
|
|
6
|
+
export declare class TwoLightBehavior extends LightBehaviorMixin implements IComponentBehavior {
|
|
7
|
+
constructor();
|
|
8
|
+
createInitialState(component: Component): ComponentState;
|
|
9
|
+
}
|
|
File without changes
|
|
@@ -29,3 +29,13 @@ export { HalfAdderState } from './arithmetic/HalfAdderState';
|
|
|
29
29
|
export { AdderState } from './arithmetic/AdderState';
|
|
30
30
|
export { EightBitAdderState } from './arithmetic/EightBitAdderState';
|
|
31
31
|
export { EightBitOnesComplementState } from './arithmetic/EightBitOnesComplementState';
|
|
32
|
+
export { InputState } from './interface/InputState';
|
|
33
|
+
export { OneInputState } from './interface/OneInputState';
|
|
34
|
+
export { TwoInputState } from './interface/TwoInputState';
|
|
35
|
+
export { FourInputState } from './interface/FourInputState';
|
|
36
|
+
export { EightInputState } from './interface/EightInputState';
|
|
37
|
+
export { LightState } from './interface/LightState';
|
|
38
|
+
export { OneLightState } from './interface/OneLightState';
|
|
39
|
+
export { TwoLightState } from './interface/TwoLightState';
|
|
40
|
+
export { FourLightState } from './interface/FourLightState';
|
|
41
|
+
export { EightLightState } from './interface/EightLightState';
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import { UUID } from '../../../utils/types';
|
|
2
|
+
import { InputState } from './InputState';
|
|
3
|
+
/** Eight-switch user input. Stable states `'00'`..`'ff'`. */
|
|
4
|
+
export declare class EightInputState extends InputState {
|
|
5
|
+
constructor(componentId: UUID, initialState?: string);
|
|
6
|
+
}
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import { UUID } from '../../../utils/types';
|
|
2
|
+
import { LightState } from './LightState';
|
|
3
|
+
/** Eight-light input mirror. Stable states `'00'`–`'ff'`. */
|
|
4
|
+
export declare class EightLightState extends LightState {
|
|
5
|
+
constructor(componentId: UUID, initialState?: string);
|
|
6
|
+
}
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import { UUID } from '../../../utils/types';
|
|
2
|
+
import { InputState } from './InputState';
|
|
3
|
+
/** Four-switch user input. Stable states `'0'`..`'f'`. */
|
|
4
|
+
export declare class FourInputState extends InputState {
|
|
5
|
+
constructor(componentId: UUID, initialState?: string);
|
|
6
|
+
}
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import { UUID } from '../../../utils/types';
|
|
2
|
+
import { LightState } from './LightState';
|
|
3
|
+
/** Four-light input mirror. Stable states `'0'`–`'f'`. */
|
|
4
|
+
export declare class FourLightState extends LightState {
|
|
5
|
+
constructor(componentId: UUID, initialState?: string);
|
|
6
|
+
}
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
import { UUID } from '../../../utils/types';
|
|
2
|
+
import { ComponentState } from '../ComponentState';
|
|
3
|
+
/**
|
|
4
|
+
* Base simulation state for user-controlled input components (OneInput,
|
|
5
|
+
* TwoInput, FourInput, EightInput).
|
|
6
|
+
*
|
|
7
|
+
* Stable states are encoded as a zero-padded hexadecimal string where each
|
|
8
|
+
* bit position maps to one logic output (bit `i` ↔ `output-i`).
|
|
9
|
+
*
|
|
10
|
+
* While at least one switch is moving, the state value is the literal
|
|
11
|
+
* `'moving'` and the `parameters` map carries:
|
|
12
|
+
* - `prevState`: the stable hex value the outputs are still energizing
|
|
13
|
+
* - one entry per pending switch keyed by its index, encoded as
|
|
14
|
+
* `${target}-${startTick}-${endTick}` (target ∈ {0,1}).
|
|
15
|
+
*
|
|
16
|
+
* @public
|
|
17
|
+
*/
|
|
18
|
+
export declare abstract class InputState extends ComponentState {
|
|
19
|
+
/** Number of logic outputs (1, 2, 4 or 8). */
|
|
20
|
+
readonly outputCount: number;
|
|
21
|
+
/** Number of hex digits needed to encode all outputs. */
|
|
22
|
+
readonly hexDigitCount: number;
|
|
23
|
+
/** All-outputs-low state string (e.g. `'0'` for 1–4 outputs, `'00'` for 8). */
|
|
24
|
+
readonly allLowState: string;
|
|
25
|
+
protected constructor(componentId: UUID, outputCount: number, initialState: string);
|
|
26
|
+
/** True while at least one switch is mid-transition. */
|
|
27
|
+
get isInTransition(): boolean;
|
|
28
|
+
/**
|
|
29
|
+
* Stable state that effectively drives the outputs right now:
|
|
30
|
+
* - stable state → returns that state
|
|
31
|
+
* - `'moving'` → returns the previous stable kept in `parameters.prevState`
|
|
32
|
+
*/
|
|
33
|
+
get effectiveState(): string;
|
|
34
|
+
/** Whether output `index` is high in the current effective state. */
|
|
35
|
+
isOutputHigh(index: number): boolean;
|
|
36
|
+
/**
|
|
37
|
+
* Pending move descriptor for switch `index`, parsed from the parameter map,
|
|
38
|
+
* or `null` when no transition is in flight for that switch.
|
|
39
|
+
*/
|
|
40
|
+
getPendingMove(index: number): {
|
|
41
|
+
target: 0 | 1;
|
|
42
|
+
startTick: number;
|
|
43
|
+
endTick: number;
|
|
44
|
+
} | null;
|
|
45
|
+
}
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
import { UUID } from '../../../utils/types';
|
|
2
|
+
import { ComponentState } from '../ComponentState';
|
|
3
|
+
/**
|
|
4
|
+
* Base simulation state for input-driven multi-light components (OneLight,
|
|
5
|
+
* TwoLight, FourLight, EightLight).
|
|
6
|
+
*
|
|
7
|
+
* Stable states are encoded as a zero-padded hexadecimal string where each
|
|
8
|
+
* bit position maps to one logic output (bit `i` ↔ `output-i`). Outputs
|
|
9
|
+
* mirror their corresponding `input-i` after `transitionSpan` ticks so the
|
|
10
|
+
* component can be cascaded.
|
|
11
|
+
*
|
|
12
|
+
* While at least one light is moving, the state value is the literal
|
|
13
|
+
* `'moving'` and the `parameters` map carries:
|
|
14
|
+
* - `prevState`: the stable hex value the outputs are still energizing
|
|
15
|
+
* - one entry per pending light keyed by its index, encoded as
|
|
16
|
+
* `${target}-${startTick}-${endTick}` (target ∈ {0,1}).
|
|
17
|
+
*
|
|
18
|
+
* A special `'indeterminate'` state is used when any logic input is
|
|
19
|
+
* ill-defined (set immediately by the non-logic-input guard).
|
|
20
|
+
*
|
|
21
|
+
* @public
|
|
22
|
+
*/
|
|
23
|
+
export declare abstract class LightState extends ComponentState {
|
|
24
|
+
/** Number of lights / logic outputs (1, 2, 4 or 8). */
|
|
25
|
+
readonly lightCount: number;
|
|
26
|
+
/** Number of hex digits needed to encode all outputs. */
|
|
27
|
+
readonly hexDigitCount: number;
|
|
28
|
+
/** All-outputs-low state string (e.g. `'0'` for 1–4 lights, `'00'` for 8). */
|
|
29
|
+
readonly allLowState: string;
|
|
30
|
+
protected constructor(componentId: UUID, lightCount: number, initialState: string);
|
|
31
|
+
/** True while at least one light is mid-transition. */
|
|
32
|
+
get isInTransition(): boolean;
|
|
33
|
+
/**
|
|
34
|
+
* Stable state that effectively drives the outputs right now:
|
|
35
|
+
* - stable hex state → returns that state
|
|
36
|
+
* - `'moving'` → returns the previous stable kept in `parameters.prevState`
|
|
37
|
+
* - `'indeterminate'` → returns `'indeterminate'`
|
|
38
|
+
*/
|
|
39
|
+
get effectiveState(): string;
|
|
40
|
+
/**
|
|
41
|
+
* Whether output `index` is high in the current effective state.
|
|
42
|
+
* Returns `false` when effective state is `'indeterminate'`.
|
|
43
|
+
*/
|
|
44
|
+
isOutputHigh(index: number): boolean;
|
|
45
|
+
/**
|
|
46
|
+
* Pending move descriptor for light `index`, parsed from the parameter map,
|
|
47
|
+
* or `null` when no transition is in flight for that light.
|
|
48
|
+
*/
|
|
49
|
+
getPendingMove(index: number): {
|
|
50
|
+
target: 0 | 1;
|
|
51
|
+
startTick: number;
|
|
52
|
+
endTick: number;
|
|
53
|
+
} | null;
|
|
54
|
+
}
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import { UUID } from '../../../utils/types';
|
|
2
|
+
import { InputState } from './InputState';
|
|
3
|
+
/** Single-switch user input. Stable states `'0'` and `'1'`. */
|
|
4
|
+
export declare class OneInputState extends InputState {
|
|
5
|
+
constructor(componentId: UUID, initialState?: string);
|
|
6
|
+
}
|