diff --git a/mise.toml b/mise.toml index e0ffbc08..12c3835d 100644 --- a/mise.toml +++ b/mise.toml @@ -1,5 +1,4 @@ [tools] -node = "latest" "npm:vite" = "8.1.3" tinymist = "0.15.0" typst = "0.15.0" diff --git a/src/blockstate.js b/src/blockstate.js index 989ef0c8..21d1a4ac 100644 --- a/src/blockstate.js +++ b/src/blockstate.js @@ -157,7 +157,7 @@ export class BlockstateResolver { if (!this.pending.has(id)) { const [space, name] = id.split(':'); - const url = `assets/${space}/blockstates/${name}.json`; + const url = `/assets/${space}/blockstates/${name}.json`; this.pending.set(id, fetch(url) .then(res => res.json()) @@ -165,8 +165,11 @@ export class BlockstateResolver { const source = renderBlockstateResolver(data); /** @type {ResolverFunction} */ - const resolver = new Function(`return function (state, hash) { ${source} } //# sourceURL=${url}`)(); - + const resolver = new Function( + import.meta.env.DEV + ? `const raw_data = ${JSON.stringify(data)};\n\nreturn (state, hash) => { ${source} }\n//# sourceURL=${url}` + : `return (state, hash) => { ${source} }` + )(); this.resolvers.set(id, resolver); this.pending.delete(id); @@ -178,10 +181,15 @@ export class BlockstateResolver { this.resolvers.set(id, this.resolvers.get(':invalid')); this.pending.delete(id); console.log(`failed to resolve blockstate ${id}: ${reason}`); - }) - ); + })); } return this.resolvers.get(':pending'); } + + resolve(id, pos, state) { + const resolver = this.getResolver(id); + const hash = pos[0] * 3.236 + pos[1] * 4.854 + pos[2] * 8.090; + return resolver(state, hash); + } } \ No newline at end of file