diff --git a/index.html b/index.html index 854fd8f6..54e4ca6c 100644 --- a/index.html +++ b/index.html @@ -74,6 +74,51 @@
+
+
+
+ +
+ +
+
+
+ +
+ +
+
+
+ + + +
+ + + + + + + + + +
+
+
+ +
+
+ + +
+
+
+
@@ -1002,6 +1047,7 @@ + diff --git a/structure.json b/structure.json new file mode 100644 index 00000000..dc43d9a5 --- /dev/null +++ b/structure.json @@ -0,0 +1,182 @@ +{ + "root": { + "fields": [ + { + "id": "type", + "type": "enum", + "values": [ + "minecraft:empty", + "minecraft:entity", + "minecraft:block", + "minecraft:chest", + "minecraft:fishing", + "minecraft:generic" + ], + "default": "minecraft:generic" + }, + { + "id": "pools", + "type": "array", + "values": "pool" + } + ] + }, + "components": [ + { + "id": "pool", + "type": "object", + "class": "card bg-success", + "default": { + "rolls": 1, + "entries": [ + { + "type": "minecraft:item", + "name": "minecraft:stone" + } + ] + }, + "fields": [ + { + "id": "rolls", + "type": "range", + "default": 1 + }, + { + "id": "bonus_rolls", + "type": "number", + "default": 1 + }, + { + "id": "entries", + "type": "array", + "values": "entry" + }, + { + "id": "conditions", + "type": "array", + "values": "condition" + } + ] + }, + { + "id": "entry", + "type": "object", + "class": "card", + "default": { + "type": "minecraft:item", + "name": "minecraft:stone" + }, + "fields": [ + { + "id": "type", + "type": "enum", + "values": [ + "minecraft:empty", + "minecraft:item", + "minecraft:tag", + "minecraft:loot_table", + "minecraft:alternatives", + "minecraft:sequence", + "minecraft:group", + "minecraft:dynamic" + ], + "default": "minecraft:item" + }, + { + "id": "name", + "type": "string", + "default": "minecraft:stone", + "require": [ + "minecraft:item", + "minecraft:tag", + "minecraft:loot_table", + "minecraft:dynamic" + ] + }, + { + "id": "children", + "type": "array", + "values": "entry", + "require": [ + "minecraft:alternatives", + "minecraft:sequence", + "minecraft:group" + ] + }, + { + "id": "functions", + "type": "array", + "values": "function" + }, + { + "id": "conditions", + "type": "array", + "values": "condition" + } + ] + }, + { + "id": "function", + "type": "object", + "class": "card bg-info", + "default": { + "function": "minecraft:set_count", + "count": 2 + }, + "fields": [ + { + "id": "function", + "type": "enum", + "values": [ + "minecraft:set_count", + "minecraft:set_damage", + "minecraft:set_name", + "minecraft:set_lore", + "minecraft:set_nbt", + "minecraft:set_attributes", + "minecraft:set_contents", + "minecraft:enchant_randomly", + "minecraft:enchant_with_levels", + "minecraft:looting_enchant", + "minecraft:limit_count", + "minecraft:furnace_smelt", + "minecraft:explosion_decay", + "minecraft:fill_player_head", + "minecraft:copy_name", + "minecraft:copy_nbt", + "minecraft:apply_bonus" + ], + "default": "set_count" + }, + { + "id": "count", + "type": "range", + "default": 2, + "require": [ + "minecraft:set_count" + ] + }, + { + "id": "damage", + "type": "range", + "default": 1, + "require": [ + "minecraft:set_damage" + ] + } + ] + }, + { + "id": "condition", + "type": "object", + "card": true, + "default": { + "condition": "minecraft:random_chance", + "chance": 0.5 + }, + "fields": [ + + ] + } + ] +} diff --git a/validate.js b/validate.js index 7b1865a0..d2e0ce48 100644 --- a/validate.js +++ b/validate.js @@ -1,24 +1,24 @@ function isString(data) { - return data && typeof data === 'string'; + return data != undefined && typeof data === 'string'; } -function isNumber(var) { - return data && typeof data === 'number'; +function isNumber(data) { + return data != undefined && typeof data === 'number'; } -function isObject(var) { - return data && typeof data === 'object'; +function isObject(data) { + return data != undefined && typeof data === 'object' && !Array.isArray(data); } -function isArray(var) { - return data && typeof data === 'object' && Array.isArray(data); +function isArray(data) { + return data != undefined && typeof data === 'object' && Array.isArray(data); } -function validateRange(data, default) { +function validateRange(data) { if (data === undefined) return false; if (isObject(data)) { - if (isString(data.type) && var.type.endsWith('binomial')) + if (isString(data.type) && data.type.endsWith('binomial')) { if (isNumber(data.n) && isNumber(data.p)) { return { type: 'minecraft:binomial', @@ -30,12 +30,11 @@ function validateRange(data, default) { let res = {}; if (isNumber(data.min)) res.min = data.min; if (isNumber(data.max)) res.max = data.max; - } } return false; } -function chooseOption(options, value, default) { +function chooseOption(options, value, def) { for (option of options) { if (value === option) { return value; @@ -43,23 +42,31 @@ function chooseOption(options, value, default) { return 'minecraft:' + value; } } - return default; + 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)) { - res.pools = []; - for (let entry of table.pools) { - res.pools.push(validatePool(pools)); + for (let pool of table.pools) { + res.pools.push(validatePool(pool)); } } return res; } function validatePool() { - let newpool = {}; - + let res = {}; + res return res; }