diff options
-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] ]; + } } |