Added ProgressFilter to allow for more accurate progress bar in GuiReplayEditingProcess and implemented it | https://trello.com/c/qXWxoTc1/
This commit is contained in:
@@ -0,0 +1,53 @@
|
||||
package eu.crushedpixel.replaymod.studio;
|
||||
|
||||
import com.google.gson.JsonObject;
|
||||
import de.johni0702.replaystudio.PacketData;
|
||||
import de.johni0702.replaystudio.Studio;
|
||||
import de.johni0702.replaystudio.filter.StreamFilter;
|
||||
import de.johni0702.replaystudio.stream.PacketStream;
|
||||
import eu.crushedpixel.replaymod.gui.elements.listeners.ProgressUpdateListener;
|
||||
|
||||
public class ProgressFilter implements StreamFilter {
|
||||
|
||||
private final long total;
|
||||
|
||||
private ProgressUpdateListener listener;
|
||||
private float minPerc, maxPerc;
|
||||
|
||||
public ProgressFilter(long total, ProgressUpdateListener progressUpdateListener) {
|
||||
this(total, progressUpdateListener, 0, 1);
|
||||
}
|
||||
|
||||
public ProgressFilter(long total, ProgressUpdateListener progressUpdateListener, float minPerc, float maxPerc) {
|
||||
this.total = total;
|
||||
|
||||
this.listener = progressUpdateListener;
|
||||
this.minPerc = minPerc;
|
||||
this.maxPerc = maxPerc;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getName() {
|
||||
return "progress";
|
||||
}
|
||||
|
||||
@Override
|
||||
public void init(Studio studio, JsonObject config) {}
|
||||
|
||||
@Override
|
||||
public void onStart(PacketStream stream) {}
|
||||
|
||||
@Override
|
||||
public boolean onPacket(PacketStream stream, PacketData data) {
|
||||
float percentage = (data.getTime() / (float)total);
|
||||
|
||||
float perc = minPerc+(percentage*(maxPerc-minPerc));
|
||||
|
||||
this.listener.onProgressChanged(perc);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onEnd(PacketStream stream, long timestamp) {}
|
||||
}
|
||||
@@ -18,6 +18,7 @@ import org.apache.commons.lang3.Validate;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
public class StudioImplementation {
|
||||
@@ -29,7 +30,10 @@ public class StudioImplementation {
|
||||
studio.setWrappingEnabled(false);
|
||||
ReplayFile replayFile = new ZipReplayFile(studio, file);
|
||||
|
||||
ReplayMetaData metaData = replayFile.getMetaData();
|
||||
|
||||
PacketStream stream = studio.createReplayStream(replayFile.getPacketData(), true);
|
||||
stream.addFilter(new ProgressFilter(metaData.getDuration(), updateListener, 1/100f, 9/10f));
|
||||
stream.addFilter(new SquashFilter(), -1, beginning);
|
||||
stream.addFilter(new RemoveFilter(), ending, -1);
|
||||
|
||||
@@ -43,7 +47,7 @@ public class StudioImplementation {
|
||||
ReplayOutputStream out = replayFile.writePacketData();
|
||||
PacketData packetData;
|
||||
|
||||
updateListener.onProgressChanged(1/4f, I18n.format("replaymod.gui.editor.progress.status.writing.raw"));
|
||||
updateListener.onProgressChanged(1/100f, I18n.format("replaymod.gui.editor.progress.status.writing.raw"));
|
||||
|
||||
while((packetData = stream.next()) != null) {
|
||||
out.write(packetData);
|
||||
@@ -56,15 +60,11 @@ public class StudioImplementation {
|
||||
}
|
||||
|
||||
out.close();
|
||||
|
||||
updateListener.onProgressChanged(2/4f, I18n.format("replaymod.gui.editor.progress.status.writing.zip"));
|
||||
|
||||
ReplayMetaData metaData = replayFile.getMetaData();
|
||||
ending = Math.min(metaData.getDuration(), ending);
|
||||
metaData.setDuration(ending - beginning);
|
||||
replayFile.writeMetaData(metaData);
|
||||
|
||||
updateListener.onProgressChanged(3/4f, I18n.format("replaymod.gui.editor.progress.status.writing.final"));
|
||||
updateListener.onProgressChanged(9/10f, I18n.format("replaymod.gui.editor.progress.status.writing.final"));
|
||||
|
||||
replayFile.saveTo(outputFile);
|
||||
|
||||
@@ -84,15 +84,24 @@ public class StudioImplementation {
|
||||
ConnectMetadataFilter metaDataFilter = new ConnectMetadataFilter();
|
||||
int startTime = 0;
|
||||
|
||||
updateListener.onProgressChanged(1/4f, I18n.format("replaymod.gui.editor.progress.status.writing.raw"));
|
||||
updateListener.onProgressChanged(1/100f, I18n.format("replaymod.gui.editor.progress.status.writing.raw"));
|
||||
|
||||
float i = 0;
|
||||
float size = filesToConnect.size();
|
||||
List<ReplayFile> zipReplayFiles = new ArrayList<ReplayFile>();
|
||||
long totalTime = 0;
|
||||
|
||||
for (File file : filesToConnect) {
|
||||
ReplayFile replayFile = new ZipReplayFile(studio, file);
|
||||
zipReplayFiles.add(replayFile);
|
||||
|
||||
ReplayMetaData metaData = replayFile.getMetaData();
|
||||
totalTime += metaData.getDuration();
|
||||
}
|
||||
|
||||
for (ReplayFile replayFile : zipReplayFiles) {
|
||||
PacketStream stream = studio.createReplayStream(replayFile.getPacketData(), true);
|
||||
ReplayMetaData metaData = replayFile.getMetaData();
|
||||
stream.addFilter(new ProgressFilter(metaData.getDuration(), updateListener, 1/100f + (9/10f - 1/100f) * (float)startTime/totalTime,
|
||||
1/100f + (9/10f - 1/100f) * ((float)startTime+metaData.getDuration())/totalTime));
|
||||
|
||||
stream.addFilter(new NeutralizerFilter());
|
||||
|
||||
@@ -116,17 +125,13 @@ public class StudioImplementation {
|
||||
}
|
||||
|
||||
startTime += metaData.getDuration();
|
||||
|
||||
updateListener.onProgressChanged((1/4f)+((1/4f)*(i/size)));
|
||||
}
|
||||
|
||||
out.close();
|
||||
|
||||
updateListener.onProgressChanged(2/4f, I18n.format("replaymod.gui.editor.progress.status.writing.zip"));
|
||||
|
||||
metaDataFilter.writeTo(outputReplayFile);
|
||||
|
||||
updateListener.onProgressChanged(3/4f, I18n.format("replaymod.gui.editor.progress.status.writing.final"));
|
||||
updateListener.onProgressChanged(9/10f, I18n.format("replaymod.gui.editor.progress.status.writing.final"));
|
||||
|
||||
outputReplayFile.saveTo(outputFile);
|
||||
|
||||
|
||||
@@ -185,7 +185,6 @@ replaymod.gui.editor.progress.pleasewait=Please wait while the Replay is being e
|
||||
|
||||
replaymod.gui.editor.progress.status.initializing=Initializing
|
||||
replaymod.gui.editor.progress.status.writing.raw=Rewriting Replay...
|
||||
replaymod.gui.editor.progress.status.writing.zip=Wrapping Replay File...
|
||||
replaymod.gui.editor.progress.status.writing.final=Writing File to disk...
|
||||
replaymod.gui.editor.progress.status.finished=Finished Editing!
|
||||
|
||||
|
||||
Reference in New Issue
Block a user