Validate and correct resource location

This commit is contained in:
Misode
2020-05-23 17:31:48 +02:00
parent 6cf3809d48
commit 6680b240f7
7 changed files with 93 additions and 7 deletions
+19 -1
View File
@@ -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();
+2
View File
@@ -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) {
+2
View File
@@ -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",
+8
View File
@@ -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"
},
{
+30 -3
View File
@@ -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"
]
+27 -3
View File
@@ -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"
},
+5
View File
@@ -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": {