From 4bac2fe276823ad5cd04b502dc1e68c5418f89fb Mon Sep 17 00:00:00 2001 From: Misode Date: Mon, 23 Sep 2019 00:36:06 +0200 Subject: [PATCH] Add object nesting and object collapsing --- index.html | 4 +- model.js | 87 +++------------------- schemas/1.14.json | 185 +++++++++++++++++++++++++++++++++++++++++++++- view.js | 61 +++++++++------ 4 files changed, 237 insertions(+), 100 deletions(-) diff --git a/index.html b/index.html index 68aaa770..95e68a32 100644 --- a/index.html +++ b/index.html @@ -185,7 +185,7 @@ -
+
diff --git a/model.js b/model.js index 65d4ae4e..030523ba 100644 --- a/model.js +++ b/model.js @@ -245,6 +245,17 @@ function removeFromSet(el, array) { } } +function toggleCollapseObject(el) { + let parent = getSuperParent(el); + let field = $(el).closest('[data-field]').attr('data-field'); + if (!parent[field]) { + parent[field] = {}; + } else { + delete parent[field]; + } + invalidated(); +} + function updateField(el) { let $field = $(el).closest('[data-field]'); let fields = $field.attr('data-field'); @@ -349,63 +360,6 @@ function getBooleanValue(oldvalue, newvalue) { } } -function addEnchantment(el) { - let func = getParent(el); - let enchantment = $(el).attr('data-ench'); - if (!func.enchantments) { - func.enchantments = []; - } - func.enchantments.push(enchantment); - invalidated(); -} - -function removeEnchantment(el) { - let func = getParent(el); - let ench = $(el).attr('data-ench'); - let index = func.enchantments.indexOf(ench); - if (index > -1) { - func.enchantments.splice(index, 1); - if (func.enchantments.length === 0) { - delete func.enchantments; - } - invalidated(); - } -} - -function addModifier(el) { - let func = getParent(el); - if (!func.modifiers) { - func.modifiers = []; - } - func.modifiers.push({ - attribute: 'generic.attackDamage', - name: 'Attack Damage', - amount: 1, - operation: 'addition', - slot: [] - }); - invalidated(); -} - -function addModifierSlot(el) { - let modifier = getParent(el); - if (!modifier.slot) { - modifier.slot = []; - } - modifier.slot.push($(el).attr('data-slot')); - invalidated(); -} - -function removeModifierSlot(el) { - let modifier = getParent(el); - let slot = $(el).attr('data-slot'); - let index = modifier.slot.indexOf(slot); - if (index > -1) { - modifier.slot.splice(index, 1); - invalidated(); - } -} - function addScore(el) { let condition = getParent(el); let objective = $(el).closest('.condition-entity-scores').find('input').val(); @@ -473,25 +427,6 @@ function parseJSONValue(value) { return value; } -function addOperation(el) { - let func = getParent(el); - if (!func.ops) { - func.ops = []; - } - func.ops.push({ - source: '', - target: '', - op: 'replace' - }); - invalidated(); -} - -function removeOperation(el) { - let index = parseInt($(el).closest('.operation').attr('data-index')); - getSuperParent(el).ops.splice(index, 1); - invalidated(); -} - function addBlockProperty(el) { let func = getParent(el); let blockstate = $(el).closest('.condition-block-properties').find('input').val(); diff --git a/schemas/1.14.json b/schemas/1.14.json index 64c23fb5..7182b15c 100644 --- a/schemas/1.14.json +++ b/schemas/1.14.json @@ -438,7 +438,158 @@ "chance": 0.5 }, "fields": [ - + { + "id": "condition", + "type": "enum", + "source": "condition", + "default": "minecraft:random_chance", + "values": [ + "minecraft:alternative", + "minecraft:inverted", + "minecraft:entity_properties", + "minecraft:block_state_propery", + "minecraft:match_tool", + "minecraft:damage_source_properties", + "minecraft:location_check", + "minecraft:weather_check", + "minecraft:entity_scores", + "minecraft:random_chance", + "minecraft:random_chance_with_looting", + "minecraft:table_bonus", + "minecraft:killed_by_player", + "minecraft:survives_explosion" + ] + }, + { + "id": "chance", + "type": "float", + "require": [ + "minecraft:random_chance", + "minecraft:random_chance_with_looting" + ] + }, + { + "id": "looting_multiplier", + "type": "float", + "require": [ + "minecraft:random_chance_with_looting" + ] + }, + { + "id": "inverted", + "type": "boolean", + "require": [ + "minecraft:killed_by_player" + ] + }, + { + "id": "entity", + "type": "enum", + "default": "this", + "values": [ + "this", + "killer", + "killer_player" + ], + "require": [ + "minecraft:entity_properties", + "minecraft:entity_scores" + ] + }, + { + "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:table_bonus" + ] + }, + { + "id": "chances", + "type": "list", + "require": [ + "minecraft:table_bonus" + ] + }, + { + "id": "raining", + "type": "boolean", + "require": [ + "minecraft:weather_check" + ] + }, + { + "id": "thundering", + "type": "boolean", + "require": [ + "minecraft:weather_check" + ] + }, + { + "id": "predicate", + "type": "object", + "value": "entity", + "require": [ + "minecraft:entity_properties" + ] + }, + { + "id": "term", + "type": "object", + "value": "condition", + "button": "field", + "require": [ + "minecraft:inverted" + ] + }, + { + "id": "terms", + "type": "array", + "values": "condition", + "button": "field", + "require": [ + "minecraft:alternative" + ] + } ] }, { @@ -538,6 +689,38 @@ ] } ] + }, + { + "id": "entity", + "type": "object", + "color": "dark", + "fields": [ + { + "id": "type", + "type": "string" + }, + { + "id": "nbt", + "type": "nbt" + }, + { + "id": "location", + "type": "object", + "value": "location", + "collapse": true + } + ] + }, + { + "id": "location", + "type": "object", + "color": "dark", + "fields": [ + { + "id": "biome", + "type": "string" + } + ] } ] } diff --git a/view.js b/view.js index e96d6850..9e7078f5 100644 --- a/view.js +++ b/view.js @@ -53,7 +53,7 @@ function generateComponent(data, struct) { case 'json-list': return generateJsonList(data, struct); case 'nbt': return generateNbt(data, struct); case 'array': return generateArray(data, struct); - case 'object': return generateObject(data, struct); + case 'object': return generateObject(data, struct, false); default: return generateError('Unknown component type "' + struct.type + '"')}; } @@ -131,11 +131,7 @@ function generateEnum(data, struct) { for (let value of struct.values) { $el.find('select').append(setValueAndName($('