diff --git a/src/components/Board.tsx b/src/components/Board.tsx
index b41b2a8..2f470ee 100644
--- a/src/components/Board.tsx
+++ b/src/components/Board.tsx
@@ -3,6 +3,7 @@ import { Card, CardContent, Grid, IconButton, TextField, Typography } from "@mui
import { Instruction } from "../instructions"
import KeyboardDoubleArrowRightIcon from "@mui/icons-material/KeyboardDoubleArrowRight"
import PlayArrowIcon from "@mui/icons-material/PlayArrow"
+import SaveIcon from "@mui/icons-material/Save"
import StopIcon from "@mui/icons-material/Stop"
import {
@@ -15,6 +16,8 @@ import {
TILE_SIZE
} from "../const"
import { iterate, newProgram, ProgramState, resetProgram } from "../interpreter"
+import FileUpload from "./FileUpload"
+import loadProgram, { save } from "../filehandler"
function Board() {
let key = 0
@@ -48,7 +51,7 @@ function Board() {
//iterate(x)
setProgram((prog) => {
const x = structuredClone(prog)
- iterate(x)
+ iterate(x)
return x
})
}
@@ -96,11 +99,19 @@ function Board() {
{playing ? : }
step()}>
-
-
+
+
+ {
+ console.log("TODO")
+ } /*loadProgram(program, )*/
+ }
+ />
output: {program.output}
diff --git a/src/filehandler.tsx b/src/filehandler.tsx
index 2060580..ea3a86c 100644
--- a/src/filehandler.tsx
+++ b/src/filehandler.tsx
@@ -8,6 +8,22 @@ interface SaveState {
program: string[]
}
+export default function loadProgram(to: ProgramState, save: SaveState) {
+ resetProgram(to)
+ to.board = newBoard(save.width, save.height)
+
+ save.program.forEach((line, row) => {
+ line.split("").forEach((char, col) => {
+ const index = instructions.findIndex((ins) => {
+ ins.bytecode === char
+ })
+
+ if (index !== -1) {
+ to.board[row][col] = instructions[index]
+ }
+ })
+ })
+}
export function save(program: ProgramState): string {
const saveObject: SaveState = {