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:
@@ -1,4 +1,4 @@
|
||||
'use strict';
|
||||
'use strict';
|
||||
/**
|
||||
* ElectrolysisSim v2 — Электролиз водных растворов
|
||||
* Закон Фарадея: m = M·I·t / (n·F), F = 96485 Кл/моль
|
||||
@@ -539,3 +539,45 @@ class ElectrolysisSim {
|
||||
}
|
||||
|
||||
if (typeof module !== 'undefined') module.exports = ElectrolysisSim;
|
||||
|
||||
/* ─── lab UI init ─────────────────────────────────── */
|
||||
function _openElectrolysis() {
|
||||
document.getElementById('sim-topbar-title').textContent = 'Электролиз';
|
||||
_simShow('sim-electrolysis');
|
||||
_registerSimState('electrolysis', () => elecSim?.getParams(), st => elecSim?.setParams(st));
|
||||
if (_embedMode) _startStateEmit('electrolysis');
|
||||
requestAnimationFrame(() => requestAnimationFrame(() => {
|
||||
if (!elecSim) {
|
||||
elecSim = new ElectrolysisSim(document.getElementById('electrolysis-canvas'));
|
||||
elecSim.onUpdate = _elecUpdateUI;
|
||||
}
|
||||
elecSim.fit();
|
||||
elecSim.reset();
|
||||
elecSim.play();
|
||||
}));
|
||||
}
|
||||
|
||||
function elecParam(name, val) {
|
||||
const v = parseFloat(val);
|
||||
if (name === 'voltage') document.getElementById('elec-V-val').textContent = v;
|
||||
if (elecSim) elecSim.setParams({ [name]: v });
|
||||
}
|
||||
|
||||
function elecPreset(name, btn) {
|
||||
document.querySelectorAll('.elec-type-btn').forEach(b => b.classList.remove('active'));
|
||||
if (btn) btn.classList.add('active');
|
||||
const voltages = { nacl: 6, cuso4: 4, h2so4: 3 };
|
||||
const vt = voltages[name] || 6;
|
||||
document.getElementById('sl-elec-V').value = vt; document.getElementById('elec-V-val').textContent = vt;
|
||||
if (elecSim) { elecSim.setParams({ electrolyte: name, voltage: vt }); elecSim.reset(); elecSim.play(); }
|
||||
}
|
||||
|
||||
function _elecUpdateUI(info) {
|
||||
const v = (id, val) => { const el = document.getElementById(id); if (el) el.textContent = val; };
|
||||
v('elecbar-v1', typeof info.current === 'number' ? info.current.toFixed(2) : '—');
|
||||
v('elecbar-v2', typeof info.massDeposited === 'number' ? info.massDeposited.toFixed(3) + ' г' : '—');
|
||||
v('elecbar-v3', typeof info.gasVolume === 'number' ? info.gasVolume.toFixed(1) : '—');
|
||||
v('elecbar-v4', typeof info.time === 'number' ? info.time.toFixed(0) + ' с' : '—');
|
||||
}
|
||||
|
||||
/* ── waves ── */
|
||||
|
||||
Reference in New Issue
Block a user