diff --git a/src/main/java/galaxyoyo/unknown/api/editor/sprites/Category.java b/src/main/java/galaxyoyo/unknown/api/editor/sprites/Category.java new file mode 100644 index 0000000..eacc1ba --- /dev/null +++ b/src/main/java/galaxyoyo/unknown/api/editor/sprites/Category.java @@ -0,0 +1,40 @@ +package galaxyoyo.unknown.api.editor.sprites; + +import java.util.List; + +public class Category +{ + private List sprites; + private String name; + private int index; + + private Category() + { + } + + public String getName() + { + return name; + } + + public List getSprites() + { + return sprites; + } + + public int getIndex() + { + return index; + } + + public static Category create(String name, int index, List sprites) + { + Category c = new Category(); + + c.name = name; + c.index = index; + c.sprites = sprites; + + return c; + } +} diff --git a/src/main/java/galaxyoyo/unknown/api/editor/sprites/Sprite.java b/src/main/java/galaxyoyo/unknown/api/editor/sprites/Sprite.java index 33ce4dc..221f401 100644 --- a/src/main/java/galaxyoyo/unknown/api/editor/sprites/Sprite.java +++ b/src/main/java/galaxyoyo/unknown/api/editor/sprites/Sprite.java @@ -1,20 +1,31 @@ package galaxyoyo.unknown.api.editor.sprites; import java.awt.image.BufferedImage; +import java.util.ArrayList; public class Sprite { - public static final Sprite BLANK = new Sprite(new BufferedImage(16, 16, BufferedImage.TYPE_INT_RGB)); + public static final Sprite BLANK = new Sprite(new BufferedImage(16, 16, BufferedImage.TYPE_INT_RGB), Category.create("blank", 0, new ArrayList())); + private Category cat; private final BufferedImage img; - public Sprite(BufferedImage img) + public Sprite(BufferedImage img, Category cat) { this.img = img; + this.cat = cat; + + if (!this.cat.getSprites().contains(this)) + this.cat.getSprites().add(this); } public BufferedImage getImage() { return this.img; } + + public Category getCategory() + { + return cat; + } } diff --git a/src/main/java/galaxyoyo/unknown/api/editor/sprites/SpriteRegister.java b/src/main/java/galaxyoyo/unknown/api/editor/sprites/SpriteRegister.java index 07938aa..5840fe1 100644 --- a/src/main/java/galaxyoyo/unknown/api/editor/sprites/SpriteRegister.java +++ b/src/main/java/galaxyoyo/unknown/api/editor/sprites/SpriteRegister.java @@ -19,7 +19,7 @@ import com.google.gson.Gson; public class SpriteRegister { private static Map>> nameToCoords; - private static Map> sprites = new HashMap>(); + private static Map sprites = new HashMap(); @SuppressWarnings("unchecked") public static void refreshAllSprites() @@ -41,18 +41,17 @@ public class SpriteRegister { InputStream is = SpriteRegister.class.getResourceAsStream("/assets/unknown/textures/sprites/" + key + ".png"); BufferedImage img = ImageIO.read(is); - List lSprites = new ArrayList(); + Category cat = Category.create(key, new ArrayList(nameToCoords.keySet()).indexOf(key), new ArrayList()); for (List list : nameToCoords.get(key)) { int x = list.get(0).intValue(); int y = list.get(1).intValue(); BufferedImage child = img.getSubimage(x, y, 16, 16); - Sprite sprite = new Sprite(child); - lSprites.add(sprite); + new Sprite(child, cat); } - sprites.put(key, lSprites); + sprites.put(key, cat); } catch (Throwable t) { @@ -67,23 +66,28 @@ public class SpriteRegister } } - public static List getCategory(String name) + public static Category getCategory(String name) { return sprites.get(name); } - public static List getCategory(int index) + public static Category getCategory(int index) { return getCategory(new ArrayList(sprites.keySet()).get(index)); } - - public static List getAll() + + public static List getAllCategories() + { + return (List) sprites.values(); + } + + public static List getAllSprites() { List list = new ArrayList(); - for (List l : sprites.values()) + for (Category c : sprites.values()) { - list.addAll(l); + list.addAll(c.getSprites()); } return list; diff --git a/src/main/java/galaxyoyo/unknown/editor/EditorFrame.java b/src/main/java/galaxyoyo/unknown/editor/EditorFrame.java index 1bf22ea..468b860 100644 --- a/src/main/java/galaxyoyo/unknown/editor/EditorFrame.java +++ b/src/main/java/galaxyoyo/unknown/editor/EditorFrame.java @@ -1,6 +1,6 @@ package galaxyoyo.unknown.editor; -import galaxyoyo.unknown.api.editor.sprites.Sprite; +import galaxyoyo.unknown.api.editor.sprites.Category; import galaxyoyo.unknown.api.editor.sprites.SpriteRegister; import java.awt.Color; @@ -84,7 +84,7 @@ public class EditorFrame extends JFrame implements ComponentListener, MouseListe couche2.setBackground(Color.white); couche3.setBackground(Color.white); - for (Sprite spr : SpriteRegister.getAll()) + for (Category cat : SpriteRegister.getAllCategories()) { } diff --git a/src/main/java/galaxyoyo/unknown/editor/Map.java b/src/main/java/galaxyoyo/unknown/editor/Map.java index 1ff0853..3fff9ca 100644 --- a/src/main/java/galaxyoyo/unknown/editor/Map.java +++ b/src/main/java/galaxyoyo/unknown/editor/Map.java @@ -25,7 +25,7 @@ public class Map for (RawCase rc : raw.getCases()) { - cases.add(Case.create(rc.getPosX(), rc.getPosY(), SpriteRegister.getCategory(rc.getCoucheOne().getPrimaryIndex()).get(rc.getCoucheOne().getSecondaryIndex()), SpriteRegister.getCategory(rc.getCoucheTwo().getPrimaryIndex()).get(rc.getCoucheTwo().getSecondaryIndex()), SpriteRegister.getCategory(rc.getCoucheThree().getPrimaryIndex()).get(rc.getCoucheThree().getSecondaryIndex()))); + cases.add(Case.create(rc.getPosX(), rc.getPosY(), SpriteRegister.getCategory(rc.getCoucheOne().getPrimaryIndex()).getSprites().get(rc.getCoucheOne().getSecondaryIndex()), SpriteRegister.getCategory(rc.getCoucheTwo().getPrimaryIndex()).getSprites().get(rc.getCoucheTwo().getSecondaryIndex()), SpriteRegister.getCategory(rc.getCoucheThree().getPrimaryIndex()).getSprites().get(rc.getCoucheThree().getSecondaryIndex()))); } frame = new EditorFrame(this); diff --git a/src/main/java/galaxyoyo/unknown/frame/MainFrame.java b/src/main/java/galaxyoyo/unknown/frame/MainFrame.java index d9ff417..e9b2b8f 100644 --- a/src/main/java/galaxyoyo/unknown/frame/MainFrame.java +++ b/src/main/java/galaxyoyo/unknown/frame/MainFrame.java @@ -61,7 +61,7 @@ public class MainFrame extends JFrame this.setSize(800, 700); this.setLocationRelativeTo(null); this.setExtendedState(JFrame.MAXIMIZED_BOTH); - this.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE); + this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); menuBar.add(fichier); diff --git a/src/main/resources/assets/unknown/textures/sprites/sprites.json b/src/main/resources/assets/unknown/textures/sprites/sprites.json index b450de6..702214b 100644 --- a/src/main/resources/assets/unknown/textures/sprites/sprites.json +++ b/src/main/resources/assets/unknown/textures/sprites/sprites.json @@ -79,4 +79,4 @@ [64,192], [80,192] ] -} +} \ No newline at end of file