~kylep/visual-cell-lang

945e832c7fc578720e5fbb96f41187e81aef6e9c — Kyle Perik 1 year, 8 months ago 7a29e07
UI Improvements
2 files changed, 41 insertions(+), 13 deletions(-)

M src/game.js
M src/main.js
M src/game.js => src/game.js +33 -11
@@ 52,6 52,7 @@ export function addConnection(data, gameData, gs) {
    ...data,
    g: new PIXI.Graphics(),
  };
  connection.g.zIndex = -1;
  connection.g.interactive = true;
  connection.g.on('rightdown', (e) => {
    const { start, end } = getConnectionPath(connection);


@@ 84,6 85,11 @@ export function drawBox(box) {
  boxG.x = pos.x;
  boxG.y = pos.y;

  if (box.failed) {
    boxG.lineStyle(2, hsv(0, .5, .8));
  } else {
    boxG.lineStyle(2, hsv(.3, .5, .8));
  }
  boxG.beginFill(hsv(.8, .1, .2));
  boxG.drawRect(0, 0, box.width * TILE_SIZE, box.height * TILE_SIZE);



@@ 188,7 194,13 @@ export function addBox(data, gameData, gs) {

  // Run init script
  if (box.init) {
    interpret(box.init, { value: null, data: box.data })
    try {
      interpret(box.init, { value: null, data: box.data })
    } catch (e) {
      box.failed = true;
      drawBox(box);
      throw e;
    }
  }

  return box


@@ 279,16 291,26 @@ export function evaluateNewPieces (newKey, gameData, gs) {
        return r;
      }, {});
      box.inputQueue.forEach(({value, input}) => {
        const func = boxDef.inputs[input];
        if (!func) {
          return;
        }
        const args = { value, out, data: box.data, box };
        if (box.js) {
          func(args);
        } else {
          const result = interpret(func, { value, data: box.data });
          outputEvents = result.output;
        try {
          const func = boxDef.inputs[input];
          if (!func) {
            return;
          }
          const args = { value, out, data: box.data, box };
          if (box.js) {
            func(args);
          } else {
            const result = interpret(func, { value, data: box.data });
            outputEvents = result.output;
          }
          if (box.failed) {
            box.failed = false;
            drawBox(box);
          }
        } catch (e) {
          box.failed = true;
          drawBox(box);
          throw e;
        }
      });
      box.inputQueue = [];

M src/main.js => src/main.js +8 -2
@@ 99,6 99,7 @@ export let gameData = {
  drawingConnection: null,
  gameSpeed: 2,
  movingSlider: false,
  zIndexCounter: 1,
}
const gs = {
  connections: null,


@@ 432,6 433,7 @@ def pop:
  world.addChild(gs.speedSlider);

  gs.connections = new PIXI.Graphics();
  gs.connections.zIndex = -1;
  world.addChild(gs.connections);

  gs.dataPieces = new PIXI.Graphics();


@@ 562,7 564,7 @@ function mousedown (e) {
  gameData.mousedown = true

  const mousePos = gameData.mouse.mul(1 / TILE_SIZE);
  const boxClicked = gameData.codeBoxes.find(box => {
  const boxClicked = gameData.codeBoxes.filter(box => {
    const pos = box.pos.mul(TILE_SIZE);
    return (
      gameData.mouse.x >= pos.x


@@ 570,7 572,7 @@ function mousedown (e) {
        && gameData.mouse.x <= pos.x + box.width * TILE_SIZE
        && gameData.mouse.y <= pos.y + box.height * TILE_SIZE
    )
  });
  }).sort((a, b) => b.g.zIndex - a.g.zIndex)[0];
  const outputClicked = (
    !boxClicked
      ? null


@@ 601,6 603,10 @@ function mousedown (e) {
      };
    } else if (boxClicked) {
      boxClicked.clicked = true;

      boxClicked.g.zIndex = gameData.zIndexCounter;
      gameData.zIndexCounter += 1;

      gameData.moving = {
        type: 'box',
        object: boxClicked,