Added Keyframe Repository, which is stored in Replay File itself and allows Camera Path Presets to be saved and loaded
This commit is contained in:
@@ -1,59 +0,0 @@
|
||||
package eu.crushedpixel.replaymod.registry;
|
||||
|
||||
import org.apache.commons.lang3.tuple.Pair;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.nio.file.Files;
|
||||
import java.nio.file.StandardCopyOption;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Queue;
|
||||
import java.util.concurrent.ConcurrentLinkedQueue;
|
||||
|
||||
public class FileCopyHandler extends Thread {
|
||||
|
||||
private Queue<Pair<File, File>> filesToMove = new ConcurrentLinkedQueue<Pair<File, File>>();
|
||||
private boolean shutdown = false;
|
||||
|
||||
public FileCopyHandler() {
|
||||
Runtime.getRuntime().addShutdownHook(new Thread(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
FileCopyHandler.this.shutdown();
|
||||
}
|
||||
}));
|
||||
}
|
||||
|
||||
public void registerModifiedFile(File tempFile, File destination) {
|
||||
filesToMove.add(Pair.of(tempFile, destination));
|
||||
|
||||
for(Pair<File, File> p : new ArrayList<Pair<File, File>>(filesToMove)) {
|
||||
if(p.equals(tempFile)) {
|
||||
filesToMove.remove(p);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void shutdown() {
|
||||
shutdown = true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void run() {
|
||||
while(!shutdown || !filesToMove.isEmpty()) {
|
||||
Pair<File, File> mv = filesToMove.poll();
|
||||
if(mv != null) {
|
||||
try {
|
||||
Files.move(mv.getLeft().toPath(), mv.getRight().toPath(), StandardCopyOption.REPLACE_EXISTING);
|
||||
} catch(IOException e) {
|
||||
filesToMove.add(mv);
|
||||
}
|
||||
}
|
||||
try {
|
||||
Thread.sleep(1000);
|
||||
} catch(Exception e) {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
@@ -15,6 +15,7 @@ public class KeybindRegistry {
|
||||
public static final String KEY_SPECTATE = "replaymod.input.spectate";
|
||||
public static final String KEY_CLEAR_KEYFRAMES = "replaymod.input.clearkeyframes";
|
||||
public static final String KEY_SYNC_TIMELINE = "replaymod.input.synctimeline";
|
||||
public static final String KEY_KEYFRAME_PRESETS = "replaymod.input.keyframerepository";
|
||||
private static Minecraft mc = Minecraft.getMinecraft();
|
||||
|
||||
public static void initialize() {
|
||||
@@ -25,6 +26,7 @@ public class KeybindRegistry {
|
||||
bindings.add(new KeyBinding(KEY_SPECTATE, Keyboard.KEY_B, "replaymod.title"));
|
||||
bindings.add(new KeyBinding(KEY_SYNC_TIMELINE, Keyboard.KEY_V, "replaymod.title"));
|
||||
bindings.add(new KeyBinding(KEY_CLEAR_KEYFRAMES, Keyboard.KEY_C, "replaymod.title"));
|
||||
bindings.add(new KeyBinding(KEY_KEYFRAME_PRESETS, Keyboard.KEY_X, "replaymod.title"));
|
||||
|
||||
mc.gameSettings.keyBindings = bindings.toArray(new KeyBinding[bindings.size()]);
|
||||
}
|
||||
|
||||
@@ -0,0 +1,61 @@
|
||||
package eu.crushedpixel.replaymod.registry;
|
||||
|
||||
import eu.crushedpixel.replaymod.utils.ReplayFileIO;
|
||||
import org.apache.commons.lang3.tuple.Pair;
|
||||
|
||||
import java.io.File;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Queue;
|
||||
import java.util.concurrent.ConcurrentLinkedQueue;
|
||||
|
||||
public class ReplayFileAppender extends Thread {
|
||||
|
||||
private Queue<Pair<Pair<File, String>, File>> filesToMove = new ConcurrentLinkedQueue<Pair<Pair<File, String>, File>>();
|
||||
private boolean shutdown = false;
|
||||
|
||||
public ReplayFileAppender() {
|
||||
Runtime.getRuntime().addShutdownHook(new Thread(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
ReplayFileAppender.this.shutdown();
|
||||
}
|
||||
}));
|
||||
}
|
||||
|
||||
public void registerModifiedFile(File toAdd, String name, File replayFile) {
|
||||
for(Pair<Pair<File, String>, File> p : new ArrayList<Pair<Pair<File, String>, File>>(filesToMove)) {
|
||||
if(p.getLeft().getRight().equals(name) && p.getRight().equals(replayFile)) {
|
||||
filesToMove.remove(p);
|
||||
}
|
||||
}
|
||||
|
||||
filesToMove.add(Pair.of(Pair.of(toAdd, name), replayFile));
|
||||
}
|
||||
|
||||
public void shutdown() {
|
||||
shutdown = true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void run() {
|
||||
while(!shutdown || !filesToMove.isEmpty()) {
|
||||
Pair<Pair<File, String>, File> mv = filesToMove.poll();
|
||||
if(mv != null) {
|
||||
if(mv.getRight().canWrite()) {
|
||||
try {
|
||||
ReplayFileIO.addFileToZip(mv.getRight(), mv.getLeft().getLeft(), mv.getLeft().getRight());
|
||||
} catch(Exception e) {
|
||||
e.printStackTrace();
|
||||
filesToMove.add(mv);
|
||||
}
|
||||
} else {
|
||||
filesToMove.add(mv);
|
||||
}
|
||||
}
|
||||
try {
|
||||
Thread.sleep(1000);
|
||||
} catch(Exception e) {}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user