Pour une meilleure utilisation, les sprites sont désormais exportés pour
permettre au joueur de créer ses propres sprites
This commit is contained in:
parent
873609a43b
commit
eba4deb674
|
@ -1,10 +1,15 @@
|
|||
package galaxyoyo.unknown.api.editor.sprites;
|
||||
|
||||
import java.awt.image.BufferedImage;
|
||||
import java.io.BufferedInputStream;
|
||||
import java.io.BufferedReader;
|
||||
import java.io.File;
|
||||
import java.io.FileInputStream;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.io.InputStreamReader;
|
||||
import java.net.URISyntaxException;
|
||||
import java.nio.file.Files;
|
||||
import java.nio.file.Paths;
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
|
@ -21,6 +26,38 @@ public class SpriteRegister
|
|||
private static Map<String, List<List<Double>>> nameToCoords;
|
||||
private static Map<String, Category> sprites = new HashMap<String, Category>();
|
||||
|
||||
public static void unpack()
|
||||
{
|
||||
try
|
||||
{
|
||||
File dir = new File(SpriteRegister.class.getResource("/assets").toURI());
|
||||
unpackDir(dir);
|
||||
}
|
||||
catch (URISyntaxException | IOException e)
|
||||
{
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
private static void unpackDir(File dir) throws IOException
|
||||
{
|
||||
for (File f : dir.listFiles())
|
||||
{
|
||||
if (f.isDirectory())
|
||||
{
|
||||
unpackDir(f);
|
||||
continue;
|
||||
}
|
||||
|
||||
String path = f.getAbsolutePath().substring(f.getAbsolutePath().indexOf(File.separatorChar + "assets") + 1);
|
||||
File local = new File(path);
|
||||
local.getParentFile().mkdirs();
|
||||
if (local.exists())
|
||||
local.delete();
|
||||
Files.copy(Paths.get(f.toURI()), Paths.get(local.toURI()));
|
||||
}
|
||||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
public static void refreshAllSprites()
|
||||
{
|
||||
|
@ -29,9 +66,21 @@ public class SpriteRegister
|
|||
return;
|
||||
}
|
||||
|
||||
File assetsDir = new File("assets");
|
||||
List<String> assets = new ArrayList<String>();
|
||||
|
||||
for (File dir : assetsDir.listFiles())
|
||||
{
|
||||
assets.add(dir.getName());
|
||||
}
|
||||
|
||||
for (String asset : assets)
|
||||
{
|
||||
try
|
||||
{
|
||||
BufferedReader br = new BufferedReader(new InputStreamReader(SpriteRegister.class.getResourceAsStream("/assets/unknown/textures/sprites/sprites.json")));
|
||||
File f = new File(assetsDir.getAbsolutePath() + "/" + asset + "/textures/sprites");
|
||||
f.mkdirs();
|
||||
BufferedReader br = new BufferedReader(new InputStreamReader(new FileInputStream(new File(f, "sprites.json"))));
|
||||
nameToCoords = new Gson().fromJson(br, Map.class);
|
||||
br.close();
|
||||
|
||||
|
@ -39,7 +88,8 @@ public class SpriteRegister
|
|||
{
|
||||
try
|
||||
{
|
||||
InputStream is = SpriteRegister.class.getResourceAsStream("/assets/unknown/textures/sprites/" + key + ".png");
|
||||
|
||||
BufferedInputStream is = new BufferedInputStream(new FileInputStream(new File(f, key + ".png")));
|
||||
BufferedImage img = ImageIO.read(is);
|
||||
Category cat = Category.create(key, new ArrayList<String>(nameToCoords.keySet()).indexOf(key), new ArrayList<Sprite>());
|
||||
|
||||
|
@ -65,6 +115,7 @@ public class SpriteRegister
|
|||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public static Category getCategory(String name)
|
||||
{
|
||||
|
|
|
@ -110,6 +110,8 @@ public class Main
|
|||
}
|
||||
}
|
||||
|
||||
SpriteRegister.unpack();
|
||||
|
||||
SpriteRegister.refreshAllSprites();
|
||||
|
||||
if (set.has(edit))
|
||||
|
|
|
@ -20,6 +20,7 @@ import java.awt.event.KeyEvent;
|
|||
import java.awt.event.WindowEvent;
|
||||
import java.awt.event.WindowListener;
|
||||
import java.awt.image.BufferedImage;
|
||||
import java.io.File;
|
||||
|
||||
import javax.swing.ButtonGroup;
|
||||
import javax.swing.ImageIcon;
|
||||
|
@ -158,9 +159,9 @@ public class EditorFrame extends JFrame implements ChangeListener, ActionListene
|
|||
scroll2.getHorizontalScrollBar().setMaximum(0);
|
||||
scroll3.getHorizontalScrollBar().setMaximum(0);
|
||||
|
||||
resources.addTab("", new ImageIcon(getClass().getResource("/assets/unknown/textures/layer 1.png")), scroll1);
|
||||
resources.addTab("", new ImageIcon(getClass().getResource("/assets/unknown/textures/layer 2.png")), scroll2);
|
||||
resources.addTab("", new ImageIcon(getClass().getResource("/assets/unknown/textures/layer 3.png")), scroll3);
|
||||
resources.addTab("", new ImageIcon(new File("assets/unknown/textures/layer 1.png").getAbsolutePath()), scroll1);
|
||||
resources.addTab("", new ImageIcon(new File("assets/unknown/textures/layer 2.png").getAbsolutePath()), scroll2);
|
||||
resources.addTab("", new ImageIcon(new File("assets/unknown/textures/layer 3.png").getAbsolutePath()), scroll3);
|
||||
resources.addChangeListener(this);
|
||||
resources.setBackgroundAt(0, Color.white);
|
||||
resources.setBackgroundAt(1, Color.white);
|
||||
|
|
Loading…
Reference in New Issue