Save modifications of downloaded replays to separate file

This commit is contained in:
johni0702
2015-11-14 17:48:24 +01:00
parent 48fb3e6f82
commit 393a08e2da
8 changed files with 126 additions and 171 deletions

View File

@@ -4,14 +4,21 @@ import com.replaymod.core.ReplayMod;
import com.replaymod.online.api.ApiClient;
import com.replaymod.online.gui.GuiLoginPrompt;
import com.replaymod.online.gui.GuiReplayDownloading;
import com.replaymod.online.gui.GuiSaveModifiedReplay;
import com.replaymod.online.handler.GuiHandler;
import com.replaymod.replay.ReplayModReplay;
import com.replaymod.replay.events.ReplayCloseEvent;
import de.johni0702.minecraft.gui.container.GuiScreen;
import de.johni0702.replaystudio.replay.ReplayFile;
import de.johni0702.replaystudio.replay.ZipReplayFile;
import de.johni0702.replaystudio.studio.ReplayStudio;
import net.minecraftforge.common.config.Configuration;
import net.minecraftforge.fml.common.FMLCommonHandler;
import net.minecraftforge.fml.common.Mod;
import net.minecraftforge.fml.common.event.FMLInitializationEvent;
import net.minecraftforge.fml.common.event.FMLPostInitializationEvent;
import net.minecraftforge.fml.common.event.FMLPreInitializationEvent;
import net.minecraftforge.fml.common.eventhandler.SubscribeEvent;
import org.apache.logging.log4j.Logger;
import java.io.File;
@@ -36,6 +43,13 @@ public class ReplayModOnline {
private ApiClient apiClient;
/**
* In case the currently opened replay gets modified, the resulting replay file is saved to this location.
* Usually a file within the normal replays folder with a unique name.
* When the replay is closed, the user is asked whether they want to give it a proper name.
*/
private File currentReplayOutputFile;
@Mod.EventHandler
public void preInit(FMLPreInitializationEvent event) {
logger = event.getModLog();
@@ -55,6 +69,7 @@ public class ReplayModOnline {
}
new GuiHandler(this).register();
FMLCommonHandler.instance().bus().register(this);
}
@Mod.EventHandler
@@ -102,9 +117,21 @@ public class ReplayModOnline {
public void startReplay(int id, String name, GuiScreen onDownloadCancelled) throws IOException {
File file = getDownloadedFile(id);
if (file.exists()) {
replayModule.startReplay(file);
currentReplayOutputFile = new File(core.getReplayFolder(), System.currentTimeMillis() + ".mcpr");
ReplayFile replayFile = new ZipReplayFile(new ReplayStudio(), file, currentReplayOutputFile);
replayModule.startReplay(replayFile);
} else {
new GuiReplayDownloading(onDownloadCancelled, this, id, name).display();
}
}
@SubscribeEvent
public void onReplayClosed(ReplayCloseEvent.Post event) {
if (currentReplayOutputFile != null) {
if (currentReplayOutputFile.exists()) { // Replay was modified, ask user for new name
new GuiSaveModifiedReplay(currentReplayOutputFile).display();
}
currentReplayOutputFile = null;
}
}
}