diff --git a/js/model.js b/js/model.js index 11b1a5d3..0ff9e0da 100644 --- a/js/model.js +++ b/js/model.js @@ -49,7 +49,6 @@ function loadGenerator(generator) { } function loadVersion(generator, version) { - console.warn(generator, version); return $.getJSON('../schemas/' + version + '.json', json => { structure = json.root || json.roots.find(e => e.id === generator); components = json.components; @@ -287,6 +286,9 @@ function addToMap(el) { if (!isValidMapKey(key, node[map])) { return; } + if ($field.attr('data-resource')) { + key = fixResource(key) + } if (type === 'int' || type === 'float' || type === 'random' || type === 'range' || type === 'boundary') { node[map][key] = 0; } else if (type === 'boolean') { @@ -413,6 +415,11 @@ function updateField(el) { } else if (type === 'boolean') { value = getBooleanValue(node[field], ($(el).val() === 'true')); } + + if ($field.attr('data-resource')) { + value = fixResource(value) + } + if (value === '') { delete node[field]; } else { @@ -424,6 +431,17 @@ function updateField(el) { invalidated(); } +function fixResource(value) { + const test = /^([a-z0-9_.-]*:)?[a-z0-9/_.-]+$/; + if (value.match(test) === null) { + value = value.toLowerCase(); + if (value.match(test) === null) { + value = value.replace(/[^a-z0-9_.-]/g, '') + } + } + return value; +} + function updateRangeType(el) { let path = getPath(el); let field = path.pop(); diff --git a/js/view.js b/js/view.js index c8a26217..e2f77e7e 100644 --- a/js/view.js +++ b/js/view.js @@ -104,6 +104,7 @@ function generateString(data, struct) { let $el = $('#components').find('[data-type="string"]').clone(); $el.attr('data-type', struct.type); $el.attr('data-index', struct.id); + $el.attr('data-resource', struct.resource); $el.find('[data-name]').attr('data-i18n', struct.translate); $el.find('input').val(data); if (struct.help) { @@ -262,6 +263,7 @@ function generateMap(data, struct) { let $input = $el.find('input') let out; $el.attr('data-index', struct.id).attr('data-item-type', struct.values.type); + $el.attr('data-resource', struct.resource); $el.find('[data-name="1"]').attr('data-i18n', struct.translate); $el.find('[data-name="2"]').attr('data-i18n', struct.translate + '_add'); if (struct.help) { diff --git a/schemas/1.13.json b/schemas/1.13.json index 0a0c9209..9ce3bc29 100644 --- a/schemas/1.13.json +++ b/schemas/1.13.json @@ -66,6 +66,7 @@ { "id": "name", "type": "string", + "resource": true, "translate": "entry.name", "require": [ "minecraft:item", @@ -394,6 +395,7 @@ { "id": "effects", "type": "map", + "resource": true, "translate": "entity.status_effect", "values": { "type": "object", diff --git a/schemas/1.14.json b/schemas/1.14.json index 55ed0769..cb2576df 100644 --- a/schemas/1.14.json +++ b/schemas/1.14.json @@ -93,6 +93,7 @@ { "id": "name", "type": "string", + "resource": true, "translate": "entry.name", "require": [ "minecraft:item", @@ -563,6 +564,7 @@ { "id": "block", "type": "string", + "resource": true, "translate": "condition.block", "require": [ "minecraft:block_state_property" @@ -571,6 +573,7 @@ { "id": "properties", "type": "map", + "resource": true, "translate": "condition.block_state", "values": { "type": "string" @@ -870,6 +873,7 @@ { "id": "effects", "type": "map", + "resource": true, "translate": "entity.status_effect", "values": { "type": "object", @@ -1000,6 +1004,7 @@ { "id": "type", "type": "string", + "resource": true, "translate": "potion_effect.type" }, { @@ -1017,11 +1022,13 @@ { "id": "item", "type": "string", + "resource": true, "translate": "item.name" }, { "id": "tag", "type": "string", + "resource": true, "translate": "item.tag" }, { @@ -1037,6 +1044,7 @@ { "id": "potion", "type": "string", + "resource": true, "translate": "item.potion" }, { diff --git a/schemas/1.15.json b/schemas/1.15.json index 7b113572..ec0d98bd 100644 --- a/schemas/1.15.json +++ b/schemas/1.15.json @@ -76,7 +76,8 @@ { "id": "item", "translate": "display.icon.item", - "type": "string" + "type": "string", + "resource": true }, { "id": "nbt", @@ -132,7 +133,8 @@ { "id": "parent", "translate": "parent", - "type": "string" + "type": "string", + "resource": true }, { "id": "rewards", @@ -144,7 +146,8 @@ { "id": "function", "translate": "rewards.function", - "type": "string" + "type": "string", + "resource": true }, { "id": "loot", @@ -252,6 +255,7 @@ { "id": "name", "type": "string", + "resource": true, "translate": "entry.name", "require": [ "minecraft:item", @@ -475,6 +479,7 @@ { "id": "block", "type": "string", + "resource": true, "translate": "function.block", "require": [ "minecraft:copy_state" @@ -666,6 +671,7 @@ { "id": "name", "type": "string", + "resource": true, "translate": "condition.name", "require": [ "minecraft:reference" @@ -767,6 +773,7 @@ { "id": "block", "type": "string", + "resource": true, "translate": "condition.block", "require": [ "minecraft:block_state_property" @@ -775,6 +782,7 @@ { "id": "properties", "type": "map", + "resource": true, "translate": "condition.block_state", "translatePlaceholder": "block_state", "values": { @@ -1131,6 +1139,7 @@ { "id": "advancements", "type": "map", + "resource": true, "translate": "entity.player.advancements", "translatePlaceholder": "advancement", "values": { @@ -1140,6 +1149,7 @@ { "id": "recipes", "type": "map", + "resource": true, "translate": "entity.player.recipes", "translatePlaceholder": "recipe", "values": { @@ -1158,6 +1168,7 @@ { "id": "effects", "type": "map", + "resource": true, "translate": "entity.status_effect", "translatePlaceholder": "effect", "values": { @@ -1243,11 +1254,13 @@ { "id": "block", "type": "string", + "resource": true, "translate": "location.block.block" }, { "id": "tag", "type": "string", + "resource": true, "translate": "location.block.tag" }, { @@ -1258,6 +1271,7 @@ { "id": "state", "type": "map", + "resource": true, "translate": "location.block.state", "translatePlaceholder": "block_state", "values": { @@ -1276,16 +1290,19 @@ { "id": "fluid", "type": "string", + "resource": true, "translate": "location.fluid.fluid" }, { "id": "tag", "type": "string", + "resource": true, "translate": "location.fluid.tag" }, { "id": "state", "type": "map", + "resource": true, "translate": "location.fluid.state", "translatePlaceholder": "fluid_state", "values": { @@ -1380,6 +1397,7 @@ { "id": "type", "type": "string", + "resource": true, "translate": "potion_effect.type" }, { @@ -1397,11 +1415,13 @@ { "id": "item", "type": "string", + "resource": true, "translate": "item.name" }, { "id": "tag", "type": "string", + "resource": true, "translate": "item.tag" }, { @@ -1417,6 +1437,7 @@ { "id": "potion", "type": "string", + "resource": true, "translate": "item.potion" }, { @@ -1596,6 +1617,7 @@ { "id": "stat", "type": "string", + "resource": true, "translate": "statistic.stat" }, { @@ -1668,6 +1690,7 @@ "id": "block", "translate": "criteria.block", "type": "string", + "resource": true, "require": [ "minecraft:bee_nest_destroyed", "minecraft:enter_block", @@ -1717,6 +1740,7 @@ "id": "potion", "translate": "criteria.potion", "type": "string", + "resource": true, "require": [ "minecraft:brewed_potion" ] @@ -1777,6 +1801,7 @@ "translate": "criteria.effects", "translatePlaceholder": "effect", "type": "map", + "resource": true, "button": "field", "values": { "type": "object", @@ -1791,6 +1816,7 @@ "translate": "criteria.state", "translatePlaceholder": "block_state", "type": "map", + "resource": true, "values": { "type": "string" }, @@ -1999,6 +2025,7 @@ "id": "recipe", "translate": "criteria.recipe", "type": "string", + "resource": true, "require": [ "minecraft:recipe_unlocked" ] diff --git a/schemas/1.16.json b/schemas/1.16.json index 07873382..74ee56c0 100644 --- a/schemas/1.16.json +++ b/schemas/1.16.json @@ -76,7 +76,8 @@ { "id": "item", "translate": "display.icon.item", - "type": "string" + "type": "string", + "resource": true }, { "id": "nbt", @@ -132,7 +133,8 @@ { "id": "parent", "translate": "parent", - "type": "string" + "type": "string", + "resource": true }, { "id": "rewards", @@ -144,7 +146,8 @@ { "id": "function", "translate": "rewards.function", - "type": "string" + "type": "string", + "resource": true }, { "id": "loot", @@ -252,6 +255,7 @@ { "id": "name", "type": "string", + "resource": true, "translate": "entry.name", "require": [ "minecraft:item", @@ -475,6 +479,7 @@ { "id": "block", "type": "string", + "resource": true, "translate": "function.block", "require": [ "minecraft:copy_state" @@ -666,6 +671,7 @@ { "id": "name", "type": "string", + "resource": true, "translate": "condition.name", "require": [ "minecraft:reference" @@ -767,6 +773,7 @@ { "id": "block", "type": "string", + "resource": true, "translate": "condition.block", "require": [ "minecraft:block_state_property" @@ -775,6 +782,7 @@ { "id": "properties", "type": "map", + "resource": true, "translate": "condition.block_state", "translatePlaceholder": "block_state", "values": { @@ -1145,6 +1153,7 @@ { "id": "advancements", "type": "map", + "resource": true, "translate": "entity.player.advancements", "translatePlaceholder": "advancement", "values": { @@ -1154,6 +1163,7 @@ { "id": "recipes", "type": "map", + "resource": true, "translate": "entity.player.recipes", "translatePlaceholder": "recipe", "values": { @@ -1186,6 +1196,7 @@ { "id": "effects", "type": "map", + "resource": true, "translate": "entity.status_effect", "translatePlaceholder": "effect", "values": { @@ -1276,6 +1287,7 @@ { "id": "block", "type": "string", + "resource": true, "translate": "location.block.block" }, { @@ -1291,6 +1303,7 @@ { "id": "state", "type": "map", + "resource": true, "translate": "location.block.state", "translatePlaceholder": "block_state", "values": { @@ -1309,6 +1322,7 @@ { "id": "fluid", "type": "string", + "resource": true, "translate": "location.fluid.fluid" }, { @@ -1319,6 +1333,7 @@ { "id": "state", "type": "map", + "resource": true, "translate": "location.fluid.state", "translatePlaceholder": "fluid_state", "values": { @@ -1413,6 +1428,7 @@ { "id": "type", "type": "string", + "resource": true, "translate": "potion_effect.type" }, { @@ -1430,11 +1446,13 @@ { "id": "item", "type": "string", + "resource": true, "translate": "item.name" }, { "id": "tag", "type": "string", + "resource": true, "translate": "item.tag" }, { @@ -1450,6 +1468,7 @@ { "id": "potion", "type": "string", + "resource": true, "translate": "item.potion" }, { @@ -1629,6 +1648,7 @@ { "id": "stat", "type": "string", + "resource": true, "translate": "statistic.stat" }, { @@ -1714,6 +1734,7 @@ "id": "block", "translate": "criteria.block", "type": "string", + "resource": true, "require": [ "minecraft:bee_nest_destroyed", "minecraft:enter_block", @@ -1763,6 +1784,7 @@ "id": "potion", "translate": "criteria.potion", "type": "string", + "resource": true, "require": [ "minecraft:brewed_potion" ] @@ -1823,6 +1845,7 @@ "translate": "criteria.effects", "translatePlaceholder": "effect", "type": "map", + "resource": true, "button": "field", "values": { "type": "object", @@ -1837,6 +1860,7 @@ "translate": "criteria.state", "translatePlaceholder": "block_state", "type": "map", + "resource": true, "values": { "type": "string" }, diff --git a/schemas/worldgen.json b/schemas/worldgen.json index b5968b62..ad7e24a3 100644 --- a/schemas/worldgen.json +++ b/schemas/worldgen.json @@ -26,6 +26,7 @@ "translate": "dimension", "translatePlaceholder": "dimension", "type": "map", + "resource": true, "help": true, "values": { "type": "object", @@ -258,6 +259,7 @@ "translate": "generator.settings.block_states", "translatePlaceholder": "block_state", "type": "map", + "resource": true, "default": {}, "values": { "type": "string" @@ -284,6 +286,7 @@ "translate": "generator.settings.fluid_states", "translatePlaceholder": "fluid_state", "type": "map", + "resource": true, "default": {}, "values": { "type": "string" @@ -453,6 +456,7 @@ "translate": "generator.settings.structures", "translatePlaceholder": "structure", "type": "map", + "resource": true, "help": true, "default": {}, "values": { @@ -501,6 +505,7 @@ "translate": "generator.settings.structures", "translatePlaceholder": "structure", "type": "map", + "resource": true, "help": true, "default": {}, "values": {