Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

External generator settings (new implementation) #10

Closed
wants to merge 17 commits into from
Closed
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
Expand Up @@ -61,7 +61,7 @@ public void onButtonPressed(GuiScreenEvent.ActionPerformedEvent.Pre action) {
String json = CustomGeneratorSettings.loadJsonStringFromSaveFolder(isavehandler);
isavehandler.flush();
if (json != null) {
CustomCubicGui.settingsJsonString = json;
CustomCubicWorldType.pendingCustomCubicSettingsJsonString = json;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I really don't like that static field here. Verifying that this field has the right value at the right time is nearly impossible without actually trying every possibility.

Instead I would suggest just mixing into WorldSettings and WorldInfo (same as what I did in CC itself, with MixinWorldSettings and MixinWorldInfo).

This also should remove the need for createNewWorld variable.

This would also allow to actually store the loaded preset text somewhere instead of loading it from disk each time it's needed.

If you actually inject in the right place, you can almost completely hide the fact that the preset is not saved in level.dat, by just not saving that part into level.dat for CustomCubic worlds, and instead have code somewhere else that saves it.

}
}
}
Expand Down
Expand Up @@ -57,6 +57,7 @@ public class CustomCubicWorldType extends WorldType implements ICubicWorldType {
// This string is not empty when and only when someone used a CustomCubicGUI
// and press a Done button both in this CustomCubicGUI and in a WorldCreationGUI
public static String pendingCustomCubicSettingsJsonString = "";
public static boolean createNewWorld = false;

private CustomCubicWorldType() {
super("CustomCubic");
Expand Down Expand Up @@ -98,8 +99,7 @@ public boolean isCustomizable() {

@Override
public void onGUICreateWorldPress() {
pendingCustomCubicSettingsJsonString = CustomCubicGui.settingsJsonString;
CustomCubicGui.settingsJsonString = "";
createNewWorld = true;
}

@SideOnly(Side.CLIENT)
Expand Down
Expand Up @@ -237,9 +237,10 @@ public static CustomGeneratorSettings load(World world) {
settings = fromJson(jsonString);
if (isOutdated)
settings.save(world);
} else if (!CustomCubicWorldType.pendingCustomCubicSettingsJsonString.isEmpty()) {
} else if (CustomCubicWorldType.createNewWorld && !CustomCubicWorldType.pendingCustomCubicSettingsJsonString.isEmpty()) {
settings = CustomGeneratorSettings.fromJson(CustomCubicWorldType.pendingCustomCubicSettingsJsonString);
CustomCubicWorldType.pendingCustomCubicSettingsJsonString = "";
CustomCubicWorldType.createNewWorld = false;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There should be a better way to determine if it's a new world that is used in common event handler.

Copy link
Contributor Author

@Foghrye4 Foghrye4 Jan 20, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I can suggest to do a same thing but in a AttachCapabilitiesEvent<World> handler with high priority. Another option is to retrieve saveDirName from GuiCreateWorld and create generator settings file before World instance creation on CustomCubicWorldType.onGUICreateWorldPress().

settings.save(world);
} else {
CustomCubicMod.LOGGER
Expand Down
Expand Up @@ -32,6 +32,7 @@
import io.github.opencubicchunks.cubicchunks.cubicgen.common.gui.ExtraGui;
import io.github.opencubicchunks.cubicchunks.cubicgen.common.gui.component.UISplitLayout;
import io.github.opencubicchunks.cubicchunks.cubicgen.common.gui.component.UITextFieldFixed;
import io.github.opencubicchunks.cubicchunks.cubicgen.customcubic.CustomCubicWorldType;
import io.github.opencubicchunks.cubicchunks.cubicgen.customcubic.CustomGeneratorSettings;
import io.github.opencubicchunks.cubicchunks.cubicgen.common.gui.component.NoTranslationFont;
import io.github.opencubicchunks.cubicchunks.cubicgen.common.gui.component.UIBorderLayout;
Expand Down Expand Up @@ -75,10 +76,6 @@ public class CustomCubicGui extends ExtraGui {
private AdvancedTerrainShapeTab advancedterrainShapeSettings;
private Map<CustomGeneratorSettings.IntAABB, CustomGeneratorSettings> areas;
private BiomeBlockReplacerConfig replacerConf;
// Store config here between GUI calls, so we would not need to store it in
// parent GUI. Whenever player will press create world GUI button it will be
// transfered to CustomCubicWorld type to be saved.
public static String settingsJsonString = "";

public CustomCubicGui(GuiCreateWorld parent) {
super();
Expand All @@ -92,10 +89,10 @@ public CustomCubicGui(GuiCreateWorld parent) {
@Override
public void construct() {
CustomGeneratorSettings conf = null;
if (!settingsJsonString.isEmpty())
conf = CustomGeneratorSettings.fromJson(settingsJsonString);
if (!CustomCubicWorldType.pendingCustomCubicSettingsJsonString.isEmpty())
conf = CustomGeneratorSettings.fromJson(CustomCubicWorldType.pendingCustomCubicSettingsJsonString);
else
conf = new CustomGeneratorSettings();
conf = CustomGeneratorSettings.defaults();
reinit(conf);
}

Expand Down Expand Up @@ -254,7 +251,7 @@ public void onClick(UIButton.ClickEvent evt) {
}

private void done() {
settingsJsonString = getSettingsJson(getConfig());
CustomCubicWorldType.pendingCustomCubicSettingsJsonString = getSettingsJson(getConfig());
this.mc.displayGuiScreen(parent);
}

Expand Down