Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Rename Xor files to match chip name #205

Merged
merged 2 commits into from
Dec 25, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion projects/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ export const CHIP_PROJECTS: Record<"01" | "02" | "03" | "05", string[]> = {
"Not",
"And",
"Or",
"XOr",
"Xor",
"Mux",
"DMux",
"Not16",
Expand Down
8 changes: 4 additions & 4 deletions projects/src/project_01/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,10 +33,10 @@ export const CHIPS = {
"Or.tst": Or.tst,
"Or.cmp": Or.cmp,
},
XOr: {
"XOr.hdl": Xor.hdl,
"XOr.tst": Xor.tst,
"XOr.cmp": Xor.cmp,
Xor: {
"Xor.hdl": Xor.hdl,
"Xor.tst": Xor.tst,
"Xor.cmp": Xor.cmp,
},
Mux: {
"Mux.hdl": Mux.hdl,
Expand Down
2 changes: 2 additions & 0 deletions web/src/App.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ import "./pico/pico.scss";
import "./pico/tooltip.scss";
import { TrackingBanner } from "./tracking";
import { ErrorBoundary, RenderError } from "./ErrorBoundary";
import { updateVersion } from "./versions";

i18n.load("en", messages.messages);
i18n.load("en-PL", plMessages.messages);
Expand All @@ -54,6 +55,7 @@ function App() {
fs.stat("/projects/01/Not/Not.hdl").catch(async () => {
await loaders.resetFiles(fs);
});
updateVersion(fs);
}, [fs]);

useEffect(() => {
Expand Down
25 changes: 25 additions & 0 deletions web/src/versions.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
import { FileSystem } from "@davidsouther/jiffies/lib/esm/fs";

const CURRENT_VERSION = 1;

export async function updateVersion(fs: FileSystem) {
let version = Number(localStorage.getItem("version")) ?? 0;

while (version < CURRENT_VERSION) {
await versionUpdates[version](fs);
version++;
}

localStorage.setItem("version", CURRENT_VERSION.toString());
}

const versionUpdates: Record<number, (fs: FileSystem) => Promise<void>> = {
0: async (fs: FileSystem) => {
for (const suffix of ["hdl", "cmp", "tst"]) {
await fs.writeFile(
`/projects/01/Xor/Xor.${suffix}`,
await fs.readFile(`/projects/01/XOr/XOr.${suffix}`)
);
}
},
};