Make options in the start export window persist in config

This commit is contained in:
Moulberry committed 2025-02-11 17:15:04 +08:00
1 parent d8109f495f
commit 07a52ac5ca
3 files changed
+148 -123

No files matched your search

@@ -4,6 +4,9 @@ import com.mojang.serialization.Codec;
import com.moulberry.flashback.Flashback; import com.moulberry.flashback.Flashback;
import com.moulberry.flashback.FlashbackGson; import com.moulberry.flashback.FlashbackGson;
import com.moulberry.flashback.SneakyThrow; import com.moulberry.flashback.SneakyThrow;
import com.moulberry.flashback.combo_options.AudioCodec;
import com.moulberry.flashback.combo_options.VideoCodec;
import com.moulberry.flashback.combo_options.VideoContainer;
import com.moulberry.flashback.keyframe.interpolation.InterpolationType; import com.moulberry.flashback.keyframe.interpolation.InterpolationType;
import com.moulberry.flashback.screen.select_replay.ReplaySorting; import com.moulberry.flashback.screen.select_replay.ReplaySorting;
import net.fabricmc.loader.api.FabricLoader; import net.fabricmc.loader.api.FabricLoader;
@@ -83,6 +86,24 @@ public class FlashbackConfig {
public ReplaySorting replaySorting = ReplaySorting.CREATED_DATE; public ReplaySorting replaySorting = ReplaySorting.CREATED_DATE;
public boolean sortDescending = true; public boolean sortDescending = true;
public int[] resolution = new int[]{1920, 1080};
public float[] framerate = new float[]{60};
public boolean resetRng = false;
public boolean ssaa = false;
public boolean noGui = false;
public VideoContainer container = null;
public VideoCodec videoCodec = null;
public int[] selectedVideoEncoder = new int[]{0};
public boolean useMaximumBitrate = false;
public boolean recordAudio = false;
public boolean transparentBackground = false;
public AudioCodec audioCodec = AudioCodec.AAC;
public boolean stereoAudio = false;
public String defaultExportPath = null;
private transient int saveDelay = 0; private transient int saveDelay = 0;
@SuppressWarnings("unchecked") @SuppressWarnings("unchecked")
@@ -4,6 +4,7 @@ import com.moulberry.flashback.Flashback;
import com.moulberry.flashback.Utils; import com.moulberry.flashback.Utils;
import com.moulberry.flashback.combo_options.VideoCodec; import com.moulberry.flashback.combo_options.VideoCodec;
import com.moulberry.flashback.combo_options.VideoContainer; import com.moulberry.flashback.combo_options.VideoContainer;
import com.moulberry.flashback.configuration.FlashbackConfig;
import com.moulberry.flashback.editor.ui.ImGuiHelper; import com.moulberry.flashback.editor.ui.ImGuiHelper;
import com.moulberry.flashback.exporting.AsyncFileDialogs; import com.moulberry.flashback.exporting.AsyncFileDialogs;
import com.moulberry.flashback.exporting.ExportJob; import com.moulberry.flashback.exporting.ExportJob;
@@ -23,8 +24,6 @@ public class ExportScreenshotWindow {
private static boolean open = false; private static boolean open = false;
private static boolean close = false; private static boolean close = false;
private static final int[] resolution = new int[]{1920, 1080};
public static void render() { public static void render() {
if (open) { if (open) {
open = false; open = false;
@@ -39,45 +38,50 @@ public class ExportScreenshotWindow {
return; return;
} }
ImGuiHelper.inputInt("Resolution", resolution); FlashbackConfig config = Flashback.getConfig();
resolution[0] = Math.max(1, resolution[0]); if (config.resolution == null || config.resolution.length != 2) {
resolution[1] = Math.max(1, resolution[1]); config.resolution = new int[]{1920, 1080};
}
ImGuiHelper.inputInt("Resolution", config.resolution);
config.resolution[0] = Math.max(1, config.resolution[0]);
config.resolution[1] = Math.max(1, config.resolution[1]);
EditorState editorState = EditorStateManager.getCurrent(); EditorState editorState = EditorStateManager.getCurrent();
if (ImGui.checkbox("SSAA", StartExportWindow.ssaa)) { if (ImGui.checkbox("SSAA", config.ssaa)) {
StartExportWindow.ssaa = !StartExportWindow.ssaa; config.ssaa = !config.ssaa;
} }
ImGuiHelper.tooltip("Supersampling Anti-Aliasing: Remove jagged edges by rendering the game at double resolution and downscaling"); ImGuiHelper.tooltip("Supersampling Anti-Aliasing: Remove jagged edges by rendering the game at double resolution and downscaling");
ImGui.sameLine(); ImGui.sameLine();
if (ImGui.checkbox("No GUI", StartExportWindow.noGui)) { if (ImGui.checkbox("No GUI", config.noGui)) {
StartExportWindow.noGui = !StartExportWindow.noGui; config.noGui = !config.noGui;
} }
ImGuiHelper.tooltip("Removes all UI from the screen, rendering only the world"); ImGuiHelper.tooltip("Removes all UI from the screen, rendering only the world");
if (editorState != null && !editorState.replayVisuals.renderSky) { if (editorState != null && !editorState.replayVisuals.renderSky) {
if (ImGui.checkbox("Transparent Sky", StartExportWindow.transparentBackground)) { if (ImGui.checkbox("Transparent Sky", config.transparentBackground)) {
StartExportWindow.transparentBackground = !StartExportWindow.transparentBackground; config.transparentBackground = !config.transparentBackground;
} }
} }
if (editorState != null && ImGui.button("Take Screenshot")) { if (editorState != null && ImGui.button("Take Screenshot")) {
String defaultName = StartExportWindow.getDefaultFilename(null, "png"); String defaultName = StartExportWindow.getDefaultFilename(null, "png", config);
String defaultExportPathString = StartExportWindow.defaultExportPath.toString(); String defaultExportPathString = config.defaultExportPath;
AsyncFileDialogs.saveFileDialog(defaultExportPathString, defaultName, "PNG", "png").thenAccept(pathStr -> { AsyncFileDialogs.saveFileDialog(defaultExportPathString, defaultName, "PNG", "png").thenAccept(pathStr -> {
if (pathStr != null) { if (pathStr != null) {
Path path = Path.of(pathStr); Path path = Path.of(pathStr);
StartExportWindow.defaultExportPath = path.getParent(); config.defaultExportPath = path.getParent().toString();
LocalPlayer player = Minecraft.getInstance().player; LocalPlayer player = Minecraft.getInstance().player;
int tick = Flashback.getReplayServer().getReplayTick(); int tick = Flashback.getReplayServer().getReplayTick();
boolean transparent = StartExportWindow.transparentBackground && !editorState.replayVisuals.renderSky; boolean transparent = config.transparentBackground && !editorState.replayVisuals.renderSky;
boolean ssaa = StartExportWindow.ssaa; boolean ssaa = config.ssaa;
boolean noGui = StartExportWindow.noGui; boolean noGui = config.noGui;
EditorState copiedEditorState = editorState.copy(); EditorState copiedEditorState = editorState.copy();
for (EditorScene scene : copiedEditorState.scenes) { for (EditorScene scene : copiedEditorState.scenes) {
@@ -86,7 +90,7 @@ public class ExportScreenshotWindow {
ExportSettings settings = new ExportSettings(null, copiedEditorState, ExportSettings settings = new ExportSettings(null, copiedEditorState,
player.position(), player.getYRot(), player.getXRot(), player.position(), player.getYRot(), player.getXRot(),
resolution[0], resolution[1], tick, tick, config.resolution[0], config.resolution[1], tick, tick,
1, false, VideoContainer.PNG_SEQUENCE, null, null, 0, transparent, ssaa, noGui, 1, false, VideoContainer.PNG_SEQUENCE, null, null, 0, transparent, ssaa, noGui,
false, false, null, false, false, null,
path); path);
@@ -8,6 +8,7 @@ import com.moulberry.flashback.combo_options.AudioCodec;
import com.moulberry.flashback.combo_options.Sizing; import com.moulberry.flashback.combo_options.Sizing;
import com.moulberry.flashback.combo_options.VideoCodec; import com.moulberry.flashback.combo_options.VideoCodec;
import com.moulberry.flashback.combo_options.VideoContainer; import com.moulberry.flashback.combo_options.VideoContainer;
import com.moulberry.flashback.configuration.FlashbackConfig;
import com.moulberry.flashback.editor.ui.ReplayUI; import com.moulberry.flashback.editor.ui.ReplayUI;
import com.moulberry.flashback.exporting.ExportJobQueue; import com.moulberry.flashback.exporting.ExportJobQueue;
import com.moulberry.flashback.state.EditorScene; import com.moulberry.flashback.state.EditorScene;
@@ -43,28 +44,13 @@ public class StartExportWindow {
private static final int[] lastFramebufferSize = new int[]{0, 0}; private static final int[] lastFramebufferSize = new int[]{0, 0};
private static AspectRatio lastCustomAspectRatio = null; private static AspectRatio lastCustomAspectRatio = null;
private static final int[] resolution = new int[]{1920, 1080};
private static final int[] startEndTick = new int[]{0, 100}; private static final int[] startEndTick = new int[]{0, 100};
private static final float[] framerate = new float[]{60};
private static boolean resetRng = false;
public static boolean ssaa = false;
public static boolean noGui = false;
private static VideoContainer[] supportedContainers = null; private static VideoContainer[] supportedContainers = null;
private static VideoContainer[] supportedContainersWithTransparency = null; private static VideoContainer[] supportedContainersWithTransparency = null;
private static VideoContainer container = null;
private static VideoCodec videoCodec = null;
private static int[] selectedVideoEncoder = new int[]{0};
private static boolean useMaximumBitrate = false;
private static final ImString bitrate = ImGuiHelper.createResizableImString("20m"); private static final ImString bitrate = ImGuiHelper.createResizableImString("20m");
private static boolean recordAudio = false;
public static boolean transparentBackground = false;
private static AudioCodec audioCodec = AudioCodec.AAC;
private static boolean stereoAudio = false;
public static Path defaultExportPath = null;
private static final ImString jobName = ImGuiHelper.createResizableImString(""); private static final ImString jobName = ImGuiHelper.createResizableImString("");
private static String installedIncompatibleModsString = null; private static String installedIncompatibleModsString = null;
@@ -92,45 +78,50 @@ public class StartExportWindow {
} }
} }
ImGui.openPopup("###StartExport"); FlashbackConfig config = Flashback.getConfig();
Window window = Minecraft.getInstance().getWindow();
// Only update the resolution if the framebuffer size changes if (config.resolution == null || config.resolution.length != 2) {
// This way, when users input custom resolutions it persists between opens config.resolution = new int[]{1920, 1080};
if (window.framebufferWidth != lastFramebufferSize[0] || window.framebufferHeight != lastFramebufferSize[1]) {
resolution[0] = window.framebufferWidth;
resolution[1] = window.framebufferHeight;
lastFramebufferSize[0] = window.framebufferWidth;
lastFramebufferSize[1] = window.framebufferHeight;
} }
if (config.framerate == null || config.framerate.length != 1) {
config.framerate = new float[]{60};
}
if (config.selectedVideoEncoder == null || config.selectedVideoEncoder.length != 1) {
config.selectedVideoEncoder = new int[]{0};
}
if (config.audioCodec == null) {
config.audioCodec = AudioCodec.AAC;
}
ImGui.openPopup("###StartExport");
if (editorState != null && editorState.replayVisuals.sizing == Sizing.CHANGE_ASPECT_RATIO) { if (editorState != null && editorState.replayVisuals.sizing == Sizing.CHANGE_ASPECT_RATIO) {
AspectRatio aspectRatio = editorState.replayVisuals.changeAspectRatio; AspectRatio aspectRatio = editorState.replayVisuals.changeAspectRatio;
if (aspectRatio != null && aspectRatio != lastCustomAspectRatio) { if (aspectRatio != null && aspectRatio != lastCustomAspectRatio) {
switch (aspectRatio) { switch (aspectRatio) {
case ASPECT_16_9 -> { case ASPECT_16_9 -> {
resolution[0] = 1920; config.resolution[0] = 1920;
resolution[1] = 1080; config.resolution[1] = 1080;
} }
case ASPECT_9_16 -> { case ASPECT_9_16 -> {
resolution[0] = 1080; config.resolution[0] = 1080;
resolution[1] = 1920; config.resolution[1] = 1920;
} }
case ASPECT_240_1 -> { case ASPECT_240_1 -> {
resolution[0] = 1920; config.resolution[0] = 1920;
resolution[1] = 800; config.resolution[1] = 800;
} }
case ASPECT_1_1 -> { case ASPECT_1_1 -> {
resolution[0] = 1920; config.resolution[0] = 1920;
resolution[1] = 1920; config.resolution[1] = 1920;
} }
case ASPECT_4_3 -> { case ASPECT_4_3 -> {
resolution[0] = 1600; config.resolution[0] = 1600;
resolution[1] = 1200; config.resolution[1] = 1200;
} }
case ASPECT_3_2 -> { case ASPECT_3_2 -> {
resolution[0] = 2160; config.resolution[0] = 2160;
resolution[1] = 1440; config.resolution[1] = 1440;
} }
} }
} }
@@ -148,14 +139,16 @@ public class StartExportWindow {
return; return;
} }
FlashbackConfig config = Flashback.getConfig();
ImGuiHelper.separatorWithText("Capture Options"); ImGuiHelper.separatorWithText("Capture Options");
ImGuiHelper.inputInt("Resolution", resolution); ImGuiHelper.inputInt("Resolution", config.resolution);
if (resolution[0] < 16) resolution[0] = 16; if (config.resolution[0] < 16) config.resolution[0] = 16;
if (resolution[1] < 16) resolution[1] = 16; if (config.resolution[1] < 16) config.resolution[1] = 16;
if (resolution[0] % 2 != 0) resolution[0] += 1; if (config.resolution[0] % 2 != 0) config.resolution[0] += 1;
if (resolution[1] % 2 != 0) resolution[1] += 1; if (config.resolution[1] % 2 != 0) config.resolution[1] += 1;
if (ImGuiHelper.inputInt("Start/end tick", startEndTick)) { if (ImGuiHelper.inputInt("Start/end tick", startEndTick)) {
ReplayServer replayServer = Flashback.getReplayServer(); ReplayServer replayServer = Flashback.getReplayServer();
@@ -164,47 +157,47 @@ public class StartExportWindow {
editorState.markDirty(); editorState.markDirty();
} }
} }
ImGuiHelper.inputFloat("Framerate", framerate); ImGuiHelper.inputFloat("Framerate", config.framerate);
if (ImGui.checkbox("Reset RNG", resetRng)) { if (ImGui.checkbox("Reset RNG", config.resetRng)) {
resetRng = !resetRng; config.resetRng = !config.resetRng;
} }
ImGuiHelper.tooltip("Attempts to remove randomness from the replay in order to produce more consistent outputs when recording the same scene multiple times"); ImGuiHelper.tooltip("Attempts to remove randomness from the replay in order to produce more consistent outputs when recording the same scene multiple times");
ImGui.sameLine(); ImGui.sameLine();
if (ImGui.checkbox("SSAA", ssaa)) { if (ImGui.checkbox("SSAA", config.ssaa)) {
ssaa = !ssaa; config.ssaa = !config.ssaa;
} }
ImGuiHelper.tooltip("Supersampling Anti-Aliasing: Remove jagged edges by rendering the game at double resolution and downscaling"); ImGuiHelper.tooltip("Supersampling Anti-Aliasing: Remove jagged edges by rendering the game at double resolution and downscaling");
ImGui.sameLine(); ImGui.sameLine();
if (ImGui.checkbox("No GUI", noGui)) { if (ImGui.checkbox("No GUI", config.noGui)) {
noGui = !noGui; config.noGui = !config.noGui;
} }
ImGuiHelper.tooltip("Removes all UI from the screen, rendering only the world"); ImGuiHelper.tooltip("Removes all UI from the screen, rendering only the world");
ImGuiHelper.separatorWithText("Video Options"); ImGuiHelper.separatorWithText("Video Options");
renderVideoOptions(editorState); renderVideoOptions(editorState, config);
AudioCodec[] supportedAudioCodecs = container.getSupportedAudioCodecs(); AudioCodec[] supportedAudioCodecs = config.container.getSupportedAudioCodecs();
if (supportedAudioCodecs.length > 0) { if (supportedAudioCodecs.length > 0) {
ImGuiHelper.separatorWithText("Audio Options"); ImGuiHelper.separatorWithText("Audio Options");
if (ImGui.checkbox("Record Audio", recordAudio)) { if (ImGui.checkbox("Record Audio", config.recordAudio)) {
recordAudio = !recordAudio; config.recordAudio = !config.recordAudio;
} }
if (recordAudio) { if (config.recordAudio) {
if (ImGui.checkbox("Stereo (2 channel)", stereoAudio)) { if (ImGui.checkbox("Stereo (2 channel)", config.stereoAudio)) {
stereoAudio = !stereoAudio; config.stereoAudio = !config.stereoAudio;
} }
AudioCodec newAudioCodec = ImGuiHelper.enumCombo("Audio Codec", audioCodec, supportedAudioCodecs); AudioCodec newAudioCodec = ImGuiHelper.enumCombo("Audio Codec", config.audioCodec, supportedAudioCodecs);
if (newAudioCodec != audioCodec) { if (newAudioCodec != config.audioCodec) {
audioCodec = newAudioCodec; config.audioCodec = newAudioCodec;
} }
if (editorState != null && editorState.audioSourceEntity != null) { if (editorState != null && editorState.audioSourceEntity != null) {
@@ -214,7 +207,7 @@ public class StartExportWindow {
} }
} }
} else { } else {
recordAudio = false; config.recordAudio = false;
} }
if (installedIncompatibleModsString != null) { if (installedIncompatibleModsString != null) {
@@ -230,11 +223,12 @@ public class StartExportWindow {
float buttonSize = (ImGui.getContentRegionAvailX() - ImGui.getStyle().getItemSpacingX()) / 2f; float buttonSize = (ImGui.getContentRegionAvailX() - ImGui.getStyle().getItemSpacingX()) / 2f;
if (ImGui.button("Start Export", buttonSize, ReplayUI.scaleUi(25))) { if (ImGui.button("Start Export", buttonSize, ReplayUI.scaleUi(25))) {
createExportSettings(null).thenAccept(settings -> { createExportSettings(null, config).thenAccept(settings -> {
if (settings != null) { if (settings != null) {
close = true; close = true;
Utils.exportSequenceCount += 1; Utils.exportSequenceCount += 1;
Flashback.EXPORT_JOB = new ExportJob(settings); Flashback.EXPORT_JOB = new ExportJob(settings);
config.delayedSaveToDefaultFolder();
} }
}); });
} }
@@ -249,7 +243,7 @@ public class StartExportWindow {
ImGui.inputText("Job Name", jobName); ImGui.inputText("Job Name", jobName);
if (ImGui.button("Queue Job")) { if (ImGui.button("Queue Job")) {
createExportSettings(ImGuiHelper.getString(jobName)).thenAccept(settings -> { createExportSettings(ImGuiHelper.getString(jobName), config).thenAccept(settings -> {
if (settings != null) { if (settings != null) {
close = true; close = true;
Utils.exportSequenceCount += 1; Utils.exportSequenceCount += 1;
@@ -270,17 +264,17 @@ public class StartExportWindow {
close = false; close = false;
} }
private static void renderVideoOptions(EditorState editorState) { private static void renderVideoOptions(EditorState editorState, FlashbackConfig config) {
if (editorState != null && !editorState.replayVisuals.renderSky) { if (editorState != null && !editorState.replayVisuals.renderSky) {
if (ImGui.checkbox("Transparent Sky", transparentBackground)) { if (ImGui.checkbox("Transparent Sky", config.transparentBackground)) {
transparentBackground = !transparentBackground; config.transparentBackground = !config.transparentBackground;
} }
} else { } else {
transparentBackground = false; config.transparentBackground = false;
} }
VideoContainer[] containers; VideoContainer[] containers;
if (transparentBackground) { if (config.transparentBackground) {
if (supportedContainersWithTransparency == null) { if (supportedContainersWithTransparency == null) {
supportedContainersWithTransparency = VideoContainer.findSupportedContainers(true); supportedContainersWithTransparency = VideoContainer.findSupportedContainers(true);
} }
@@ -297,45 +291,45 @@ public class StartExportWindow {
return; return;
} }
if (container == null || !Arrays.asList(containers).contains(container)) { if (config.container == null || !Arrays.asList(containers).contains(config.container)) {
container = containers[0]; config.container = containers[0];
} }
container = ImGuiHelper.enumCombo("Container", container, containers); config.container = ImGuiHelper.enumCombo("Container", config.container, containers);
if (container == VideoContainer.PNG_SEQUENCE) { if (config.container == VideoContainer.PNG_SEQUENCE) {
return; return;
} }
VideoCodec[] codecs = container.getSupportedVideoCodecs(transparentBackground); VideoCodec[] codecs = config.container.getSupportedVideoCodecs(config.transparentBackground);
if (codecs.length == 0) { if (codecs.length == 0) {
ImGui.text("No supported codecs found"); ImGui.text("No supported codecs found");
return; return;
} }
if (videoCodec == null || !Arrays.asList(codecs).contains(videoCodec)) { if (config.videoCodec == null || !Arrays.asList(codecs).contains(config.videoCodec)) {
videoCodec = codecs[0]; config.videoCodec = codecs[0];
} }
if (codecs.length > 1) { if (codecs.length > 1) {
VideoCodec newCodec = ImGuiHelper.enumCombo("Codec", videoCodec, codecs); VideoCodec newCodec = ImGuiHelper.enumCombo("Codec", config.videoCodec, codecs);
if (newCodec != videoCodec) { if (newCodec != config.videoCodec) {
videoCodec = newCodec; config.videoCodec = newCodec;
selectedVideoEncoder[0] = 0; config.selectedVideoEncoder[0] = 0;
} }
} }
String[] encoders = videoCodec.getEncoders(); String[] encoders = config.videoCodec.getEncoders();
if (encoders.length > 1) { if (encoders.length > 1) {
ImGuiHelper.combo("Encoder", selectedVideoEncoder, encoders); ImGuiHelper.combo("Encoder", config.selectedVideoEncoder, encoders);
} }
if (videoCodec != VideoCodec.GIF) { if (config.videoCodec != VideoCodec.GIF) {
if (ImGui.checkbox("Use Maximum Bitrate", useMaximumBitrate)) { if (ImGui.checkbox("Use Maximum Bitrate", config.useMaximumBitrate)) {
useMaximumBitrate = !useMaximumBitrate; config.useMaximumBitrate = !config.useMaximumBitrate;
} }
if (!useMaximumBitrate) { if (!config.useMaximumBitrate) {
ImGui.inputText("Bitrate", bitrate); ImGui.inputText("Bitrate", bitrate);
if (ImGui.isItemDeactivatedAfterEdit()) { if (ImGui.isItemDeactivatedAfterEdit()) {
int numBitrate = stringToBitrate(ImGuiHelper.getString(bitrate)); int numBitrate = stringToBitrate(ImGuiHelper.getString(bitrate));
@@ -349,15 +343,15 @@ public class StartExportWindow {
} }
} }
private static CompletableFuture<ExportSettings> createExportSettings(@Nullable String name) { private static CompletableFuture<ExportSettings> createExportSettings(@Nullable String name, FlashbackConfig config) {
int numBitrate; int numBitrate;
if (useMaximumBitrate) { if (config.useMaximumBitrate) {
numBitrate = 0; numBitrate = 0;
} else { } else {
numBitrate = stringToBitrate(ImGuiHelper.getString(bitrate)); numBitrate = stringToBitrate(ImGuiHelper.getString(bitrate));
} }
String defaultName = getDefaultFilename(name, container.extension()); String defaultName = getDefaultFilename(name, config.container.extension(), config);
Function<String, ExportSettings> callback = pathStr -> { Function<String, ExportSettings> callback = pathStr -> {
if (pathStr != null) { if (pathStr != null) {
@@ -381,14 +375,14 @@ public class StartExportWindow {
return null; return null;
} }
boolean transparent = transparentBackground && !editorState.replayVisuals.renderSky; boolean transparent = config.transparentBackground && !editorState.replayVisuals.renderSky;
String encoder = videoCodec.getEncoders()[selectedVideoEncoder[0]]; String encoder = config.videoCodec.getEncoders()[config.selectedVideoEncoder[0]];
VideoCodec useVideoCodec = videoCodec; VideoCodec useVideoCodec = config.videoCodec;
AudioCodec useAudioCodec = audioCodec; AudioCodec useAudioCodec = config.audioCodec;
boolean shouldRecordAudio = recordAudio; boolean shouldRecordAudio = config.recordAudio;
if (container == VideoContainer.PNG_SEQUENCE) { if (config.container == VideoContainer.PNG_SEQUENCE) {
useVideoCodec = null; useVideoCodec = null;
encoder = null; encoder = null;
shouldRecordAudio = false; shouldRecordAudio = false;
@@ -399,43 +393,49 @@ public class StartExportWindow {
} }
Path path = Path.of(pathStr); Path path = Path.of(pathStr);
defaultExportPath = path.getParent(); config.defaultExportPath = path.getParent().toString();
return new ExportSettings(name, editorState.copy(), return new ExportSettings(name, editorState.copy(),
player.position(), player.getYRot(), player.getXRot(), player.position(), player.getYRot(), player.getXRot(),
resolution[0], resolution[1], start, end, config.resolution[0], config.resolution[1], start, end,
Math.max(1, framerate[0]), resetRng, container, useVideoCodec, encoder, numBitrate, transparent, ssaa, noGui, Math.max(1, config.framerate[0]), config.resetRng, config.container, useVideoCodec, encoder, numBitrate, transparent, config.ssaa, config.noGui,
shouldRecordAudio, stereoAudio, useAudioCodec, shouldRecordAudio, config.stereoAudio, useAudioCodec,
path); path);
} }
return null; return null;
}; };
String defaultExportPathString = defaultExportPath.toString(); String defaultExportPathString = config.defaultExportPath;
if (container == VideoContainer.PNG_SEQUENCE) { if (config.container == VideoContainer.PNG_SEQUENCE) {
return AsyncFileDialogs.openFolderDialog(defaultExportPathString).thenApply(callback); return AsyncFileDialogs.openFolderDialog(defaultExportPathString).thenApply(callback);
} else { } else {
return AsyncFileDialogs.saveFileDialog(defaultExportPathString, defaultName, return AsyncFileDialogs.saveFileDialog(defaultExportPathString, defaultName,
container.extension(), container.extension()).thenApply(callback); config.container.extension(), config.container.extension()).thenApply(callback);
} }
} }
public static @NotNull String getDefaultFilename(@Nullable String name, String extension) { public static @NotNull String getDefaultFilename(@Nullable String name, String extension, FlashbackConfig config) {
if (defaultExportPath == null || !Files.exists(defaultExportPath)) { Path defaultPath = FabricLoader.getInstance().getGameDir();
defaultExportPath = FabricLoader.getInstance().getGameDir();
} try {
if (config.defaultExportPath == null || config.defaultExportPath.isBlank() || !Files.exists(Path.of(config.defaultExportPath))) {
config.defaultExportPath = defaultPath.toString();
} else {
defaultPath = Path.of(config.defaultExportPath);
}
} catch (Exception ignored) {}
String defaultName = null; String defaultName = null;
if (name != null) { if (name != null) {
try { try {
defaultName = FileUtil.findAvailableName(defaultExportPath, name, "." + extension); defaultName = FileUtil.findAvailableName(defaultPath, name, "." + extension);
} catch (Exception ignored) {} } catch (Exception ignored) {}
} }
if (defaultName == null) { if (defaultName == null) {
String desiredName = Utils.resolveFilenameTemplate(Flashback.getConfig().defaultExportFilename); String desiredName = Utils.resolveFilenameTemplate(Flashback.getConfig().defaultExportFilename);
try { try {
defaultName = FileUtil.findAvailableName(defaultExportPath, desiredName, "." + extension); defaultName = FileUtil.findAvailableName(defaultPath, desiredName, "." + extension);
} catch (Exception ignored) {} } catch (Exception ignored) {}
} }
if (defaultName == null) { if (defaultName == null) {