fixes to preset button activation

This commit is contained in:
dags- 2020-06-27 09:39:54 +01:00
parent d4d888f330
commit 4190d40a2b
7 changed files with 36 additions and 27 deletions

2
Engine

@ -1 +1 @@
Subproject commit 5b2c44a6c2fd3a440e6600060780ba9193b8f389
Subproject commit b0a2908a05efa2390580cd147f4313a77bffc270

View File

@ -97,10 +97,7 @@ task collectLibs(type: Copy) {
duplicatesStrategy = "EXCLUDE"
}
// runs during publication
task apiJar(type: Jar) {
// make sure jar is reobf'd before creating the api jar
// dependents must use fg.deobf("dependency") for their environment
dependsOn("reobfJar")
// copy contents of the main mod jar but only select packages
@ -127,8 +124,8 @@ classes {
dependsOn(collectLibs)
}
build {
dependsOn("reobfJar")
jar {
finalizedBy("reobfJar")
}
publishing {

View File

@ -26,8 +26,8 @@
package com.terraforged.mod;
import com.terraforged.api.material.WGTags;
import com.terraforged.fm.template.TemplateManager;
import com.terraforged.mod.chunk.settings.SettingsHelper;
import com.terraforged.mod.server.command.TerraCommand;
import com.terraforged.mod.config.ConfigManager;
import com.terraforged.mod.data.DataGen;
import com.terraforged.mod.feature.context.ContextSelectorFeature;
@ -35,7 +35,7 @@ import com.terraforged.mod.feature.decorator.poisson.PoissonAtSurface;
import com.terraforged.mod.feature.feature.BushFeature;
import com.terraforged.mod.feature.feature.DiskFeature;
import com.terraforged.mod.feature.feature.FreezeLayer;
import com.terraforged.fm.template.TemplateManager;
import com.terraforged.mod.server.command.TerraCommand;
import com.terraforged.mod.util.DataPackFinder;
import com.terraforged.mod.util.Environment;
import net.minecraft.world.biome.Biomes;

View File

@ -54,26 +54,32 @@ public class SettingsHelper {
return options;
}
public static TerraSettings getSettings(WorldInfo info) {
public static TerraSettings readDefaults() {
TerraSettings settings = new TerraSettings();
if (info.getGeneratorOptions().isEmpty()) {
if (DEFAULTS_FILE.exists()) {
try (Reader reader = new BufferedReader(new FileReader(DEFAULTS_FILE))) {
Log.info("Loading generator settings from json");
JsonElement json = new JsonParser().parse(reader);
CompoundNBT root = NBTHelper.fromJson(json);
NBTHelper.deserialize(root, settings);
} catch (Throwable t) {
t.printStackTrace();
}
if (DEFAULTS_FILE.exists()) {
try (Reader reader = new BufferedReader(new FileReader(DEFAULTS_FILE))) {
Log.info("Loading generator settings from json");
JsonElement json = new JsonParser().parse(reader);
CompoundNBT root = NBTHelper.fromJson(json);
NBTHelper.deserialize(root, settings);
} catch (Throwable t) {
t.printStackTrace();
}
} else {
Log.info("Loading generator settings from level.dat");
NBTHelper.deserialize(info.getGeneratorOptions(), settings);
}
return settings;
}
public static TerraSettings getSettings(WorldInfo info) {
if (info.getGeneratorOptions().isEmpty()) {
return readDefaults();
} else {
Log.info("Loading generator settings from level.dat");
TerraSettings settings = new TerraSettings();
NBTHelper.deserialize(info.getGeneratorOptions(), settings);
return settings;
}
}
public static void init() {
if (!DEFAULTS_FILE.exists()) {
exportDefaults(new TerraSettings());

View File

@ -116,7 +116,7 @@ public class PresetManager implements Iterable<Preset> {
}
File[] files = PRESETS_DIR.listFiles();
if (files == null || files.length == 0) {
if (files == null) {
return new PresetManager(new ArrayList<>());
}

View File

@ -17,4 +17,10 @@ public class Instance {
this.settings = settings;
this.settingsData = NBTHelper.serialize(settings);
}
public TerraSettings createCopy() {
TerraSettings settings = new TerraSettings();
NBTHelper.deserialize(settingsData, settings);
return settings;
}
}

View File

@ -77,8 +77,8 @@ public class PresetsPage extends BasePage {
@Override
public void onClick(double x, double y) {
super.onClick(x, y);
// create new preset with default settings
Preset preset = new Preset(nameInput.getValue(), new TerraSettings());
// create new preset with current settings
Preset preset = new Preset(nameInput.getValue(), instance.createCopy());
// register with the manager & reset the text field
manager.add(preset);
@ -121,8 +121,7 @@ public class PresetsPage extends BasePage {
super.onClick(x, y);
getSelected().ifPresent(preset -> {
// create a copy of the settings
TerraSettings settings = new TerraSettings();
NBTHelper.deserialize(instance.settingsData, settings);
TerraSettings settings = instance.createCopy();
// replace the current preset with the updated version
manager.add(new Preset(preset.getName(), settings));
@ -234,6 +233,7 @@ public class PresetsPage extends BasePage {
private void rebuildPresetList() {
Column left = getColumn(0);
left.scrollPane.setSelected(null);
left.scrollPane.setRenderSelection(true);
left.scrollPane.children().clear();