From e0c723930e339b18fa89338aaf33a6384ddba700 Mon Sep 17 00:00:00 2001 From: Neta London Date: Tue, 2 Jan 2024 16:19:59 +0200 Subject: [PATCH 01/13] Add missing project 4 test files --- projects/src/project_04/02_fill.ts | 54 ++++++++++++++++++++++++++++++ projects/src/project_04/index.ts | 6 ++++ web/src/shell/test_panel.tsx | 23 ++++++++----- web/src/versions.ts | 15 +++++++-- 4 files changed, 86 insertions(+), 12 deletions(-) create mode 100644 projects/src/project_04/02_fill.ts diff --git a/projects/src/project_04/02_fill.ts b/projects/src/project_04/02_fill.ts new file mode 100644 index 000000000..5bfd872c4 --- /dev/null +++ b/projects/src/project_04/02_fill.ts @@ -0,0 +1,54 @@ +export const tst = `// This file is part of www.nand2tetris.org +// and the book "The Elements of Computing Systems" +// by Nisan and Schocken, MIT Press. +// File name: projects/04/fill/Fill.tst + +// Tests the Fill.hack program in the CPU emulator. + +echo "Make sure that 'No Animation' is selected. Then, select the keyboard, press any key for some time, and inspect the screen."; + +repeat { + ticktock; +}`; + +export const autoTst = `// This file is part of www.nand2tetris.org +// and the book "The Elements of Computing Systems" +// by Nisan and Schocken, MIT Press. +// File name: projects/04/fill/FillAutomatic.tst + +// This script can be used to test the Fill program automatically, +// rather than interactively. Specifically, the script sets the keyboard +// memory map (RAM[24576]) to 0, runs a million cycles, then it sets it +// to 1, runs a million cycles, then it sets it again to 0, and runs a +// million cycles. These actions simulate the events of leaving the keyboard +// untouched, pressing some key, and then releasing the key. +// After each on of these simulated events, the script outputs the values +// of selected registers from the screen memory map (RAM[16384] - RAM[24576]). +// This is done in order to test that these registers are set to 000...0 or to +// 111....1 (-1 in decimal), as mandated by how the Fill program should +// react to keyboard events. + +output-list RAM[16384]%D2.6.2 RAM[17648]%D2.6.2 RAM[18349]%D2.6.2 RAM[19444]%D2.6.2 RAM[20771]%D2.6.2 RAM[21031]%D2.6.2 RAM[22596]%D2.6.2 RAM[23754]%D2.6.2 RAM[24575]%D2.6.2; + +set RAM[24576] 0; // the keyboard is untouched +repeat 1000000 { + ticktock; +} +output; // tests that the screen is white + +set RAM[24576] 1; // a keyboard key is pressed (1 is an arbitrary non-zero value) +repeat 1000000 { + ticktock; +} +output; // tests that the screen is black + +set RAM[24576] 0; // the keyboard in untouched +repeat 1000000 { + ticktock; +} +output;`; + +export const autoCmp = `|RAM[16384]|RAM[17648]|RAM[18349]|RAM[19444]|RAM[20771]|RAM[21031]|RAM[22596]|RAM[23754]|RAM[24575]| +| 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | +| -1 | -1 | -1 | -1 | -1 | -1 | -1 | -1 | -1 | +| 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 |`; diff --git a/projects/src/project_04/index.ts b/projects/src/project_04/index.ts index 163b7bd7c..8f0885613 100644 --- a/projects/src/project_04/index.ts +++ b/projects/src/project_04/index.ts @@ -1,12 +1,18 @@ import { FileSystem, reset } from "@davidsouther/jiffies/lib/esm/fs.js"; import * as Mult from "./01_mult.js"; +import * as Fill from "./02_fill.js"; export const TESTS = { Mult: { "Mult.tst": Mult.tst, "Mult.cmp": Mult.cmp, }, + Fill: { + "Fill.tst": Fill.tst, + "FillAutomatic.tst": Fill.autoTst, + "FillAutomatic.cmp": Fill.autoCmp, + }, }; export async function resetFiles(fs: FileSystem): Promise { diff --git a/web/src/shell/test_panel.tsx b/web/src/shell/test_panel.tsx index 9bea545d7..b2080b773 100644 --- a/web/src/shell/test_panel.tsx +++ b/web/src/shell/test_panel.tsx @@ -1,3 +1,11 @@ +import { Trans } from "@lingui/macro"; +import { DiffTable } from "@nand2tetris/components/difftable.js"; +import { Runbar } from "@nand2tetris/components/runbar.js"; +import { BaseContext } from "@nand2tetris/components/stores/base.context.js"; +import { Span } from "@nand2tetris/simulator/languages/base"; +import { CMP } from "@nand2tetris/simulator/languages/cmp.js"; +import { TST } from "@nand2tetris/simulator/languages/tst.js"; +import { Timer } from "@nand2tetris/simulator/timer.js"; import { CSSProperties, Dispatch, @@ -6,17 +14,9 @@ import { useContext, useState, } from "react"; -import { Trans } from "@lingui/macro"; -import { DiffTable } from "@nand2tetris/components/difftable.js"; -import { Runbar } from "@nand2tetris/components/runbar.js"; -import { CMP } from "@nand2tetris/simulator/languages/cmp.js"; -import { BaseContext } from "@nand2tetris/components/stores/base.context.js"; -import { Timer } from "@nand2tetris/simulator/timer.js"; -import { TST } from "@nand2tetris/simulator/languages/tst.js"; import { AppContext } from "../App.context"; import { Editor } from "./editor"; import { Panel } from "./panel"; -import { Span } from "@nand2tetris/simulator/languages/base"; export const TestPanel = ({ runner, @@ -52,7 +52,12 @@ export const TestPanel = ({ try { const path = await filePicker.select(); const tst = await fs.readFile(path); - const cmp = await fs.readFile(path.replace(/\.tst$/, ".cmp")); + let cmp: string | undefined = undefined; + try { + cmp = await fs.readFile(path.replace(/\.tst$/, ".cmp")); + } catch (e) { + // The doesn't have to be a compare file + } onLoadTest?.(tst, cmp); // await compile.current({ tst }); } catch (e) { diff --git a/web/src/versions.ts b/web/src/versions.ts index c21d7a245..5e5557a9d 100644 --- a/web/src/versions.ts +++ b/web/src/versions.ts @@ -1,13 +1,19 @@ import { FileSystem } from "@davidsouther/jiffies/lib/esm/fs"; +import * as project_04 from "@nand2tetris/projects/project_04/index.js"; -const CURRENT_VERSION = 1; +const CURRENT_VERSION = 2; export async function updateVersion(fs: FileSystem) { + console.log("updating version"); let version = Number(localStorage.getItem("version")) ?? 0; while (version < CURRENT_VERSION) { - await versionUpdates[version](fs); - version++; + try { + await versionUpdates[version](fs); + version++; + } catch (e) { + version++; + } } localStorage.setItem("version", CURRENT_VERSION.toString()); @@ -22,4 +28,7 @@ const versionUpdates: Record Promise> = { ); } }, + 1: async (fs: FileSystem) => { + await project_04.resetFiles(fs); + }, }; From 1f29e8284f3bab77fd140a0063b488e259b9d63a Mon Sep 17 00:00:00 2001 From: Neta London Date: Tue, 2 Jan 2024 17:20:20 +0200 Subject: [PATCH 02/13] Enable running test scripts at highest speeds --- components/src/stores/cpu.store.ts | 11 +++++++++-- web/src/pages/cpu.tsx | 3 +++ web/src/shell/test_panel.tsx | 6 +++++- 3 files changed, 17 insertions(+), 3 deletions(-) diff --git a/components/src/stores/cpu.store.ts b/components/src/stores/cpu.store.ts index 7b3d3ed7d..b67e67ce8 100644 --- a/components/src/stores/cpu.store.ts +++ b/components/src/stores/cpu.store.ts @@ -8,8 +8,8 @@ import { } from "@nand2tetris/simulator/cpu/memory.js"; import { Span } from "@nand2tetris/simulator/languages/base.js"; import { TST } from "@nand2tetris/simulator/languages/tst.js"; -import { HACK } from "@nand2tetris/simulator/testing/mult.js"; import { CPUTest } from "@nand2tetris/simulator/test/cputst.js"; +import { HACK } from "@nand2tetris/simulator/testing/mult.js"; import { Dispatch, MutableRefObject, useContext, useMemo, useRef } from "react"; import { compare } from "../compare.js"; import { useImmerReducer } from "../react.js"; @@ -76,6 +76,7 @@ export function makeCpuStore( dispatch: MutableRefObject ) { let test = new CPUTest(new ROM(HACK)); + let animate = true; const reducers = { update(state: CpuPageState) { @@ -109,9 +110,15 @@ export function makeCpuStore( test.cpu.tick(); }, + setAnimate(value: boolean) { + animate = value; + }, + testStep() { const done = test.step(); - dispatch.current({ action: "testStep" }); + if (animate || done) { + dispatch.current({ action: "testStep" }); + } if (done) { dispatch.current({ action: "testFinished" }); } diff --git a/web/src/pages/cpu.tsx b/web/src/pages/cpu.tsx index ffbbb21e6..4e5158fe4 100644 --- a/web/src/pages/cpu.tsx +++ b/web/src/pages/cpu.tsx @@ -181,6 +181,9 @@ export const CPU = () => { out={[out, setOut]} cmp={[cmp, setCmp]} onLoadTest={onLoadTest} + onSpeedChange={(speed) => { + actions.setAnimate(speed <= 2); + }} /> )} diff --git a/web/src/shell/test_panel.tsx b/web/src/shell/test_panel.tsx index b2080b773..97a9e51c5 100644 --- a/web/src/shell/test_panel.tsx +++ b/web/src/shell/test_panel.tsx @@ -25,6 +25,7 @@ export const TestPanel = ({ out: [out], disabled = false, onLoadTest = undefined, + onSpeedChange = undefined, }: { runner: RefObject; tst: [string, Dispatch, Span | undefined]; @@ -32,6 +33,7 @@ export const TestPanel = ({ out: [string, Dispatch]; disabled?: boolean; onLoadTest?: (tst: string, cmp?: string) => void; + onSpeedChange?: (speed: number) => void; }) => { const { fs, setStatus } = useContext(BaseContext); const { filePicker, tracking } = useContext(AppContext); @@ -75,7 +77,9 @@ export const TestPanel = ({ Test
- {runner.current && } + {runner.current && ( + + )}
From 17e7762ff3cd10b52d94d72bac3c378dd058011f Mon Sep 17 00:00:00 2001 From: Neta London Date: Wed, 3 Jan 2024 15:53:35 +0200 Subject: [PATCH 03/13] Fix repeat instruction parsing --- simulator/src/languages/tst.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/simulator/src/languages/tst.ts b/simulator/src/languages/tst.ts index 54941dea9..1f0e8b3ac 100644 --- a/simulator/src/languages/tst.ts +++ b/simulator/src/languages/tst.ts @@ -209,7 +209,7 @@ tstSemantics.addAttribute("statement", { TstRepeat(op, count, _o, statements, _c) { return { statements: statements.children.map(({ statement }) => statement), - count: count.child(0)?.value ?? -1, + count: Number(count.sourceString) ?? -1, span: span(this.source), }; }, From 0e5fc71cd1d0dcf776e0477adbc2aed77eb253ba Mon Sep 17 00:00:00 2001 From: Neta London Date: Wed, 3 Jan 2024 16:03:16 +0200 Subject: [PATCH 04/13] Preserve version when resetting files --- web/src/shell/settings.tsx | 9 ++++++--- web/src/versions.ts | 13 +++++++++++-- 2 files changed, 17 insertions(+), 5 deletions(-) diff --git a/web/src/shell/settings.tsx b/web/src/shell/settings.tsx index 9fa7fd9d5..330a66b48 100644 --- a/web/src/shell/settings.tsx +++ b/web/src/shell/settings.tsx @@ -1,13 +1,14 @@ -import loaders from "@nand2tetris/projects/loader.js"; import { i18n } from "@lingui/core"; import { Trans } from "@lingui/macro"; -import { useContext, useEffect, useMemo } from "react"; import { BaseContext } from "@nand2tetris/components/stores/base.context.js"; +import loaders from "@nand2tetris/projects/loader.js"; +import { useContext, useEffect, useMemo } from "react"; import { AppContext } from "../App.context"; +import { TrackingDisclosure } from "src/tracking"; +import { getVersion, setVersion } from "src/versions"; import "../pico/button-group.scss"; import "../pico/property.scss"; -import { TrackingDisclosure } from "src/tracking"; import { useDialog } from "./dialog"; export const Settings = () => { @@ -32,7 +33,9 @@ export const Settings = () => { const resetWarning = useDialog(); const resetFiles = async () => { + const version = getVersion(); localStorage.clear(); + setVersion(version); localStorage["/chip/project"] = "01"; localStorage["/chip/chip"] = "Not"; await loaders.resetFiles(fs); diff --git a/web/src/versions.ts b/web/src/versions.ts index 5e5557a9d..21b318b58 100644 --- a/web/src/versions.ts +++ b/web/src/versions.ts @@ -1,11 +1,20 @@ import { FileSystem } from "@davidsouther/jiffies/lib/esm/fs"; import * as project_04 from "@nand2tetris/projects/project_04/index.js"; +const VERSION_KEY = "version"; const CURRENT_VERSION = 2; +export function getVersion() { + return Number(localStorage.getItem(VERSION_KEY)) ?? 0; +} + +export function setVersion(version: number) { + localStorage.setItem(VERSION_KEY, version.toString()); +} + export async function updateVersion(fs: FileSystem) { console.log("updating version"); - let version = Number(localStorage.getItem("version")) ?? 0; + let version = getVersion(); while (version < CURRENT_VERSION) { try { @@ -16,7 +25,7 @@ export async function updateVersion(fs: FileSystem) { } } - localStorage.setItem("version", CURRENT_VERSION.toString()); + setVersion(CURRENT_VERSION); } const versionUpdates: Record Promise> = { From b4e57c978ab1a70e18259f111c4c652e1ced5cd5 Mon Sep 17 00:00:00 2001 From: Neta London Date: Wed, 3 Jan 2024 16:07:34 +0200 Subject: [PATCH 05/13] Modify fill.tst message --- projects/src/project_04/02_fill.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/projects/src/project_04/02_fill.ts b/projects/src/project_04/02_fill.ts index 5bfd872c4..5d2bb2644 100644 --- a/projects/src/project_04/02_fill.ts +++ b/projects/src/project_04/02_fill.ts @@ -5,7 +5,7 @@ export const tst = `// This file is part of www.nand2tetris.org // Tests the Fill.hack program in the CPU emulator. -echo "Make sure that 'No Animation' is selected. Then, select the keyboard, press any key for some time, and inspect the screen."; +echo "Make the highest speed is selected. Then, select the keyboard, press any key for some time, and inspect the screen."; repeat { ticktock; From fd8d87e03f2db118f2c8f1349b8d0f2a9a15b868 Mon Sep 17 00:00:00 2001 From: Neta London Date: Wed, 3 Jan 2024 16:10:44 +0200 Subject: [PATCH 06/13] Fix broken infinite repeat --- simulator/src/languages/tst.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/simulator/src/languages/tst.ts b/simulator/src/languages/tst.ts index 1f0e8b3ac..c374d8098 100644 --- a/simulator/src/languages/tst.ts +++ b/simulator/src/languages/tst.ts @@ -209,7 +209,7 @@ tstSemantics.addAttribute("statement", { TstRepeat(op, count, _o, statements, _c) { return { statements: statements.children.map(({ statement }) => statement), - count: Number(count.sourceString) ?? -1, + count: count.sourceString ? Number(count.sourceString) : -1, span: span(this.source), }; }, From 1aa5a4756720f8b40c359bd4f7b501cc9d299c8d Mon Sep 17 00:00:00 2001 From: Neta London Date: Wed, 3 Jan 2024 16:17:13 +0200 Subject: [PATCH 07/13] Don't compare to empty compare file --- components/src/stores/cpu.store.ts | 3 +++ 1 file changed, 3 insertions(+) diff --git a/components/src/stores/cpu.store.ts b/components/src/stores/cpu.store.ts index b67e67ce8..559a85b4d 100644 --- a/components/src/stores/cpu.store.ts +++ b/components/src/stores/cpu.store.ts @@ -96,6 +96,9 @@ export function makeCpuStore( }, testFinished(state: CpuPageState) { + if (state.test.cmp.trim() === "") { + return; + } const passed = compare(state.test.cmp.trim(), test.log().trim()); setStatus( passed From b1309ea95aa2758a8faf95ba2bd07fdd82b634bb Mon Sep 17 00:00:00 2001 From: Neta London Date: Wed, 3 Jan 2024 16:18:50 +0200 Subject: [PATCH 08/13] Fix Fill.tst message --- projects/src/project_04/02_fill.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/projects/src/project_04/02_fill.ts b/projects/src/project_04/02_fill.ts index 5d2bb2644..9a3c76e2c 100644 --- a/projects/src/project_04/02_fill.ts +++ b/projects/src/project_04/02_fill.ts @@ -5,7 +5,7 @@ export const tst = `// This file is part of www.nand2tetris.org // Tests the Fill.hack program in the CPU emulator. -echo "Make the highest speed is selected. Then, select the keyboard, press any key for some time, and inspect the screen."; +echo "Make sure the highest speed is selected. Then, select the keyboard, press any key for some time, and inspect the screen."; repeat { ticktock; From b6f80380f24085d8dc71c58add9ff6309d7589f2 Mon Sep 17 00:00:00 2001 From: Neta London Date: Wed, 3 Jan 2024 16:20:24 +0200 Subject: [PATCH 09/13] Remove console.log --- web/src/versions.ts | 1 - 1 file changed, 1 deletion(-) diff --git a/web/src/versions.ts b/web/src/versions.ts index 21b318b58..807ce65ec 100644 --- a/web/src/versions.ts +++ b/web/src/versions.ts @@ -13,7 +13,6 @@ export function setVersion(version: number) { } export async function updateVersion(fs: FileSystem) { - console.log("updating version"); let version = getVersion(); while (version < CURRENT_VERSION) { From 916a96346813c95bd5ab52423c7b7c307cad681f Mon Sep 17 00:00:00 2001 From: Neta London Date: Wed, 3 Jan 2024 18:01:55 +0200 Subject: [PATCH 10/13] Make requested changes --- web/src/shell/test_panel.tsx | 2 +- web/src/versions.ts | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/web/src/shell/test_panel.tsx b/web/src/shell/test_panel.tsx index 97a9e51c5..c3d2c2bd1 100644 --- a/web/src/shell/test_panel.tsx +++ b/web/src/shell/test_panel.tsx @@ -58,7 +58,7 @@ export const TestPanel = ({ try { cmp = await fs.readFile(path.replace(/\.tst$/, ".cmp")); } catch (e) { - // The doesn't have to be a compare file + // There doesn't have to be a compare file } onLoadTest?.(tst, cmp); // await compile.current({ tst }); diff --git a/web/src/versions.ts b/web/src/versions.ts index 807ce65ec..c5155d70f 100644 --- a/web/src/versions.ts +++ b/web/src/versions.ts @@ -5,7 +5,7 @@ const VERSION_KEY = "version"; const CURRENT_VERSION = 2; export function getVersion() { - return Number(localStorage.getItem(VERSION_KEY)) ?? 0; + return Number(localStorage.getItem(VERSION_KEY) ?? "0"); } export function setVersion(version: number) { From baed946963739def0719dc004e187dec0d110d08 Mon Sep 17 00:00:00 2001 From: Neta London Date: Thu, 4 Jan 2024 12:06:12 +0200 Subject: [PATCH 11/13] Fix imports --- web/src/shell/settings.tsx | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/web/src/shell/settings.tsx b/web/src/shell/settings.tsx index 330a66b48..62b19cd2c 100644 --- a/web/src/shell/settings.tsx +++ b/web/src/shell/settings.tsx @@ -5,10 +5,10 @@ import loaders from "@nand2tetris/projects/loader.js"; import { useContext, useEffect, useMemo } from "react"; import { AppContext } from "../App.context"; -import { TrackingDisclosure } from "src/tracking"; -import { getVersion, setVersion } from "src/versions"; import "../pico/button-group.scss"; import "../pico/property.scss"; +import { TrackingDisclosure } from "../tracking"; +import { getVersion, setVersion } from "../versions"; import { useDialog } from "./dialog"; export const Settings = () => { From 9b96c97d98ae26e87b3148263c3f6ac3ae478f71 Mon Sep 17 00:00:00 2001 From: Neta London Date: Thu, 4 Jan 2024 12:15:28 +0200 Subject: [PATCH 12/13] Alert on version update fail --- web/src/App.tsx | 6 +++--- web/src/versions.ts | 15 ++++++++++++++- 2 files changed, 17 insertions(+), 4 deletions(-) diff --git a/web/src/App.tsx b/web/src/App.tsx index 47637223b..9c857ab84 100644 --- a/web/src/App.tsx +++ b/web/src/App.tsx @@ -21,13 +21,13 @@ import Header from "./shell/header"; import { Settings } from "./shell/settings"; import urls from "./urls"; +import { ErrorBoundary, RenderError } from "./ErrorBoundary"; +import { Redirect } from "./pages/redirect"; import "./pico/flex.scss"; import "./pico/pico.scss"; import "./pico/tooltip.scss"; import { TrackingBanner } from "./tracking"; -import { ErrorBoundary, RenderError } from "./ErrorBoundary"; import { updateVersion } from "./versions"; -import { Redirect } from "./pages/redirect"; i18n.load("en", messages.messages); i18n.load("en-PL", plMessages.messages); @@ -51,7 +51,7 @@ function App() { fs.stat("/projects/01/Not/Not.hdl").catch(async () => { await loaders.resetFiles(fs); }); - updateVersion(fs); + updateVersion(fs, baseContext.setStatus); }, [fs]); useEffect(() => { diff --git a/web/src/versions.ts b/web/src/versions.ts index c5155d70f..9a7354bee 100644 --- a/web/src/versions.ts +++ b/web/src/versions.ts @@ -4,6 +4,9 @@ import * as project_04 from "@nand2tetris/projects/project_04/index.js"; const VERSION_KEY = "version"; const CURRENT_VERSION = 2; +const VERSION_MISMATCH_WARNING = + "Error occurred while updating file templates, your files may differ from the latest official version"; + export function getVersion() { return Number(localStorage.getItem(VERSION_KEY) ?? "0"); } @@ -12,18 +15,28 @@ export function setVersion(version: number) { localStorage.setItem(VERSION_KEY, version.toString()); } -export async function updateVersion(fs: FileSystem) { +export async function updateVersion( + fs: FileSystem, + setStatus: (status: string) => void +) { let version = getVersion(); + let success = true; while (version < CURRENT_VERSION) { try { await versionUpdates[version](fs); version++; } catch (e) { + success = false; version++; } } + if (!success) { + console.warn(VERSION_MISMATCH_WARNING); + alert(`Warning: ${VERSION_MISMATCH_WARNING}`); + } + setVersion(CURRENT_VERSION); } From 17dc09ab65098dfda6fb1f08ebeaceb77c3a4083 Mon Sep 17 00:00:00 2001 From: Neta London Date: Thu, 4 Jan 2024 14:56:41 +0200 Subject: [PATCH 13/13] Remove alert --- web/src/App.tsx | 2 +- web/src/versions.ts | 16 ++-------------- 2 files changed, 3 insertions(+), 15 deletions(-) diff --git a/web/src/App.tsx b/web/src/App.tsx index 9c857ab84..899cce05d 100644 --- a/web/src/App.tsx +++ b/web/src/App.tsx @@ -51,7 +51,7 @@ function App() { fs.stat("/projects/01/Not/Not.hdl").catch(async () => { await loaders.resetFiles(fs); }); - updateVersion(fs, baseContext.setStatus); + updateVersion(fs); }, [fs]); useEffect(() => { diff --git a/web/src/versions.ts b/web/src/versions.ts index 9a7354bee..efeba5750 100644 --- a/web/src/versions.ts +++ b/web/src/versions.ts @@ -4,9 +4,6 @@ import * as project_04 from "@nand2tetris/projects/project_04/index.js"; const VERSION_KEY = "version"; const CURRENT_VERSION = 2; -const VERSION_MISMATCH_WARNING = - "Error occurred while updating file templates, your files may differ from the latest official version"; - export function getVersion() { return Number(localStorage.getItem(VERSION_KEY) ?? "0"); } @@ -15,28 +12,19 @@ export function setVersion(version: number) { localStorage.setItem(VERSION_KEY, version.toString()); } -export async function updateVersion( - fs: FileSystem, - setStatus: (status: string) => void -) { +export async function updateVersion(fs: FileSystem) { let version = getVersion(); - let success = true; while (version < CURRENT_VERSION) { try { await versionUpdates[version](fs); version++; } catch (e) { - success = false; + console.warn(`Error loading files at version ${version}`, e); version++; } } - if (!success) { - console.warn(VERSION_MISMATCH_WARNING); - alert(`Warning: ${VERSION_MISMATCH_WARNING}`); - } - setVersion(CURRENT_VERSION); }