Preparations for structure abstraction

This commit is contained in:
Misode
2019-09-11 00:09:25 +02:00
parent 2d5f87a27f
commit 16e7d37ffc
3 changed files with 252 additions and 17 deletions

View File

@@ -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;
}