From 86d8a8b1664aaad1e94cec7644866cf933f64bf2 Mon Sep 17 00:00:00 2001 From: dylan <> Date: Sat, 6 May 2023 15:12:42 -0700 Subject: [PATCH] allow saving and loading carts --- builtins.ts | 3 +++ cart.ts | 10 +++++++--- carts/.gitkeep | 0 3 files changed, 10 insertions(+), 3 deletions(-) create mode 100644 carts/.gitkeep diff --git a/builtins.ts b/builtins.ts index 88fe81d..e5b7ddc 100644 --- a/builtins.ts +++ b/builtins.ts @@ -9,6 +9,7 @@ import { addToContext, runCode } from "./runcode.ts"; import { resetRepl } from "./repl.ts"; import { COLOR } from "./colors.ts"; import { getSheet, getCodeSheet } from "./sheet.ts"; +import { saveCart, loadCart } from "./cart.ts"; let spritesheet: number | null = null; @@ -58,6 +59,8 @@ const faux = { }, log: console.log, JSON: JSON, + save: saveCart, + load: loadCart, }; for (const key in faux) { diff --git a/cart.ts b/cart.ts index f8fab9b..7a75fbf 100644 --- a/cart.ts +++ b/cart.ts @@ -1,10 +1,14 @@ import fakeCart from "./cart_unpacked.json" assert { type: "json" }; import { Sheet } from "./sheet.ts"; -const cart = fakeCart as Array; +let cart = fakeCart as Array; -export const loadCart = (_name: string) => { - return; +export const saveCart = async (fname: string) => { + await Deno.writeTextFile("./carts/"+fname+".fx", JSON.stringify(getCart())); +} + +export const loadCart = async (fname: string) => { + cart = JSON.parse(await Deno.readTextFile("./carts/"+fname+".fx")); } export const getCart = () => { diff --git a/carts/.gitkeep b/carts/.gitkeep new file mode 100644 index 0000000..e69de29