diff --git a/.npmrc b/.npmrc new file mode 100644 index 0000000..41583e3 --- /dev/null +++ b/.npmrc @@ -0,0 +1 @@ +@jsr:registry=https://npm.jsr.io diff --git a/package-lock.json b/package-lock.json index 41e4bee..f12cf72 100644 --- a/package-lock.json +++ b/package-lock.json @@ -9,7 +9,7 @@ "version": "1.0.0", "license": "ISC", "dependencies": { - "@j0code/yson": "^1.0.4", + "@j0code/yson": "npm:@jsr/j0code__yson@^1.1.1", "typescript": "^5.4.2" }, "devDependencies": { @@ -116,9 +116,10 @@ "dev": true }, "node_modules/@j0code/yson": { - "version": "1.0.4", - "resolved": "https://registry.npmjs.org/@j0code/yson/-/yson-1.0.4.tgz", - "integrity": "sha512-6JE1vxGOwi4OMuPqNzvfupgu9aedDA1/KA0QdjhdOv9qvfxcQV3locoxmiHzF7zHDGGTR4FXf8mmRfqLKAJBoQ==" + "name": "@jsr/j0code__yson", + "version": "1.1.1", + "resolved": "https://npm.jsr.io/~/7/@jsr/j0code__yson/1.1.1.tgz", + "integrity": "sha512-rUW3OMVNTg9OckTw1Nbcb1fPcsoWtVGOonlHGQ2/N5HhaJzjV+FCdpnJ1gEqAQARTIOk9Z+5dTL67i4lyf2faQ==" }, "node_modules/@nodelib/fs.scandir": { "version": "2.1.5", diff --git a/package.json b/package.json index f734c75..8957c5f 100644 --- a/package.json +++ b/package.json @@ -19,7 +19,7 @@ }, "homepage": "https://github.com/creelonestudios/tinymc#readme", "dependencies": { - "@j0code/yson": "^1.0.4", + "@j0code/yson": "npm:@jsr/j0code__yson@^1.1.1", "typescript": "^5.4.2" }, "devDependencies": { diff --git a/src/gui/state/gameMenu.ts b/src/gui/state/gameMenu.ts index 96ff0bf..273ac91 100644 --- a/src/gui/state/gameMenu.ts +++ b/src/gui/state/gameMenu.ts @@ -6,9 +6,7 @@ import MenuState from "../../enums/MenuState.js" import TextRenderer from "../../util/TextRenderer.js" import Texture from "../../texture/Texture.js" import World from "../../world/World.js" - - -// import YSON from "https://j0code.github.io/browserjs-yson/main.mjs" +import YSON from "https://j0code.github.io/yson/main.js" let logoTex: Texture const singleplayerButton = new Button(0, -100, 800, 80, "Singleplayer") @@ -19,7 +17,7 @@ const createWorldButton = new Button(600, 400, 300, 60, "Create World") singleplayerButton.on("click", () => { worldButtons = [] - const worldSaves = JSON.parse(localStorage.getItem("worlds") || "[]") + const worldSaves = YSON.parse(localStorage.getItem("worlds") || "[]") for (let i = 0; i < worldSaves.length; i++) { const worldSave = worldSaves[i] diff --git a/src/main.ts b/src/main.ts index 07fc620..6f0af76 100644 --- a/src/main.ts +++ b/src/main.ts @@ -18,7 +18,7 @@ import MenuState from "./enums/MenuState.js" import Sound from "./sound/Sound.js" import Texture from "./texture/Texture.js" import World from "./world/World.js" -import YSON from "https://j0code.github.io/browserjs-yson/main.mjs" +import YSON from "https://j0code.github.io/yson/main.js" // eslint-disable-next-line no-console console.log("Never Gonna Give You Up") @@ -130,7 +130,7 @@ function perfRun(name: "tick" | "draw", fn: () => void, target: number) { } async function loadDefs(path: string, cls: { new(ns: string, id: string, data: unknown): T }): Promise> { - const data = await YSON.load(path) + const data = await YSON.load(`./${path}`) const defs = new Map() const namespaces = Object.keys(data) @@ -196,21 +196,21 @@ export function saveGame() { if (menuState != MenuState.INGAME && menuState != MenuState.INGAME_MENU) return if (!ingameState.world) return - const currentWorlds = JSON.parse(localStorage.getItem("worlds") || "[]") + const currentWorlds = YSON.parse(localStorage.getItem("worlds") || "[]") const currentWorldIndex = currentWorlds.findIndex((worldSave: { name: string, data: unknown }) => worldSave.name == ingameState.world.name) currentWorlds[currentWorldIndex] = { ...currentWorlds[currentWorldIndex], ...ingameState.world.save() } - localStorage.setItem("worlds", JSON.stringify(currentWorlds)) + localStorage.setItem("worlds", YSON.stringify(currentWorlds)) } export function saveNewWorld(world: World) { - const currentWorlds = JSON.parse(localStorage.getItem("worlds") || "[]") + const currentWorlds = YSON.parse(localStorage.getItem("worlds") || "[]") currentWorlds.push({ ...world.save() }) - localStorage.setItem("worlds", JSON.stringify(currentWorlds)) + localStorage.setItem("worlds", YSON.stringify(currentWorlds)) } window.addEventListener("beforeunload", () => { diff --git a/src/util/typecheck.ts b/src/util/typecheck.ts index ae7e969..669847e 100644 --- a/src/util/typecheck.ts +++ b/src/util/typecheck.ts @@ -1,5 +1,5 @@ import { type NamespacedId } from "./interfaces" -import YSON from "https://j0code.github.io/browserjs-yson/main.mjs" +import YSON from "https://j0code.github.io/yson/main.js" export const namespacedIdRegex = /^([a-z_]+):([a-z_]+)$/ export function isNamespacedId(s: string): s is NamespacedId { diff --git a/src/world/WorldGenerator.ts b/src/world/WorldGenerator.ts index 42a42e4..cab4a1e 100644 --- a/src/world/WorldGenerator.ts +++ b/src/world/WorldGenerator.ts @@ -3,8 +3,6 @@ import { NamespacedId } from "../util/interfaces.js" import World from "./World.js" import { blockdefs } from "../main.js" -// import YSON from "https://j0code.github.io/browserjs-yson/main.mjs" - export default class WorldGenerator { static flat(world: World) { diff --git a/tsconfig.json b/tsconfig.json index c5c3194..c6862f8 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -25,12 +25,12 @@ // "moduleDetection": "auto", /* Control what method is used to detect module-format JS files. */ /* Modules */ - "module": "esnext", /* Specify what module code is generated. */ + "module": "ESNext", /* Specify what module code is generated. */ "rootDir": "./src", /* Specify the root folder within your source files. */ - // "moduleResolution": "node", /* Specify how TypeScript looks up a file from a given module specifier. */ + // "moduleResolution": "ES", /* Specify how TypeScript looks up a file from a given module specifier. */ // "baseUrl": "./", /* Specify the base directory to resolve non-relative module names. */ "paths": { /* Specify a set of entries that re-map imports to additional lookup locations. */ - "https://j0code.github.io/browserjs-yson/main.mjs": ["./node_modules/@j0code/main.mjs"] + "https://j0code.github.io/yson/main.js": ["./node_modules/@j0code/yson/dist/main.js"] }, // "rootDirs": [], /* Allow multiple folders to be treated as one when resolving modules. */ // "typeRoots": [], /* Specify multiple folders that act like './node_modules/@types'. */