Created CustomObjectRepository which can be serialized by Gson, storing all CustomImageObjects created
CustomObjectRepository is now being saved to and loaded from the ReplayFile The CustomObjectRenderer uses the GuiObjectManager's timeline cursor position as interpolation timestamp for the CustomImageObjects which are drawn if a GuiObjectManager is open (instant preview) KeyframeList's add() method now removes Keyframes with the same timestamp before adding the new Keyframe Transformations class now holds default values to prevent NullPointerExceptions in methods calling getTransformationForTimestamp() Added Javadoc to Transformation POJO Created NumberValueChangeListener which can be applied to GuiNumberInput objects Made step size customizable in GuiDraggingNumberInput Changing a ReplayImageAssets image now notifies the CustomImageObjects linked to that asset Modified RoundUtils to provide a round() method which uses the DecimalFormat class instead of Math.round which is unstable
This commit is contained in:
@@ -5,6 +5,7 @@ import com.google.gson.Gson;
|
||||
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.KeyframeSet;
|
||||
import eu.crushedpixel.replaymod.holders.MarkerKeyframe;
|
||||
import eu.crushedpixel.replaymod.holders.PlayerVisibility;
|
||||
@@ -31,11 +32,12 @@ public class ReplayFile extends ZipFile {
|
||||
public static final String ENTRY_PATHS = "paths" + JSON_FILE_EXTENSION;
|
||||
public static final String ENTRY_THUMB = "thumb";
|
||||
public static final String ENTRY_RESOURCE_PACK = "resourcepack/%s.zip";
|
||||
public static final String ENTRY_RESOURCE_PACK_INDEX = "resourcepack/index.json";
|
||||
public static final String ENTRY_RESOURCE_PACK_INDEX = "resourcepack/index"+JSON_FILE_EXTENSION;
|
||||
public static final String ENTRY_VISIBILITY_OLD = "visibility";
|
||||
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;
|
||||
|
||||
@@ -258,4 +260,27 @@ 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;
|
||||
}
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
@@ -2,6 +2,7 @@ package eu.crushedpixel.replaymod.utils;
|
||||
|
||||
import com.google.gson.Gson;
|
||||
import eu.crushedpixel.replaymod.ReplayMod;
|
||||
import eu.crushedpixel.replaymod.assets.CustomObjectRepository;
|
||||
import eu.crushedpixel.replaymod.holders.KeyframeSet;
|
||||
import eu.crushedpixel.replaymod.holders.MarkerKeyframe;
|
||||
import eu.crushedpixel.replaymod.holders.PacketData;
|
||||
@@ -169,6 +170,10 @@ public class ReplayFileIO {
|
||||
write((Object) markers, file);
|
||||
}
|
||||
|
||||
public static void write(CustomObjectRepository repository, File file) throws IOException {
|
||||
write((Object) repository, file);
|
||||
}
|
||||
|
||||
/**
|
||||
* Adds Files as entries to a ZIP File.
|
||||
* @param zipFile The ZIP File to add the files to.
|
||||
|
||||
@@ -1,7 +1,23 @@
|
||||
package eu.crushedpixel.replaymod.utils;
|
||||
|
||||
import java.text.DecimalFormat;
|
||||
|
||||
public class RoundUtils {
|
||||
|
||||
public static double round2Decimals(double val) { return Math.round(val*100.0) / 100.0; }
|
||||
public static double round2Decimals(double val) {
|
||||
return round(val, 2);
|
||||
}
|
||||
|
||||
public static double round(double value, int places) {
|
||||
if (places < 0) throw new IllegalArgumentException();
|
||||
|
||||
StringBuilder format = new StringBuilder("#.");
|
||||
for(int i=0; i<places; i++) {
|
||||
format.append("#");
|
||||
}
|
||||
|
||||
DecimalFormat df = new DecimalFormat(format.toString());
|
||||
return Double.valueOf(df.format(value));
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user