From 9e97ccd3637065e71d2c8b771058c284a879d898 Mon Sep 17 00:00:00 2001 From: Misode Date: Fri, 13 Sep 2019 12:51:03 +0200 Subject: [PATCH] Add attribute modifiers + improve translation keys for enums and sets --- index.html | 1 - model.js | 3 -- schemas/1.14.json | 96 +++++++++++++++++++++++++++++++++++++++++++---- validate.js | 72 ----------------------------------- view.js | 28 +++++++++----- 5 files changed, 107 insertions(+), 93 deletions(-) delete mode 100644 validate.js diff --git a/index.html b/index.html index 4f26a961..0459ceb3 100644 --- a/index.html +++ b/index.html @@ -1107,7 +1107,6 @@ - diff --git a/model.js b/model.js index 95ad1cc6..bd43c1e6 100644 --- a/model.js +++ b/model.js @@ -199,9 +199,6 @@ function removeFromSet(el, array) { let index = parent[array].indexOf($(el).attr('value')); if (index > -1) { parent[array].splice(index, 1); - if (parent[array].length === 0) { - delete parent[array]; - } invalidated(); } } diff --git a/schemas/1.14.json b/schemas/1.14.json index 64933b72..b11323f6 100644 --- a/schemas/1.14.json +++ b/schemas/1.14.json @@ -102,6 +102,7 @@ "type": "array", "values": "entry", "button": "field", + "color": "success", "require": [ "minecraft:alternatives", "minecraft:sequence", @@ -187,13 +188,6 @@ "minecraft:set_lore" ] }, - { - "id": "replace", - "type": "boolean", - "require": [ - "minecraft:set_lore" - ] - }, { "id": "tag", "type": "string", @@ -233,6 +227,8 @@ { "id": "entity", "type": "enum", + "source": "source", + "default": "minecraft:this", "values": [ "minecraft:this", "minecraft:killer", @@ -247,6 +243,8 @@ { "id": "source", "type": "enum", + "source": "source", + "default": "minecraft:this", "values": [ "minecraft:block_entity", "minecraft:this", @@ -258,9 +256,17 @@ "minecraft:copy_nbt" ] }, + { + "id": "replace", + "type": "boolean", + "require": [ + "minecraft:set_lore" + ] + }, { "id": "enchantments", "type": "set", + "source": "enchantment", "values": [ "minecraft:aqua_affinity", "minecraft:bane_of_arthropods", @@ -304,6 +310,15 @@ "minecraft:enchant_randomly" ] }, + { + "id": "modifiers", + "type": "array", + "button": "field", + "values": "attribute_modifier", + "require": [ + "minecraft:set_attributes" + ] + }, { "id": "conditions", "type": "array", @@ -323,6 +338,73 @@ "fields": [ ] + }, + { + "id": "attribute_modifier", + "type": "object", + "color": "dark", + "default": { + "attribute": "generic.attackDamage", + "name": "Attack Damage", + "amount": 1, + "operation": "addition", + "slot": [] + }, + "fields": [ + { + "id": "attribute", + "type": "enum", + "source": "attribute", + "default": "generic.attackDamage", + "values": [ + "generic.maxHealth", + "generic.followRange", + "generic.knockbackResistance", + "generic.movementSpeed", + "generic.attackDamage", + "generic.armor", + "generic.armorToughness", + "generic.attackSpeed", + "generic.luck", + "horse.jumpStrength", + "generic.attackKnockback", + "generic.flyingSpeed", + "zombie.spawnReinforcements" + ] + }, + { + "id": "name", + "type": "string" + }, + { + "id": "amount", + "type": "float", + "default": 1 + }, + { + "id": "operation", + "type": "enum", + "source": "modifier.operation", + "default": "addition", + "values": [ + "addition", + "multiply_base", + "multiply_total" + ] + }, + { + "id": "slots", + "type": "set", + "values": [ + "mainhand", + "offhand", + "head", + "chest", + "legs", + "feet" + ] + } + ] } ] } diff --git a/validate.js b/validate.js deleted file mode 100644 index d2e0ce48..00000000 --- a/validate.js +++ /dev/null @@ -1,72 +0,0 @@ - -function isString(data) { - return data != undefined && typeof data === 'string'; -} - -function isNumber(data) { - return data != undefined && typeof data === 'number'; -} - -function isObject(data) { - return data != undefined && typeof data === 'object' && !Array.isArray(data); -} - -function isArray(data) { - return data != undefined && typeof data === 'object' && Array.isArray(data); -} - -function validateRange(data) { - if (data === undefined) return false; - if (isObject(data)) { - if (isString(data.type) && data.type.endsWith('binomial')) { - if (isNumber(data.n) && isNumber(data.p)) { - return { - type: 'minecraft:binomial', - n: data.n, - p: data.p - }; - } - } - let res = {}; - if (isNumber(data.min)) res.min = data.min; - if (isNumber(data.max)) res.max = data.max; - } - return false; -} - -function chooseOption(options, value, def) { - for (option of options) { - if (value === option) { - return value; - } else if('minecraft:' + value === option) { - return 'minecraft:' + value; - } - } - return def; -} - -function namespace(list) { - let res = []; - for (let item of list) { - res.push('minecraft:' + item); - } - return res; -} - -function validateTable(table) { - let res = {}; - res.type = chooseOption(namespace(['empty', 'entity', 'block', 'chest', 'fishing', 'generic']), table.type, 'minecraft:generic'); - res.pools = []; - if (isArray(table.pools)) { - for (let pool of table.pools) { - res.pools.push(validatePool(pool)); - } - } - return res; -} - -function validatePool() { - let res = {}; - res - return res; -} diff --git a/view.js b/view.js index 92d62500..a8749b9d 100644 --- a/view.js +++ b/view.js @@ -127,8 +127,8 @@ function generateEnum(data, struct) { let $el = $('#components').find('[data-type="enum"]').clone(); $el.attr('data-field', struct.id); $el.find('[data-name]').attr('data-i18n', struct.id); - for (let option of struct.values) { - $('