Add preset option for collapsed objects

This commit is contained in:
Misode
2020-05-20 22:35:49 +02:00
parent 40bf1784f3
commit d423139bb3
5 changed files with 154 additions and 13 deletions

View File

@@ -336,7 +336,7 @@ function toggleCollapseObject(el) {
let path = getPath(el);
let index = path.pop();
let node = getNode(path);
if (!node[index]) {
if (typeof node[index] !== 'object') {
node[index] = {};
} else {
delete node[index];

View File

@@ -22,6 +22,9 @@ function updateView() {
$('#descriptionSpan').attr('data-i18n', structure.description);
$('title').attr('data-i18n', structure.title);
$('#structure').append($component);
if (structure.id === 'worldgen') {
$('#versionLabel').addClass('d-none')
}
if (i18next.isInitialized) {
$('html').localize();
}
@@ -403,14 +406,30 @@ function generateObject(data, struct, options) {
}
}
if (field.collapse) {
let hasNoValue = data[field.id] === undefined;
let hasNoValue = typeof data[field.id] !== 'object';
let arrowDirection = hasNoValue ? 'dropright' : 'dropdown'
$body.append('<span class="' + arrowDirection + '"><button type="button" class="mt-3 btn btn-light dropdown-toggle" onclick="toggleCollapseObject(this)" data-index="' + field.id + '" data-i18n="' + field.translate + '"></button></span>');
if (field.help) {
$body.find('span').append(generateTooltip(field.translate));
}
if (hasNoValue) {
$body.append('<div/>');
if (field.values) {
let outValue, $field;
({out: outValue, component: $field} = generateEnum(data[field.id], field));
out[field.id] = outValue;
const $selection = $($field.children()[1]);
const $dropdown = $body.children().last();
$selection.addClass('mt-3');
$dropdown.addClass('input-group');
$($dropdown.children()[0])
.css('border-top-right-radius', '0')
.css('border-bottom-right-radius', '0');
$selection.attr('data-type', 'enum');
$selection.attr('data-index', field.id);
$dropdown.append($selection);
} else {
$body.append('<div/>');
}
continue;
}
}

View File

@@ -149,6 +149,16 @@
"dimension.overworld": "Overworld",
"dimension.the_end": "The End",
"dimension.the_nether": "The Nether",
"dimension.nether": "Nether",
"dimension.end": "End",
"dimension.type": "Dimension Flags",
"dimension.type.ultrawarm": "Ultrawarm",
"dimension.type.natural": "Natural",
"dimension.type.shrunk": "Shrunk",
"dimension.type.ambient_light": "Ambient Light",
"dimension.type.fixed_time": "Fixed Time",
"dimension.type.has_skylight": "Has Skylight",
"dimension.type.has_ceiling": "Has Ceiling",
"display": "Display",
"display.icon": "Icon",
"display.icon.item": "Icon Item",
@@ -312,7 +322,15 @@
"generator.type": "Type",
"generator.seed": "Dimension Seed",
"generator.settings": "Generator Settings",
"generator.settings.bedrock_roof_position": "Bedrock Roof Position",
"generator.settings.bedrock_floor_position": "Bedrock Floor Position",
"generator.settings.sea_level": "Sea Level",
"generator.settings.disable_mob_generation": "Disable Mob Generation",
"generator.settings.default_block": "Default Block",
"generator.settings.default_fluid": "Default Fluid",
"help.condition.time_period": "If present, time will be modulo-divided by this value. For example, if set to 24000, value will operate on a time period of days.",
"help.dimension.type.ultrawarm": "If true, water cannot exist and sponges will dry.",
"help.dimension.type.shrunk": "Whether coordinates should be scaled down by a factor of 8.",
"help.display": "If present, advancement will be visible in the advancement tabs.",
"help.entry.expand": "If false, entry will return all contents of tag, otherwise entry will behave as multiple item entries",
"help.entry.type.alternatives": "Tests conditions of the child entries and executes the first that can run",

View File

@@ -101,16 +101,6 @@
"translate": "generator.seed",
"type": "int"
},
{
"id": "settings",
"translate": "generator.settings",
"type": "enum",
"values": [
"minecraft:overworld",
"minecraft:nether",
"minecraft:end"
]
},
{
"id": "biome_source",
"type": "object",
@@ -136,6 +126,7 @@
{
"id": "preset",
"translate": "biome_source.preset",
"translateValue": "dimension",
"type": "enum",
"unset": true,
"values": [
@@ -148,6 +139,117 @@
"type": "boolean"
}
]
},
{
"id": "settings",
"translate": "generator.settings",
"translateValue": "dimension",
"type": "object",
"color": "dark",
"collapse": true,
"values": [
"minecraft:overworld",
"minecraft:nether",
"minecraft:end"
],
"fields": [
{
"id": "bedrock_roof_position",
"translate": "generator.settings.bedrock_roof_position",
"type": "int"
},
{
"id": "bedrock_floor_position",
"translate": "generator.settings.bedrock_floor_position",
"type": "int"
},
{
"id": "sea_level",
"translate": "generator.settings.sea_level",
"type": "int"
},
{
"id": "disable_mob_generation",
"translate": "generator.settings.disable_mob_generation",
"type": "boolean"
},
{
"id": "default_block",
"type": "object",
"card": false,
"fields": [
{
"id": "Name",
"translate": "generator.settings.default_block",
"type": "string"
}
]
},
{
"id": "default_fluid",
"type": "object",
"card": false,
"fields": [
{
"id": "Name",
"translate": "generator.settings.default_fluid",
"type": "string"
}
]
}
]
}
]
},
{
"id": "type",
"translate": "dimension.type",
"translateValue": "dimension",
"type": "object",
"color": "dark",
"collapse": true,
"values": [
"minecraft:overworld",
"minecraft:the_nether",
"minecraft:the_end"
],
"fields": [
{
"id": "ultrawarm",
"translate": "dimension.type.ultrawarm",
"type": "boolean",
"help": true
},
{
"id": "natural",
"translate": "dimension.type.natural",
"type": "boolean"
},
{
"id": "shrunk",
"translate": "dimension.type.shrunk",
"type": "boolean",
"help": true
},
{
"id": "ambient_light",
"translate": "dimension.type.ambient_light",
"type": "float"
},
{
"id": "fixed_time",
"translate": "dimension.type.fixed_time",
"type": "int"
},
{
"id": "has_skylight",
"translate": "dimension.type.has_skylight",
"type": "boolean"
},
{
"id": "has_ceiling",
"translate": "dimension.type.has_ceiling",
"type": "boolean"
}
]
}

View File

@@ -18,6 +18,8 @@
<body>
<nav class="navbar navbar-expand-md navbar-dark bg-dark">
<a id="descriptionSpan" class="navbar-brand mb-0 h1" href="../" data-i18n="description.worldgen"></a>
<span class="badge badge-danger">Experimental</span>
<span class="badge badge-danger ml-1">Unstable</span>
<button class="navbar-toggler navbar-toggler-right" type="button" data-toggle="collapse" data-target="#collapsibleNavbar">
<span class="navbar-toggler-icon"></span>
</button>