diff --git a/custom.css b/custom.css index bb6c5143..1d873ce5 100644 --- a/custom.css +++ b/custom.css @@ -64,3 +64,9 @@ textarea.invalid:focus { max-height: 300px; overflow-x: hidden; } + +#source { + white-space: pre; + overflow-wrap: normal; + overflow-x: scroll; +} diff --git a/index.html b/index.html index dd229990..4f26a961 100644 --- a/index.html +++ b/index.html @@ -132,7 +132,16 @@ -
+
+
+ +
+ + + + +
+
@@ -141,6 +150,33 @@
+
+
+ +
+ +
+
+ +
+
+
+ +
+ +
+
+
+
+ +
+
+ + +
+
+
diff --git a/model.js b/model.js index d89291b6..95ad1cc6 100644 --- a/model.js +++ b/model.js @@ -185,6 +185,26 @@ function removeComponent(el) { } invalidated(); } +function addToSet(el, array) { + let parent = getParent(el); + if (!parent[array]) { + parent[array] = []; + } + parent[array].push($(el).attr('value')); + invalidated(); +} + +function removeFromSet(el, array) { + let parent = getParent(el); + 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(); + } +} function updateField(el) { let $field = $(el).closest('[data-field]'); @@ -217,6 +237,14 @@ function updateField(el) { } } else if (type === 'json') { value = parseJSONValue(value) + } else if (type === 'json-list') { + let value = []; + for (let line of $(el).val().split('\n')) { + value.push(parseJSONValue(line)); + } + if (value.length === 0) { + value = ''; + } } else if (type === 'range' || type === 'random') { value = getRangeValue($field, node[field]); } else if (type === 'checkbox') { @@ -406,16 +434,6 @@ function parseJSONValue(value) { return value; } -function updateLoreField(el) { - let lines = $(el).val().split('\n'); - let parent = getParent(el); - parent.lore = []; - for (let line of lines) { - parent.lore.push(parseJSONValue(line)); - } - invalidated(); -} - function addOperation(el) { let func = getParent(el); if (!func.ops) { diff --git a/schemas/1.14.json b/schemas/1.14.json index 86a9f039..64933b72 100644 --- a/schemas/1.14.json +++ b/schemas/1.14.json @@ -161,7 +161,8 @@ "type": "random", "default": 2, "require": [ - "minecraft:set_count" + "minecraft:set_count", + "minecraft:looting_enchant" ] }, { @@ -172,6 +173,137 @@ "minecraft:set_damage" ] }, + { + "id": "name", + "type": "json", + "require": [ + "minecraft:set_name" + ] + }, + { + "id": "lore", + "type": "json-list", + "require": [ + "minecraft:set_lore" + ] + }, + { + "id": "replace", + "type": "boolean", + "require": [ + "minecraft:set_lore" + ] + }, + { + "id": "tag", + "type": "string", + "require": [ + "minecraft:set_nbt" + ] + }, + { + "id": "levels", + "type": "random", + "require": [ + "minecraft:enchant_with_levels" + ] + }, + { + "id": "treasure", + "type": "boolean", + "default": false, + "require": [ + "minecraft:enchant_with_levels" + ] + }, + { + "id": "limit", + "type": "int", + "require": [ + "minecraft:looting_enchant" + ] + }, + { + "id": "limit", + "type": "boundary", + "require": [ + "minecraft:limit_count" + ] + }, + { + "id": "entity", + "type": "enum", + "values": [ + "minecraft:this", + "minecraft:killer", + "minecraft:killer_player" + ], + "require": [ + "minecraft:set_name", + "minecraft:set_lore", + "minecraft:fill_player_head" + ] + }, + { + "id": "source", + "type": "enum", + "values": [ + "minecraft:block_entity", + "minecraft:this", + "minecraft:killer", + "minecraft:killer_player" + ], + "require": [ + "minecraft:copy_name", + "minecraft:copy_nbt" + ] + }, + { + "id": "enchantments", + "type": "set", + "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:enchant_randomly" + ] + }, { "id": "conditions", "type": "array", diff --git a/view.js b/view.js index e06f87a7..92d62500 100644 --- a/view.js +++ b/view.js @@ -41,13 +41,19 @@ function generateTable() { function generateComponent(data, struct) { switch (struct.type) { case 'string': return generateString(data, struct); + case 'int': return generateString(data, struct); + case 'float': return generateString(data, struct); case 'boolean': return generateBoolean(data, struct); case 'random': return generateRandom(data, struct); case 'range': return generateRange(data, struct); + case 'boundary': return generateBoundary(data, struct); case 'enum': return generateEnum(data, struct); + case 'set': return generateSet(data, struct); + case 'json': return generateJson(data, struct); + case 'json-list': return generateJsonList(data, struct); case 'array': return generateArray(data, struct); case 'object': return generateObject(data, struct); - } + default: return generateError('Unknown component type "' + struct.type + '"')}; } function generateString(data, struct) { @@ -106,6 +112,17 @@ function generateRange(data, struct) { return $el; } +function generateBoundary(data, struct) { + let $el = $('#components').find('[data-type="boundary"]').clone(); + $el.attr('data-field', struct.id); + $el.find('[data-name]').attr('data-i18n', struct.id); + if (data) { + $el.find('.range.min').val(data.min); + $el.find('.range.max').val(data.max); + } + return $el; +} + function generateEnum(data, struct) { let $el = $('#components').find('[data-type="enum"]').clone(); $el.attr('data-field', struct.id); @@ -121,6 +138,65 @@ function generateEnum(data, struct) { return $el; } +function generateSet(data, struct) { + let $el = $('#components').find('[data-type="set"]').clone(); + $el.attr('data-field', struct.id); + $el.find('[data-name]').attr('data-i18n', struct.id); + for (let option of struct.values) { + $('').appendTo($el.find('.dropdown-menu')).attr('value', option).attr('data-i18n', struct.source + '.' + option); + } + if (data) { + console.log(data); + let $setContainer = $('
'); + for (let option of data) { + let $item = $('