Created ReplayAsset interface and AssetRepository class which can contain such ReplayAssets. ReplayAssets allow users to add custom Files (so far only images, might be extended by .obj files) to the Replay which will later be used for CustomImageObjects.

Created GuiReplayManager to allow users to manage their assets.
Created BoundingUtils class to provide a simple method to fit an image into given bounds. This implementation fixes https://trello.com/c/WTnicWkJ/
This commit is contained in:
CrushedPixel
2015-07-07 18:45:48 +02:00
parent 0b1d3d9001
commit e22b37babe
14 changed files with 468 additions and 62 deletions

View File

@@ -0,0 +1,25 @@
package eu.crushedpixel.replaymod.utils;
import org.lwjgl.util.Dimension;
public class BoundingUtils {
public static Dimension fitIntoBounds(Dimension toFit, Dimension bounds) {
int width = toFit.getWidth();
int height = toFit.getHeight();
float w = (float)width/bounds.getWidth();
float h = (float)height/bounds.getHeight();
if(w > h) {
height = (int)(height/w);
width = (int)(width/w);
} else {
height = (int)(height/h);
width = (int)(width/h);
}
return new Dimension(width, height);
}
}

View File

@@ -4,6 +4,7 @@ import com.google.common.base.Supplier;
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.holders.KeyframeSet;
import eu.crushedpixel.replaymod.holders.MarkerKeyframe;
import eu.crushedpixel.replaymod.holders.PlayerVisibility;
@@ -14,6 +15,7 @@ import org.apache.commons.compress.archivers.zip.ZipFile;
import javax.imageio.ImageIO;
import java.awt.image.BufferedImage;
import java.io.*;
import java.util.Enumeration;
import java.util.HashMap;
import java.util.Map;
@@ -32,6 +34,7 @@ public class ReplayFile extends ZipFile {
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/";
private final File file;
@@ -220,4 +223,32 @@ public class ReplayFile extends ZipFile {
}
};
}
public Supplier<AssetRepository> assetRepository() {
return new Supplier<AssetRepository>() {
@Override
@SuppressWarnings("unchecked")
public AssetRepository get() {
AssetRepository assetRepository = new AssetRepository();
Enumeration<ZipArchiveEntry> entries = getEntries();
while(entries.hasMoreElements()) {
try {
ZipArchiveEntry entry = entries.nextElement();
if(entry.getName().startsWith(ENTRY_ASSET_FOLDER)) {
String name = entry.getName().substring(ENTRY_ASSET_FOLDER.length());
assetRepository.addAsset(name, getInputStream(entry));
}
} catch(IOException e) {
e.printStackTrace();
}
}
return assetRepository;
}
};
}
}