mirror of
https://github.com/misode/misode.github.io.git
synced 2026-04-23 07:10:41 +00:00
Fix issue with rarity ores + improve error reporting
This commit is contained in:
@@ -1,19 +1,20 @@
|
||||
import type { ComponentChildren } from 'preact'
|
||||
import { getCurrentUrl } from 'preact-router'
|
||||
import { useEffect, useMemo, useState } from 'preact/hooks'
|
||||
import { useVersion } from '../contexts/Version.jsx'
|
||||
import { latestVersion } from '../services/DataFetcher.js'
|
||||
import { Store } from '../Store.js'
|
||||
import { getGenerator } from '../Utils.js'
|
||||
import { useVersion } from '../contexts/Version.jsx'
|
||||
import { latestVersion } from '../services/DataFetcher.js'
|
||||
import { Octicon } from './index.js'
|
||||
|
||||
type ErrorPanelProps = {
|
||||
error: string | Error,
|
||||
reportable?: boolean,
|
||||
onDismiss?: () => unknown,
|
||||
body?: string,
|
||||
children?: ComponentChildren,
|
||||
}
|
||||
export function ErrorPanel({ error, reportable, onDismiss, children }: ErrorPanelProps) {
|
||||
export function ErrorPanel({ error, reportable, onDismiss, body: body_, children }: ErrorPanelProps) {
|
||||
const { version } = useVersion()
|
||||
const [stackVisible, setStackVisible] = useState(false)
|
||||
const [stack, setStack] = useState<string | undefined>(undefined)
|
||||
@@ -54,9 +55,12 @@ export function ErrorPanel({ error, reportable, onDismiss, children }: ErrorPane
|
||||
if (source) {
|
||||
body += `\n### Generator JSON\n<details>\n<pre>\n${JSON.stringify(source, null, 2)}\n</pre>\n</details>\n`
|
||||
}
|
||||
if (body_) {
|
||||
body += body_
|
||||
}
|
||||
url += `&body=${encodeURIComponent(body)}`
|
||||
return url
|
||||
}, [error, version, stack, source, gen?.id])
|
||||
}, [error, body_, version, stack, source, gen?.id])
|
||||
|
||||
return <div class="error">
|
||||
{onDismiss && <div class="error-dismiss" onClick={onDismiss}>{Octicon.x}</div>}
|
||||
|
||||
@@ -261,7 +261,7 @@ function generateOreFeatures(ctx: Context) {
|
||||
} else {
|
||||
const placed = deepClone(ctx.vanilla['worldgen/placed_feature'].get(name))
|
||||
if (value.tries !== initial.tries) {
|
||||
const modifier = placed.placement.find((m: any) => m.type === 'minecraft:count' || m.type === 'rarity_filter')
|
||||
const modifier = placed.placement.find((m: any) => m.type === 'minecraft:count' || m.type === 'minecraft:rarity_filter')
|
||||
if (Number.isInteger(value.tries)) {
|
||||
modifier.type = 'minecraft:count',
|
||||
modifier.count = value.tries
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
import { useCallback, useEffect, useErrorBoundary, useMemo, useRef, useState } from 'preact/hooks'
|
||||
import config from '../Config.js'
|
||||
import { writeZip } from '../Utils.js'
|
||||
import { deepClone, deepEqual, writeZip } from '../Utils.js'
|
||||
import { BasicSettings } from '../components/customized/BasicSettings.jsx'
|
||||
import { generateCustomized } from '../components/customized/CustomizedGenerator.js'
|
||||
import { CustomizedModel } from '../components/customized/CustomizedModel.js'
|
||||
@@ -89,8 +89,21 @@ export function Customized({}: Props) {
|
||||
<Btn icon="download" label="Create" class="customized-create" onClick={generate} />
|
||||
<a ref={download} style="display: none;"></a>
|
||||
</div>
|
||||
{error && <ErrorPanel error={error} onDismiss={() => setError(null)} />}
|
||||
{error && <ErrorPanel error={error} onDismiss={() => setError(null)} body={`\n### Customized settings\n<details>\n<pre>\n${JSON.stringify(getDiffModel(model, initialModel), null, 2)}\n</pre>\n</details>\n`} />}
|
||||
</div>
|
||||
<Footer />
|
||||
</main>
|
||||
}
|
||||
|
||||
function getDiffModel(model: any, initial: any) {
|
||||
const result = deepClone(model)
|
||||
if (typeof result !== 'object' || result === null) return
|
||||
Object.keys(result).forEach(key => {
|
||||
if (deepEqual(result[key], initial[key])) {
|
||||
delete result[key]
|
||||
} else if (typeof result[key] === 'object' && result[key] !== null) {
|
||||
result[key] = getDiffModel(result[key], initial[key])
|
||||
}
|
||||
})
|
||||
return result
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user