diff options
author | sanine <sanine.not@pm.me> | 2024-07-06 01:12:53 -0500 |
---|---|---|
committer | sanine <sanine.not@pm.me> | 2024-07-06 01:12:53 -0500 |
commit | 71a61ed1c3929f9d4cb615cf691bb980a8005c9e (patch) | |
tree | 5d0ae2a9b1cd32546ce978b21369a2f12fa0088f /level.js | |
parent | 9b2bed395c82bc1644ef86a096f33b876358af40 (diff) |
fix console errors when changing expressions
Diffstat (limited to 'level.js')
-rw-r--r-- | level.js | 18 |
1 files changed, 13 insertions, 5 deletions
@@ -55,7 +55,9 @@ export function setupLevelUi(level, root, audio) { ui.xeq = document.createElement('input'); ui.xeq.value = X_START; ui.xeq.onchange = (e) => { - level.equations.x = math.compile(e.target.value); + try { + level.equations.x = math.compile(e.target.value); + } catch(err) { } level.running = false; level.path = computePath(level.equations); render(ui.ctx, level, 0); @@ -66,7 +68,9 @@ export function setupLevelUi(level, root, audio) { ui.yeq = document.createElement('input'); ui.yeq.value = Y_START; ui.yeq.onchange = (e) => { - level.equations.y = math.compile(e.target.value); + try { + level.equations.y = math.compile(e.target.value); + } catch(err) { } level.running = false; level.path = computePath(level.equations); render(ui.ctx, level, 0); @@ -74,7 +78,7 @@ export function setupLevelUi(level, root, audio) { ui.yeq.onkeydown = ui.yeq.onchange; ui.yeq.onkeyup = ui.yeq.onchange; - ui.message = document.createElement('h1'); + ui.message = document.createElement('div'); ui.id = "level-message"; root.appendChild(ui.launchButton); @@ -128,8 +132,12 @@ function stepLevel(ui, level, index) { function computePath(equations, start, end, step) { - const ts = [...Array(Math.floor((PATH_LEN)/PATH_STEP)).keys()].map(k => PATH_STEP * k); - return ts.map(t => [ equations.x.eval({t}), equations.y.eval({t}) ]); + try { + const ts = [...Array(Math.floor((PATH_LEN)/PATH_STEP)).keys()].map(k => PATH_STEP * k); + return ts.map(t => [ equations.x.eval({t}), equations.y.eval({t}) ]); + } catch (err) { + return [ [0, 0] ]; + } } |