Add predicate mode

This commit is contained in:
Misode
2019-12-13 18:53:01 +01:00
parent d56b6d5495
commit 2ac16fd0e7
9 changed files with 77 additions and 43 deletions

View File

@@ -11,13 +11,13 @@
</script> </script>
<meta charset="utf-8"> <meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no"> <meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
<title data-i18n="title"></title> <title data-i18n="title.loot-table"></title>
<link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.2.1/css/bootstrap.min.css" integrity="sha384-GJzZqFGwb1QTTN6wy59ffF1BuGJpLSa9DkKMp0DgiMDm4iYMj70gZWKYbI706tWS" crossorigin="anonymous"> <link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.2.1/css/bootstrap.min.css" integrity="sha384-GJzZqFGwb1QTTN6wy59ffF1BuGJpLSa9DkKMp0DgiMDm4iYMj70gZWKYbI706tWS" crossorigin="anonymous">
<link rel="stylesheet" href="custom.css"> <link rel="stylesheet" href="custom.css">
</head> </head>
<body> <body>
<nav class="navbar navbar-expand-md navbar-dark bg-dark"> <nav class="navbar navbar-expand-md navbar-dark bg-dark">
<span class="navbar-brand mb-0 h1" data-i18n="description"></span> <span id="descriptionSpan" class="navbar-brand mb-0 h1" data-i18n="description.loot-table"></span>
<button class="navbar-toggler navbar-toggler-right" type="button" data-toggle="collapse" data-target="#collapsibleNavbar"> <button class="navbar-toggler navbar-toggler-right" type="button" data-toggle="collapse" data-target="#collapsibleNavbar">
<span class="navbar-toggler-icon"></span> <span class="navbar-toggler-icon"></span>
</button> </button>
@@ -43,8 +43,8 @@
</nav> </nav>
<div class="container d-none"> <div class="container d-none">
<div class="row my-4"> <div class="row my-4">
<div class="col-12 col-lg-7 mb-3 structure-container" data-index="table"> <div class="col-12 col-lg-7 mb-3 structure-container" data-index="root">
<div class="input-group"> <div id="lootTableToolbar" class="input-group d-none mb-3">
<button type="button" class="btn btn-success d-block mr-3 float-left" onclick="addComponent(this, 'pools')" data-field="table" data-i18n="pool_add"></button> <button type="button" class="btn btn-success d-block mr-3 float-left" onclick="addComponent(this, 'pools')" data-field="table" data-i18n="pool_add"></button>
<div class="input-group-prepend table-type"> <div class="input-group-prepend table-type">
<span class="input-group-text rounded-left" data-i18n="table.type"></span> <span class="input-group-text rounded-left" data-i18n="table.type"></span>
@@ -58,7 +58,7 @@
<button type="button" class="btn btn-secondary" onclick="showSource()" data-i18n="show_source"></button> <button type="button" class="btn btn-secondary" onclick="showSource()" data-i18n="show_source"></button>
</div> </div>
</div> </div>
<div id="structure" class="loot-table mt-3" data-index="pools"> <div id="structure" class="loot-table" data-index="root">
</div> </div>
</div> </div>
<div class="col-12 col-lg-5 source-container"> <div class="col-12 col-lg-5 source-container">

View File

@@ -75,7 +75,8 @@
"damage_source.is_magic": "Magic", "damage_source.is_magic": "Magic",
"damage_source.is_projectile": "Projectile", "damage_source.is_projectile": "Projectile",
"damage_source.source_entity": "Source Entity", "damage_source.source_entity": "Source Entity",
"description": "Loot Table Generator for Minecraft", "description.loot-table": "Loot Table Generator for Minecraft",
"description.predicate": "Predicate Generator for Minecraft",
"dimension.overworld": "Overworld", "dimension.overworld": "Overworld",
"dimension.the_end": "The End", "dimension.the_end": "The End",
"dimension.the_nether": "The Nether", "dimension.the_nether": "The Nether",
@@ -290,7 +291,8 @@
"tabs": "Tabs", "tabs": "Tabs",
"term_add": "Add Term", "term_add": "Add Term",
"term_remove": "Remove Term", "term_remove": "Remove Term",
"title": "Loot Table Generator", "title.loot-table": "Loot Table Generator",
"title.predicate": "Predicate Generator",
"true": "True", "true": "True",
"unset": "Unset" "unset": "Unset"
} }

View File

@@ -82,7 +82,7 @@
"damage_source.is_magic": "Магия", "damage_source.is_magic": "Магия",
"damage_source.is_projectile": "Снаряд", "damage_source.is_projectile": "Снаряд",
"damage_source.source_entity": "Сущность-источник урона", "damage_source.source_entity": "Сущность-источник урона",
"description": "Генератор таблицы добычи для Minecraft", "description.loot-table": "Генератор таблицы добычи для Minecraft",
"dimension.overworld": "Обычный мир", "dimension.overworld": "Обычный мир",
"dimension.the_end": "Энд", "dimension.the_end": "Энд",
"dimension.the_nether": "Незер", "dimension.the_nether": "Незер",
@@ -298,7 +298,7 @@
"tabs": "Табуляция", "tabs": "Табуляция",
"term_add": "Добавить выражение", "term_add": "Добавить выражение",
"term_remove": "Удалить выражение", "term_remove": "Удалить выражение",
"title": "Генератор таблицы добычи", "title.loot-table": "Генератор таблицы добычи",
"true": "Да", "true": "Да",
"unset": "Не задано" "unset": "Не задано"
} }

View File

@@ -82,7 +82,7 @@
"damage_source.is_magic": "魔法", "damage_source.is_magic": "魔法",
"damage_source.is_projectile": "弹射物", "damage_source.is_projectile": "弹射物",
"damage_source.source_entity": "根本来源实体", "damage_source.source_entity": "根本来源实体",
"description": "Minecraft 战利品表生成器", "description.loot-table": "Minecraft 战利品表生成器",
"dimension.overworld": "主世界", "dimension.overworld": "主世界",
"dimension.the_end": "末路之地", "dimension.the_end": "末路之地",
"dimension.the_nether": "下界", "dimension.the_nether": "下界",
@@ -299,7 +299,7 @@
"tabs": "Tab 缩进", "tabs": "Tab 缩进",
"term_add": "添加条件", "term_add": "添加条件",
"term_remove": "移除条件", "term_remove": "移除条件",
"title": "战利品表生成器", "title.loot-table": "战利品表生成器",
"true": "是", "true": "是",
"unset": "未指定" "unset": "未指定"
} }

View File

@@ -148,7 +148,7 @@ function copySource(el) {
function getPath(el) { function getPath(el) {
let $node = $(el).closest('[data-index]'); let $node = $(el).closest('[data-index]');
let index = $node.attr('data-index'); let index = $node.attr('data-index');
if (index === 'table') return []; if (index === 'root') return [];
let parent = getPath($node.parent()); let parent = getPath($node.parent());
parent = parent.concat(index.split('.')); parent = parent.concat(index.split('.'));
return parent; return parent;

View File

@@ -1,5 +1,6 @@
{ {
"root": { "root": {
"id": "loot-table",
"fields": [ "fields": [
{ {
"id": "pools", "id": "pools",

View File

@@ -1,5 +1,6 @@
{ {
"root": { "root": {
"id": "loot-table",
"fields": [ "fields": [
{ {
"id": "type", "id": "type",

View File

@@ -1,5 +1,9 @@
{ {
"root": { "roots": [
{
"id": "loot-table",
"title": "title.loot-table",
"description": "description.loot-table",
"fields": [ "fields": [
{ {
"id": "type", "id": "type",
@@ -24,6 +28,14 @@
} }
] ]
}, },
{
"id": "predicate",
"title": "title.predicate",
"description": "description.predicate",
"type": "object",
"value": "condition"
}
],
"components": [ "components": [
{ {
"id": "pool", "id": "pool",

28
view.js
View File

@@ -2,10 +2,16 @@ let structure;
let components; let components;
let collections; let collections;
changeVersion('1.14'); changeVersion('1.15');
function changeVersion(version) { function changeVersion(version) {
$.getJSON('schemas/' + version + '.json', json => { $.getJSON('schemas/' + version + '.json', json => {
console.log(json);
if (json.root) {
structure = json.root; structure = json.root;
} else if (json.roots) {
let id = window.location.pathname.replace(/\/$/, '').replace(/^\//, '');
structure = json.roots.find(e => e.id === id);
}
components = json.components; components = json.components;
collections = json.collections; collections = json.collections;
}).fail((jqXHR, textStatus, errorThrown) => { }).fail((jqXHR, textStatus, errorThrown) => {
@@ -28,19 +34,31 @@ function changeVersion(version) {
function updateView() { function updateView() {
if (structure) { if (structure) {
let {out: tableOut, component: $table} = generateTable(table, structure); let {out: sourceOut, component: $component} = generateSourceAndView(table, structure);
$('#structure').append($table); $('#structure').removeClass('d-none').html('');
$('#descriptionSpan').attr('data-i18n', structure.description);
$('title').attr('data-i18n', structure.title);
$('#structure').append($component);
if (i18next.isInitialized) { if (i18next.isInitialized) {
$('html').localize(); $('html').localize();
} }
$('#source').val(JSON.stringify(tableOut, null, indentation)); $('#source').val(JSON.stringify(sourceOut, null, indentation));
}
}
function generateSourceAndView(data, struct) {
if (struct.id === 'loot-table') {
$('#lootTableToolbar').removeClass('d-none');
$('#structure').attr('data-index', 'pools');
return generateTable(data, struct);
} else {
return generateObject(data, struct, false);
} }
} }
function generateTable(data, struct) { function generateTable(data, struct) {
let out = {}; let out = {};
let $el = $('<div/>'); let $el = $('<div/>');
$('#structure').removeClass('d-none').html('');
let type = struct.fields.find(e => e.id === 'type'); let type = struct.fields.find(e => e.id === 'type');
if (type) { if (type) {