Répertorié les sprites par catégories
This commit is contained in:
parent
11a8931f6b
commit
136bf70409
|
@ -0,0 +1,40 @@
|
||||||
|
package galaxyoyo.unknown.api.editor.sprites;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
public class Category
|
||||||
|
{
|
||||||
|
private List<Sprite> sprites;
|
||||||
|
private String name;
|
||||||
|
private int index;
|
||||||
|
|
||||||
|
private Category()
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getName()
|
||||||
|
{
|
||||||
|
return name;
|
||||||
|
}
|
||||||
|
|
||||||
|
public List<Sprite> getSprites()
|
||||||
|
{
|
||||||
|
return sprites;
|
||||||
|
}
|
||||||
|
|
||||||
|
public int getIndex()
|
||||||
|
{
|
||||||
|
return index;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static Category create(String name, int index, List<Sprite> sprites)
|
||||||
|
{
|
||||||
|
Category c = new Category();
|
||||||
|
|
||||||
|
c.name = name;
|
||||||
|
c.index = index;
|
||||||
|
c.sprites = sprites;
|
||||||
|
|
||||||
|
return c;
|
||||||
|
}
|
||||||
|
}
|
|
@ -1,20 +1,31 @@
|
||||||
package galaxyoyo.unknown.api.editor.sprites;
|
package galaxyoyo.unknown.api.editor.sprites;
|
||||||
|
|
||||||
import java.awt.image.BufferedImage;
|
import java.awt.image.BufferedImage;
|
||||||
|
import java.util.ArrayList;
|
||||||
|
|
||||||
public class Sprite
|
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<Sprite>()));
|
||||||
|
private Category cat;
|
||||||
|
|
||||||
private final BufferedImage img;
|
private final BufferedImage img;
|
||||||
|
|
||||||
public Sprite(BufferedImage img)
|
public Sprite(BufferedImage img, Category cat)
|
||||||
{
|
{
|
||||||
this.img = img;
|
this.img = img;
|
||||||
|
this.cat = cat;
|
||||||
|
|
||||||
|
if (!this.cat.getSprites().contains(this))
|
||||||
|
this.cat.getSprites().add(this);
|
||||||
}
|
}
|
||||||
|
|
||||||
public BufferedImage getImage()
|
public BufferedImage getImage()
|
||||||
{
|
{
|
||||||
return this.img;
|
return this.img;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public Category getCategory()
|
||||||
|
{
|
||||||
|
return cat;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -19,7 +19,7 @@ import com.google.gson.Gson;
|
||||||
public class SpriteRegister
|
public class SpriteRegister
|
||||||
{
|
{
|
||||||
private static Map<String, List<List<Double>>> nameToCoords;
|
private static Map<String, List<List<Double>>> nameToCoords;
|
||||||
private static Map<String, List<Sprite>> sprites = new HashMap<String, List<Sprite>>();
|
private static Map<String, Category> sprites = new HashMap<String, Category>();
|
||||||
|
|
||||||
@SuppressWarnings("unchecked")
|
@SuppressWarnings("unchecked")
|
||||||
public static void refreshAllSprites()
|
public static void refreshAllSprites()
|
||||||
|
@ -41,18 +41,17 @@ public class SpriteRegister
|
||||||
{
|
{
|
||||||
InputStream is = SpriteRegister.class.getResourceAsStream("/assets/unknown/textures/sprites/" + key + ".png");
|
InputStream is = SpriteRegister.class.getResourceAsStream("/assets/unknown/textures/sprites/" + key + ".png");
|
||||||
BufferedImage img = ImageIO.read(is);
|
BufferedImage img = ImageIO.read(is);
|
||||||
List<Sprite> lSprites = new ArrayList<Sprite>();
|
Category cat = Category.create(key, new ArrayList<String>(nameToCoords.keySet()).indexOf(key), new ArrayList<Sprite>());
|
||||||
|
|
||||||
for (List<Double> list : nameToCoords.get(key))
|
for (List<Double> list : nameToCoords.get(key))
|
||||||
{
|
{
|
||||||
int x = list.get(0).intValue();
|
int x = list.get(0).intValue();
|
||||||
int y = list.get(1).intValue();
|
int y = list.get(1).intValue();
|
||||||
BufferedImage child = img.getSubimage(x, y, 16, 16);
|
BufferedImage child = img.getSubimage(x, y, 16, 16);
|
||||||
Sprite sprite = new Sprite(child);
|
new Sprite(child, cat);
|
||||||
lSprites.add(sprite);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
sprites.put(key, lSprites);
|
sprites.put(key, cat);
|
||||||
}
|
}
|
||||||
catch (Throwable t)
|
catch (Throwable t)
|
||||||
{
|
{
|
||||||
|
@ -67,23 +66,28 @@ public class SpriteRegister
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public static List<Sprite> getCategory(String name)
|
public static Category getCategory(String name)
|
||||||
{
|
{
|
||||||
return sprites.get(name);
|
return sprites.get(name);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static List<Sprite> getCategory(int index)
|
public static Category getCategory(int index)
|
||||||
{
|
{
|
||||||
return getCategory(new ArrayList<String>(sprites.keySet()).get(index));
|
return getCategory(new ArrayList<String>(sprites.keySet()).get(index));
|
||||||
}
|
}
|
||||||
|
|
||||||
public static List<Sprite> getAll()
|
public static List<Category> getAllCategories()
|
||||||
|
{
|
||||||
|
return (List<Category>) sprites.values();
|
||||||
|
}
|
||||||
|
|
||||||
|
public static List<Sprite> getAllSprites()
|
||||||
{
|
{
|
||||||
List<Sprite> list = new ArrayList<Sprite>();
|
List<Sprite> list = new ArrayList<Sprite>();
|
||||||
|
|
||||||
for (List<Sprite> l : sprites.values())
|
for (Category c : sprites.values())
|
||||||
{
|
{
|
||||||
list.addAll(l);
|
list.addAll(c.getSprites());
|
||||||
}
|
}
|
||||||
|
|
||||||
return list;
|
return list;
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
package galaxyoyo.unknown.editor;
|
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 galaxyoyo.unknown.api.editor.sprites.SpriteRegister;
|
||||||
|
|
||||||
import java.awt.Color;
|
import java.awt.Color;
|
||||||
|
@ -84,7 +84,7 @@ public class EditorFrame extends JFrame implements ComponentListener, MouseListe
|
||||||
couche2.setBackground(Color.white);
|
couche2.setBackground(Color.white);
|
||||||
couche3.setBackground(Color.white);
|
couche3.setBackground(Color.white);
|
||||||
|
|
||||||
for (Sprite spr : SpriteRegister.getAll())
|
for (Category cat : SpriteRegister.getAllCategories())
|
||||||
{
|
{
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -25,7 +25,7 @@ public class Map
|
||||||
|
|
||||||
for (RawCase rc : raw.getCases())
|
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);
|
frame = new EditorFrame(this);
|
||||||
|
|
|
@ -61,7 +61,7 @@ public class MainFrame extends JFrame
|
||||||
this.setSize(800, 700);
|
this.setSize(800, 700);
|
||||||
this.setLocationRelativeTo(null);
|
this.setLocationRelativeTo(null);
|
||||||
this.setExtendedState(JFrame.MAXIMIZED_BOTH);
|
this.setExtendedState(JFrame.MAXIMIZED_BOTH);
|
||||||
this.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
|
this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
|
||||||
|
|
||||||
menuBar.add(fichier);
|
menuBar.add(fichier);
|
||||||
|
|
||||||
|
|
|
@ -79,4 +79,4 @@
|
||||||
[64,192],
|
[64,192],
|
||||||
[80,192]
|
[80,192]
|
||||||
]
|
]
|
||||||
}
|
}
|
Loading…
Reference in New Issue