From dec0e82eb3a9ecc11e837e8e2be7c059d7c7e7f3 Mon Sep 17 00:00:00 2001 From: Misode Date: Fri, 13 Sep 2019 16:44:01 +0200 Subject: [PATCH] Improve filtering + add apply_bonus parameters --- model.js | 8 ++-- schemas/1.14.json | 93 +++++++++++++++++++++++++++++++++++++++++++++++ view.js | 67 ++++++++++++++++++++++++++-------- 3 files changed, 149 insertions(+), 19 deletions(-) diff --git a/model.js b/model.js index ccf494f7..65d4ae4e 100644 --- a/model.js +++ b/model.js @@ -5,7 +5,7 @@ $('#tableType').val("minecraft:generic"); $('#indentationSelect').val("2"); let indentation = 2; -let luck_based = false; +let luckBased = false; let table = { type: "minecraft:generic", pools: [ @@ -21,8 +21,8 @@ let table = { ] }; let historyBuffer = 100; -let history = []; -let historyIndex = -1; +let history = ['{}']; +let historyIndex = 0; invalidated(); const params = new URLSearchParams(window.location.search); @@ -82,7 +82,7 @@ function updateTableType() { } function updateLuckBased() { - luck_based = $('#luckBased').prop('checked'); + luckBased = $('#luckBased').prop('checked'); invalidated(); } diff --git a/schemas/1.14.json b/schemas/1.14.json index dca1ffa6..64c23fb5 100644 --- a/schemas/1.14.json +++ b/schemas/1.14.json @@ -328,6 +328,99 @@ "minecraft:copy_nbt" ] }, + { + "id": "enchantment", + "type": "enum", + "source": "enchantment", + "values": [ + "minecraft:aqua_affinity", + "minecraft:bane_of_arthropods", + "minecraft:blast_protection", + "minecraft:channeling", + "minecraft:binding_curse", + "minecraft:vanishing_curse", + "minecraft:depth_strider", + "minecraft:efficiency", + "minecraft:feather_falling", + "minecraft:fire_aspect", + "minecraft:fire_protection", + "minecraft:flame", + "minecraft:fortune", + "minecraft:frost_walker", + "minecraft:impaling", + "minecraft:infinity", + "minecraft:knockback", + "minecraft:looting", + "minecraft:loyalty", + "minecraft:luck_of_the_sea", + "minecraft:lure", + "minecraft:mending", + "minecraft:multishot", + "minecraft:piercing", + "minecraft:power", + "minecraft:projectile_protection", + "minecraft:protection", + "minecraft:punch", + "minecraft:quick_charge", + "minecraft:respiration", + "minecraft:riptide", + "minecraft:sharpness", + "minecraft:silk_touch", + "minecraft:smite", + "minecraft:sweeping", + "minecraft:thorns", + "minecraft:unbreaking" + ], + "require": [ + "minecraft:apply_bonus" + ] + }, + { + "id": "formula", + "type": "enum", + "default": "minecraft:uniform_bonus_count", + "values": [ + "minecraft:uniform_bonus_count", + "minecraft:binomial_with_bonus_count", + "minecraft:ore_drops" + ], + "require": [ + "minecraft:apply_bonus" + ] + }, + { + "id": "parameters.bonusMultiplier", + "type": "float", + "default": 1, + "require": [ + { + "function": "minecraft:apply_bonus", + "formula": "minecraft:uniform_bonus_count" + } + ] + }, + { + "id": "parameters.extra", + "type": "int", + "default": 0, + "require": [ + { + "function": "minecraft:apply_bonus", + "formula": "minecraft:binomial_with_bonus_count" + } + ] + }, + { + "id": "parameters.probability", + "type": "float", + "default": 0.5, + "require": [ + { + "function": "minecraft:apply_bonus", + "formula": "minecraft:binomial_with_bonus_count" + } + ] + }, { "id": "conditions", "type": "array", diff --git a/view.js b/view.js index da1907eb..e96d6850 100644 --- a/view.js +++ b/view.js @@ -34,7 +34,7 @@ function generateTable() { $('#structure').append($table); } - $('#luck-based').attr('checked', luck_based); + $('#luck-based').attr('checked', luckBased); } @@ -234,24 +234,16 @@ function generateObject(data, struct) { let $el = $('
').addClass('card bg-' + struct.color + ' mt-3'); let $header = $('
').appendTo($el); let $body = $('
').appendTo($el); - let filter = struct.fields.find(e => e.type === 'enum'); $header.append(''); if (data._collapsed) { return $el; } for (let field of struct.fields) { - if ((luck_based || !field.luck_based) && (!field.require || (filter && field.require.includes(data[filter.id])))) { - let $field; - try { - $field = generateComponent(data[field.id], field); - } catch (e) { - console.error(e); - $field = generateError('Failed generating "' + field.id + '" component'); - } - if (field.class) { - $field.addClass(field.class); - } + let $field = generateField(data, field, struct); + if ($field !== false) { if (field.type === 'array') { + console.log('array!'); + console.log(field.id); let color = field.color; if (color === undefined) { color = components.find(e => e.id === field.values).color; @@ -262,8 +254,6 @@ function generateObject(data, struct) { if (field.button === 'field') { $body.append(''); } - } else { - $field.attr('data-field', field.id); } $body.append($field); } else { @@ -274,6 +264,53 @@ function generateObject(data, struct) { return $el; } +function generateField(data, field, parent) { + if (!luckBased && field.luck_based) { + return false; + } + if (field.require) { + let passing = false; + let filter = parent.fields.find(e => e.type === 'enum'); + for (let requirement of field.require) { + if (typeof requirement === 'string') { + if (requirement === data[filter.id]) { + passing = true; + } + } else { + let match = true; + for (let id in requirement) { + if (requirement.hasOwnProperty(id)) { + if (requirement[id] !== data[parent.fields.find(e => e.id === id).id]) { + match = false; + } + } + } + if (match) { + passing = true; + } + } + } + if (!passing) { + return false; + } + } + + let $field; + try { + $field = generateComponent(data[field.id], field); + } catch (e) { + console.error(e); + $field = generateError('Failed generating "' + field.id + '" component'); + } + if (field.class) { + $field.addClass(field.class); + } + if (field.type !== 'array') { + $field.attr('data-field', field.id); + } + return $field; +} + function preventNewline(e) { if (e.which === 13) { $(e.target).trigger('change');