From b9f53b79c997a0e8d2ee70d139d908b233d72d01 Mon Sep 17 00:00:00 2001 From: Misode Date: Thu, 18 Jun 2020 23:01:13 +0200 Subject: [PATCH] Refactor error view and make loot table default --- src/app/ErrorsView.ts | 21 ++++++++++++++------- src/app/app.ts | 3 +++ src/home.html | 13 ------------- src/{generator.html => index.html} | 0 webpack.config.js | 14 +++++++------- 5 files changed, 24 insertions(+), 27 deletions(-) delete mode 100644 src/home.html rename src/{generator.html => index.html} (100%) diff --git a/src/app/ErrorsView.ts b/src/app/ErrorsView.ts index 539e2a35..528cb161 100644 --- a/src/app/ErrorsView.ts +++ b/src/app/ErrorsView.ts @@ -1,18 +1,25 @@ -import { AbstractView, Path, locale, DataModel } from "minecraft-schemas"; +import { IView, locale, DataModel, ModelListener } from "minecraft-schemas"; +import { Errors } from "minecraft-schemas/lib/model/Errors"; -export class ErrorsView extends AbstractView { +export class ErrorsView implements ModelListener, IView { + model: DataModel target: HTMLElement constructor(model: DataModel, target: HTMLElement) { - super(model) + this.model = model this.target = target } - render(): void { - this.target.style.display = this.model.errors.count() > 0 ? 'flex' : 'none' + setModel(newModel: DataModel) { + this.model.removeListener(this) + this.model = newModel + this.model.addListener(this) + } + + errors(errors: Errors): void { + this.target.style.display = errors.count() > 0 ? 'flex' : 'none' - const errors = this.model.errors.get(new Path()) - this.target.children[0].innerHTML = errors.map(err => + this.target.children[0].innerHTML = errors.getAll().map(err => `
${err.path.toString()} diff --git a/src/app/app.ts b/src/app/app.ts index dc976efb..7a5dc030 100644 --- a/src/app/app.ts +++ b/src/app/app.ts @@ -99,6 +99,9 @@ Promise.all([ const treeControlsRedo = document.getElementById('tree-controls-redo')! let selected = modelFromPath(location.pathname) + if (selected.length === 0) { + selected = 'loot-table' + } const models: { [key: string]: DataModel } = { 'loot-table': new DataModel(LootTableSchema), diff --git a/src/home.html b/src/home.html deleted file mode 100644 index c1815bc9..00000000 --- a/src/home.html +++ /dev/null @@ -1,13 +0,0 @@ - - - - - - <%= htmlWebpackPlugin.options.title %> - - - -
-
- - diff --git a/src/generator.html b/src/index.html similarity index 100% rename from src/generator.html rename to src/index.html diff --git a/webpack.config.js b/webpack.config.js index 433683aa..68abcfff 100644 --- a/webpack.config.js +++ b/webpack.config.js @@ -36,37 +36,37 @@ module.exports = (env, argv) => ({ new HtmlWebpackPlugin({ title: 'Minecraft Generators', filename: 'index.html', - template: 'src/home.html' + template: 'src/index.html' }), new HtmlWebpackPlugin({ title: 'Loot Table Generator Minecraft', filename: 'loot-table/index.html', - template: 'src/generator.html' + template: 'src/index.html' }), new HtmlWebpackPlugin({ title: 'Predicate Generator Minecraft', filename: 'predicate/index.html', - template: 'src/generator.html' + template: 'src/index.html' }), new HtmlWebpackPlugin({ title: 'Advancement Generator Minecraft', filename: 'advancement/index.html', - template: 'src/generator.html' + template: 'src/index.html' }), new HtmlWebpackPlugin({ title: 'Dimension Generator Minecraft', filename: 'dimension/index.html', - template: 'src/generator.html' + template: 'src/index.html' }), new HtmlWebpackPlugin({ title: 'Dimension Type Generator Minecraft', filename: 'dimension-type/index.html', - template: 'src/generator.html' + template: 'src/index.html' }), new HtmlWebpackPlugin({ title: 'Sandbox Generator Minecraft', filename: 'sandbox/index.html', - template: 'src/generator.html' + template: 'src/index.html' }) ] })