Skip to content

Commit

Permalink
update yson
Browse files Browse the repository at this point in the history
  • Loading branch information
j0code committed Apr 3, 2024
1 parent ae2ddb6 commit 93dbdf4
Show file tree
Hide file tree
Showing 8 changed files with 19 additions and 21 deletions.
1 change: 1 addition & 0 deletions .npmrc
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
@jsr:registry=https://npm.jsr.io
9 changes: 5 additions & 4 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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": {
Expand Down
6 changes: 2 additions & 4 deletions src/gui/state/gameMenu.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand All @@ -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]
Expand Down
12 changes: 6 additions & 6 deletions src/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down Expand Up @@ -130,7 +130,7 @@ function perfRun(name: "tick" | "draw", fn: () => void, target: number) {
}

async function loadDefs<T>(path: string, cls: { new(ns: string, id: string, data: unknown): T }): Promise<Map<NamespacedId, T>> {
const data = await YSON.load(path)
const data = await YSON.load(`./${path}`)
const defs = new Map<NamespacedId, T>()
const namespaces = Object.keys(data)

Expand Down Expand Up @@ -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", () => {
Expand Down
2 changes: 1 addition & 1 deletion src/util/typecheck.ts
Original file line number Diff line number Diff line change
@@ -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 {
Expand Down
2 changes: 0 additions & 2 deletions src/world/WorldGenerator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
6 changes: 3 additions & 3 deletions tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -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'. */
Expand Down

0 comments on commit 93dbdf4

Please sign in to comment.