Renom de 'unknown' à 'Alice Game Engine'

This commit is contained in:
BuildTools 2015-03-03 15:32:11 +01:00
parent e6fefeaf5b
commit ac4d682de9
26 changed files with 2211 additions and 2210 deletions

View File

@ -1,23 +1,23 @@
<?xml version="1.0" encoding="UTF-8"?> <?xml version="1.0" encoding="UTF-8"?>
<projectDescription> <projectDescription>
<name>unknown</name> <name>Alice Game Engine</name>
<comment></comment> <comment></comment>
<projects> <projects>
</projects> </projects>
<buildSpec> <buildSpec>
<buildCommand> <buildCommand>
<name>org.eclipse.jdt.core.javabuilder</name> <name>org.eclipse.jdt.core.javabuilder</name>
<arguments> <arguments>
</arguments> </arguments>
</buildCommand> </buildCommand>
<buildCommand> <buildCommand>
<name>org.eclipse.m2e.core.maven2Builder</name> <name>org.eclipse.m2e.core.maven2Builder</name>
<arguments> <arguments>
</arguments> </arguments>
</buildCommand> </buildCommand>
</buildSpec> </buildSpec>
<natures> <natures>
<nature>org.eclipse.jdt.core.javanature</nature> <nature>org.eclipse.jdt.core.javanature</nature>
<nature>org.eclipse.m2e.core.maven2Nature</nature> <nature>org.eclipse.m2e.core.maven2Nature</nature>
</natures> </natures>
</projectDescription> </projectDescription>

View File

@ -1,61 +1,61 @@
package galaxyoyo.unknown.api.editor; package galaxyoyo.alice.gameengine.api.editor;
import galaxyoyo.unknown.api.editor.sprites.Sprite; import galaxyoyo.alice.gameengine.api.editor.sprites.Sprite;
public class Case public class Case
{ {
private int x; private int x;
private int y; private int y;
private Sprite couche1; private Sprite couche1;
private Sprite couche2; private Sprite couche2;
private Sprite couche3; private Sprite couche3;
private Collision collision; private Collision collision;
public int getPosX() public int getPosX()
{ {
return x; return x;
} }
public int getPosY() public int getPosY()
{ {
return y; return y;
} }
public Sprite getCoucheOne() public Sprite getCoucheOne()
{ {
return couche1; return couche1;
} }
public Sprite getCoucheTwo() public Sprite getCoucheTwo()
{ {
return couche2; return couche2;
} }
public Sprite getCoucheThree() public Sprite getCoucheThree()
{ {
return couche3; return couche3;
} }
public Collision getCollision() public Collision getCollision()
{ {
return collision; return collision;
} }
public static Case create(int posX, int posY, Sprite couche1, Sprite couche2, Sprite couche3, Collision collision) public static Case create(int posX, int posY, Sprite couche1, Sprite couche2, Sprite couche3, Collision collision)
{ {
Case c = new Case(); Case c = new Case();
c.x = posX; c.x = posX;
c.y = posY; c.y = posY;
c.couche1 = couche1; c.couche1 = couche1;
c.couche2 = couche2; c.couche2 = couche2;
c.couche3 = couche3; c.couche3 = couche3;
c.collision = collision; c.collision = collision;
return c; return c;
} }
@Override @Override
public String toString() public String toString()
{ {
return "{Case x=" + x + " y=" + y + " couche1=" + couche1 + " couche2=" + couche2 + " couche3=" + couche3 + " collision=" + collision.name().toUpperCase() + "}\n"; return "{Case x=" + x + " y=" + y + " couche1=" + couche1 + " couche2=" + couche2 + " couche3=" + couche3 + " collision=" + collision.name().toUpperCase() + "}\n";
} }
} }

View File

@ -1,6 +1,6 @@
package galaxyoyo.unknown.api.editor; package galaxyoyo.alice.gameengine.api.editor;
public enum Collision public enum Collision
{ {
FULL, PARTIAL, ANY; FULL, PARTIAL, ANY;
} }

View File

@ -1,191 +1,191 @@
package galaxyoyo.unknown.api.editor; package galaxyoyo.alice.gameengine.api.editor;
import galaxyoyo.unknown.editor.Map; import galaxyoyo.alice.gameengine.editor.Map;
import java.awt.Color; import java.awt.Color;
import java.awt.Graphics2D; import java.awt.Graphics2D;
import java.awt.image.BufferedImage; import java.awt.image.BufferedImage;
import java.io.BufferedInputStream; import java.io.BufferedInputStream;
import java.io.BufferedOutputStream; import java.io.BufferedOutputStream;
import java.io.File; import java.io.File;
import java.io.FileInputStream; import java.io.FileInputStream;
import java.io.FileOutputStream; import java.io.FileOutputStream;
import java.io.IOException; import java.io.IOException;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.List; import java.util.List;
import java.util.zip.GZIPInputStream; import java.util.zip.GZIPInputStream;
import java.util.zip.GZIPOutputStream; import java.util.zip.GZIPOutputStream;
import javax.swing.JFileChooser; import javax.swing.JFileChooser;
import javax.swing.filechooser.FileNameExtensionFilter; import javax.swing.filechooser.FileNameExtensionFilter;
import com.google.gson.Gson; import com.google.gson.Gson;
import com.google.gson.GsonBuilder; import com.google.gson.GsonBuilder;
public class EditorAPI public class EditorAPI
{ {
private static File LAST_FILE; private static File LAST_FILE;
public static RawMap toRawMap(int width, int height) public static RawMap toRawMap(int width, int height)
{ {
List<RawCase> cases = new ArrayList<RawCase>(); List<RawCase> cases = new ArrayList<RawCase>();
for (int y = 1; y < height; y += 16) for (int y = 1; y < height; y += 16)
{ {
for (int x = 1; x < width; x += 16) for (int x = 1; x < width; x += 16)
{ {
RawCase c = RawCase.create(x / 16, y / 16, RawSprite.BLANK, RawSprite.BLANK, RawSprite.BLANK, Collision.ANY); RawCase c = RawCase.create(x / 16, y / 16, RawSprite.BLANK, RawSprite.BLANK, RawSprite.BLANK, Collision.ANY);
cases.add(c); cases.add(c);
} }
} }
return RawMap.create(cases, width, height); return RawMap.create(cases, width, height);
} }
public static Gson createGson() public static Gson createGson()
{ {
GsonBuilder builder = new GsonBuilder(); GsonBuilder builder = new GsonBuilder();
builder.enableComplexMapKeySerialization(); builder.enableComplexMapKeySerialization();
builder.serializeNulls(); builder.serializeNulls();
builder.setPrettyPrinting(); builder.setPrettyPrinting();
return builder.create(); return builder.create();
} }
public static JFileChooser createJFC() public static JFileChooser createJFC()
{ {
JFileChooser jfc = new JFileChooser(); JFileChooser jfc = new JFileChooser();
jfc.setFileFilter(new FileNameExtensionFilter("Fichiers monde (*.gmap, *.dat)", "gmap", "dat")); jfc.setFileFilter(new FileNameExtensionFilter("Fichiers monde (*.gmap, *.dat)", "gmap", "dat"));
jfc.setFileHidingEnabled(true); jfc.setFileHidingEnabled(true);
jfc.setFileSelectionMode(JFileChooser.FILES_ONLY); jfc.setFileSelectionMode(JFileChooser.FILES_ONLY);
File dir = new File("maps"); File dir = new File("maps");
dir.mkdirs(); dir.mkdirs();
jfc.setCurrentDirectory(dir); jfc.setCurrentDirectory(dir);
return jfc; return jfc;
} }
public static void saveAs(RawMap map) public static void saveAs(RawMap map)
{ {
JFileChooser jfc = createJFC(); JFileChooser jfc = createJFC();
File file = null; File file = null;
jfc.showSaveDialog(null); jfc.showSaveDialog(null);
file = jfc.getSelectedFile(); file = jfc.getSelectedFile();
if (file == null) if (file == null)
return; return;
if (!file.getName().toLowerCase().endsWith(".gmap") && !file.getName().toLowerCase().endsWith(".dat")) if (!file.getName().toLowerCase().endsWith(".gmap") && !file.getName().toLowerCase().endsWith(".dat"))
{ {
file = new File(file.getParentFile(), file.getName() + ".gmap"); file = new File(file.getParentFile(), file.getName() + ".gmap");
} }
LAST_FILE = file; LAST_FILE = file;
save(file, map); save(file, map);
} }
public static void save(RawMap map) public static void save(RawMap map)
{ {
if (LAST_FILE != null) if (LAST_FILE != null)
save(LAST_FILE, map); save(LAST_FILE, map);
else else
saveAs(map); saveAs(map);
} }
public static void save(File file, RawMap map) public static void save(File file, RawMap map)
{ {
String json = createGson().toJson(map); String json = createGson().toJson(map);
try try
{ {
file.createNewFile(); file.createNewFile();
BufferedOutputStream bos = new BufferedOutputStream(new GZIPOutputStream(new FileOutputStream(file))); BufferedOutputStream bos = new BufferedOutputStream(new GZIPOutputStream(new FileOutputStream(file)));
bos.write(json.getBytes("UTF-8")); bos.write(json.getBytes("UTF-8"));
bos.close(); bos.close();
} }
catch (IOException ex) catch (IOException ex)
{ {
ex.printStackTrace(); ex.printStackTrace();
} }
} }
public static Map open() public static Map open()
{ {
JFileChooser jfc = createJFC(); JFileChooser jfc = createJFC();
File file = null; File file = null;
jfc.showOpenDialog(null); jfc.showOpenDialog(null);
file = jfc.getSelectedFile(); file = jfc.getSelectedFile();
if (file == null) if (file == null)
return null; return null;
LAST_FILE = file; LAST_FILE = file;
return open(file); return open(file);
} }
public static Map open(File f) public static Map open(File f)
{ {
String json = null; String json = null;
try try
{ {
GZIPInputStream gis = new GZIPInputStream(new BufferedInputStream(new FileInputStream(f))); GZIPInputStream gis = new GZIPInputStream(new BufferedInputStream(new FileInputStream(f)));
byte[] bytes = new byte[512*1024]; byte[] bytes = new byte[512*1024];
int count = 0; int count = 0;
String text = ""; String text = "";
while ((count = gis.read(bytes)) != -1) while ((count = gis.read(bytes)) != -1)
{ {
text += new String(bytes, 0, count, "UTF-8"); text += new String(bytes, 0, count, "UTF-8");
} }
gis.close(); gis.close();
bytes = null; bytes = null;
json = text; json = text;
} }
catch (IOException e) catch (IOException e)
{ {
e.printStackTrace(); e.printStackTrace();
} }
RawMap rm = createGson().fromJson(json, RawMap.class); RawMap rm = createGson().fromJson(json, RawMap.class);
return open(rm); return open(rm);
} }
public static Map open(RawMap map) public static Map open(RawMap map)
{ {
if (map.getFont() == null) if (map.getFont() == null)
{ {
int baseWidth = map.getWidth(); int baseWidth = map.getWidth();
int baseHeight = map.getHeight(); int baseHeight = map.getHeight();
int width = baseWidth + ((int) baseWidth / 16) + 1; int width = baseWidth + ((int) baseWidth / 16) + 1;
int height = baseHeight + ((int) baseHeight / 16) + 1; int height = baseHeight + ((int) baseHeight / 16) + 1;
BufferedImage image = new BufferedImage(width, height, BufferedImage.TYPE_INT_ARGB); BufferedImage image = new BufferedImage(width, height, BufferedImage.TYPE_INT_ARGB);
Graphics2D g = image.createGraphics(); Graphics2D g = image.createGraphics();
g.setColor(Color.white); g.setColor(Color.white);
g.fillRect(0, 0, width, height); g.fillRect(0, 0, width, height);
g.setColor(Color.black); g.setColor(Color.black);
g.drawLine(0, 0, width, 0); g.drawLine(0, 0, width, 0);
g.drawLine(0, 0, 0, height); g.drawLine(0, 0, 0, height);
for (int x = 17; x <= width; x += 17) for (int x = 17; x <= width; x += 17)
{ {
g.drawLine(x, 0, x, height); g.drawLine(x, 0, x, height);
} }
for (int y = 17; y <= height; y += 17) for (int y = 17; y <= height; y += 17)
{ {
g.drawLine(0, y, width, y); g.drawLine(0, y, width, y);
} }
map.setFont(image); map.setFont(image);
} }
return new Map(map); return new Map(map);
} }
} }

View File

@ -1,65 +1,65 @@
package galaxyoyo.unknown.api.editor; package galaxyoyo.alice.gameengine.api.editor;
public class RawCase public class RawCase
{ {
private int x; private int x;
private int y; private int y;
private RawSprite couche1; private RawSprite couche1;
private RawSprite couche2; private RawSprite couche2;
private RawSprite couche3; private RawSprite couche3;
private Collision collision; private Collision collision;
public int getPosX() public int getPosX()
{ {
return x; return x;
} }
public int getPosY() public int getPosY()
{ {
return y; return y;
} }
public RawSprite getCoucheOne() public RawSprite getCoucheOne()
{ {
return couche1; return couche1;
} }
public RawSprite getCoucheTwo() public RawSprite getCoucheTwo()
{ {
return couche2; return couche2;
} }
public RawSprite getCoucheThree() public RawSprite getCoucheThree()
{ {
return couche3; return couche3;
} }
public Collision getCollision() public Collision getCollision()
{ {
return collision; return collision;
} }
public static RawCase create(int posX, int posY, RawSprite couche1, RawSprite couche2, RawSprite couche3, Collision collision) public static RawCase create(int posX, int posY, RawSprite couche1, RawSprite couche2, RawSprite couche3, Collision collision)
{ {
RawCase c = new RawCase(); RawCase c = new RawCase();
c.x = posX; c.x = posX;
c.y = posY; c.y = posY;
c.couche1 = couche1; c.couche1 = couche1;
c.couche2 = couche2; c.couche2 = couche2;
c.couche3 = couche3; c.couche3 = couche3;
c.collision = collision;; c.collision = collision;;
return c; return c;
} }
public static RawCase create(Case c) public static RawCase create(Case c)
{ {
RawCase raw = new RawCase(); RawCase raw = new RawCase();
raw.x = c.getPosX(); raw.x = c.getPosX();
raw.y = c.getPosY(); raw.y = c.getPosY();
raw.couche1 = RawSprite.create(c.getCoucheOne()); raw.couche1 = RawSprite.create(c.getCoucheOne());
raw.couche2 = RawSprite.create(c.getCoucheTwo()); raw.couche2 = RawSprite.create(c.getCoucheTwo());
raw.couche3 = RawSprite.create(c.getCoucheThree()); raw.couche3 = RawSprite.create(c.getCoucheThree());
raw.collision = c.getCollision(); raw.collision = c.getCollision();
return raw; return raw;
} }
} }

View File

@ -1,63 +1,63 @@
package galaxyoyo.unknown.api.editor; package galaxyoyo.alice.gameengine.api.editor;
import galaxyoyo.unknown.editor.Map; import galaxyoyo.alice.gameengine.editor.Map;
import java.awt.image.BufferedImage; import java.awt.image.BufferedImage;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.List; import java.util.List;
public class RawMap public class RawMap
{ {
private List<RawCase> cases; private List<RawCase> cases;
private int width; private int width;
private int height; private int height;
private transient BufferedImage font; private transient BufferedImage font;
public List<RawCase> getCases() public List<RawCase> getCases()
{ {
return cases; return cases;
} }
public int getWidth() public int getWidth()
{ {
return width; return width;
} }
public int getHeight() public int getHeight()
{ {
return height; return height;
} }
public static RawMap create(List<RawCase> cases, int width, int height) public static RawMap create(List<RawCase> cases, int width, int height)
{ {
RawMap rm = new RawMap(); RawMap rm = new RawMap();
rm.cases = cases; rm.cases = cases;
rm.width = width; rm.width = width;
rm.height = height; rm.height = height;
return rm; return rm;
} }
public BufferedImage getFont() public BufferedImage getFont()
{ {
return font; return font;
} }
public void setFont(BufferedImage font) public void setFont(BufferedImage font)
{ {
this.font = font; this.font = font;
} }
public static RawMap create(Map map) public static RawMap create(Map map)
{ {
RawMap raw = new RawMap(); RawMap raw = new RawMap();
raw.width = map.getWidth(); raw.width = map.getWidth();
raw.height = map.getHeight(); raw.height = map.getHeight();
raw.cases = new ArrayList<RawCase>(); raw.cases = new ArrayList<RawCase>();
for (Case c : map.getAllCases()) for (Case c : map.getAllCases())
{ {
RawCase rc = RawCase.create(c); RawCase rc = RawCase.create(c);
raw.cases.add(rc); raw.cases.add(rc);
} }
return raw; return raw;
} }
} }

View File

@ -1,29 +1,29 @@
package galaxyoyo.unknown.api.editor; package galaxyoyo.alice.gameengine.api.editor;
import galaxyoyo.unknown.api.editor.sprites.Sprite; import galaxyoyo.alice.gameengine.api.editor.sprites.Sprite;
public class RawSprite public class RawSprite
{ {
private String category = "blank"; private String category = "blank";
private int index = 0; private int index = 0;
public static transient final RawSprite BLANK = new RawSprite(); public static transient final RawSprite BLANK = new RawSprite();
public String getCategory() public String getCategory()
{ {
return category; return category;
} }
public int getIndex() public int getIndex()
{ {
return index; return index;
} }
public static RawSprite create(Sprite spr) public static RawSprite create(Sprite spr)
{ {
RawSprite raw = new RawSprite(); RawSprite raw = new RawSprite();
raw.category = spr.getCategory().getName(); raw.category = spr.getCategory().getName();
raw.index = spr.getIndex(); raw.index = spr.getIndex();
return raw; return raw;
} }
} }

View File

@ -0,0 +1,4 @@
/**
* @author galaxyoyo
*/
package galaxyoyo.alice.gameengine.api.editor;

View File

@ -1,40 +1,40 @@
package galaxyoyo.unknown.api.editor.sprites; package galaxyoyo.alice.gameengine.api.editor.sprites;
import java.util.List; import java.util.List;
public class Category public class Category
{ {
private List<Sprite> sprites; private List<Sprite> sprites;
private String name; private String name;
private int index; private int index;
private Category() private Category()
{ {
} }
public String getName() public String getName()
{ {
return name; return name;
} }
public List<Sprite> getSprites() public List<Sprite> getSprites()
{ {
return sprites; return sprites;
} }
public int getIndex() public int getIndex()
{ {
return index; return index;
} }
public static Category create(String name, int index, List<Sprite> sprites) public static Category create(String name, int index, List<Sprite> sprites)
{ {
Category c = new Category(); Category c = new Category();
c.name = name; c.name = name;
c.index = index; c.index = index;
c.sprites = sprites; c.sprites = sprites;
return c; return c;
} }
} }

View File

@ -1,72 +1,72 @@
package galaxyoyo.unknown.api.editor.sprites; package galaxyoyo.alice.gameengine.api.editor.sprites;
import java.awt.AlphaComposite; import java.awt.AlphaComposite;
import java.awt.Color; import java.awt.Color;
import java.awt.Graphics2D; import java.awt.Graphics2D;
import java.awt.image.BufferedImage; import java.awt.image.BufferedImage;
import java.util.ArrayList; import java.util.ArrayList;
public class Sprite public class Sprite
{ {
public static final Sprite BLANK = new Sprite(new BufferedImage(16, 16, BufferedImage.TYPE_INT_ARGB), Category.create("blank", 0, new ArrayList<Sprite>()), 0); public static final Sprite BLANK = new Sprite(new BufferedImage(16, 16, BufferedImage.TYPE_INT_ARGB), Category.create("blank", 0, new ArrayList<Sprite>()), 0);
static static
{ {
Graphics2D g = BLANK.getImage().createGraphics(); Graphics2D g = BLANK.getImage().createGraphics();
g.setComposite(AlphaComposite.Clear); g.setComposite(AlphaComposite.Clear);
g.setColor(new Color(0, true)); g.setColor(new Color(0, true));
g.fillRect(0, 0, 16, 16); g.fillRect(0, 0, 16, 16);
} }
private final Category cat; private final Category cat;
private final BufferedImage img; private final BufferedImage img;
private final int index; private final int index;
public Sprite(BufferedImage img, Category cat, int index) public Sprite(BufferedImage img, Category cat, int index)
{ {
this.img = img; this.img = img;
this.cat = cat; this.cat = cat;
this.index = index; this.index = index;
if (!this.cat.getSprites().contains(this)) if (!this.cat.getSprites().contains(this))
this.cat.getSprites().add(this); this.cat.getSprites().add(this);
} }
public BufferedImage getImage() public BufferedImage getImage()
{ {
return this.img; return this.img;
} }
public Category getCategory() public Category getCategory()
{ {
return cat; return cat;
} }
public int getIndex() public int getIndex()
{ {
return index; return index;
} }
@Override @Override
public int hashCode() public int hashCode()
{ {
return cat.hashCode() ^ getIndex(); return cat.hashCode() ^ getIndex();
} }
@Override @Override
public boolean equals(Object o) public boolean equals(Object o)
{ {
if (!(o instanceof Sprite)) if (!(o instanceof Sprite))
return false; return false;
Sprite other = (Sprite) o; Sprite other = (Sprite) o;
return hashCode() == other.hashCode(); return hashCode() == other.hashCode();
} }
@Override @Override
public String toString() public String toString()
{ {
return "{Sprite img=" + img + " cat=" + cat.getName() + "}"; return "{Sprite img=" + img + " cat=" + cat.getName() + "}";
} }
} }

View File

@ -1,175 +1,175 @@
package galaxyoyo.unknown.api.editor.sprites; package galaxyoyo.alice.gameengine.api.editor.sprites;
import galaxyoyo.unknown.client.main.Main; import galaxyoyo.alice.gameengine.client.main.Main;
import java.awt.image.BufferedImage; import java.awt.image.BufferedImage;
import java.io.BufferedInputStream; import java.io.BufferedInputStream;
import java.io.BufferedReader; import java.io.BufferedReader;
import java.io.File; import java.io.File;
import java.io.FileInputStream; import java.io.FileInputStream;
import java.io.IOException; import java.io.IOException;
import java.io.InputStreamReader; import java.io.InputStreamReader;
import java.net.URISyntaxException; import java.net.URISyntaxException;
import java.net.URLDecoder; import java.net.URLDecoder;
import java.nio.file.Files; import java.nio.file.Files;
import java.nio.file.Paths; import java.nio.file.Paths;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Enumeration; import java.util.Enumeration;
import java.util.HashMap; import java.util.HashMap;
import java.util.List; import java.util.List;
import java.util.Map; import java.util.Map;
import java.util.jar.JarEntry; import java.util.jar.JarEntry;
import java.util.jar.JarFile; import java.util.jar.JarFile;
import javax.imageio.ImageIO; import javax.imageio.ImageIO;
import org.apache.logging.log4j.LogManager; import org.apache.logging.log4j.LogManager;
import com.google.gson.Gson; 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, Category> sprites = new HashMap<String, Category>(); private static Map<String, Category> sprites = new HashMap<String, Category>();
public static void unpack() throws IOException, URISyntaxException public static void unpack() throws IOException, URISyntaxException
{ {
if (Main.isInDevelopmentMode()) if (Main.isInDevelopmentMode())
{ {
File dir = new File(SpriteRegister.class.getResource("/assets").toURI()); File dir = new File(SpriteRegister.class.getResource("/assets").toURI());
unpackDir(dir); unpackDir(dir);
} }
else else
{ {
@SuppressWarnings("deprecation") @SuppressWarnings("deprecation")
String path = URLDecoder.decode(SpriteRegister.class.getProtectionDomain().getCodeSource().getLocation().getPath()); String path = URLDecoder.decode(SpriteRegister.class.getProtectionDomain().getCodeSource().getLocation().getPath());
path = path.substring(1, path.length()); path = path.substring(1, path.length());
File jarFile = new File(path); File jarFile = new File(path);
if(jarFile.isFile()) if(jarFile.isFile())
{ {
JarFile jar = new JarFile(jarFile); JarFile jar = new JarFile(jarFile);
Enumeration<JarEntry> entries = jar.entries(); Enumeration<JarEntry> entries = jar.entries();
while (entries.hasMoreElements()) while (entries.hasMoreElements())
{ {
JarEntry je = entries.nextElement(); JarEntry je = entries.nextElement();
String name = je.getName(); String name = je.getName();
if (name.startsWith("assets/")) if (name.startsWith("assets/"))
{ {
File f = new File(name); File f = new File(name);
if (name.endsWith("/")) if (name.endsWith("/"))
f.mkdirs(); f.mkdirs();
else if (!f.isFile()) else if (!f.isFile())
Files.copy(jar.getInputStream(je), Paths.get(f.toURI())); Files.copy(jar.getInputStream(je), Paths.get(f.toURI()));
} }
} }
jar.close(); jar.close();
} }
} }
} }
private static void unpackDir(File dir) throws IOException private static void unpackDir(File dir) throws IOException
{ {
for (File f : dir.listFiles()) for (File f : dir.listFiles())
{ {
if (f.isDirectory()) if (f.isDirectory())
{ {
unpackDir(f); unpackDir(f);
continue; continue;
} }
String path = f.getAbsolutePath().substring(f.getAbsolutePath().indexOf(File.separatorChar + "assets") + 1); String path = f.getAbsolutePath().substring(f.getAbsolutePath().indexOf(File.separatorChar + "assets") + 1);
File local = new File(path); File local = new File(path);
local.getParentFile().mkdirs(); local.getParentFile().mkdirs();
if (local.exists()) if (local.exists())
local.delete(); local.delete();
Files.copy(Paths.get(f.toURI()), Paths.get(local.toURI())); Files.copy(Paths.get(f.toURI()), Paths.get(local.toURI()));
} }
} }
@SuppressWarnings("unchecked") @SuppressWarnings("unchecked")
public static void refreshAllSprites() public static void refreshAllSprites()
{ {
if (nameToCoords != null && !nameToCoords.isEmpty() && !sprites.isEmpty()) if (nameToCoords != null && !nameToCoords.isEmpty() && !sprites.isEmpty())
{ {
return; return;
} }
File assetsDir = new File("assets"); File assetsDir = new File("assets");
List<String> assets = new ArrayList<String>(); List<String> assets = new ArrayList<String>();
for (File dir : assetsDir.listFiles()) for (File dir : assetsDir.listFiles())
{ {
assets.add(dir.getName()); assets.add(dir.getName());
} }
for (String asset : assets) for (String asset : assets)
{ {
try try
{ {
File f = new File(assetsDir.getAbsolutePath() + "/" + asset + "/textures/sprites"); File f = new File(assetsDir.getAbsolutePath() + "/" + asset + "/textures/sprites");
f.mkdirs(); f.mkdirs();
BufferedReader br = new BufferedReader(new InputStreamReader(new FileInputStream(new File(f, "sprites.json")))); BufferedReader br = new BufferedReader(new InputStreamReader(new FileInputStream(new File(f, "sprites.json"))));
nameToCoords = new Gson().fromJson(br, Map.class); nameToCoords = new Gson().fromJson(br, Map.class);
br.close(); br.close();
for (String key : nameToCoords.keySet()) for (String key : nameToCoords.keySet())
{ {
try try
{ {
BufferedInputStream is = new BufferedInputStream(new FileInputStream(new File(f, key + ".png"))); BufferedInputStream is = new BufferedInputStream(new FileInputStream(new File(f, key + ".png")));
BufferedImage img = ImageIO.read(is); BufferedImage img = ImageIO.read(is);
Category cat = Category.create(key, new ArrayList<String>(nameToCoords.keySet()).indexOf(key), 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);
new Sprite(child, cat, nameToCoords.get(key).indexOf(list)); new Sprite(child, cat, nameToCoords.get(key).indexOf(list));
} }
sprites.put(key, cat); sprites.put(key, cat);
} }
catch (Throwable t) catch (Throwable t)
{ {
LogManager.getLogger("SpriteRegister").fatal("Erreur lors de la lecture du sprite '" + key + "'", t); LogManager.getLogger("SpriteRegister").fatal("Erreur lors de la lecture du sprite '" + key + "'", t);
continue; continue;
} }
} }
} }
catch (IOException e) catch (IOException e)
{ {
e.printStackTrace(); e.printStackTrace();
} }
} }
} }
public static Category getCategory(String name) public static Category getCategory(String name)
{ {
return sprites.get(name); return sprites.get(name);
} }
public static Category 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<Category> getAllCategories() public static List<Category> getAllCategories()
{ {
return new ArrayList<Category>(sprites.values()); return new ArrayList<Category>(sprites.values());
} }
public static List<Sprite> getAllSprites() public static List<Sprite> getAllSprites()
{ {
List<Sprite> list = new ArrayList<Sprite>(); List<Sprite> list = new ArrayList<Sprite>();
for (Category c : sprites.values()) for (Category c : sprites.values())
{ {
list.addAll(c.getSprites()); list.addAll(c.getSprites());
} }
return list; return list;
} }
} }

View File

@ -1,289 +1,289 @@
/** /**
* @author galaxyoyo * @author galaxyoyo
*/ */
package galaxyoyo.unknown.client.main; package galaxyoyo.alice.gameengine.client.main;
import galaxyoyo.unknown.api.editor.EditorAPI; import galaxyoyo.alice.gameengine.api.editor.EditorAPI;
import galaxyoyo.unknown.api.editor.RawMap; import galaxyoyo.alice.gameengine.api.editor.RawMap;
import galaxyoyo.unknown.api.editor.sprites.SpriteRegister; import galaxyoyo.alice.gameengine.api.editor.sprites.SpriteRegister;
import galaxyoyo.unknown.frame.MainFrame; import galaxyoyo.gameengine.frame.MainFrame;
import java.awt.Color; import java.awt.Color;
import java.awt.Desktop; import java.awt.Desktop;
import java.awt.Graphics2D; import java.awt.Graphics2D;
import java.awt.GraphicsEnvironment; import java.awt.GraphicsEnvironment;
import java.awt.HeadlessException; import java.awt.HeadlessException;
import java.awt.image.BufferedImage; import java.awt.image.BufferedImage;
import java.io.File; import java.io.File;
import java.io.IOException; import java.io.IOException;
import java.net.URISyntaxException; import java.net.URISyntaxException;
import java.net.URL; import java.net.URL;
import java.util.Locale; import java.util.Locale;
import java.util.Map; import java.util.Map;
import javax.swing.JOptionPane; import javax.swing.JOptionPane;
import joptsimple.OptionParser; import joptsimple.OptionParser;
import joptsimple.OptionSet; import joptsimple.OptionSet;
import joptsimple.OptionSpec; import joptsimple.OptionSpec;
import org.apache.logging.log4j.Level; import org.apache.logging.log4j.Level;
import org.apache.logging.log4j.LogManager; import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.core.Logger; import org.apache.logging.log4j.core.Logger;
import org.apache.logging.log4j.core.appender.ConsoleAppender; import org.apache.logging.log4j.core.appender.ConsoleAppender;
import org.apache.logging.log4j.core.layout.PatternLayout; import org.apache.logging.log4j.core.layout.PatternLayout;
/** /**
* Class principale qui lance le jeu * Class principale qui lance le jeu
* @author galaxyoyo * @author galaxyoyo
* @see #main(String...) * @see #main(String...)
*/ */
public class Main public class Main
{ {
/** /**
* Variable disant si le jeu est en d&eacute;bogage ou non. S'active en ins&eacute;rant l'argument --debug dans le lancement. * Variable disant si le jeu est en d&eacute;bogage ou non. S'active en ins&eacute;rant l'argument --debug dans le lancement.
* @see #isInDebugMode() * @see #isInDebugMode()
* @see #main(String...) * @see #main(String...)
* @since 0.1-aplha * @since 0.1-aplha
*/ */
private static boolean DEBUG; private static boolean DEBUG;
/** /**
* Variable disant si le jeu est lanc&eacute; en d&eacute;veloppement ou non. * Variable disant si le jeu est lanc&eacute; en d&eacute;veloppement ou non.
* @see #isInDevelopmentMode() * @see #isInDevelopmentMode()
* @see #main(String...) * @see #main(String...)
* @since 0.1-aplha * @since 0.1-aplha
*/ */
private static boolean DEV; private static boolean DEV;
/** /**
* @param args arguments du jeu. Possibilit&eacute;s :<br>&nbsp;&nbsp;&nbsp;&nbsp;<strong>--edit</strong> lancera un &eacute;diteur<br>&nbsp;&nbsp;&nbsp;&nbsp;<strong>--help</strong> lance l'aide affichant toutes les options possibles * @param args arguments du jeu. Possibilit&eacute;s :<br>&nbsp;&nbsp;&nbsp;&nbsp;<strong>--edit</strong> lancera un &eacute;diteur<br>&nbsp;&nbsp;&nbsp;&nbsp;<strong>--help</strong> lance l'aide affichant toutes les options possibles
* @see #launchEditMode() * @see #launchEditMode()
* @since 0.1-alpha * @since 0.1-alpha
*/ */
public static void main(String ... args) public static void main(String ... args)
{ {
System.setProperty("sun.java2d.noddraw", "true"); System.setProperty("sun.java2d.noddraw", "true");
Locale.setDefault(Locale.FRANCE); Locale.setDefault(Locale.FRANCE);
try try
{ {
new File(Main.class.getResource("/assets").toURI()); new File(Main.class.getResource("/assets").toURI());
DEV = true; DEV = true;
} }
catch (Throwable t) catch (Throwable t)
{ {
DEV = false; DEV = false;
} }
Logger LOGGER = (Logger) LogManager.getRootLogger(); Logger LOGGER = (Logger) LogManager.getRootLogger();
ConsoleAppender console = ConsoleAppender.newBuilder().setLayout(PatternLayout.newBuilder().withPattern("[%d{dd/MM/yyyy}] [%d{HH:mm:ss}] [%t] [%c] [%p] %m%n").build()).setName("Console").build(); ConsoleAppender console = ConsoleAppender.newBuilder().setLayout(PatternLayout.newBuilder().withPattern("[%d{dd/MM/yyyy}] [%d{HH:mm:ss}] [%t] [%c] [%p] %m%n").build()).setName("Console").build();
console.start(); console.start();
LOGGER.addAppender(console); LOGGER.addAppender(console);
LOGGER.setLevel(Level.INFO); LOGGER.setLevel(Level.INFO);
checkJava(); checkJava();
OptionParser parser = new OptionParser(); OptionParser parser = new OptionParser();
OptionSpec<String> edit = parser.accepts("edit", "Lancer l'\u00e9diteur de monde").withOptionalArg(); OptionSpec<String> edit = parser.accepts("edit", "Lancer l'\u00e9diteur de monde").withOptionalArg();
OptionSpec<Boolean> debug = parser.accepts("debug").withOptionalArg().ofType(Boolean.class).defaultsTo(true); OptionSpec<Boolean> debug = parser.accepts("debug").withOptionalArg().ofType(Boolean.class).defaultsTo(true);
OptionSpec<String> help = parser.accepts("help", "Affiche ce menu d'aide").withOptionalArg().forHelp(); OptionSpec<String> help = parser.accepts("help", "Affiche ce menu d'aide").withOptionalArg().forHelp();
OptionSet set = parser.parse(args); OptionSet set = parser.parse(args);
if (set.has(help)) if (set.has(help))
{ {
try try
{ {
parser.printHelpOn(System.out); parser.printHelpOn(System.out);
} }
catch (IOException e) catch (IOException e)
{ {
e.printStackTrace(); e.printStackTrace();
} }
finally finally
{ {
System.exit(0); System.exit(0);
} }
} }
if (set.has(debug)) if (set.has(debug))
{ {
DEBUG = set.valueOf(debug); DEBUG = set.valueOf(debug);
if (DEBUG) if (DEBUG)
{ {
LOGGER.setLevel(Level.ALL); LOGGER.setLevel(Level.ALL);
} }
} }
try try
{ {
SpriteRegister.unpack(); SpriteRegister.unpack();
} }
catch (IOException | URISyntaxException e) catch (IOException | URISyntaxException e)
{ {
e.printStackTrace(); e.printStackTrace();
} }
SpriteRegister.refreshAllSprites(); SpriteRegister.refreshAllSprites();
if (set.has(edit)) if (set.has(edit))
{ {
launchEditMode(); launchEditMode();
return; return;
} }
launchFrame(); launchFrame();
} }
private static void checkJava() private static void checkJava()
{ {
if (GraphicsEnvironment.isHeadless()) if (GraphicsEnvironment.isHeadless())
{ {
HeadlessException ex = new HeadlessException("Impossible de lancer un jeu sans \u00e9cran !"); HeadlessException ex = new HeadlessException("Impossible de lancer un jeu sans \u00e9cran !");
LogManager.getLogger("JAVAX-SWING").fatal("Cette application est un jeu, sans écran, elle aura du mal \u00e0 tourner ..."); LogManager.getLogger("JAVAX-SWING").fatal("Cette application est un jeu, sans écran, elle aura du mal \u00e0 tourner ...");
LogManager.getLogger("JAVAX-SWING").catching(Level.FATAL, ex); LogManager.getLogger("JAVAX-SWING").catching(Level.FATAL, ex);
System.exit(1); System.exit(1);
} }
try try
{ {
Map.class.getDeclaredMethod("getOrDefault", Object.class, Object.class); Map.class.getDeclaredMethod("getOrDefault", Object.class, Object.class);
} }
catch (NoSuchMethodException ex) catch (NoSuchMethodException ex)
{ {
ex.printStackTrace(); ex.printStackTrace();
JOptionPane.showMessageDialog(null, "<html>Cette application requiert <strong>Java 8</strong>.<br />La page de t\u00e9l\u00e9chargement va maintenant s'ouvrir.</html>"); JOptionPane.showMessageDialog(null, "<html>Cette application requiert <strong>Java 8</strong>.<br />La page de t\u00e9l\u00e9chargement va maintenant s'ouvrir.</html>");
JOptionPane.showMessageDialog(null, "<html>Si vous êtes certain que Java 8 est installé sur votre machine, assurez-vous qu'il n'y a pas de versions obsolètes de Java,<br />ou si vous êtes plus expérimentés si le path vers Java est bien défini vers la bonne version.</html>"); JOptionPane.showMessageDialog(null, "<html>Si vous êtes certain que Java 8 est installé sur votre machine, assurez-vous qu'il n'y a pas de versions obsolètes de Java,<br />ou si vous êtes plus expérimentés si le path vers Java est bien défini vers la bonne version.</html>");
try try
{ {
if (Desktop.isDesktopSupported()) if (Desktop.isDesktopSupported())
Desktop.getDesktop().browse(new URL("http://java.com/download").toURI()); Desktop.getDesktop().browse(new URL("http://java.com/download").toURI());
else else
JOptionPane.showMessageDialog(null, "<html>Votre machine ne supporte pas la classe Desktop, impossible d'ouvrir la page.<br />Rendez-vous y manuellement sur <a href=\"http://java.com/download\">http://java.com/download</a> pour installer Java.</html>"); JOptionPane.showMessageDialog(null, "<html>Votre machine ne supporte pas la classe Desktop, impossible d'ouvrir la page.<br />Rendez-vous y manuellement sur <a href=\"http://java.com/download\">http://java.com/download</a> pour installer Java.</html>");
} }
catch (IOException | URISyntaxException e) catch (IOException | URISyntaxException e)
{ {
e.printStackTrace(); e.printStackTrace();
} }
System.exit(1); System.exit(1);
} }
} }
/** /**
* Lance la fen&ecirc;tre principale * Lance la fen&ecirc;tre principale
* @see #main(String...) * @see #main(String...)
* @see #launchEditMode() * @see #launchEditMode()
*/ */
private static void launchFrame() private static void launchFrame()
{ {
MainFrame.getInstance().setVisible(true); MainFrame.getInstance().setVisible(true);
} }
/** /**
* Permet de lancer l'&eacute;diteur de carte * Permet de lancer l'&eacute;diteur de carte
* @return * @return
* @see #main(String...) * @see #main(String...)
* @see #launchFrame() * @see #launchFrame()
* @since 0.1-aplha * @since 0.1-aplha
*/ */
public static boolean launchEditMode() public static boolean launchEditMode()
{ {
System.out.println("Lancement de l'\u00e9diteur de monde ..."); System.out.println("Lancement de l'\u00e9diteur de monde ...");
int baseWidth; int baseWidth;
int baseHeight; int baseHeight;
int width; int width;
int height; int height;
while (true) while (true)
{ {
try try
{ {
String baseWidthStr = JOptionPane.showInputDialog(null, "Veuillez entrez le nombre de cases longueur de votre carte (0 pour annuler) :"); String baseWidthStr = JOptionPane.showInputDialog(null, "Veuillez entrez le nombre de cases longueur de votre carte (0 pour annuler) :");
if (baseWidthStr == null) if (baseWidthStr == null)
return false; return false;
baseWidth = Integer.parseInt(baseWidthStr) * 16; baseWidth = Integer.parseInt(baseWidthStr) * 16;
JOptionPane.showMessageDialog(null, "NOMBRE : " + baseWidth); JOptionPane.showMessageDialog(null, "NOMBRE : " + baseWidth);
if (baseWidth < 0) if (baseWidth < 0)
throw new NumberFormatException(); throw new NumberFormatException();
if (baseWidth == 0) if (baseWidth == 0)
return false; return false;
break; break;
} }
catch (NumberFormatException ex) catch (NumberFormatException ex)
{ {
continue; continue;
} }
} }
while (true) while (true)
{ {
try try
{ {
String baseHeightStr = JOptionPane.showInputDialog("Veuillez entrez le nombre de cases hauteur de votre carte (0 pour annuler) :"); String baseHeightStr = JOptionPane.showInputDialog("Veuillez entrez le nombre de cases hauteur de votre carte (0 pour annuler) :");
if (baseHeightStr == null) if (baseHeightStr == null)
return false; return false;
baseHeight = Integer.parseInt(baseHeightStr) * 16; baseHeight = Integer.parseInt(baseHeightStr) * 16;
if (baseHeight < 0) if (baseHeight < 0)
throw new NumberFormatException(); throw new NumberFormatException();
if (baseHeight == 0) if (baseHeight == 0)
return false; return false;
break; break;
} }
catch (NumberFormatException ex) catch (NumberFormatException ex)
{ {
continue; continue;
} }
} }
width = baseWidth + ((int) baseWidth / 16) + 1; width = baseWidth + ((int) baseWidth / 16) + 1;
height = baseHeight + ((int) baseHeight / 16) + 1; height = baseHeight + ((int) baseHeight / 16) + 1;
BufferedImage image = new BufferedImage(width, height, BufferedImage.TYPE_INT_ARGB); BufferedImage image = new BufferedImage(width, height, BufferedImage.TYPE_INT_ARGB);
Graphics2D g = image.createGraphics(); Graphics2D g = image.createGraphics();
g.setColor(Color.white); g.setColor(Color.white);
g.fillRect(0, 0, width, height); g.fillRect(0, 0, width, height);
g.setColor(Color.black); g.setColor(Color.black);
g.drawLine(0, 0, width, 0); g.drawLine(0, 0, width, 0);
g.drawLine(0, 0, 0, height); g.drawLine(0, 0, 0, height);
for (int x = 17; x <= width; x += 17) for (int x = 17; x <= width; x += 17)
{ {
g.drawLine(x, 0, x, height); g.drawLine(x, 0, x, height);
} }
for (int y = 17; y <= height; y += 17) for (int y = 17; y <= height; y += 17)
{ {
g.drawLine(0, y, width, y); g.drawLine(0, y, width, y);
} }
RawMap rm = EditorAPI.toRawMap(baseWidth, baseHeight); RawMap rm = EditorAPI.toRawMap(baseWidth, baseHeight);
rm.setFont(image); rm.setFont(image);
EditorAPI.open(rm); EditorAPI.open(rm);
return true; return true;
} }
/** /**
* Accesseur disant si le jeu est en d&eacute;bogage ou non. S'active en ins&eacute;rant l'argument --debug dans le lancement. * Accesseur disant si le jeu est en d&eacute;bogage ou non. S'active en ins&eacute;rant l'argument --debug dans le lancement.
* @see #DEBUG * @see #DEBUG
* @since 0.1-aplha * @since 0.1-aplha
*/ */
public static boolean isInDebugMode() public static boolean isInDebugMode()
{ {
return DEBUG; return DEBUG;
} }
/** /**
* Accesseur disant si le jeu est lanc&eacute; en d&eacute;veloppement ou non. * Accesseur disant si le jeu est lanc&eacute; en d&eacute;veloppement ou non.
* @see #DEV * @see #DEV
* @since 0.1-alpha * @since 0.1-alpha
*/ */
public static boolean isInDevelopmentMode() public static boolean isInDevelopmentMode()
{ {
return DEV; return DEV;
} }
} }

View File

@ -1,7 +1,7 @@
/** /**
* Ce package comprend uniquement la classe Main, qui lance l'application. * Ce package comprend uniquement la classe Main, qui lance l'application.
*/ */
/** /**
* @author galaxyoyo * @author galaxyoyo
*/ */
package galaxyoyo.unknown.client.main; package galaxyoyo.alice.gameengine.client.main;

View File

@ -1,104 +1,104 @@
package galaxyoyo.unknown.editor; package galaxyoyo.alice.gameengine.editor;
import galaxyoyo.unknown.api.editor.Case; import galaxyoyo.alice.gameengine.api.editor.Case;
import galaxyoyo.unknown.api.editor.Collision; import galaxyoyo.alice.gameengine.api.editor.Collision;
import java.awt.Color; import java.awt.Color;
import java.awt.Graphics; import java.awt.Graphics;
import java.awt.Graphics2D; import java.awt.Graphics2D;
import java.awt.image.BufferedImage; import java.awt.image.BufferedImage;
import javax.swing.JPanel; import javax.swing.JPanel;
public class CollidPanel extends JPanel public class CollidPanel extends JPanel
{ {
private static final long serialVersionUID = -138754019431984881L; private static final long serialVersionUID = -138754019431984881L;
private final EditorFrame frame; private final EditorFrame frame;
public CollidPanel(EditorFrame frame) public CollidPanel(EditorFrame frame)
{ {
super (); super ();
this.frame = frame; this.frame = frame;
} }
public EditorFrame getFrame() public EditorFrame getFrame()
{ {
return frame; return frame;
} }
public Map getMap() public Map getMap()
{ {
return frame.getMap(); return frame.getMap();
} }
@Override @Override
public void paintComponent(Graphics g) public void paintComponent(Graphics g)
{ {
g.fillRect(0, 0, getWidth(), getHeight()); g.fillRect(0, 0, getWidth(), getHeight());
BufferedImage img = getMap().getFont(); BufferedImage img = getMap().getFont();
int x = getWidth() / 2 - img.getWidth(); int x = getWidth() / 2 - img.getWidth();
int y = getHeight() / 2 - img.getHeight(); int y = getHeight() / 2 - img.getHeight();
int width = img.getWidth() * 2; int width = img.getWidth() * 2;
int height = img.getHeight() * 2; int height = img.getHeight() * 2;
g.drawImage(getMap().getFont(), x, y, width, height, null); g.drawImage(getMap().getFont(), x, y, width, height, null);
for (Case c : getMap().getAllCases()) for (Case c : getMap().getAllCases())
{ {
if (isEmpty(c.getCoucheOne().getImage())) if (isEmpty(c.getCoucheOne().getImage()))
continue; continue;
g.drawImage(c.getCoucheOne().getImage(), x + c.getPosX() * 34 + 2, y + c.getPosY() * 34 + 2, 32, 32, null); g.drawImage(c.getCoucheOne().getImage(), x + c.getPosX() * 34 + 2, y + c.getPosY() * 34 + 2, 32, 32, null);
if (isEmpty(c.getCoucheTwo().getImage())) if (isEmpty(c.getCoucheTwo().getImage()))
continue; continue;
g.drawImage(c.getCoucheTwo().getImage(), x + c.getPosX() * 34 + 2, y + c.getPosY() * 34 + 2, 32, 32, null); g.drawImage(c.getCoucheTwo().getImage(), x + c.getPosX() * 34 + 2, y + c.getPosY() * 34 + 2, 32, 32, null);
if (isEmpty(c.getCoucheThree().getImage())) if (isEmpty(c.getCoucheThree().getImage()))
continue; continue;
g.drawImage(c.getCoucheThree().getImage(), x + c.getPosX() * 34 + 2, y + c.getPosY() * 34 + 2, 32, 32, null); g.drawImage(c.getCoucheThree().getImage(), x + c.getPosX() * 34 + 2, y + c.getPosY() * 34 + 2, 32, 32, null);
} }
for (Case c : getMap().getAllCases()) for (Case c : getMap().getAllCases())
{ {
if (c.getCollision() != Collision.ANY) if (c.getCollision() != Collision.ANY)
{ {
BufferedImage alpha = new BufferedImage(16, 16, BufferedImage.TYPE_INT_ARGB); BufferedImage alpha = new BufferedImage(16, 16, BufferedImage.TYPE_INT_ARGB);
if (c.getCollision() == Collision.FULL) if (c.getCollision() == Collision.FULL)
{ {
Graphics2D grap = alpha.createGraphics(); Graphics2D grap = alpha.createGraphics();
grap.setColor(new Color(0, 0, 0, 100)); grap.setColor(new Color(0, 0, 0, 100));
grap.fillRect(0, 0, 16, 16); grap.fillRect(0, 0, 16, 16);
grap.dispose(); grap.dispose();
} }
else if (c.getCollision() == Collision.PARTIAL) else if (c.getCollision() == Collision.PARTIAL)
{ {
Graphics2D grap = alpha.createGraphics(); Graphics2D grap = alpha.createGraphics();
grap.setColor(new Color(255, 0, 255, 70)); grap.setColor(new Color(255, 0, 255, 70));
grap.fillRect(0, 0, 16, 16); grap.fillRect(0, 0, 16, 16);
grap.dispose(); grap.dispose();
} }
g.drawImage(alpha, x + c.getPosX() * 34 + 2, y + c.getPosY() * 34 + 2, 32, 32, null); g.drawImage(alpha, x + c.getPosX() * 34 + 2, y + c.getPosY() * 34 + 2, 32, 32, null);
} }
} }
} }
private boolean isEmpty(BufferedImage image) private boolean isEmpty(BufferedImage image)
{ {
int allrgba = 0; int allrgba = 0;
for (int x = 0; x < image.getWidth(); ++x) for (int x = 0; x < image.getWidth(); ++x)
{ {
for (int y = 0; y < image.getHeight(); ++y) for (int y = 0; y < image.getHeight(); ++y)
{ {
allrgba += image.getRGB(x, y) + 1; allrgba += image.getRGB(x, y) + 1;
} }
} }
return allrgba == 0; return allrgba == 0;
} }
} }

View File

@ -1,381 +1,382 @@
package galaxyoyo.unknown.editor; package galaxyoyo.alice.gameengine.editor;
import galaxyoyo.unknown.api.editor.EditorAPI; import galaxyoyo.alice.gameengine.api.editor.EditorAPI;
import galaxyoyo.unknown.api.editor.RawMap; import galaxyoyo.alice.gameengine.api.editor.RawMap;
import galaxyoyo.unknown.api.editor.sprites.Category; import galaxyoyo.alice.gameengine.api.editor.sprites.Category;
import galaxyoyo.unknown.api.editor.sprites.Sprite; import galaxyoyo.alice.gameengine.api.editor.sprites.Sprite;
import galaxyoyo.unknown.api.editor.sprites.SpriteRegister; import galaxyoyo.alice.gameengine.api.editor.sprites.SpriteRegister;
import galaxyoyo.unknown.frame.listeners.CollidMapMouseListener; import galaxyoyo.gameengine.frame.listeners.CollidMapMouseListener;
import galaxyoyo.unknown.frame.listeners.CreateMapListener; import galaxyoyo.gameengine.frame.listeners.CreateMapListener;
import galaxyoyo.unknown.frame.listeners.MapMouseListener; import galaxyoyo.gameengine.frame.listeners.MapMouseListener;
import galaxyoyo.unknown.frame.listeners.OpenMapListener; import galaxyoyo.gameengine.frame.listeners.OpenMapListener;
import galaxyoyo.unknown.frame.listeners.SpriteMouseListener; import galaxyoyo.gameengine.frame.listeners.SpriteMouseListener;
import java.awt.BorderLayout; import java.awt.BorderLayout;
import java.awt.Color; import java.awt.Color;
import java.awt.Dimension; import java.awt.Dimension;
import java.awt.event.ActionEvent; import java.awt.event.ActionEvent;
import java.awt.event.ActionListener; import java.awt.event.ActionListener;
import java.awt.event.KeyEvent; import java.awt.event.KeyEvent;
import java.awt.event.WindowEvent; import java.awt.event.WindowEvent;
import java.awt.event.WindowListener; import java.awt.event.WindowListener;
import java.awt.image.BufferedImage; import java.awt.image.BufferedImage;
import java.io.File; import java.io.File;
import javax.swing.ButtonGroup; import javax.swing.ButtonGroup;
import javax.swing.ImageIcon; import javax.swing.ImageIcon;
import javax.swing.JFrame; import javax.swing.JFrame;
import javax.swing.JMenu; import javax.swing.JMenu;
import javax.swing.JMenuBar; import javax.swing.JMenuBar;
import javax.swing.JMenuItem; import javax.swing.JMenuItem;
import javax.swing.JOptionPane; import javax.swing.JOptionPane;
import javax.swing.JPanel; import javax.swing.JPanel;
import javax.swing.JRadioButtonMenuItem; import javax.swing.JRadioButtonMenuItem;
import javax.swing.JScrollPane; import javax.swing.JScrollPane;
import javax.swing.JTabbedPane; import javax.swing.JTabbedPane;
import javax.swing.KeyStroke; import javax.swing.KeyStroke;
import javax.swing.event.ChangeEvent; import javax.swing.event.ChangeEvent;
import javax.swing.event.ChangeListener; import javax.swing.event.ChangeListener;
public class EditorFrame extends JFrame implements ChangeListener, ActionListener, WindowListener public class EditorFrame extends JFrame implements ChangeListener, ActionListener, WindowListener
{ {
private static final long serialVersionUID = -2705122356101556462L; private static final long serialVersionUID = -2705122356101556462L;
private final Map map; private final Map map;
private final JPanel content = new JPanel(); private final JPanel content = new JPanel();
private final JMenuBar menuBar = new JMenuBar(); private final JMenuBar menuBar = new JMenuBar();
private final JMenu fichier = new JMenu("Fichier"); private final JMenu fichier = new JMenu("Fichier");
private final JMenu tools = new JMenu("Outils"); private final JMenu tools = new JMenu("Outils");
private final JMenuItem nouveau = new JMenuItem("Nouveau"); private final JMenuItem nouveau = new JMenuItem("Nouveau");
private final JMenuItem open = new JMenuItem("Ouvrir"); private final JMenuItem open = new JMenuItem("Ouvrir");
private final JMenuItem save = new JMenuItem("Sauvegarder"); private final JMenuItem save = new JMenuItem("Sauvegarder");
private final JMenuItem saveAs = new JMenuItem("Sauvegarder sous ..."); private final JMenuItem saveAs = new JMenuItem("Sauvegarder sous ...");
private final JMenuItem exit = new JMenuItem("Quitter"); private final JMenuItem exit = new JMenuItem("Quitter");
private final JMenu selectionMode = new JMenu("Mode de s\u00e9lection"); private final JMenu selectionMode = new JMenu("Mode de s\u00e9lection");
ButtonGroup group = new ButtonGroup(); ButtonGroup group = new ButtonGroup();
private final JRadioButtonMenuItem pen = new JRadioButtonMenuItem("Pinceau"); private final JRadioButtonMenuItem pen = new JRadioButtonMenuItem("Pinceau");
private final JRadioButtonMenuItem pot = new JRadioButtonMenuItem("Pot de peinture"); private final JRadioButtonMenuItem pot = new JRadioButtonMenuItem("Pot de peinture");
private final JTabbedPane tabs = new JTabbedPane(); private final JTabbedPane tabs = new JTabbedPane();
private final JPanel tabEvents = new JPanel(); private final JPanel tabEvents = new JPanel();
private final CollidPanel tabColl; private final CollidPanel tabColl;
private final MapPanel mapPanel; private final MapPanel mapPanel;
private final JTabbedPane resources = new JTabbedPane(); private final JTabbedPane resources = new JTabbedPane();
private final JPanel couche1 = new JPanel(); private final JPanel couche1 = new JPanel();
private final JPanel couche2 = new JPanel(); private final JPanel couche2 = new JPanel();
private final JPanel couche3 = new JPanel(); private final JPanel couche3 = new JPanel();
private SpriteComp selectedSprite; private SpriteComp selectedSprite;
public EditorFrame(Map map) public EditorFrame(Map map)
{ {
this.map = map; super ("Alice Game Engine");
this.setSize(600, 600); this.map = map;
this.setPreferredSize(getSize()); this.setSize(600, 600);
this.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE); this.setPreferredSize(getSize());
this.setExtendedState(JFrame.MAXIMIZED_BOTH); this.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
this.setLocationRelativeTo(null); this.setExtendedState(JFrame.MAXIMIZED_BOTH);
this.addWindowListener(this); this.setLocationRelativeTo(null);
content.setLayout(new BorderLayout()); this.addWindowListener(this);
this.setContentPane(content); content.setLayout(new BorderLayout());
this.setVisible(true); this.setContentPane(content);
this.setVisible(false); this.setVisible(true);
this.setVisible(false);
fichier.setMnemonic(KeyEvent.VK_F + KeyEvent.ALT_DOWN_MASK);
fichier.setMnemonic(KeyEvent.VK_F + KeyEvent.ALT_DOWN_MASK);
nouveau.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_N, KeyEvent.CTRL_DOWN_MASK, true));
nouveau.addActionListener(new CreateMapListener()); nouveau.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_N, KeyEvent.CTRL_DOWN_MASK, true));
fichier.add(nouveau); nouveau.addActionListener(new CreateMapListener());
fichier.add(nouveau);
open.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_O, KeyEvent.CTRL_DOWN_MASK, true));
open.addActionListener(new OpenMapListener()); open.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_O, KeyEvent.CTRL_DOWN_MASK, true));
fichier.add(open); open.addActionListener(new OpenMapListener());
fichier.add(open);
fichier.addSeparator();
fichier.addSeparator();
save.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_S, KeyEvent.CTRL_DOWN_MASK, true));
save.addActionListener(this); save.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_S, KeyEvent.CTRL_DOWN_MASK, true));
fichier.add(save); save.addActionListener(this);
fichier.add(save);
saveAs.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_S, KeyEvent.CTRL_DOWN_MASK + KeyEvent.SHIFT_DOWN_MASK, true));
saveAs.addActionListener(this); saveAs.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_S, KeyEvent.CTRL_DOWN_MASK + KeyEvent.SHIFT_DOWN_MASK, true));
fichier.add(saveAs); saveAs.addActionListener(this);
fichier.add(saveAs);
fichier.addSeparator();
fichier.addSeparator();
exit.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_Q, KeyEvent.CTRL_DOWN_MASK, true));
exit.addActionListener(this); exit.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_Q, KeyEvent.CTRL_DOWN_MASK, true));
fichier.add(exit); exit.addActionListener(this);
fichier.add(exit);
menuBar.add(fichier);
menuBar.add(fichier);
pen.setSelected(true);
pen.addActionListener(this); pen.setSelected(true);
pot.addActionListener(this); pen.addActionListener(this);
group.add(pen); pot.addActionListener(this);
group.add(pot); group.add(pen);
selectionMode.add(pen); group.add(pot);
selectionMode.add(pot); selectionMode.add(pen);
selectionMode.add(pot);
tools.setMnemonic(KeyEvent.VK_O + KeyEvent.ALT_DOWN_MASK);
tools.setMnemonic(KeyEvent.VK_O + KeyEvent.ALT_DOWN_MASK);
tools.add(selectionMode);
tools.add(selectionMode);
menuBar.add(tools);
menuBar.add(tools);
this.setJMenuBar(menuBar);
this.setJMenuBar(menuBar);
mapPanel = new MapPanel(this);
mapPanel.addMouseListener(new MapMouseListener(mapPanel, this)); mapPanel = new MapPanel(this);
mapPanel.addMouseMotionListener(new MapMouseListener(mapPanel, this)); mapPanel.addMouseListener(new MapMouseListener(mapPanel, this));
mapPanel.addMouseMotionListener(new MapMouseListener(mapPanel, this));
tabColl = new CollidPanel(this);
tabColl.addMouseListener(new CollidMapMouseListener(tabColl, this)); tabColl = new CollidPanel(this);
tabColl.addMouseMotionListener(new CollidMapMouseListener(tabColl, this)); tabColl.addMouseListener(new CollidMapMouseListener(tabColl, this));
tabColl.addMouseMotionListener(new CollidMapMouseListener(tabColl, this));
JScrollPane scrollMap = new JScrollPane(mapPanel);
scrollMap.getHorizontalScrollBar().setUnitIncrement(34); JScrollPane scrollMap = new JScrollPane(mapPanel);
scrollMap.getVerticalScrollBar().setUnitIncrement(34); scrollMap.getHorizontalScrollBar().setUnitIncrement(34);
JScrollPane scrollCollidMap = new JScrollPane(tabColl); scrollMap.getVerticalScrollBar().setUnitIncrement(34);
scrollCollidMap.getHorizontalScrollBar().setUnitIncrement(34); JScrollPane scrollCollidMap = new JScrollPane(tabColl);
scrollCollidMap.getVerticalScrollBar().setUnitIncrement(34); scrollCollidMap.getHorizontalScrollBar().setUnitIncrement(34);
scrollCollidMap.getVerticalScrollBar().setUnitIncrement(34);
tabs.addTab("Carte", scrollMap);
tabs.addTab("\u00c9vennments", new JScrollPane(tabEvents)); tabs.addTab("Carte", scrollMap);
tabs.addTab("Collisions", scrollCollidMap); tabs.addTab("\u00c9vennments", new JScrollPane(tabEvents));
tabs.addChangeListener(this); tabs.addTab("Collisions", scrollCollidMap);
tabs.addChangeListener(this);
content.add(tabs, BorderLayout.CENTER);
content.add(tabs, BorderLayout.CENTER);
couche1.setLayout(new WrapLayout(WrapLayout.LEFT));
couche2.setLayout(new WrapLayout(WrapLayout.LEFT)); couche1.setLayout(new WrapLayout(WrapLayout.LEFT));
couche3.setLayout(new WrapLayout(WrapLayout.LEFT)); couche2.setLayout(new WrapLayout(WrapLayout.LEFT));
couche3.setLayout(new WrapLayout(WrapLayout.LEFT));
JScrollPane scroll1 = new JScrollPane(couche1, JScrollPane.VERTICAL_SCROLLBAR_ALWAYS, JScrollPane.HORIZONTAL_SCROLLBAR_NEVER);
JScrollPane scroll2 = new JScrollPane(couche2, JScrollPane.VERTICAL_SCROLLBAR_ALWAYS, JScrollPane.HORIZONTAL_SCROLLBAR_NEVER); JScrollPane scroll1 = new JScrollPane(couche1, JScrollPane.VERTICAL_SCROLLBAR_ALWAYS, JScrollPane.HORIZONTAL_SCROLLBAR_NEVER);
JScrollPane scroll3 = new JScrollPane(couche3, JScrollPane.VERTICAL_SCROLLBAR_ALWAYS, JScrollPane.HORIZONTAL_SCROLLBAR_NEVER); JScrollPane scroll2 = new JScrollPane(couche2, JScrollPane.VERTICAL_SCROLLBAR_ALWAYS, JScrollPane.HORIZONTAL_SCROLLBAR_NEVER);
JScrollPane scroll3 = new JScrollPane(couche3, JScrollPane.VERTICAL_SCROLLBAR_ALWAYS, JScrollPane.HORIZONTAL_SCROLLBAR_NEVER);
scroll1.getHorizontalScrollBar().setMaximum(0);
scroll2.getHorizontalScrollBar().setMaximum(0); scroll1.getHorizontalScrollBar().setMaximum(0);
scroll3.getHorizontalScrollBar().setMaximum(0); scroll2.getHorizontalScrollBar().setMaximum(0);
scroll3.getHorizontalScrollBar().setMaximum(0);
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 1.png").getAbsolutePath()), scroll1);
resources.addTab("", new ImageIcon(new File("assets/unknown/textures/layer 3.png").getAbsolutePath()), scroll3); resources.addTab("", new ImageIcon(new File("assets/unknown/textures/layer 2.png").getAbsolutePath()), scroll2);
resources.addChangeListener(this); resources.addTab("", new ImageIcon(new File("assets/unknown/textures/layer 3.png").getAbsolutePath()), scroll3);
resources.setBackgroundAt(0, Color.white); resources.addChangeListener(this);
resources.setBackgroundAt(1, Color.white); resources.setBackgroundAt(0, Color.white);
resources.setBackgroundAt(2, Color.white); resources.setBackgroundAt(1, Color.white);
resources.setBackgroundAt(2, Color.white);
content.add(resources, BorderLayout.EAST);
content.add(resources, BorderLayout.EAST);
resize();
resize();
drawResources();
drawResources();
revalidate();
repaint(); revalidate();
} repaint();
}
private void drawResources()
{ private void drawResources()
couche1.removeAll(); {
couche2.removeAll(); couche1.removeAll();
couche3.removeAll(); couche2.removeAll();
couche3.removeAll();
if (couche1.getComponents().length > 0)
{ if (couche1.getComponents().length > 0)
return; {
} return;
}
if (couche1.getWidth() == 0 || couche2.getWidth() == 0 || couche3.getWidth() == 0)
{ if (couche1.getWidth() == 0 || couche2.getWidth() == 0 || couche3.getWidth() == 0)
couche1.repaint(); {
couche2.repaint(); couche1.repaint();
couche3.repaint(); couche2.repaint();
} couche3.repaint();
}
for (Category cat : SpriteRegister.getAllCategories())
{ for (Category cat : SpriteRegister.getAllCategories())
for (Sprite spr : cat.getSprites()) {
{ for (Sprite spr : cat.getSprites())
SpriteComp sprc1 = new SpriteComp(spr, 0); {
SpriteComp sprc2 = new SpriteComp(spr, 1); SpriteComp sprc1 = new SpriteComp(spr, 0);
SpriteComp sprc3 = new SpriteComp(spr, 2); SpriteComp sprc2 = new SpriteComp(spr, 1);
sprc1.addMouseListener(new SpriteMouseListener(sprc1, this)); SpriteComp sprc3 = new SpriteComp(spr, 2);
sprc2.addMouseListener(new SpriteMouseListener(sprc2, this)); sprc1.addMouseListener(new SpriteMouseListener(sprc1, this));
sprc3.addMouseListener(new SpriteMouseListener(sprc3, this)); sprc2.addMouseListener(new SpriteMouseListener(sprc2, this));
couche1.add(sprc1); sprc3.addMouseListener(new SpriteMouseListener(sprc3, this));
couche2.add(sprc2); couche1.add(sprc1);
couche3.add(sprc3); couche2.add(sprc2);
} couche3.add(sprc3);
} }
}
couche1.revalidate();
couche2.revalidate(); couche1.revalidate();
couche3.revalidate(); couche2.revalidate();
couche1.repaint(); couche3.revalidate();
couche2.repaint(); couche1.repaint();
couche3.repaint(); couche2.repaint();
} couche3.repaint();
}
public void resize()
{ public void resize()
{
int cursorPos = ((JScrollPane) resources.getSelectedComponent()).getVerticalScrollBar().getValue();
tabs.setPreferredSize(new Dimension(getWidth(), getHeight() / 5)); int cursorPos = ((JScrollPane) resources.getSelectedComponent()).getVerticalScrollBar().getValue();
tabs.setLocation(0, 0); tabs.setPreferredSize(new Dimension(getWidth(), getHeight() / 5));
BufferedImage img = getMap().getFont(); tabs.setLocation(0, 0);
int width = img.getWidth() * 2; BufferedImage img = getMap().getFont();
int height = img.getHeight() * 2; int width = img.getWidth() * 2;
mapPanel.setPreferredSize(new Dimension(width, height)); int height = img.getHeight() * 2;
mapPanel.setLocation(0, getHeight() / 5); mapPanel.setPreferredSize(new Dimension(width, height));
tabColl.setPreferredSize(new Dimension(width, height)); mapPanel.setLocation(0, getHeight() / 5);
tabColl.setLocation(0, getHeight() / 5); tabColl.setPreferredSize(new Dimension(width, height));
resources.setPreferredSize(new Dimension(getWidth() / 4 - 15, getHeight() / 5 * 4 - 40)); tabColl.setLocation(0, getHeight() / 5);
resources.setLocation(getWidth() / 4 * 3, getHeight() / 5); resources.setPreferredSize(new Dimension(getWidth() / 4 - 15, getHeight() / 5 * 4 - 40));
resources.setLocation(getWidth() / 4 * 3, getHeight() / 5);
JScrollPane scroll1 = (JScrollPane) resources.getComponent(0);
JScrollPane scroll2 = (JScrollPane) resources.getComponent(1); JScrollPane scroll1 = (JScrollPane) resources.getComponent(0);
JScrollPane scroll3 = (JScrollPane) resources.getComponent(2); JScrollPane scroll2 = (JScrollPane) resources.getComponent(1);
JScrollPane scroll3 = (JScrollPane) resources.getComponent(2);
scroll1.getHorizontalScrollBar().setMaximum(0);
scroll2.getHorizontalScrollBar().setMaximum(0); scroll1.getHorizontalScrollBar().setMaximum(0);
scroll3.getHorizontalScrollBar().setMaximum(0); scroll2.getHorizontalScrollBar().setMaximum(0);
scroll3.getHorizontalScrollBar().setMaximum(0);
drawResources();
drawResources();
((JScrollPane) resources.getSelectedComponent()).getVerticalScrollBar().setValue(cursorPos);
} ((JScrollPane) resources.getSelectedComponent()).getVerticalScrollBar().setValue(cursorPos);
}
public Map getMap()
{ public Map getMap()
return map; {
} return map;
}
public SpriteComp getSelectedSprite()
{ public SpriteComp getSelectedSprite()
return selectedSprite; {
} return selectedSprite;
}
public void setSelectedSprite(SpriteComp sprite)
{ public void setSelectedSprite(SpriteComp sprite)
this.selectedSprite = sprite; {
} this.selectedSprite = sprite;
}
@Override
public void stateChanged(ChangeEvent event) @Override
{ public void stateChanged(ChangeEvent event)
if (event.getSource() == resources) {
{ if (event.getSource() == resources)
if (getSelectedLayerIndex() == 0) {
{ if (getSelectedLayerIndex() == 0)
resources.setBackgroundAt(0, Color.white); {
resources.setBackgroundAt(1, Color.white); resources.setBackgroundAt(0, Color.white);
resources.setBackgroundAt(2, Color.white); resources.setBackgroundAt(1, Color.white);
} resources.setBackgroundAt(2, Color.white);
else if (getSelectedLayerIndex() == 1) }
{ else if (getSelectedLayerIndex() == 1)
resources.setBackgroundAt(0, Color.black); {
resources.setBackgroundAt(1, Color.white); resources.setBackgroundAt(0, Color.black);
resources.setBackgroundAt(2, Color.white); resources.setBackgroundAt(1, Color.white);
} resources.setBackgroundAt(2, Color.white);
else if (getSelectedLayerIndex() == 2) }
{ else if (getSelectedLayerIndex() == 2)
resources.setBackgroundAt(0, Color.black); {
resources.setBackgroundAt(1, Color.black); resources.setBackgroundAt(0, Color.black);
resources.setBackgroundAt(2, Color.white); resources.setBackgroundAt(1, Color.black);
} resources.setBackgroundAt(2, Color.white);
}
repaint();
} repaint();
else if (event.getSource() == tabs) }
{ else if (event.getSource() == tabs)
resources.setEnabled(tabs.getSelectedIndex() == 0); {
couche1.setEnabled(resources.isEnabled()); resources.setEnabled(tabs.getSelectedIndex() == 0);
couche2.setEnabled(resources.isEnabled()); couche1.setEnabled(resources.isEnabled());
couche3.setEnabled(resources.isEnabled()); couche2.setEnabled(resources.isEnabled());
couche3.setEnabled(resources.isEnabled());
repaint();
} repaint();
} }
}
public int getSelectedLayerIndex()
{ public int getSelectedLayerIndex()
return resources.getSelectedIndex(); {
} return resources.getSelectedIndex();
}
@Override
public void actionPerformed(ActionEvent event) @Override
{ public void actionPerformed(ActionEvent event)
if (event.getSource() == save) {
{ if (event.getSource() == save)
EditorAPI.save(RawMap.create(map)); {
} EditorAPI.save(RawMap.create(map));
else if (event.getSource() == saveAs) }
{ else if (event.getSource() == saveAs)
EditorAPI.saveAs(RawMap.create(map)); {
} EditorAPI.saveAs(RawMap.create(map));
else if (event.getSource() == exit) }
{ else if (event.getSource() == exit)
int result = JOptionPane.showConfirmDialog(null, "Voulez-vous sauvegarder votre carte avant de quitter ? Toute modification sera perdue", "Confirmation", JOptionPane.YES_NO_CANCEL_OPTION); {
int result = JOptionPane.showConfirmDialog(null, "Voulez-vous sauvegarder votre carte avant de quitter ? Toute modification sera perdue", "Confirmation", JOptionPane.YES_NO_CANCEL_OPTION);
if (result == 0)
save.doClick(); if (result == 0)
save.doClick();
if (result != 2)
dispose(); if (result != 2)
} dispose();
} }
}
public int getSelectedPaintingMode()
{ public int getSelectedPaintingMode()
return pen.isSelected() ? 0 : pot.isSelected() ? 1 : -1; {
} return pen.isSelected() ? 0 : pot.isSelected() ? 1 : -1;
}
@Override
public void windowActivated(WindowEvent event) @Override
{ public void windowActivated(WindowEvent event)
} {
}
@Override
public void windowClosed(WindowEvent event) @Override
{ public void windowClosed(WindowEvent event)
} {
}
@Override
public void windowClosing(WindowEvent event) @Override
{ public void windowClosing(WindowEvent event)
int result = JOptionPane.showConfirmDialog(null, "Voulez-vous sauvegarder avant de quitter ?", "Confirmation", JOptionPane.YES_NO_CANCEL_OPTION); {
int result = JOptionPane.showConfirmDialog(null, "Voulez-vous sauvegarder avant de quitter ?", "Confirmation", JOptionPane.YES_NO_CANCEL_OPTION);
if (result == 0)
{ if (result == 0)
EditorAPI.save(RawMap.create(map)); {
} EditorAPI.save(RawMap.create(map));
}
if (result != 2)
{ if (result != 2)
dispose(); {
} dispose();
} }
}
@Override
public void windowDeactivated(WindowEvent event) @Override
{ public void windowDeactivated(WindowEvent event)
} {
}
@Override
public void windowDeiconified(WindowEvent event) @Override
{ public void windowDeiconified(WindowEvent event)
} {
}
@Override
public void windowIconified(WindowEvent event) @Override
{ public void windowIconified(WindowEvent event)
} {
}
@Override
public void windowOpened(WindowEvent event) @Override
{ public void windowOpened(WindowEvent event)
} {
} }
}

View File

@ -1,101 +1,101 @@
package galaxyoyo.unknown.editor; package galaxyoyo.alice.gameengine.editor;
import galaxyoyo.unknown.api.editor.Case; import galaxyoyo.alice.gameengine.api.editor.Case;
import galaxyoyo.unknown.api.editor.RawCase; import galaxyoyo.alice.gameengine.api.editor.RawCase;
import galaxyoyo.unknown.api.editor.RawMap; import galaxyoyo.alice.gameengine.api.editor.RawMap;
import galaxyoyo.unknown.api.editor.sprites.SpriteRegister; import galaxyoyo.alice.gameengine.api.editor.sprites.SpriteRegister;
import java.awt.image.BufferedImage; import java.awt.image.BufferedImage;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.HashMap; import java.util.HashMap;
import java.util.List; import java.util.List;
public class Map public class Map
{ {
@Deprecated @Deprecated
private static List<Case> cases; private static List<Case> cases;
private final EditorFrame frame; private final EditorFrame frame;
private int width; private int width;
private int height; private int height;
private java.util.Map<Integer, java.util.Map<Integer, Case>> casesMap = new HashMap<Integer, java.util.Map<Integer, Case>>(); private java.util.Map<Integer, java.util.Map<Integer, Case>> casesMap = new HashMap<Integer, java.util.Map<Integer, Case>>();
private transient BufferedImage font; private transient BufferedImage font;
public Map(RawMap raw) public Map(RawMap raw)
{ {
cases = new ArrayList<Case>(); cases = new ArrayList<Case>();
this.width = raw.getWidth(); this.width = raw.getWidth();
this.height = raw.getHeight(); this.height = raw.getHeight();
this.font = raw.getFont(); this.font = raw.getFont();
for (RawCase rc : raw.getCases()) for (RawCase rc : raw.getCases())
{ {
cases.add(Case.create(rc.getPosX(), rc.getPosY(), SpriteRegister.getCategory(rc.getCoucheOne().getCategory()).getSprites().get(rc.getCoucheOne().getIndex()), SpriteRegister.getCategory(rc.getCoucheTwo().getCategory()).getSprites().get(rc.getCoucheTwo().getIndex()), SpriteRegister.getCategory(rc.getCoucheThree().getCategory()).getSprites().get(rc.getCoucheThree().getIndex()), rc.getCollision())); cases.add(Case.create(rc.getPosX(), rc.getPosY(), SpriteRegister.getCategory(rc.getCoucheOne().getCategory()).getSprites().get(rc.getCoucheOne().getIndex()), SpriteRegister.getCategory(rc.getCoucheTwo().getCategory()).getSprites().get(rc.getCoucheTwo().getIndex()), SpriteRegister.getCategory(rc.getCoucheThree().getCategory()).getSprites().get(rc.getCoucheThree().getIndex()), rc.getCollision()));
} }
reorganizeMap(); reorganizeMap();
frame = new EditorFrame(this); frame = new EditorFrame(this);
getFrame().setVisible(true); getFrame().setVisible(true);
} }
public EditorFrame getFrame() public EditorFrame getFrame()
{ {
return frame; return frame;
} }
public int getWidth() public int getWidth()
{ {
return width; return width;
} }
public int getHeight() public int getHeight()
{ {
return height; return height;
} }
public Case getCase(int x, int y) public Case getCase(int x, int y)
{ {
return casesMap.getOrDefault(x, new HashMap<Integer, Case>()).get(y); return casesMap.getOrDefault(x, new HashMap<Integer, Case>()).get(y);
} }
public void setCase(int x, int y, Case c) public void setCase(int x, int y, Case c)
{ {
casesMap.get(x).put(y, c); casesMap.get(x).put(y, c);
} }
public BufferedImage getFont() public BufferedImage getFont()
{ {
return font; return font;
} }
public void setFont(BufferedImage font) public void setFont(BufferedImage font)
{ {
this.font = font; this.font = font;
} }
private void reorganizeMap() private void reorganizeMap()
{ {
for (int i = 0; i < width; ++i) for (int i = 0; i < width; ++i)
{ {
casesMap.put(i, new HashMap<Integer, Case>()); casesMap.put(i, new HashMap<Integer, Case>());
} }
for (Case c : cases) for (Case c : cases)
{ {
setCase(c.getPosX(), c.getPosY(), c); setCase(c.getPosX(), c.getPosY(), c);
} }
} }
public List<Case> getAllCases() public List<Case> getAllCases()
{ {
List<Case> list = new ArrayList<Case>(); List<Case> list = new ArrayList<Case>();
for (java.util.Map<Integer, Case> l : casesMap.values()) for (java.util.Map<Integer, Case> l : casesMap.values())
{ {
list.addAll(l.values()); list.addAll(l.values());
} }
return list; return list;
} }
} }

View File

@ -1,93 +1,93 @@
package galaxyoyo.unknown.editor; package galaxyoyo.alice.gameengine.editor;
import galaxyoyo.unknown.api.editor.Case; import galaxyoyo.alice.gameengine.api.editor.Case;
import java.awt.Graphics; import java.awt.Graphics;
import java.awt.image.BufferedImage; import java.awt.image.BufferedImage;
import javax.swing.JPanel; import javax.swing.JPanel;
public class MapPanel extends JPanel public class MapPanel extends JPanel
{ {
private static final long serialVersionUID = 2629019576253690557L; private static final long serialVersionUID = 2629019576253690557L;
private final EditorFrame frame; private final EditorFrame frame;
public MapPanel(EditorFrame frame) public MapPanel(EditorFrame frame)
{ {
super (); super ();
this.frame = frame; this.frame = frame;
} }
public EditorFrame getFrame() public EditorFrame getFrame()
{ {
return frame; return frame;
} }
public Map getMap() public Map getMap()
{ {
return frame.getMap(); return frame.getMap();
} }
@Override @Override
public void paintComponent(Graphics g) public void paintComponent(Graphics g)
{ {
g.fillRect(0, 0, getWidth(), getHeight()); g.fillRect(0, 0, getWidth(), getHeight());
BufferedImage img = getMap().getFont(); BufferedImage img = getMap().getFont();
int x = getWidth() / 2 - img.getWidth(); int x = getWidth() / 2 - img.getWidth();
int y = getHeight() / 2 - img.getHeight(); int y = getHeight() / 2 - img.getHeight();
int width = img.getWidth() * 2; int width = img.getWidth() * 2;
int height = img.getHeight() * 2; int height = img.getHeight() * 2;
g.drawImage(getMap().getFont(), x, y, width, height, null); g.drawImage(getMap().getFont(), x, y, width, height, null);
for (Case c : getMap().getAllCases()) for (Case c : getMap().getAllCases())
{ {
// BufferedImage image; // BufferedImage image;
if (!isEmpty(c.getCoucheOne().getImage())) if (!isEmpty(c.getCoucheOne().getImage()))
{ {
g.drawImage(c.getCoucheOne().getImage(), x + c.getPosX() * 34 + 2, y + c.getPosY() * 34 + 2, 32, 32, null); g.drawImage(c.getCoucheOne().getImage(), x + c.getPosX() * 34 + 2, y + c.getPosY() * 34 + 2, 32, 32, null);
} }
/* if (frame.getSelectedLayerIndex() != 0) /* if (frame.getSelectedLayerIndex() != 0)
{ {
image = recalculateAplha(c.getCoucheOne().getImage(), 0); image = recalculateAplha(c.getCoucheOne().getImage(), 0);
g.drawImage(image, x + c.getPosX() * 34 + 2, y + c.getPosY() * 34 + 2, 32, 32, null); g.drawImage(image, x + c.getPosX() * 34 + 2, y + c.getPosY() * 34 + 2, 32, 32, null);
}*/ }*/
if (!isEmpty(c.getCoucheTwo().getImage()) && frame.getSelectedLayerIndex() >= 1) if (!isEmpty(c.getCoucheTwo().getImage()) && frame.getSelectedLayerIndex() >= 1)
{ {
g.drawImage(c.getCoucheTwo().getImage(), x + c.getPosX() * 34 + 2, y + c.getPosY() * 34 + 2, 32, 32, null); g.drawImage(c.getCoucheTwo().getImage(), x + c.getPosX() * 34 + 2, y + c.getPosY() * 34 + 2, 32, 32, null);
} }
/* if (frame.getSelectedLayerIndex() != 1) /* if (frame.getSelectedLayerIndex() != 1)
{ {
image = recalculateAplha(c.getCoucheTwo().getImage(), 1); image = recalculateAplha(c.getCoucheTwo().getImage(), 1);
g.drawImage(image, x + c.getPosX() * 34 + 2, y + c.getPosY() * 34 + 2, 32, 32, null); g.drawImage(image, x + c.getPosX() * 34 + 2, y + c.getPosY() * 34 + 2, 32, 32, null);
}*/ }*/
if (!isEmpty(c.getCoucheThree().getImage()) && frame.getSelectedLayerIndex() == 2) if (!isEmpty(c.getCoucheThree().getImage()) && frame.getSelectedLayerIndex() == 2)
{ {
g.drawImage(c.getCoucheThree().getImage(), x + c.getPosX() * 34 + 2, y + c.getPosY() * 34 + 2, 32, 32, null); g.drawImage(c.getCoucheThree().getImage(), x + c.getPosX() * 34 + 2, y + c.getPosY() * 34 + 2, 32, 32, null);
} }
/* if (frame.getSelectedLayerIndex() != 2) /* if (frame.getSelectedLayerIndex() != 2)
{ {
image = recalculateAplha(c.getCoucheThree().getImage(), 2); image = recalculateAplha(c.getCoucheThree().getImage(), 2);
g.drawImage(image, x + c.getPosX() * 34 + 2, y + c.getPosY() * 34 + 2, 32, 32, null); g.drawImage(image, x + c.getPosX() * 34 + 2, y + c.getPosY() * 34 + 2, 32, 32, null);
}*/ }*/
} }
} }
private boolean isEmpty(BufferedImage image) private boolean isEmpty(BufferedImage image)
{ {
int allrgba = 0; int allrgba = 0;
for (int x = 0; x < image.getWidth(); ++x) for (int x = 0; x < image.getWidth(); ++x)
{ {
for (int y = 0; y < image.getHeight(); ++y) for (int y = 0; y < image.getHeight(); ++y)
{ {
allrgba += image.getRGB(x, y) + 1; allrgba += image.getRGB(x, y) + 1;
} }
} }
return allrgba == 0; return allrgba == 0;
} }
} }

View File

@ -1,80 +1,80 @@
package galaxyoyo.unknown.editor; package galaxyoyo.alice.gameengine.editor;
import galaxyoyo.unknown.api.editor.sprites.Sprite; import galaxyoyo.alice.gameengine.api.editor.sprites.Sprite;
import java.awt.Color; import java.awt.Color;
import java.awt.Dimension; import java.awt.Dimension;
import java.awt.Graphics; import java.awt.Graphics;
import javax.swing.JComponent; import javax.swing.JComponent;
public class SpriteComp extends JComponent public class SpriteComp extends JComponent
{ {
private static final long serialVersionUID = -6512257366877053285L; private static final long serialVersionUID = -6512257366877053285L;
private Sprite sprite; private Sprite sprite;
private int couche; private int couche;
private boolean selected; private boolean selected;
public SpriteComp(Sprite sprite, int couche) public SpriteComp(Sprite sprite, int couche)
{ {
super (); super ();
this.sprite = sprite; this.sprite = sprite;
this.couche = couche; this.couche = couche;
this.setMinimumSize(new Dimension(32, 32)); this.setMinimumSize(new Dimension(32, 32));
this.setMaximumSize(new Dimension(32, 32)); this.setMaximumSize(new Dimension(32, 32));
this.setPreferredSize(new Dimension(32, 32)); this.setPreferredSize(new Dimension(32, 32));
this.setSize(new Dimension(32, 32)); this.setSize(new Dimension(32, 32));
repaint(); repaint();
} }
public Sprite getSprite() public Sprite getSprite()
{ {
return sprite; return sprite;
} }
public void setSprite(Sprite s) public void setSprite(Sprite s)
{ {
this.sprite = s; this.sprite = s;
} }
public int getCouche() public int getCouche()
{ {
return couche; return couche;
} }
public void setCouche(int couche) public void setCouche(int couche)
{ {
this.couche = couche; this.couche = couche;
} }
public boolean isSelected() public boolean isSelected()
{ {
return selected; return selected;
} }
public void setSelected(boolean selected) public void setSelected(boolean selected)
{ {
this.selected = selected; this.selected = selected;
} }
@Override @Override
public void paintComponent(Graphics g) public void paintComponent(Graphics g)
{ {
super.paintComponent(g); super.paintComponent(g);
g.setColor(Color.white); g.setColor(Color.white);
g.fillRect(0, 0, getWidth(), getHeight()); g.fillRect(0, 0, getWidth(), getHeight());
g.drawImage(sprite.getImage(), 0, 0, 32, 32, Color.white, null); g.drawImage(sprite.getImage(), 0, 0, 32, 32, Color.white, null);
if (isSelected()) if (isSelected())
{ {
g.setColor(Color.black); g.setColor(Color.black);
g.drawLine(0, 0, getWidth() - 1, 0); g.drawLine(0, 0, getWidth() - 1, 0);
g.drawLine(0, 0, 0, getHeight() - 1); g.drawLine(0, 0, 0, getHeight() - 1);
g.drawLine(0, getHeight() - 1, getWidth() - 1, getHeight() - 1); g.drawLine(0, getHeight() - 1, getWidth() - 1, getHeight() - 1);
g.drawLine(getWidth() - 1, 0, getWidth() - 1, getHeight() - 1); g.drawLine(getWidth() - 1, 0, getWidth() - 1, getHeight() - 1);
} }
} }
} }

View File

@ -1,112 +1,112 @@
package galaxyoyo.unknown.editor; package galaxyoyo.alice.gameengine.editor;
import java.awt.*; import java.awt.*;
import javax.swing.JScrollPane; import javax.swing.JScrollPane;
import javax.swing.SwingUtilities; import javax.swing.SwingUtilities;
public class WrapLayout extends FlowLayout public class WrapLayout extends FlowLayout
{ {
private static final long serialVersionUID = 8777237960365591646L; private static final long serialVersionUID = 8777237960365591646L;
public WrapLayout() public WrapLayout()
{ {
super(); super();
} }
public WrapLayout(int align) public WrapLayout(int align)
{ {
super(align); super(align);
} }
public WrapLayout(int align, int hgap, int vgap) public WrapLayout(int align, int hgap, int vgap)
{ {
super(align, hgap, vgap); super(align, hgap, vgap);
} }
@Override @Override
public Dimension preferredLayoutSize(Container target) public Dimension preferredLayoutSize(Container target)
{ {
return layoutSize(target, true); return layoutSize(target, true);
} }
@Override @Override
public Dimension minimumLayoutSize(Container target) public Dimension minimumLayoutSize(Container target)
{ {
Dimension minimum = layoutSize(target, false); Dimension minimum = layoutSize(target, false);
minimum.width -= (getHgap() + 1); minimum.width -= (getHgap() + 1);
return minimum; return minimum;
} }
private Dimension layoutSize(Container target, boolean preferred) private Dimension layoutSize(Container target, boolean preferred)
{ {
synchronized (target.getTreeLock()) synchronized (target.getTreeLock())
{ {
int targetWidth = target.getSize().width; int targetWidth = target.getSize().width;
if (targetWidth == 0) if (targetWidth == 0)
targetWidth = Integer.MAX_VALUE; targetWidth = Integer.MAX_VALUE;
int hgap = getHgap(); int hgap = getHgap();
int vgap = getVgap(); int vgap = getVgap();
Insets insets = target.getInsets(); Insets insets = target.getInsets();
int horizontalInsetsAndGap = insets.left + insets.right + (hgap * 2); int horizontalInsetsAndGap = insets.left + insets.right + (hgap * 2);
int maxWidth = targetWidth - horizontalInsetsAndGap; int maxWidth = targetWidth - horizontalInsetsAndGap;
Dimension dim = new Dimension(0, 0); Dimension dim = new Dimension(0, 0);
int rowWidth = 0; int rowWidth = 0;
int rowHeight = 0; int rowHeight = 0;
int nmembers = target.getComponentCount(); int nmembers = target.getComponentCount();
for (int i = 0; i < nmembers; i++) for (int i = 0; i < nmembers; i++)
{ {
Component m = target.getComponent(i); Component m = target.getComponent(i);
if (m.isVisible()) if (m.isVisible())
{ {
Dimension d = preferred ? m.getPreferredSize() : m.getMinimumSize(); Dimension d = preferred ? m.getPreferredSize() : m.getMinimumSize();
if (rowWidth + d.width > maxWidth) if (rowWidth + d.width > maxWidth)
{ {
addRow(dim, rowWidth, rowHeight); addRow(dim, rowWidth, rowHeight);
rowWidth = 0; rowWidth = 0;
rowHeight = 0; rowHeight = 0;
} }
if (rowWidth != 0) if (rowWidth != 0)
{ {
rowWidth += hgap; rowWidth += hgap;
} }
rowWidth += d.width; rowWidth += d.width;
rowHeight = Math.max(rowHeight, d.height); rowHeight = Math.max(rowHeight, d.height);
} }
} }
addRow(dim, rowWidth, rowHeight); addRow(dim, rowWidth, rowHeight);
dim.width += horizontalInsetsAndGap; dim.width += horizontalInsetsAndGap;
dim.height += insets.top + insets.bottom + vgap * 2; dim.height += insets.top + insets.bottom + vgap * 2;
Container scrollPane = SwingUtilities.getAncestorOfClass(JScrollPane.class, target); Container scrollPane = SwingUtilities.getAncestorOfClass(JScrollPane.class, target);
if (scrollPane != null) if (scrollPane != null)
{ {
dim.width -= (hgap + 1); dim.width -= (hgap + 1);
} }
return dim; return dim;
} }
} }
private void addRow(Dimension dim, int rowWidth, int rowHeight) private void addRow(Dimension dim, int rowWidth, int rowHeight)
{ {
dim.width = Math.max(dim.width, rowWidth); dim.width = Math.max(dim.width, rowWidth);
if (dim.height > 0) if (dim.height > 0)
{ {
dim.height += getVgap(); dim.height += getVgap();
} }
dim.height += rowHeight; dim.height += rowHeight;
} }
} }

View File

@ -1,93 +1,93 @@
/** /**
* @author galaxyoyo * @author galaxyoyo
*/ */
package galaxyoyo.unknown.frame; package galaxyoyo.gameengine.frame;
import galaxyoyo.unknown.frame.listeners.CreateMapListener; import galaxyoyo.gameengine.frame.listeners.CreateMapListener;
import galaxyoyo.unknown.frame.listeners.OpenMapListener; import galaxyoyo.gameengine.frame.listeners.OpenMapListener;
import java.awt.Dimension; import java.awt.Dimension;
import java.awt.event.KeyEvent; import java.awt.event.KeyEvent;
import javax.swing.JFrame; import javax.swing.JFrame;
import javax.swing.JMenu; import javax.swing.JMenu;
import javax.swing.JMenuBar; import javax.swing.JMenuBar;
import javax.swing.JMenuItem; import javax.swing.JMenuItem;
import org.apache.logging.log4j.LogManager; import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.core.Logger; import org.apache.logging.log4j.core.Logger;
/** /**
* Fen&ecirc;tre principale du jeu * Fen&ecirc;tre principale du jeu
* @author galaxyoyo * @author galaxyoyo
*/ */
public class MainFrame extends JFrame public class MainFrame extends JFrame
{ {
/** /**
* ID de s&eacute; * ID de s&eacute;
* @see {@link JFrame} * @see {@link JFrame}
*/ */
private static final long serialVersionUID = -3168760121879418534L; private static final long serialVersionUID = -3168760121879418534L;
/** /**
* Instance unique principale * Instance unique principale
* @see #MainFrame() * @see #MainFrame()
* @see #getInstance() * @see #getInstance()
*/ */
private static MainFrame INSTANCE; private static MainFrame INSTANCE;
/** /**
* Logger de la classe * Logger de la classe
* @see LogManager#getLogger(String) * @see LogManager#getLogger(String)
*/ */
private static Logger LOGGER = (Logger) LogManager.getLogger("MainFrame"); private static Logger LOGGER = (Logger) LogManager.getLogger("MainFrame");
private JMenuBar menuBar = new JMenuBar(); private JMenuBar menuBar = new JMenuBar();
private JMenu fichier = new JMenu("Fichier"); private JMenu fichier = new JMenu("Fichier");
private JMenu editMaps = new JMenu("Cartes"); private JMenu editMaps = new JMenu("Cartes");
private JMenuItem createMap = new JMenuItem("Cr\u00e9er"); private JMenuItem createMap = new JMenuItem("Cr\u00e9er");
private JMenuItem openMap = new JMenuItem("Ouvrir"); private JMenuItem openMap = new JMenuItem("Ouvrir");
/** /**
* Constructeur * Constructeur
* @see galaxyoyo.unknown.client.main.Main#launchFrame() * @see galaxyoyo.alice.gameengine.client.main.Main#launchFrame()
*/ */
private MainFrame() private MainFrame()
{ {
super (); super ();
LOGGER.info("Initialisation de la fen\u00eatre"); LOGGER.info("Initialisation de la fen\u00eatre");
this.setTitle("WHAT IS THE NAME PLEASE"); this.setTitle("Alice Game Engine");
this.setPreferredSize(new Dimension(1000, 800)); this.setPreferredSize(new Dimension(1000, 800));
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.EXIT_ON_CLOSE); this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
fichier.setMnemonic(KeyEvent.VK_F + KeyEvent.ALT_DOWN_MASK); fichier.setMnemonic(KeyEvent.VK_F + KeyEvent.ALT_DOWN_MASK);
createMap.addActionListener(new CreateMapListener()); createMap.addActionListener(new CreateMapListener());
editMaps.add(createMap); editMaps.add(createMap);
openMap.addActionListener(new OpenMapListener()); openMap.addActionListener(new OpenMapListener());
editMaps.add(openMap); editMaps.add(openMap);
fichier.add(editMaps); fichier.add(editMaps);
menuBar.add(fichier); menuBar.add(fichier);
this.setJMenuBar(menuBar); this.setJMenuBar(menuBar);
} }
/** /**
* Cet accesseur renvoie l'accesseur unique de la classe * Cet accesseur renvoie l'accesseur unique de la classe
* @see #INSTANCE * @see #INSTANCE
* @see #MainFrame() * @see #MainFrame()
* @return l'instance unique de la classe * @return l'instance unique de la classe
*/ */
public static MainFrame getInstance() public static MainFrame getInstance()
{ {
if (INSTANCE == null) if (INSTANCE == null)
return INSTANCE = new MainFrame(); return INSTANCE = new MainFrame();
return INSTANCE; return INSTANCE;
} }
} }

View File

@ -1,50 +1,50 @@
package galaxyoyo.unknown.frame.listeners; package galaxyoyo.gameengine.frame.listeners;
import galaxyoyo.unknown.api.editor.Case; import galaxyoyo.alice.gameengine.api.editor.Case;
import galaxyoyo.unknown.api.editor.Collision; import galaxyoyo.alice.gameengine.api.editor.Collision;
import galaxyoyo.unknown.editor.CollidPanel; import galaxyoyo.alice.gameengine.editor.CollidPanel;
import galaxyoyo.unknown.editor.EditorFrame; import galaxyoyo.alice.gameengine.editor.EditorFrame;
import galaxyoyo.unknown.editor.Map; import galaxyoyo.alice.gameengine.editor.Map;
import java.awt.event.MouseAdapter; import java.awt.event.MouseAdapter;
import java.awt.event.MouseEvent; import java.awt.event.MouseEvent;
public class CollidMapMouseListener extends MouseAdapter public class CollidMapMouseListener extends MouseAdapter
{ {
private final EditorFrame frame; private final EditorFrame frame;
private final CollidPanel panel; private final CollidPanel panel;
public CollidMapMouseListener(CollidPanel panel, EditorFrame frame) public CollidMapMouseListener(CollidPanel panel, EditorFrame frame)
{ {
this.frame = frame; this.frame = frame;
this.panel = panel; this.panel = panel;
} }
public EditorFrame getFrame() public EditorFrame getFrame()
{ {
return frame; return frame;
} }
@Override @Override
public void mouseReleased(MouseEvent event) public void mouseReleased(MouseEvent event)
{ {
Map map = getFrame().getMap(); Map map = getFrame().getMap();
int x = panel.getWidth() / 2 - map.getFont().getWidth(); int x = panel.getWidth() / 2 - map.getFont().getWidth();
int y = panel.getHeight() / 2 - map.getFont().getHeight(); int y = panel.getHeight() / 2 - map.getFont().getHeight();
Case c = null; Case c = null;
if ((c = map.getCase((event.getX() - x + 2) / 34, (event.getY() - y + 2) / 34)) != null && event.getX() - x >= 2 && event.getY() - y >= 2) if ((c = map.getCase((event.getX() - x + 2) / 34, (event.getY() - y + 2) / 34)) != null && event.getX() - x >= 2 && event.getY() - y >= 2)
{ {
int colIndex = c.getCollision().ordinal(); int colIndex = c.getCollision().ordinal();
int newColIndex = colIndex + 1; int newColIndex = colIndex + 1;
if (newColIndex >= Collision.values().length) if (newColIndex >= Collision.values().length)
newColIndex = 0; newColIndex = 0;
Collision col = Collision.values()[newColIndex]; Collision col = Collision.values()[newColIndex];
Case n = Case.create(c.getPosX(), c.getPosY(), c.getCoucheOne(), c.getCoucheTwo(), c.getCoucheThree(), col); Case n = Case.create(c.getPosX(), c.getPosY(), c.getCoucheOne(), c.getCoucheTwo(), c.getCoucheThree(), col);
map.setCase((event.getX() - x + 2) / 34, (event.getY() - y + 2) / 34, n); map.setCase((event.getX() - x + 2) / 34, (event.getY() - y + 2) / 34, n);
panel.repaint(); panel.repaint();
} }
} }
} }

View File

@ -1,26 +1,26 @@
/** /**
* @author galaxyoyo * @author galaxyoyo
*/ */
package galaxyoyo.unknown.frame.listeners; package galaxyoyo.gameengine.frame.listeners;
import galaxyoyo.unknown.client.main.Main; import galaxyoyo.alice.gameengine.client.main.Main;
import galaxyoyo.unknown.frame.MainFrame; import galaxyoyo.gameengine.frame.MainFrame;
import java.awt.event.ActionEvent; import java.awt.event.ActionEvent;
import java.awt.event.ActionListener; import java.awt.event.ActionListener;
/** /**
* @author galaxyoyo * @author galaxyoyo
*/ */
public class CreateMapListener implements ActionListener public class CreateMapListener implements ActionListener
{ {
/* !CodeTemplates.overridecomment.nonjd! /* !CodeTemplates.overridecomment.nonjd!
* @see java.awt.event.ActionListener#actionPerformed(java.awt.event.ActionEvent) * @see java.awt.event.ActionListener#actionPerformed(java.awt.event.ActionEvent)
*/ */
@Override @Override
public void actionPerformed(ActionEvent event) public void actionPerformed(ActionEvent event)
{ {
if (Main.launchEditMode()) if (Main.launchEditMode())
MainFrame.getInstance().dispose(); MainFrame.getInstance().dispose();
} }
} }

View File

@ -1,94 +1,94 @@
package galaxyoyo.unknown.frame.listeners; package galaxyoyo.gameengine.frame.listeners;
import galaxyoyo.unknown.api.editor.Case; import galaxyoyo.alice.gameengine.api.editor.Case;
import galaxyoyo.unknown.editor.EditorFrame; import galaxyoyo.alice.gameengine.editor.EditorFrame;
import galaxyoyo.unknown.editor.Map; import galaxyoyo.alice.gameengine.editor.Map;
import galaxyoyo.unknown.editor.MapPanel; import galaxyoyo.alice.gameengine.editor.MapPanel;
import java.awt.event.MouseAdapter; import java.awt.event.MouseAdapter;
import java.awt.event.MouseEvent; import java.awt.event.MouseEvent;
public class MapMouseListener extends MouseAdapter public class MapMouseListener extends MouseAdapter
{ {
private final EditorFrame frame; private final EditorFrame frame;
private final MapPanel panel; private final MapPanel panel;
public MapMouseListener(MapPanel panel, EditorFrame frame) public MapMouseListener(MapPanel panel, EditorFrame frame)
{ {
this.frame = frame; this.frame = frame;
this.panel = panel; this.panel = panel;
} }
public EditorFrame getFrame() public EditorFrame getFrame()
{ {
return frame; return frame;
} }
@Override @Override
public void mouseClicked(MouseEvent event) public void mouseClicked(MouseEvent event)
{ {
if (frame.getSelectedPaintingMode() == 0) if (frame.getSelectedPaintingMode() == 0)
{ {
Map map = getFrame().getMap(); Map map = getFrame().getMap();
int x = panel.getWidth() / 2 - map.getFont().getWidth(); int x = panel.getWidth() / 2 - map.getFont().getWidth();
int y = panel.getHeight() / 2 - map.getFont().getHeight(); int y = panel.getHeight() / 2 - map.getFont().getHeight();
Case c = null; Case c = null;
if ((c = map.getCase((event.getX() - x + 2) / 34, (event.getY() - y + 2) / 34)) != null && event.getX() - x >= 2 && event.getY() - y >= 2) if ((c = map.getCase((event.getX() - x + 2) / 34, (event.getY() - y + 2) / 34)) != null && event.getX() - x >= 2 && event.getY() - y >= 2)
{ {
if (getFrame().getSelectedSprite() != null) if (getFrame().getSelectedSprite() != null)
{ {
Case n; Case n;
switch (getFrame().getSelectedSprite().getCouche()) switch (getFrame().getSelectedSprite().getCouche())
{ {
case 0 : n = Case.create(c.getPosX(), c.getPosY(), getFrame().getSelectedSprite().getSprite(), c.getCoucheTwo(), c.getCoucheThree(), c.getCollision()); break; case 0 : n = Case.create(c.getPosX(), c.getPosY(), getFrame().getSelectedSprite().getSprite(), c.getCoucheTwo(), c.getCoucheThree(), c.getCollision()); break;
case 1 : n = Case.create(c.getPosX(), c.getPosY(), c.getCoucheOne(), getFrame().getSelectedSprite().getSprite(), c.getCoucheThree(), c.getCollision()); break; case 1 : n = Case.create(c.getPosX(), c.getPosY(), c.getCoucheOne(), getFrame().getSelectedSprite().getSprite(), c.getCoucheThree(), c.getCollision()); break;
case 2 : n = Case.create(c.getPosX(), c.getPosY(), c.getCoucheOne(), c.getCoucheTwo(), getFrame().getSelectedSprite().getSprite(), c.getCollision()); break; case 2 : n = Case.create(c.getPosX(), c.getPosY(), c.getCoucheOne(), c.getCoucheTwo(), getFrame().getSelectedSprite().getSprite(), c.getCollision()); break;
default : n = c; break; default : n = c; break;
} }
map.setCase(n.getPosX(), n.getPosY(), n); map.setCase(n.getPosX(), n.getPosY(), n);
panel.repaint(); panel.repaint();
} }
} }
} }
else if (frame.getSelectedPaintingMode() == 1) else if (frame.getSelectedPaintingMode() == 1)
{ {
for (Case c : getFrame().getMap().getAllCases()) for (Case c : getFrame().getMap().getAllCases())
{ {
Map map = getFrame().getMap(); Map map = getFrame().getMap();
if (getFrame().getSelectedSprite() != null) if (getFrame().getSelectedSprite() != null)
{ {
if (getFrame().getSelectedSprite().getCouche() - 1 > getFrame().getSelectedLayerIndex()) if (getFrame().getSelectedSprite().getCouche() - 1 > getFrame().getSelectedLayerIndex())
return; return;
Case n; Case n;
switch (getFrame().getSelectedSprite().getCouche()) switch (getFrame().getSelectedSprite().getCouche())
{ {
case 0 : n = Case.create(c.getPosX(), c.getPosY(), getFrame().getSelectedSprite().getSprite(), c.getCoucheTwo(), c.getCoucheThree(), c.getCollision()); break; case 0 : n = Case.create(c.getPosX(), c.getPosY(), getFrame().getSelectedSprite().getSprite(), c.getCoucheTwo(), c.getCoucheThree(), c.getCollision()); break;
case 1 : n = Case.create(c.getPosX(), c.getPosY(), c.getCoucheOne(), getFrame().getSelectedSprite().getSprite(), c.getCoucheThree(), c.getCollision()); break; case 1 : n = Case.create(c.getPosX(), c.getPosY(), c.getCoucheOne(), getFrame().getSelectedSprite().getSprite(), c.getCoucheThree(), c.getCollision()); break;
case 2 : n = Case.create(c.getPosX(), c.getPosY(), c.getCoucheOne(), c.getCoucheTwo(), getFrame().getSelectedSprite().getSprite(), c.getCollision()); break; case 2 : n = Case.create(c.getPosX(), c.getPosY(), c.getCoucheOne(), c.getCoucheTwo(), getFrame().getSelectedSprite().getSprite(), c.getCollision()); break;
default : n = c; break; default : n = c; break;
} }
map.setCase(n.getPosX(), n.getPosY(), n); map.setCase(n.getPosX(), n.getPosY(), n);
} }
} }
panel.repaint(); panel.repaint();
} }
} }
@Override @Override
public void mouseDragged(MouseEvent event) public void mouseDragged(MouseEvent event)
{ {
if (frame.getSelectedPaintingMode() == 0) if (frame.getSelectedPaintingMode() == 0)
{ {
mouseClicked(event); mouseClicked(event);
} }
} }
} }

View File

@ -1,20 +1,20 @@
package galaxyoyo.unknown.frame.listeners; package galaxyoyo.gameengine.frame.listeners;
import galaxyoyo.unknown.api.editor.EditorAPI; import galaxyoyo.alice.gameengine.api.editor.EditorAPI;
import galaxyoyo.unknown.frame.MainFrame; import galaxyoyo.gameengine.frame.MainFrame;
import java.awt.event.ActionEvent; import java.awt.event.ActionEvent;
import java.awt.event.ActionListener; import java.awt.event.ActionListener;
public class OpenMapListener implements ActionListener public class OpenMapListener implements ActionListener
{ {
/* !CodeTemplates.overridecomment.nonjd! /* !CodeTemplates.overridecomment.nonjd!
* @see java.awt.event.ActionListener#actionPerformed(java.awt.event.ActionEvent) * @see java.awt.event.ActionListener#actionPerformed(java.awt.event.ActionEvent)
*/ */
@Override @Override
public void actionPerformed(ActionEvent event) public void actionPerformed(ActionEvent event)
{ {
if (EditorAPI.open() != null) if (EditorAPI.open() != null)
MainFrame.getInstance().dispose(); MainFrame.getInstance().dispose();
} }
} }

View File

@ -1,32 +1,32 @@
package galaxyoyo.unknown.frame.listeners; package galaxyoyo.gameengine.frame.listeners;
import galaxyoyo.unknown.editor.EditorFrame; import galaxyoyo.alice.gameengine.editor.EditorFrame;
import galaxyoyo.unknown.editor.SpriteComp; import galaxyoyo.alice.gameengine.editor.SpriteComp;
import java.awt.event.MouseAdapter; import java.awt.event.MouseAdapter;
import java.awt.event.MouseEvent; import java.awt.event.MouseEvent;
public class SpriteMouseListener extends MouseAdapter public class SpriteMouseListener extends MouseAdapter
{ {
private final SpriteComp sprite; private final SpriteComp sprite;
private final EditorFrame frame; private final EditorFrame frame;
public SpriteMouseListener(SpriteComp sprc, EditorFrame frame) public SpriteMouseListener(SpriteComp sprc, EditorFrame frame)
{ {
this.sprite = sprc; this.sprite = sprc;
this.frame = frame; this.frame = frame;
} }
@Override @Override
public void mouseReleased(MouseEvent event) public void mouseReleased(MouseEvent event)
{ {
if (frame.getSelectedSprite() != null) if (frame.getSelectedSprite() != null)
{ {
frame.getSelectedSprite().setSelected(false); frame.getSelectedSprite().setSelected(false);
frame.getSelectedSprite().repaint(); frame.getSelectedSprite().repaint();
} }
frame.setSelectedSprite(sprite); frame.setSelectedSprite(sprite);
sprite.setSelected(true); sprite.setSelected(true);
sprite.repaint(); sprite.repaint();
} }
} }

View File

@ -1,4 +0,0 @@
/**
* @author galaxyoyo
*/
package galaxyoyo.unknown.api.editor;