diff --git a/src/components/Board.tsx b/src/components/Board.tsx index 0c69f54..b41b2a8 100644 --- a/src/components/Board.tsx +++ b/src/components/Board.tsx @@ -98,6 +98,9 @@ function Board() { step()}> + + + output: {program.output} diff --git a/src/filehandler.tsx b/src/filehandler.tsx new file mode 100644 index 0000000..2060580 --- /dev/null +++ b/src/filehandler.tsx @@ -0,0 +1,33 @@ +import React from "react" +import { newBoard, ProgramState, resetProgram } from "./interpreter" +import instructions, { Instruction } from "./instructions" + +interface SaveState { + width: number + height: number + program: string[] +} + + +export function save(program: ProgramState): string { + const saveObject: SaveState = { + width: program.width, + height: program.height, + program: [] + } + + program.board.forEach((row) => { + let line = "" + row.forEach((instruction) => { + line += instruction.bytecode + }) + saveObject.program.push(line) + }) + + console.log(saveObject) + + const data = new Blob([JSON.stringify(saveObject, null, 2)], { type: "text/plain" }) + + const file = window.URL.createObjectURL(data) + return file +}