From 4afc27c29ce56d2bd9d8605b59b03e42b18ba5e2 Mon Sep 17 00:00:00 2001 From: Kyle Perik Date: Fri, 21 Apr 2023 17:46:58 -0500 Subject: [PATCH] Various fixes and new opcodes --- src/game.js | 2 ++ src/lang.js | 29 +++++++++++++++++++++++++---- src/main.js | 7 ++++++- 3 files changed, 33 insertions(+), 5 deletions(-) diff --git a/src/game.js b/src/game.js index 27df6d3..bcda8bb 100644 --- a/src/game.js +++ b/src/game.js @@ -198,6 +198,8 @@ export function addBox(data, gameData, gs) { } gameData.codeBoxes.push(box); drawBox(box); + box.g.zIndex = gameData.zIndexCounter; + gameData.zIndexCounter += 1; gs.boxes.addChild(box.g); // Run init script diff --git a/src/lang.js b/src/lang.js index a4f6876..65accf1 100644 --- a/src/lang.js +++ b/src/lang.js @@ -10,6 +10,7 @@ export function parse (code) { if (r.queuedBranch) { newBranches[r.queuedBranch.name] = parse(r.queuedBranch.contents + '\n'); } + if (defDetails && defDetails.length === 3) { return { ...r, @@ -29,6 +30,10 @@ export function parse (code) { } } else { const newContents = line.slice(2); + if (!r.queuedBranch) { + console.error(`Indentation issue at line: ${line}`); + return r; + } return { ...r, queuedBranch: { @@ -128,11 +133,11 @@ export function interpret (expression, initial = null) { } else if (code === 'vecx') { const vec = r.stack[0]; - return { push: [vec.x], pop: 2 } + return { push: [vec.x], pop: 1 } } else if (code === 'vecy') { const vec = r.stack[0]; - return { push: [vec.y], pop: 2 } + return { push: [vec.y], pop: 1 } } else if (code === 'add') { const a = r.stack[0]; @@ -192,11 +197,23 @@ export function interpret (expression, initial = null) { else if (code === 'at') { const key = r.stack[0]; const index = r.stack[1]; - return {push: [r.data[key][index]], pop: 2}; + const collection = r.data[key] || {}; + return {push: [collection[index]], pop: 2}; } else if (code === 'dup') { const value = r.stack[0]; - return {push: [value, value], pop: 1}; + return {push: [value]}; + } + else if (code === 'dup2') { + const valuea = r.stack[0]; + const valueb = r.stack[1]; + return {push: [valueb, valuea]}; + } + else if (code === 'rot') { + const a = r.stack[0]; + const b = r.stack[1]; + const c = r.stack[2]; + return {push: [c, b, a], pop: 3}; } else if (code === 'swp') { const a = r.stack[0]; @@ -239,6 +256,10 @@ export function interpret (expression, initial = null) { else if (code === 'kil') { return {push: [], pop: 1}; } + else if (code === 'dbg') { + console.log(r.stack); + return {}; + } else { throw Error(`unknown code: ${code}`); } diff --git a/src/main.js b/src/main.js index 3134c6f..d79034e 100644 --- a/src/main.js +++ b/src/main.js @@ -134,7 +134,12 @@ function play (delta) { gameData.dataPieces = gameData.dataPieces.filter(piece => !piece.consumedBy); if (gameData.selectedBox) { - gameData.debugText.text = '\n' + JSON.stringify(gameData.selectedBox.data, null, 2); + const data = gameData.selectedBox.data + const preparedData = Object.keys(data).reduce((r, key) => { + r[key] = JSON.stringify(data[key]); + return r; + }, {}); + gameData.debugText.text = '\n' + JSON.stringify(preparedData, null, 2); } } -- 2.45.2