Convert getDefaultRenderSettings into default constructor

Allows us to completely get rid of the custom Gson instance and is more
idiomatic anyway.
This commit is contained in:
Jonas Herzig
2021-08-15 11:45:23 +02:00
parent 9626a4c442
commit 463c51be85
2 changed files with 29 additions and 12 deletions

View File

@@ -174,6 +174,32 @@ public class RenderSettings {
private final boolean highPerformance; private final boolean highPerformance;
public RenderSettings() {
this(
RenderSettings.RenderMethod.DEFAULT,
RenderSettings.EncodingPreset.MP4_CUSTOM,
1920,
1080,
60,
20 << 20,
null,
true,
false,
false,
false,
null,
360,
180,
false,
false,
false,
RenderSettings.AntiAliasing.NONE,
"",
RenderSettings.EncodingPreset.MP4_CUSTOM.getValue(),
false
);
}
public RenderSettings( public RenderSettings(
RenderMethod renderMethod, RenderMethod renderMethod,
EncodingPreset encodingPreset, EncodingPreset encodingPreset,

View File

@@ -2,8 +2,6 @@ package com.replaymod.render.gui;
import com.google.common.base.Preconditions; import com.google.common.base.Preconditions;
import com.google.gson.Gson; import com.google.gson.Gson;
import com.google.gson.GsonBuilder;
import com.google.gson.InstanceCreator;
import com.google.gson.JsonSyntaxException; import com.google.gson.JsonSyntaxException;
import com.replaymod.core.ReplayMod; import com.replaymod.core.ReplayMod;
import com.replaymod.render.RenderSettings; import com.replaymod.render.RenderSettings;
@@ -330,15 +328,13 @@ public class GuiRenderSettings extends AbstractGuiPopup<GuiRenderSettings> {
} }
RenderSettings settings = null; RenderSettings settings = null;
try { try {
settings = new GsonBuilder() settings = new Gson().fromJson(json, RenderSettings.class);
.registerTypeAdapter(RenderSettings.class, (InstanceCreator<RenderSettings>) type -> getDefaultRenderSettings())
.create().fromJson(json, RenderSettings.class);
} catch (JsonSyntaxException e) { } catch (JsonSyntaxException e) {
LOGGER.error("Parsing render settings:", e); LOGGER.error("Parsing render settings:", e);
LOGGER.error("Raw JSON: {}", json); LOGGER.error("Raw JSON: {}", json);
} }
if (settings == null) { if (settings == null) {
settings = getDefaultRenderSettings(); settings = new RenderSettings();
} }
load(settings); load(settings);
} }
@@ -506,7 +502,7 @@ public class GuiRenderSettings extends AbstractGuiPopup<GuiRenderSettings> {
/* encodingPreset can be null from a previously supported and later removed preset */ /* encodingPreset can be null from a previously supported and later removed preset */
boolean invalidEncodingPreset = encodingPreset == null || !encodingPreset.isSupported(); boolean invalidEncodingPreset = encodingPreset == null || !encodingPreset.isSupported();
if (invalidEncodingPreset) { if (invalidEncodingPreset) {
encodingPreset = getDefaultRenderSettings().getEncodingPreset(); encodingPreset = new RenderSettings().getEncodingPreset();
} }
encodingPresetDropdown.setSelected(encodingPreset); encodingPresetDropdown.setSelected(encodingPreset);
videoWidth.setValue(settings.getTargetVideoWidth()); videoWidth.setValue(settings.getTargetVideoWidth());
@@ -626,11 +622,6 @@ public class GuiRenderSettings extends AbstractGuiPopup<GuiRenderSettings> {
return ReplayModRender.instance.getRenderSettingsPath(); return ReplayModRender.instance.getRenderSettingsPath();
} }
private RenderSettings getDefaultRenderSettings() {
return new RenderSettings(RenderSettings.RenderMethod.DEFAULT, RenderSettings.EncodingPreset.MP4_CUSTOM, 1920, 1080, 60, 20 << 20, null,
true, false, false, false, null, 360, 180, false, false, false, RenderSettings.AntiAliasing.NONE, "", RenderSettings.EncodingPreset.MP4_CUSTOM.getValue(), false);
}
@Override @Override
public void open() { public void open() {
super.open(); super.open();