Custom Objects are now being saved with Path Presets instead of globally
This commit is contained in:
@@ -83,7 +83,7 @@ public class AssetRepository {
|
||||
try {
|
||||
String filepath = ReplayFile.ENTRY_ASSET_FOLDER + uuid.toString()+ "_" + asset.getDisplayString() + "." + asset.getSavedFileExtension();
|
||||
|
||||
File toAdd = File.createTempFile(asset.getDisplayString(), asset.getSavedFileExtension());
|
||||
File toAdd = File.createTempFile("ASSET_"+asset.getDisplayString(), asset.getSavedFileExtension());
|
||||
FileOutputStream fos = new FileOutputStream(toAdd);
|
||||
asset.writeToStream(fos);
|
||||
|
||||
|
||||
@@ -51,6 +51,15 @@ public class CustomImageObject implements GuiEntryListEntry {
|
||||
@Getter private Transformations transformations = new Transformations();
|
||||
|
||||
public void setLinkedAsset(UUID assetUUID) throws IOException {
|
||||
if(assetUUID == null) return;
|
||||
|
||||
//if no asset repository available, simply accept the UUID and it will load the image later
|
||||
//when calling getResourceLocation for the first time
|
||||
if(ReplayHandler.getAssetRepository() == null) {
|
||||
this.linkedAsset = assetUUID;
|
||||
return;
|
||||
}
|
||||
|
||||
ReplayAsset asset = ReplayHandler.getAssetRepository().getAssetByUUID(assetUUID);
|
||||
|
||||
if(asset instanceof ReplayImageAsset) {
|
||||
|
||||
@@ -139,7 +139,7 @@ public class GuiKeyframeRepository extends GuiScreen implements GuiReplayOverlay
|
||||
List<Keyframe> kfs = new ArrayList<Keyframe>(ReplayHandler.getAllKeyframes());
|
||||
|
||||
Keyframe[] keyframes = kfs.toArray(new Keyframe[ReplayHandler.getAllKeyframes().size()]);
|
||||
KeyframeSet newSet = new KeyframeSet(I18n.format("replaymod.gui.keyframerepository.preset.defaultname"), keyframes);
|
||||
KeyframeSet newSet = new KeyframeSet(I18n.format("replaymod.gui.keyframerepository.preset.defaultname"), keyframes, ReplayHandler.getCustomImageObjects());
|
||||
|
||||
try {
|
||||
CameraPathValidator.validateCameraPath(ReplayHandler.getPositionKeyframes(), ReplayHandler.getTimeKeyframes());
|
||||
@@ -161,7 +161,7 @@ public class GuiKeyframeRepository extends GuiScreen implements GuiReplayOverlay
|
||||
keyframeSetList.removeElement(keyframeSetList.getSelectionIndex());
|
||||
break;
|
||||
case GuiConstants.KEYFRAME_REPOSITORY_LOAD_BUTTON:
|
||||
ReplayHandler.useKeyframePreset(keyframeSetList.getElement(keyframeSetList.getSelectionIndex()).getKeyframes());
|
||||
ReplayHandler.useKeyframePreset(keyframeSetList.getElement(keyframeSetList.getSelectionIndex()));
|
||||
saveOnQuit();
|
||||
mc.displayGuiScreen(null);
|
||||
break;
|
||||
@@ -198,6 +198,9 @@ public class GuiKeyframeRepository extends GuiScreen implements GuiReplayOverlay
|
||||
|
||||
this.drawString(fontRendererObj, I18n.format("replaymod.gui.duration")+": "+ DurationFormatUtils.formatDurationHMS(currentSetDuration),
|
||||
loadButton.xPosition+2, removeButton.yPosition + 70, Color.WHITE.getRGB());
|
||||
|
||||
this.drawString(fontRendererObj, I18n.format("replaymod.gui.objects")+": "+currentSet.getCustomObjectCount(),
|
||||
loadButton.xPosition+2, removeButton.yPosition + 90, Color.WHITE.getRGB());
|
||||
}
|
||||
|
||||
if(message != null) {
|
||||
|
||||
@@ -1,8 +1,6 @@
|
||||
package eu.crushedpixel.replaymod.gui;
|
||||
|
||||
import eu.crushedpixel.replaymod.ReplayMod;
|
||||
import eu.crushedpixel.replaymod.assets.CustomImageObject;
|
||||
import eu.crushedpixel.replaymod.assets.CustomObjectRepository;
|
||||
import eu.crushedpixel.replaymod.assets.ReplayAsset;
|
||||
import eu.crushedpixel.replaymod.gui.elements.*;
|
||||
import eu.crushedpixel.replaymod.gui.elements.listeners.NumberValueChangeListener;
|
||||
@@ -14,8 +12,6 @@ import eu.crushedpixel.replaymod.interpolation.KeyframeList;
|
||||
import eu.crushedpixel.replaymod.interpolation.KeyframeValue;
|
||||
import eu.crushedpixel.replaymod.replay.ReplayHandler;
|
||||
import eu.crushedpixel.replaymod.utils.MouseUtils;
|
||||
import eu.crushedpixel.replaymod.utils.ReplayFile;
|
||||
import eu.crushedpixel.replaymod.utils.ReplayFileIO;
|
||||
import lombok.Getter;
|
||||
import lombok.Setter;
|
||||
import net.minecraft.client.Minecraft;
|
||||
@@ -26,7 +22,6 @@ import org.lwjgl.input.Keyboard;
|
||||
import org.lwjgl.util.Point;
|
||||
|
||||
import java.awt.*;
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.util.List;
|
||||
import java.util.UUID;
|
||||
@@ -377,18 +372,6 @@ public class GuiObjectManager extends GuiScreen implements GuiReplayOverlay.NoOv
|
||||
}
|
||||
|
||||
ReplayHandler.setCustomImageObjects(objects);
|
||||
|
||||
if(objects.size() > 0) {
|
||||
try {
|
||||
File f = File.createTempFile(ReplayFile.ENTRY_CUSTOM_OBJECTS, "json");
|
||||
ReplayFileIO.write(new CustomObjectRepository(objects), f);
|
||||
ReplayMod.replayFileAppender.registerModifiedFile(f, ReplayFile.ENTRY_CUSTOM_OBJECTS, ReplayHandler.getReplayFile());
|
||||
} catch(Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
} else {
|
||||
ReplayMod.replayFileAppender.registerModifiedFile(null, ReplayFile.ENTRY_CUSTOM_OBJECTS, ReplayHandler.getReplayFile());
|
||||
}
|
||||
}
|
||||
|
||||
private void updateValuesForTransformation(Transformation transformation) {
|
||||
|
||||
@@ -1,26 +1,45 @@
|
||||
package eu.crushedpixel.replaymod.holders;
|
||||
|
||||
import lombok.EqualsAndHashCode;
|
||||
import eu.crushedpixel.replaymod.assets.CustomImageObject;
|
||||
import lombok.Data;
|
||||
import lombok.NoArgsConstructor;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
@Data
|
||||
@NoArgsConstructor
|
||||
|
||||
@EqualsAndHashCode
|
||||
public class KeyframeSet implements GuiEntryListEntry {
|
||||
private String name;
|
||||
private Keyframe<AdvancedPosition>[] positionKeyframes;
|
||||
private Keyframe<TimestampValue>[] timeKeyframes;
|
||||
private CustomImageObject[] customObjects = new CustomImageObject[0];
|
||||
|
||||
public KeyframeSet(String name, Keyframe[] keyframes) {
|
||||
public KeyframeSet(String name, Keyframe[] keyframes, List<CustomImageObject> customObjectRepository) {
|
||||
this.name = name;
|
||||
setCustomObjects(customObjectRepository.toArray(new CustomImageObject[customObjectRepository.size()]));
|
||||
setKeyframes(keyframes);
|
||||
}
|
||||
|
||||
public void setName(String name) {
|
||||
public KeyframeSet(String name, Keyframe[] keyframes, CustomImageObject[] customObjects) {
|
||||
this.name = name;
|
||||
setCustomObjects(customObjects);
|
||||
setKeyframes(keyframes);
|
||||
}
|
||||
|
||||
public void setCustomObjects(CustomImageObject[] customObjects) {
|
||||
this.customObjects = new CustomImageObject[customObjects.length];
|
||||
|
||||
int i = 0;
|
||||
for(CustomImageObject object : customObjects) {
|
||||
try {
|
||||
this.customObjects[i] = object.copy();
|
||||
} catch(IOException ioe) {
|
||||
ioe.printStackTrace();
|
||||
}
|
||||
i++;
|
||||
}
|
||||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
@@ -39,10 +58,6 @@ public class KeyframeSet implements GuiEntryListEntry {
|
||||
timeKeyframes = timeKFList.toArray(new Keyframe[timeKFList.size()]);
|
||||
}
|
||||
|
||||
public String getName() {
|
||||
return name;
|
||||
}
|
||||
|
||||
public Keyframe[] getKeyframes() {
|
||||
Keyframe[] keyframes = new Keyframe[positionKeyframes.length + timeKeyframes.length];
|
||||
System.arraycopy(positionKeyframes, 0, keyframes, 0, positionKeyframes.length);
|
||||
@@ -73,6 +88,10 @@ public class KeyframeSet implements GuiEntryListEntry {
|
||||
return last-first;
|
||||
}
|
||||
|
||||
public int getCustomObjectCount() {
|
||||
return customObjects.length;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getDisplayString() {
|
||||
return name;
|
||||
|
||||
@@ -118,10 +118,14 @@ public class ReplayHandler {
|
||||
}
|
||||
|
||||
public static void useKeyframePresetFromRepository(int index) {
|
||||
useKeyframePreset(keyframeRepository[index].getKeyframes());
|
||||
useKeyframePreset(keyframeRepository[index]);
|
||||
}
|
||||
|
||||
public static void useKeyframePreset(Keyframe[] kfs) {
|
||||
public static void useKeyframePreset(KeyframeSet keyframeSet) {
|
||||
setCustomImageObjects(Arrays.asList(keyframeSet.getCustomObjects()));
|
||||
|
||||
Keyframe[] kfs = keyframeSet.getKeyframes();
|
||||
|
||||
positionKeyframes.clear();
|
||||
timeKeyframes.clear();
|
||||
for(Keyframe kf : kfs) {
|
||||
@@ -406,9 +410,7 @@ public class ReplayHandler {
|
||||
//load assets
|
||||
assetRepository = currentReplayFile.assetRepository().get();
|
||||
|
||||
//load custom image objects
|
||||
customImageObjects = currentReplayFile.customImageObjects().get();
|
||||
if(customImageObjects == null) customImageObjects = new CustomObjectRepository();
|
||||
customImageObjects = new CustomObjectRepository();
|
||||
|
||||
ReplayMod.replaySender = new ReplaySender(currentReplayFile, asyncMode);
|
||||
channel.pipeline().addFirst(ReplayMod.replaySender);
|
||||
|
||||
@@ -122,7 +122,7 @@ public class StudioImplementation {
|
||||
}
|
||||
if (timeKeyframes >= 2) {
|
||||
Keyframe[] keyframes = resultKeyframes.toArray(new Keyframe[resultKeyframes.size()]);
|
||||
resultSets.add(new KeyframeSet(set.getName(), keyframes));
|
||||
resultSets.add(new KeyframeSet(set.getName(), keyframes, set.getCustomObjects()));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -4,6 +4,7 @@ import com.google.gson.Gson;
|
||||
import com.google.gson.TypeAdapter;
|
||||
import com.google.gson.stream.JsonReader;
|
||||
import com.google.gson.stream.JsonWriter;
|
||||
import eu.crushedpixel.replaymod.assets.CustomImageObject;
|
||||
import eu.crushedpixel.replaymod.holders.AdvancedPosition;
|
||||
import eu.crushedpixel.replaymod.holders.Keyframe;
|
||||
import eu.crushedpixel.replaymod.holders.KeyframeSet;
|
||||
@@ -87,6 +88,11 @@ public class LegacyKeyframeSetAdapter extends TypeAdapter<KeyframeSet[]> {
|
||||
keyframes.add(newKeyframe);
|
||||
}
|
||||
in.endArray();
|
||||
|
||||
} else if("customObjects".equals(jsonTag)) {
|
||||
CustomImageObject[] customObjects = new Gson().fromJson(in, CustomImageObject[].class);
|
||||
|
||||
set.setCustomObjects(customObjects);
|
||||
}
|
||||
}
|
||||
in.endObject();
|
||||
|
||||
@@ -7,7 +7,6 @@ import com.google.gson.GsonBuilder;
|
||||
import com.google.gson.JsonElement;
|
||||
import com.google.gson.JsonObject;
|
||||
import eu.crushedpixel.replaymod.assets.AssetRepository;
|
||||
import eu.crushedpixel.replaymod.assets.CustomObjectRepository;
|
||||
import eu.crushedpixel.replaymod.holders.Keyframe;
|
||||
import eu.crushedpixel.replaymod.holders.KeyframeSet;
|
||||
import eu.crushedpixel.replaymod.holders.Marker;
|
||||
@@ -38,7 +37,6 @@ public class ReplayFile extends ZipFile {
|
||||
public static final String ENTRY_VISIBILITY = "visibility" + JSON_FILE_EXTENSION;
|
||||
public static final String ENTRY_MARKERS = "markers" + JSON_FILE_EXTENSION;
|
||||
public static final String ENTRY_ASSET_FOLDER = "asset/";
|
||||
public static final String ENTRY_CUSTOM_OBJECTS = "objects"+JSON_FILE_EXTENSION;
|
||||
|
||||
private final File file;
|
||||
|
||||
@@ -268,27 +266,4 @@ public class ReplayFile extends ZipFile {
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
public ZipArchiveEntry customObjectsEntry() {
|
||||
return getEntry(ENTRY_CUSTOM_OBJECTS);
|
||||
}
|
||||
|
||||
public Supplier<CustomObjectRepository> customImageObjects() {
|
||||
return new Supplier<CustomObjectRepository>() {
|
||||
@Override
|
||||
public CustomObjectRepository get() {
|
||||
try {
|
||||
ZipArchiveEntry entry = customObjectsEntry();
|
||||
if(entry == null) return null;
|
||||
|
||||
BufferedReader reader = new BufferedReader(new InputStreamReader(getInputStream(entry)));
|
||||
return new Gson().fromJson(reader, CustomObjectRepository.class);
|
||||
} catch(Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
@@ -413,4 +413,5 @@ replaymod.gui.objects.properties.orientation=Orientation
|
||||
replaymod.gui.objects.properties.opacity=Opacity
|
||||
replaymod.gui.objects.properties.name=Object Name
|
||||
replaymod.gui.objects.empty=No Objects added
|
||||
replaymod.gui.objects.defaultname=New Object
|
||||
replaymod.gui.objects.defaultname=New Object
|
||||
replaymod.gui.objects=Custom Objects
|
||||
Reference in New Issue
Block a user