summaryrefslogtreecommitdiff
path: root/level.js
diff options
context:
space:
mode:
authorsanine <sanine.not@pm.me>2024-07-06 01:12:53 -0500
committersanine <sanine.not@pm.me>2024-07-06 01:12:53 -0500
commit71a61ed1c3929f9d4cb615cf691bb980a8005c9e (patch)
tree5d0ae2a9b1cd32546ce978b21369a2f12fa0088f /level.js
parent9b2bed395c82bc1644ef86a096f33b876358af40 (diff)
fix console errors when changing expressions
Diffstat (limited to 'level.js')
-rw-r--r--level.js18
1 files 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] ];
+ }
}