Support 1.18 (experimental) snapshots (#158)

* Half support 1.18-experimental-snapshot-1

* Fetch 1.18 presets and improve rendering of lists

* Noise preview with deepslate

* Biome preview with deepslate

* Generalize canvas logic in one hook

* Simplify useCanvas

* Use mcschema for 1.18

* Improve noise settings preview controls

* Fix build

* Update deepslate and improve preview caching

* Cleanup, remove old preview code

* Couple seed between model and preview

* Limit output to improve performance + copy feedback
For the vanilla overworld dimension (200K lines),
it took 2+ seconds to write the output to the textarea

Now capped at 10K chars

* Add surface_relative_threshold to decorator preview

* Improve fixed list errors
This commit is contained in:
Misode
2021-09-23 03:04:52 +02:00
committed by GitHub
parent eb085737a3
commit 3b80334e2e
33 changed files with 812 additions and 639 deletions

View File

@@ -1,3 +1,6 @@
import type { DataModel } from '@mcschema/core'
import { Path } from '@mcschema/core'
import rfdc from 'rfdc'
import config from '../config.json'
export function isPromise(obj: any): obj is Promise<any> {
@@ -12,6 +15,16 @@ export function hexId(length = 12) {
return Array.from(arr, dec2hex).join('')
}
export function randomSeed() {
return BigInt(Math.floor(Math.random() * Number.MAX_SAFE_INTEGER))
}
export function newSeed(model: DataModel) {
const seed = Math.floor(Math.random() * (4294967296)) - 2147483648
model.set(new Path(['generator', 'seed']), seed, true)
model.set(new Path(['generator', 'biome_source', 'seed']), seed)
}
export function htmlEncode(str: string) {
return str.replace(/&/g, '&amp;').replace(/</g, '&lt;').replace(/>/g, '&gt;')
.replace(/"/g, '&quot;').replace(/'/g, '&#x27;').replace(/\//g, '&#x2F;')
@@ -38,6 +51,10 @@ export function stringToColor(str: string): [number, number, number] {
return [h % 256, (h >> 8) % 256, (h >> 16) % 256]
}
export function square(a: number) {
return a * a
}
export function clamp(a: number, b: number, c: number) {
return Math.max(a, Math.min(b, c))
}
@@ -72,3 +89,42 @@ export function message(e: unknown): string {
if (e instanceof Error) return e.message
return `${e}`
}
export const deepClone = rfdc()
/**
* MIT License
*
* Copyright (c) 2017 Evgeny Poberezkin
*
* https://github.com/epoberezkin/fast-deep-equal/blob/master/LICENSE
*/
export function deepEqual(a: any, b: any) {
if (a === b) return true
if (a && b && typeof a == 'object' && typeof b == 'object') {
if (a.constructor !== b.constructor) return false
let length, i
if (Array.isArray(a)) {
length = a.length
if (length != b.length) return false
for (i = length; i-- !== 0;) {
if (!deepEqual(a[i], b[i])) return false
}
return true
}
if (a.valueOf !== Object.prototype.valueOf) return a.valueOf() === b.valueOf()
if (a.toString !== Object.prototype.toString) return a.toString() === b.toString()
const keys = Object.keys(a)
length = keys.length
if (length !== Object.keys(b).length) return false
for (i = length; i-- !== 0;)
if (!Object.prototype.hasOwnProperty.call(b, keys[i])) return false
for (i = length; i-- !== 0;) {
const key = keys[i]
if (!deepEqual(a[key], b[key])) return false
}
return true
}
return a !== a && b !== b
}