add WIP upload feature
This commit is contained in:
@@ -3,6 +3,7 @@ import { Card, CardContent, Grid, IconButton, TextField, Typography } from "@mui
|
|||||||
import { Instruction } from "../instructions"
|
import { Instruction } from "../instructions"
|
||||||
import KeyboardDoubleArrowRightIcon from "@mui/icons-material/KeyboardDoubleArrowRight"
|
import KeyboardDoubleArrowRightIcon from "@mui/icons-material/KeyboardDoubleArrowRight"
|
||||||
import PlayArrowIcon from "@mui/icons-material/PlayArrow"
|
import PlayArrowIcon from "@mui/icons-material/PlayArrow"
|
||||||
|
import SaveIcon from "@mui/icons-material/Save"
|
||||||
import StopIcon from "@mui/icons-material/Stop"
|
import StopIcon from "@mui/icons-material/Stop"
|
||||||
|
|
||||||
import {
|
import {
|
||||||
@@ -15,6 +16,8 @@ import {
|
|||||||
TILE_SIZE
|
TILE_SIZE
|
||||||
} from "../const"
|
} from "../const"
|
||||||
import { iterate, newProgram, ProgramState, resetProgram } from "../interpreter"
|
import { iterate, newProgram, ProgramState, resetProgram } from "../interpreter"
|
||||||
|
import FileUpload from "./FileUpload"
|
||||||
|
import loadProgram, { save } from "../filehandler"
|
||||||
|
|
||||||
function Board() {
|
function Board() {
|
||||||
let key = 0
|
let key = 0
|
||||||
@@ -101,6 +104,14 @@ function Board() {
|
|||||||
<IconButton href={save(program)} download="save.json">
|
<IconButton href={save(program)} download="save.json">
|
||||||
<SaveIcon />
|
<SaveIcon />
|
||||||
</IconButton>
|
</IconButton>
|
||||||
|
<input
|
||||||
|
type="file"
|
||||||
|
onInput={
|
||||||
|
() => {
|
||||||
|
console.log("TODO")
|
||||||
|
} /*loadProgram(program, )*/
|
||||||
|
}
|
||||||
|
/>
|
||||||
</Grid>
|
</Grid>
|
||||||
<Grid item xs={4}>
|
<Grid item xs={4}>
|
||||||
<Typography>output: {program.output}</Typography>
|
<Typography>output: {program.output}</Typography>
|
||||||
|
|||||||
@@ -8,6 +8,22 @@ interface SaveState {
|
|||||||
program: string[]
|
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 {
|
export function save(program: ProgramState): string {
|
||||||
const saveObject: SaveState = {
|
const saveObject: SaveState = {
|
||||||
|
|||||||
Reference in New Issue
Block a user