Added Event Markers to Replay, which allow players to quickly mark important events while recording (M key by default)

Added Event Marker Indicators to be displayed on GuiTimeline
This commit is contained in:
CrushedPixel
2015-06-09 16:08:06 +02:00
parent ea968ca418
commit d30ef19c89
13 changed files with 235 additions and 20 deletions

View File

@@ -3,6 +3,7 @@ package eu.crushedpixel.replaymod.utils;
import com.google.gson.Gson;
import eu.crushedpixel.replaymod.ReplayMod;
import eu.crushedpixel.replaymod.holders.KeyframeSet;
import eu.crushedpixel.replaymod.holders.Marker;
import eu.crushedpixel.replaymod.holders.PacketData;
import eu.crushedpixel.replaymod.holders.PlayerVisibility;
import eu.crushedpixel.replaymod.recording.PacketSerializer;
@@ -57,7 +58,7 @@ public class ReplayFileIO {
return files;
}
public static void writeReplayFile(File replayFile, File tempFile, ReplayMetaData metaData,
public static void writeReplayFile(File replayFile, File tempFile, ReplayMetaData metaData, Set<Marker> markers,
Map<String, File> resourcePacks, Map<Integer, String> resourcePackRequests) throws IOException {
byte[] buffer = new byte[1024];
@@ -86,14 +87,23 @@ public class ReplayFileIO {
fis.close();
zos.closeEntry();
if (!resourcePackRequests.isEmpty()) {
if(!markers.isEmpty()) {
zos.putNextEntry(new ZipEntry(ReplayFile.ENTRY_MARKERS));
pw = new PrintWriter(zos);
pw.write(new Gson().toJson(markers.toArray(new Marker[markers.size()])));
pw.flush();
zos.closeEntry();
}
if(!resourcePackRequests.isEmpty()) {
zos.putNextEntry(new ZipEntry(ReplayFile.ENTRY_RESOURCE_PACK_INDEX));
pw = new PrintWriter(zos);
pw.write(new Gson().toJson(resourcePackRequests));
pw.flush();
zos.closeEntry();
for (Map.Entry<String, File> entry : resourcePacks.entrySet()) {
for(Map.Entry<String, File> entry : resourcePacks.entrySet()) {
zos.putNextEntry(new ZipEntry(String.format(ReplayFile.ENTRY_RESOURCE_PACK, entry.getKey())));
IOUtils.copy(new FileInputStream(entry.getValue()), zos);
zos.closeEntry();
@@ -322,6 +332,14 @@ public class ReplayFileIO {
FileUtils.write(file, json);
}
public static void writeMarkersToFile(Marker[] markers, File file) throws IOException {
file.mkdirs();
file.createNewFile();
String json = gson.toJson(markers);
FileUtils.write(file, json);
}
/**
* Adds Files as entries to a ZIP File.
* @param zipFile The ZIP File to add the files to.