refactor: distribute lab-init.js into 34 engine files

lab-init.js: 4098 -> 543 lines (infrastructure + THEORY only)

Each sim's _open*() + UI helpers moved to its engine file:
graph.js, projectile.js, collision.js, magnetic.js, triangle.js,
geometry.js, trigcircle.js, gas.js (molphys), coulomb.js, circuit.js,
reactions.js (chemistry), newton.js (dynamics), chemsandbox.js,
celldivision.js, photosynthesis.js, angrybirds.js, quadratic.js,
normaldist.js, graphtransform.js, pendulum.js, equilibrium.js,
thinlens.js, mirror.js, isoprocess.js, titration.js, refraction.js,
probability.js, bohratom.js, electrolysis.js, waves.js,
crystal.js, orbitals.js, stereo.js, hydrostatics.js

All 34 engine files syntax-checked OK.
This commit is contained in:
Maxim Dolgolyov
2026-05-08 14:54:54 +03:00
parent d5f77bb648
commit ae31e4c4e8
35 changed files with 3657 additions and 3589 deletions
+86 -1
View File
@@ -1,4 +1,4 @@
/**
/**
* CircuitSim — Enhanced Electric Circuits Simulation v2
* MNA solver · L-shape wires · Drag · Undo/Redo · Tooltip
* New: Capacitor · Diode · LED · AC source · Junction dots
@@ -1306,3 +1306,88 @@ class CircuitSim {
if (this.onUpdate) this.onUpdate(this.info());
}
}
/* ─── lab UI init ─────────────────────────────────── */
var cirSim = null;
var reacSim = null;
var flaskSim = null;
function _openCircuit() {
document.getElementById('sim-topbar-title').textContent = 'Электрические цепи';
_simShow('sim-circuit');
_simShow('ctrl-circuit');
requestAnimationFrame(() => requestAnimationFrame(() => {
const canvas = document.getElementById('circuit-canvas');
if (!cirSim) {
cirSim = new CircuitSim(canvas);
cirSim.onUpdate = _circUpdateUI;
cirSim.onModeChange = (mode) => {
document.querySelectorAll('.circ-tool-btn').forEach(b => {
b.classList.toggle('active', b.dataset.tool === mode);
});
document.querySelectorAll('.circ-top-btn').forEach(b => {
b.classList.toggle('active', b.id === 'ctool-' + mode);
});
};
} else {
cirSim.stop();
}
cirSim.fit();
if (cirSim.components.length === 0) cirSim.preset('serial');
cirSim.start();
_circUpdateUI(cirSim.info());
}));
}
function circTool(tool, el) {
if (cirSim) cirSim.addMode = tool;
document.querySelectorAll('.circ-tool-btn').forEach(b => b.classList.toggle('active', b.dataset.tool === tool));
document.querySelectorAll('.circ-top-btn').forEach(b => b.classList.toggle('active', b.id === 'ctool-' + tool));
}
function circPreset(name) {
if (!cirSim) return;
cirSim.preset(name);
}
function circRChange() {
const v = +document.getElementById('sl-circR').value;
document.getElementById('circ-R-val').textContent = v + ' Ω';
if (cirSim) cirSim.R_value = v;
}
function circUChange() {
const v = +document.getElementById('sl-circU').value;
document.getElementById('circ-U-val').textContent = v + ' В';
if (cirSim) cirSim.U_value = v;
}
function circCChange() {
const v = +document.getElementById('sl-circC').value;
document.getElementById('circ-C-val').textContent = v + ' µF';
if (cirSim) cirSim.C_value = v;
}
function circFChange() {
const v = +document.getElementById('sl-circF').value;
document.getElementById('circ-F-val').textContent = v + ' Гц';
if (cirSim) cirSim.acFreq = v;
}
function _circUpdateUI(info) {
if (!info) return;
document.getElementById('cirbar-comps').textContent = info.components;
document.getElementById('cirbar-U').textContent = info.voltage ? info.voltage + ' В' : '—';
document.getElementById('cirbar-I').textContent = info.current ? info.current + ' А' : '—';
document.getElementById('cirbar-P').textContent = info.power ? info.power + ' Вт' : '—';
const st = document.getElementById('cirbar-status');
st.textContent = info.solved ? 'Замкнута' : 'Разомкнута';
st.style.color = info.solved ? '#7BF5A4' : '#EF476F';
}
/* ════════════════════════════════
ХИМИЯ (unified: кинетика + колба + ОВР + ионный обмен)
════════════════════════════════ */
let _chemMode = 'kinetics'; // 'kinetics' | 'flask' | 'redox' | 'ionex'