mirror of
https://github.com/misode/misode.github.io.git
synced 2026-04-29 01:22:44 +00:00
Add world settings generator + improve visualizers
This commit is contained in:
20
package-lock.json
generated
20
package-lock.json
generated
@@ -5,22 +5,22 @@
|
||||
"requires": true,
|
||||
"dependencies": {
|
||||
"@mcschema/core": {
|
||||
"version": "0.6.3",
|
||||
"resolved": "https://registry.npmjs.org/@mcschema/core/-/core-0.6.3.tgz",
|
||||
"integrity": "sha512-38sdUsiAzzHEl6vo6h7yud9BxjPB56CUIG3HETpCKdORN3KyETbYDOlajXHXmbrYvtPwIh0QMWNRmenkuNnthA=="
|
||||
"version": "0.6.4",
|
||||
"resolved": "https://registry.npmjs.org/@mcschema/core/-/core-0.6.4.tgz",
|
||||
"integrity": "sha512-CGPp8ccnwPNfPacVS8mwImP8kxAuPMhE6halZuOl70Rd4bK3sfAl8Nd+UWMnA3tR5d1fOI3Z0RAgp1eB/DYAOw=="
|
||||
},
|
||||
"@mcschema/java-1.16": {
|
||||
"version": "0.3.4",
|
||||
"resolved": "https://registry.npmjs.org/@mcschema/java-1.16/-/java-1.16-0.3.4.tgz",
|
||||
"integrity": "sha512-r15OHlez2Cj7brfStXX27PSniSsZNt25Cws7kMzKqmiYpom1SRO+WMS5mvbCfzuztxaA1qR8b+UX4r3/2qMXTg==",
|
||||
"version": "0.3.5",
|
||||
"resolved": "https://registry.npmjs.org/@mcschema/java-1.16/-/java-1.16-0.3.5.tgz",
|
||||
"integrity": "sha512-q4Njxud9ghSdNPIqYqDBSBoxZcycq+AXts2EDk4EofFMmKM11CVQRlL51CWO0LqV57k8s2X1v4ItsnLMTw1ekQ==",
|
||||
"requires": {
|
||||
"@mcschema/core": "^0.6.3"
|
||||
"@mcschema/core": "^0.6.4"
|
||||
}
|
||||
},
|
||||
"@mcschema/locales": {
|
||||
"version": "0.1.7",
|
||||
"resolved": "https://registry.npmjs.org/@mcschema/locales/-/locales-0.1.7.tgz",
|
||||
"integrity": "sha512-KJbKzWpw5XJdRtmih1cN5LqmMeoxtYeRkWu7fkfpH5Vo6ZshxceGyIqyIDsn06+rxkT5jyZX6bokmbn/P0Xwbg=="
|
||||
"version": "0.1.8",
|
||||
"resolved": "https://registry.npmjs.org/@mcschema/locales/-/locales-0.1.8.tgz",
|
||||
"integrity": "sha512-CnmN0ytut+moXDcDhvMVe0zrrYwM7pWa2RqxsFGa7a6QlID/TaYhUdfXqNpUbr1npu8EcEKV4nzSF7ev/XPghA=="
|
||||
},
|
||||
"@nodelib/fs.scandir": {
|
||||
"version": "2.1.3",
|
||||
|
||||
@@ -12,9 +12,9 @@
|
||||
"author": "Misode",
|
||||
"license": "MIT",
|
||||
"dependencies": {
|
||||
"@mcschema/core": "^0.6.3",
|
||||
"@mcschema/java-1.16": "^0.3.4",
|
||||
"@mcschema/locales": "^0.1.7",
|
||||
"@mcschema/core": "^0.6.4",
|
||||
"@mcschema/java-1.16": "^0.3.5",
|
||||
"@mcschema/locales": "^0.1.8",
|
||||
"@types/google.analytics": "0.0.40",
|
||||
"@types/split.js": "^1.4.0",
|
||||
"copy-webpack-plugin": "^6.0.1",
|
||||
|
||||
@@ -63,11 +63,10 @@ const treeViewObserver = (el: HTMLElement) => {
|
||||
|
||||
const treeViewNodeInjector = (path: ModelPath, view: TreeView) => {
|
||||
return VisualizerView.visualizers
|
||||
.filter(v => v.onPath(path))
|
||||
.filter(v => v.active(path.getModel()))
|
||||
.filter(v => v.active(path))
|
||||
.map(v => {
|
||||
const id = view.registerClick(() => {
|
||||
views.visualizer.set(v)
|
||||
views.visualizer.set(v, path)
|
||||
})
|
||||
return `<button data-id=${id}>${locale('visualize')} <svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 16 16" width="16" height="16"><path fill-rule="evenodd" d="M1.5 8a6.5 6.5 0 1113 0 6.5 6.5 0 01-13 0zM8 0a8 8 0 100 16A8 8 0 008 0zM6.379 5.227A.25.25 0 006 5.442v5.117a.25.25 0 00.379.214l4.264-2.559a.25.25 0 000-.428L6.379 5.227z"></path></svg></button>`
|
||||
})
|
||||
|
||||
@@ -1,11 +1,10 @@
|
||||
import SimplexNoise from 'simplex-noise'
|
||||
import { DataModel, Path } from "@mcschema/core"
|
||||
import { DataModel, Path, ModelPath } from "@mcschema/core"
|
||||
import { Visualizer } from './Visualizer'
|
||||
|
||||
|
||||
export class BiomeNoiseVisualizer extends Visualizer {
|
||||
static readonly noiseMaps = ['altitude', 'temperature', 'humidity', 'weirdness']
|
||||
static readonly path = new Path(['generator', 'biome_source'])
|
||||
private noise: SimplexNoise[]
|
||||
private offsetX: number = 0
|
||||
private offsetY: number = 0
|
||||
@@ -15,17 +14,9 @@ export class BiomeNoiseVisualizer extends Visualizer {
|
||||
this.noise = BiomeNoiseVisualizer.noiseMaps.map(e => new SimplexNoise())
|
||||
}
|
||||
|
||||
onPath(path: Path) {
|
||||
return path.equals(BiomeNoiseVisualizer.path)
|
||||
}
|
||||
|
||||
active(model: DataModel) {
|
||||
return model.get(BiomeNoiseVisualizer.path) !== undefined
|
||||
&& model.get(BiomeNoiseVisualizer.path.push('type')) === 'minecraft:multi_noise'
|
||||
}
|
||||
|
||||
getState(model: DataModel) {
|
||||
return model.get(BiomeNoiseVisualizer.path)
|
||||
active(path: ModelPath) {
|
||||
return path.endsWith(new Path(['generator', 'biome_source']))
|
||||
&& path.push('type').get() === 'minecraft:multi_noise'
|
||||
}
|
||||
|
||||
draw(model: DataModel, img: ImageData) {
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
import SimplexNoise from 'simplex-noise'
|
||||
import { DataModel, Path } from "@mcschema/core"
|
||||
import { DataModel, Path, ModelPath } from "@mcschema/core"
|
||||
import { Visualizer } from './Visualizer'
|
||||
|
||||
const debug = false
|
||||
@@ -14,22 +14,8 @@ export class NoiseSettingsVisualizer extends Visualizer {
|
||||
this.offsetX = 0
|
||||
}
|
||||
|
||||
onPath(path: Path) {
|
||||
return path.equals(new Path(['generator', 'settings', 'noise']))
|
||||
|| path.equals(new Path(['noise']))
|
||||
}
|
||||
|
||||
active(model: DataModel) {
|
||||
return true
|
||||
}
|
||||
|
||||
getState(model: DataModel) {
|
||||
return model.get(new Path(['generator', 'settings', 'noise']))
|
||||
?? model.get(new Path(['noise']))
|
||||
}
|
||||
|
||||
onDrag(from: number[], to: number[]) {
|
||||
this.offsetX += (to[0] - from[0])
|
||||
active(path: ModelPath) {
|
||||
return path.endsWith(new Path(['noise']))
|
||||
}
|
||||
|
||||
draw(model: DataModel, img: ImageData) {
|
||||
@@ -47,6 +33,10 @@ export class NoiseSettingsVisualizer extends Visualizer {
|
||||
}
|
||||
}
|
||||
|
||||
onDrag(from: number[], to: number[]) {
|
||||
this.offsetX += (to[0] - from[0])
|
||||
}
|
||||
|
||||
private getColor(densities: number[], y: number): number {
|
||||
if (debug) {
|
||||
return -densities[y] * 128 + 128
|
||||
|
||||
@@ -1,20 +1,13 @@
|
||||
import { DataModel, Path } from "@mcschema/core"
|
||||
import { BiomeNoiseVisualizer } from "./BiomeNoiseVisualizer"
|
||||
import { NoiseSettingsVisualizer } from "./NoiseSettingsVisualizer"
|
||||
import { DataModel, ModelPath } from "@mcschema/core"
|
||||
|
||||
export abstract class Visualizer {
|
||||
state: any
|
||||
|
||||
dirty(model: DataModel): boolean {
|
||||
return JSON.stringify(this.state) !== JSON.stringify(this.getState(model))
|
||||
dirty(path: ModelPath): boolean {
|
||||
return JSON.stringify(this.state) !== JSON.stringify(path.get())
|
||||
}
|
||||
|
||||
active(model: DataModel): boolean {
|
||||
return true
|
||||
}
|
||||
|
||||
abstract onPath(path: Path): boolean
|
||||
abstract getState(model: DataModel): any
|
||||
abstract active(path: ModelPath): boolean
|
||||
abstract draw(model: DataModel, img: ImageData): void
|
||||
|
||||
onDrag(from: number[], to: number[]): void {}
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
import { AbstractView, DataModel, Path } from "@mcschema/core"
|
||||
import { AbstractView, DataModel, Path, ModelPath } from "@mcschema/core"
|
||||
import { BiomeNoiseVisualizer } from "./BiomeNoiseVisualizer"
|
||||
import { NoiseSettingsVisualizer } from "./NoiseSettingsVisualizer"
|
||||
import { Visualizer } from "./Visualizer"
|
||||
@@ -7,6 +7,7 @@ export class VisualizerView extends AbstractView {
|
||||
ctx: CanvasRenderingContext2D
|
||||
visualizer?: Visualizer
|
||||
active: boolean
|
||||
path?: ModelPath
|
||||
canvas: HTMLElement
|
||||
sourceView: HTMLElement
|
||||
gutter: HTMLElement
|
||||
@@ -39,11 +40,12 @@ export class VisualizerView extends AbstractView {
|
||||
}
|
||||
|
||||
invalidated() {
|
||||
this.path = this.path?.withModel(this.model)
|
||||
let newState: any
|
||||
if (this.active && this.visualizer
|
||||
&& this.visualizer.active(this.model)
|
||||
&& (newState = this.visualizer.getState(this.model))) {
|
||||
if (this.visualizer.dirty(this.model)) {
|
||||
if (this.active && this.visualizer && this.path
|
||||
&& this.visualizer.active(this.path)
|
||||
&& (newState = this.path.get())) {
|
||||
if (newState && this.visualizer.dirty(this.path)) {
|
||||
const img = this.ctx.createImageData(200, 100)
|
||||
this.visualizer.state = JSON.parse(JSON.stringify(newState))
|
||||
this.visualizer.draw(this.model, img)
|
||||
@@ -60,13 +62,13 @@ export class VisualizerView extends AbstractView {
|
||||
this.gutter.style.display = 'none'
|
||||
this.lastHeight = this.sourceView.style.height
|
||||
this.sourceView.style.height = '100%'
|
||||
this.ctx.clearRect(0, 0, 200, 100)
|
||||
}
|
||||
}
|
||||
|
||||
set(visualizer: Visualizer) {
|
||||
set(visualizer: Visualizer, path: ModelPath) {
|
||||
this.active = true
|
||||
this.visualizer = visualizer
|
||||
this.path = path
|
||||
this.visualizer.state = undefined
|
||||
this.invalidated()
|
||||
}
|
||||
|
||||
@@ -108,6 +108,11 @@
|
||||
"schema": "template_pool"
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
"id": "world",
|
||||
"name": "Import World Settings",
|
||||
"schema": "world_settings"
|
||||
}
|
||||
],
|
||||
"registries": [
|
||||
|
||||
@@ -12,6 +12,7 @@
|
||||
"title.generator": "%0% Generator",
|
||||
"title.home": "Data Pack Generators",
|
||||
"visualize": "Visualize",
|
||||
"world": "World Settings",
|
||||
"worldgen/biome": "Biome",
|
||||
"worldgen/carver": "Carver",
|
||||
"worldgen/feature": "Feature",
|
||||
|
||||
Reference in New Issue
Block a user