mirror of
https://github.com/misode/misode.github.io.git
synced 2026-04-24 07:37:10 +00:00
Preparations for structure abstraction
This commit is contained in:
46
index.html
46
index.html
@@ -74,6 +74,51 @@
|
||||
</div>
|
||||
|
||||
<div class="d-none">
|
||||
<div id="components">
|
||||
<div data-type="string">
|
||||
<div class="input-group-prepend">
|
||||
<span class="input-group-text"></span>
|
||||
</div>
|
||||
<input type="text" class="form-control" onchange="updateField(this)" onfocus="this.select()">
|
||||
</div>
|
||||
<div data-type="enum">
|
||||
<div class="input-group-prepend">
|
||||
<span class="input-group-text"></span>
|
||||
</div>
|
||||
<select class="form-control entry-type" onchange="updateField(this)">
|
||||
</select>
|
||||
</div>
|
||||
<div data-type="range">
|
||||
<div class="input-group-prepend">
|
||||
<span class="input-group-text"></span>
|
||||
<button type="button" class="btn btn-outline-secondary bg-light dropdown-toggle dropdown-toggle-split" data-toggle="dropdown"></button>
|
||||
<div class="dropdown-menu">
|
||||
<a class="dropdown-item" value="exact" onclick="updateRangeType(this)" data-i18n="range.exact"></a>
|
||||
<a class="dropdown-item" value="range" onclick="updateRangeType(this)" data-i18n="range.range"></a>
|
||||
<a class="dropdown-item" value="binomial" onclick="updateRangeType(this)" data-i18n="range.binomial"></a>
|
||||
</div>
|
||||
</div>
|
||||
<input type="text" class="form-control exact d-none rounded-right" value="1" onchange="updateField(this)" onfocus="this.select()">
|
||||
<span class="input-group-text rounded-0 range d-none" data-i18n="range.min"></span>
|
||||
<input type="text" class="form-control range min d-none" value="1" onchange="updateField(this)" onfocus="this.select()">
|
||||
<span class="input-group-text rounded-0 range d-none" data-i18n="range.max"></span>
|
||||
<input type="text" class="form-control range max d-none rounded-right" value="2" onchange="updateField(this)" onfocus="this.select()">
|
||||
<span class="input-group-text rounded-0 binomial d-none" data-i18n="range.n"></span>
|
||||
<input type="text" class="form-control binomial n d-none" value="1" onchange="updateField(this)" onfocus="this.select()">
|
||||
<span class="input-group-text rounded-0 binomial d-none" data-i18n="range.p"></span>
|
||||
<input type="text" class="form-control binomial p d-none rounded-right" value="0.5" onchange="updateField(this)" onfocus="this.select()">
|
||||
</div>
|
||||
<div data-type="radio">
|
||||
<div class="input-group-prepend">
|
||||
<span class="input-group-text"></span>
|
||||
</div>
|
||||
<div class="btn-group">
|
||||
<button type="button" value="false" class="btn btn-secondary rounded-0" onclick="updateField(this)" data-i18n="false"></button>
|
||||
<button type="button" value="true" class="btn btn-secondary" onclick="updateField(this)" data-i18n="true"></button>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div id="poolTemplate" class="card bg-success text-white mt-3 pool" data-field="pools[]">
|
||||
<div class="card-header pb-1">
|
||||
<button type="button" class="btn btn-danger mb-2 float-right" onclick="removeField(this)" data-i18n="remove_pool"></button>
|
||||
@@ -1002,6 +1047,7 @@
|
||||
<script src="https://cdnjs.cloudflare.com/ajax/libs/i18next-xhr-backend/3.0.0/i18nextXHRBackend.min.js" integrity="sha384-dK+VwLEvPDbpKM7G7D/LtbW6W2zlt99nuVTwoYIkMulAedST9Vj9OCRkv2xV8GjD" crossorigin="anonymous"></script>
|
||||
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery-i18next/1.2.1/jquery-i18next.min.js" integrity="sha384-fLTSt6zHOb152KeFkj7kSiXdkyjKf6fjk5bdzWYLDPDo9evwd9PVs3TKoYYaaxdl" crossorigin="anonymous"></script>
|
||||
<script src="i18n.js" charset="utf-8"></script>
|
||||
<script src="validate.js" charset="utf-8"></script>
|
||||
<script src="view.js" charset="utf-8"></script>
|
||||
<script src="model.js" charset="utf-8"></script>
|
||||
</body>
|
||||
|
||||
182
structure.json
Normal file
182
structure.json
Normal file
@@ -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": [
|
||||
|
||||
]
|
||||
}
|
||||
]
|
||||
}
|
||||
41
validate.js
41
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;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user