From 71a61ed1c3929f9d4cb615cf691bb980a8005c9e Mon Sep 17 00:00:00 2001 From: sanine Date: Sat, 6 Jul 2024 01:12:53 -0500 Subject: fix console errors when changing expressions --- level.js | 18 +++++++++++++----- 1 file changed, 13 insertions(+), 5 deletions(-) diff --git a/level.js b/level.js index e2018e2..17ccee7 100644 --- a/level.js +++ b/level.js @@ -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] ]; + } } -- cgit v1.2.1