Reformat code

This commit is contained in:
Yohann D'ANELLO 2020-02-25 00:23:01 +01:00
parent 397a2c337a
commit 6795917373
27 changed files with 1994 additions and 2090 deletions

View File

@ -2,8 +2,7 @@ package fr.ynerant.leveleditor.api.editor;
import fr.ynerant.leveleditor.api.editor.sprites.Sprite;
public class Case
{
public class Case {
private int x;
private int y;
private Sprite couche1;
@ -11,38 +10,7 @@ public class Case
private Sprite couche3;
private Collision collision;
public int getPosX()
{
return x;
}
public int getPosY()
{
return y;
}
public Sprite getCoucheOne()
{
return couche1;
}
public Sprite getCoucheTwo()
{
return couche2;
}
public Sprite getCoucheThree()
{
return couche3;
}
public Collision getCollision()
{
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();
c.x = posX;
c.y = posY;
@ -53,9 +21,32 @@ public class Case
return c;
}
public int getPosX() {
return x;
}
public int getPosY() {
return y;
}
public Sprite getCoucheOne() {
return couche1;
}
public Sprite getCoucheTwo() {
return couche2;
}
public Sprite getCoucheThree() {
return couche3;
}
public Collision getCollision() {
return collision;
}
@Override
public String toString()
{
public String toString() {
return "{Case x=" + x + " y=" + y + " couche1=" + couche1 + " couche2=" + couche2 + " couche3=" + couche3 + " collision=" + collision.name().toUpperCase() + "}\n";
}
}

View File

@ -1,6 +1,5 @@
package fr.ynerant.leveleditor.api.editor;
public enum Collision
{
FULL, PARTIAL, ANY;
public enum Collision {
FULL, PARTIAL, ANY
}

View File

@ -1,39 +1,28 @@
package fr.ynerant.leveleditor.api.editor;
import com.google.gson.Gson;
import com.google.gson.GsonBuilder;
import fr.ynerant.leveleditor.editor.Map;
import java.awt.Color;
import java.awt.Graphics2D;
import javax.swing.*;
import javax.swing.filechooser.FileNameExtensionFilter;
import java.awt.*;
import java.awt.image.BufferedImage;
import java.io.BufferedInputStream;
import java.io.BufferedOutputStream;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.*;
import java.nio.charset.StandardCharsets;
import java.util.ArrayList;
import java.util.List;
import java.util.zip.GZIPInputStream;
import java.util.zip.GZIPOutputStream;
import javax.swing.JFileChooser;
import javax.swing.filechooser.FileNameExtensionFilter;
import com.google.gson.Gson;
import com.google.gson.GsonBuilder;
public class EditorAPI
{
public class EditorAPI {
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>();
for (int y = 1; y < height; y += 16)
{
for (int x = 1; x < width; x += 16)
{
for (int y = 1; y < height; y += 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);
cases.add(c);
}
@ -42,8 +31,7 @@ public class EditorAPI
return RawMap.create(cases, width, height);
}
public static Gson createGson()
{
public static Gson createGson() {
GsonBuilder builder = new GsonBuilder();
builder.enableComplexMapKeySerialization();
@ -53,8 +41,7 @@ public class EditorAPI
return builder.create();
}
public static JFileChooser createJFC()
{
public static JFileChooser createJFC() {
JFileChooser jfc = new JFileChooser();
jfc.setFileFilter(new FileNameExtensionFilter("Fichiers monde (*.gmap, *.dat)", "gmap", "dat"));
@ -67,8 +54,7 @@ public class EditorAPI
return jfc;
}
public static void saveAs(RawMap map)
{
public static void saveAs(RawMap map) {
JFileChooser jfc = createJFC();
File file = null;
jfc.showSaveDialog(null);
@ -77,8 +63,7 @@ public class EditorAPI
if (file == null)
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");
}
@ -87,35 +72,29 @@ public class EditorAPI
save(file, map);
}
public static void save(RawMap map)
{
public static void save(RawMap map) {
if (LAST_FILE != null)
save(LAST_FILE, map);
else
saveAs(map);
}
public static void save(File file, RawMap map)
{
public static void save(File file, RawMap map) {
String json = createGson().toJson(map);
try
{
try {
file.createNewFile();
BufferedOutputStream bos = new BufferedOutputStream(new GZIPOutputStream(new FileOutputStream(file)));
bos.write(json.getBytes("UTF-8"));
bos.write(json.getBytes(StandardCharsets.UTF_8));
bos.close();
}
catch (IOException ex)
{
} catch (IOException ex) {
ex.printStackTrace();
}
}
public static Map open()
{
public static Map open() {
JFileChooser jfc = createJFC();
File file = null;
@ -130,26 +109,21 @@ public class EditorAPI
return open(file);
}
public static Map open(File f)
{
public static Map open(File f) {
String json = null;
try
{
try {
GZIPInputStream gis = new GZIPInputStream(new BufferedInputStream(new FileInputStream(f)));
byte[] bytes = new byte[512*1024];
byte[] bytes = new byte[512 * 1024];
int count = 0;
String text = "";
while ((count = gis.read(bytes)) != -1)
{
text += new String(bytes, 0, count, "UTF-8");
while ((count = gis.read(bytes)) != -1) {
text += new String(bytes, 0, count, StandardCharsets.UTF_8);
}
gis.close();
bytes = null;
json = text;
}
catch (IOException e)
{
} catch (IOException e) {
e.printStackTrace();
}
@ -158,14 +132,12 @@ public class EditorAPI
return open(rm);
}
public static Map open(RawMap map)
{
if (map.getFont() == null)
{
public static Map open(RawMap map) {
if (map.getFont() == null) {
int baseWidth = map.getWidth();
int baseHeight = map.getHeight();
int width = baseWidth + ((int) baseWidth / 16) + 1;
int height = baseHeight + ((int) baseHeight / 16) + 1;
int width = baseWidth + (baseWidth / 16) + 1;
int height = baseHeight + (baseHeight / 16) + 1;
BufferedImage image = new BufferedImage(width, height, BufferedImage.TYPE_INT_ARGB);
Graphics2D g = image.createGraphics();
g.setColor(Color.white);
@ -173,13 +145,11 @@ public class EditorAPI
g.setColor(Color.black);
g.drawLine(0, 0, width, 0);
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);
}
for (int y = 17; y <= height; y += 17)
{
for (int y = 17; y <= height; y += 17) {
g.drawLine(0, y, width, y);
}

View File

@ -1,7 +1,6 @@
package fr.ynerant.leveleditor.api.editor;
public class RawCase
{
public class RawCase {
private int x;
private int y;
private RawSprite couche1;
@ -9,50 +8,18 @@ public class RawCase
private RawSprite couche3;
private Collision collision;
public int getPosX()
{
return x;
}
public int getPosY()
{
return y;
}
public RawSprite getCoucheOne()
{
return couche1;
}
public RawSprite getCoucheTwo()
{
return couche2;
}
public RawSprite getCoucheThree()
{
return couche3;
}
public Collision getCollision()
{
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();
c.x = posX;
c.y = posY;
c.couche1 = couche1;
c.couche2 = couche2;
c.couche3 = couche3;
c.collision = collision;;
c.collision = collision;
return c;
}
public static RawCase create(Case c)
{
public static RawCase create(Case c) {
RawCase raw = new RawCase();
raw.x = c.getPosX();
raw.y = c.getPosY();
@ -62,4 +29,28 @@ public class RawCase
raw.collision = c.getCollision();
return raw;
}
public int getPosX() {
return x;
}
public int getPosY() {
return y;
}
public RawSprite getCoucheOne() {
return couche1;
}
public RawSprite getCoucheTwo() {
return couche2;
}
public RawSprite getCoucheThree() {
return couche3;
}
public Collision getCollision() {
return collision;
}
}

View File

@ -6,30 +6,13 @@ import java.awt.image.BufferedImage;
import java.util.ArrayList;
import java.util.List;
public class RawMap
{
public class RawMap {
private List<RawCase> cases;
private int width;
private int height;
private transient BufferedImage font;
public List<RawCase> getCases()
{
return cases;
}
public int getWidth()
{
return width;
}
public int getHeight()
{
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();
rm.cases = cases;
rm.width = width;
@ -37,27 +20,35 @@ public class RawMap
return rm;
}
public BufferedImage getFont()
{
return font;
}
public void setFont(BufferedImage font)
{
this.font = font;
}
public static RawMap create(Map map)
{
public static RawMap create(Map map) {
RawMap raw = new RawMap();
raw.width = map.getWidth();
raw.height = map.getHeight();
raw.cases = new ArrayList<RawCase>();
for (Case c : map.getAllCases())
{
for (Case c : map.getAllCases()) {
RawCase rc = RawCase.create(c);
raw.cases.add(rc);
}
return raw;
}
public List<RawCase> getCases() {
return cases;
}
public int getWidth() {
return width;
}
public int getHeight() {
return height;
}
public BufferedImage getFont() {
return font;
}
public void setFont(BufferedImage font) {
this.font = font;
}
}

View File

@ -2,28 +2,23 @@ package fr.ynerant.leveleditor.api.editor;
import fr.ynerant.leveleditor.api.editor.sprites.Sprite;
public class RawSprite
{
public class RawSprite {
public static transient final RawSprite BLANK = new RawSprite();
private String category = "blank";
private int index = 0;
public static transient final RawSprite BLANK = new RawSprite();
public String getCategory()
{
return category;
}
public int getIndex()
{
return index;
}
public static RawSprite create(Sprite spr)
{
public static RawSprite create(Sprite spr) {
RawSprite raw = new RawSprite();
raw.category = spr.getCategory().getName();
raw.index = spr.getIndex();
return raw;
}
public String getCategory() {
return category;
}
public int getIndex() {
return index;
}
}

View File

@ -2,33 +2,15 @@ package fr.ynerant.leveleditor.api.editor.sprites;
import java.util.List;
public class Category
{
public class Category {
private List<Sprite> sprites;
private String name;
private int index;
private Category()
{
private Category() {
}
public String getName()
{
return name;
}
public List<Sprite> getSprites()
{
return sprites;
}
public int getIndex()
{
return index;
}
public static Category create(String name, int index, List<Sprite> sprites)
{
public static Category create(String name, int index, List<Sprite> sprites) {
Category c = new Category();
c.name = name;
@ -37,4 +19,16 @@ public class Category
return c;
}
public String getName() {
return name;
}
public List<Sprite> getSprites() {
return sprites;
}
public int getIndex() {
return index;
}
}

View File

@ -1,17 +1,13 @@
package fr.ynerant.leveleditor.api.editor.sprites;
import java.awt.AlphaComposite;
import java.awt.Color;
import java.awt.Graphics2D;
import java.awt.*;
import java.awt.image.BufferedImage;
import java.util.ArrayList;
public class Sprite
{
public class Sprite {
public static final Sprite BLANK = new Sprite(new BufferedImage(16, 16, BufferedImage.TYPE_INT_ARGB), Category.create("blank", 0, new ArrayList<Sprite>()), 0);
static
{
static {
Graphics2D g = BLANK.getImage().createGraphics();
g.setComposite(AlphaComposite.Clear);
g.setColor(new Color(0, true));
@ -22,8 +18,7 @@ public class Sprite
private final BufferedImage img;
private final int index;
public Sprite(BufferedImage img, Category cat, int index)
{
public Sprite(BufferedImage img, Category cat, int index) {
this.img = img;
this.cat = cat;
this.index = index;
@ -32,30 +27,25 @@ public class Sprite
this.cat.getSprites().add(this);
}
public BufferedImage getImage()
{
public BufferedImage getImage() {
return this.img;
}
public Category getCategory()
{
public Category getCategory() {
return cat;
}
public int getIndex()
{
public int getIndex() {
return index;
}
@Override
public int hashCode()
{
public int hashCode() {
return cat.hashCode() ^ getIndex();
}
@Override
public boolean equals(Object o)
{
public boolean equals(Object o) {
if (!(o instanceof Sprite))
return false;
@ -65,8 +55,7 @@ public class Sprite
}
@Override
public String toString()
{
public String toString() {
return "{Sprite img=" + img + " cat=" + cat.getName() + "}";
}
}

View File

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

View File

@ -3,16 +3,21 @@
*/
package fr.ynerant.leveleditor.client.main;
import fr.ynerant.leveleditor.frame.MainFrame;
import fr.ynerant.leveleditor.api.editor.EditorAPI;
import fr.ynerant.leveleditor.api.editor.RawMap;
import fr.ynerant.leveleditor.api.editor.sprites.SpriteRegister;
import fr.ynerant.leveleditor.frame.MainFrame;
import joptsimple.OptionParser;
import joptsimple.OptionSet;
import joptsimple.OptionSpec;
import org.apache.logging.log4j.Level;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.core.Logger;
import org.apache.logging.log4j.core.appender.ConsoleAppender;
import org.apache.logging.log4j.core.layout.PatternLayout;
import java.awt.Color;
import java.awt.Desktop;
import java.awt.Graphics2D;
import java.awt.GraphicsEnvironment;
import java.awt.HeadlessException;
import javax.swing.*;
import java.awt.*;
import java.awt.image.BufferedImage;
import java.io.File;
import java.io.IOException;
@ -21,28 +26,16 @@ import java.net.URL;
import java.util.Locale;
import java.util.Map;
import javax.swing.JOptionPane;
import javax.swing.UIManager;
import joptsimple.OptionParser;
import joptsimple.OptionSet;
import joptsimple.OptionSpec;
import org.apache.logging.log4j.Level;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.core.Logger;
import org.apache.logging.log4j.core.appender.ConsoleAppender;
import org.apache.logging.log4j.core.layout.PatternLayout;
/**
* Class principale qui lance le jeu
*
* @author ÿnérant
* @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.
*
* @see #isInDebugMode()
* @see #main(String...)
* @since 0.1-aplha
@ -51,6 +44,7 @@ public class Main
/**
* Variable disant si le jeu est lanc&eacute; en d&eacute;veloppement ou non.
*
* @see #isInDevelopmentMode()
* @see #main(String...)
* @since 0.1-aplha
@ -62,30 +56,23 @@ public class Main
* @see #launchEditMode()
* @since 0.1-alpha
*/
public static void main(String ... args)
{
public static void main(String... args) {
System.setProperty("sun.java2d.noddraw", "true");
Locale.setDefault(Locale.FRANCE);
try
{
try {
UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());
}
catch (Exception e)
{
} catch (Exception e) {
new ExceptionInInitializerError("Erreur lors du changement de 'look and feel'").printStackTrace();
System.err.print("Caused by ");
e.printStackTrace();
}
try
{
try {
new File(Main.class.getResource("/assets").toURI());
DEV = true;
}
catch (Throwable t)
{
} catch (Throwable t) {
DEV = false;
}
@ -105,45 +92,33 @@ public class Main
OptionSet set = parser.parse(args);
if (set.has(help))
{
try
{
if (set.has(help)) {
try {
parser.printHelpOn(System.out);
}
catch (IOException e)
{
} catch (IOException e) {
e.printStackTrace();
}
finally
{
} finally {
System.exit(0);
}
}
if (set.has(debug))
{
if (set.has(debug)) {
DEBUG = set.valueOf(debug);
if (DEBUG)
{
if (DEBUG) {
LOGGER.setLevel(Level.ALL);
}
}
try
{
try {
SpriteRegister.unpack();
}
catch (IOException | URISyntaxException e)
{
} catch (IOException | URISyntaxException e) {
e.printStackTrace();
}
SpriteRegister.refreshAllSprites();
if (set.has(edit))
{
if (set.has(edit)) {
launchEditMode();
return;
}
@ -151,34 +126,26 @@ public class Main
launchFrame();
}
private static void checkJava()
{
if (GraphicsEnvironment.isHeadless())
{
private static void checkJava() {
if (GraphicsEnvironment.isHeadless()) {
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").catching(Level.FATAL, ex);
System.exit(1);
}
try
{
try {
Map.class.getDeclaredMethod("getOrDefault", Object.class, Object.class);
}
catch (NoSuchMethodException ex)
{
} catch (NoSuchMethodException ex) {
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>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())
Desktop.getDesktop().browse(new URL("http://java.com/download").toURI());
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>");
}
catch (IOException | URISyntaxException e)
{
} catch (IOException | URISyntaxException e) {
e.printStackTrace();
}
System.exit(1);
@ -187,32 +154,30 @@ public class Main
/**
* Lance la fen&ecirc;tre principale
*
* @see #main(String...)
* @see #launchEditMode()
*/
private static void launchFrame()
{
private static void launchFrame() {
MainFrame.getInstance().setVisible(true);
}
/**
* Permet de lancer l'&eacute;diteur de carte
*
* @return
* @see #main(String...)
* @see #launchFrame()
* @since 0.1-aplha
*/
public static boolean launchEditMode()
{
public static boolean launchEditMode() {
System.out.println("Lancement de l'\u00e9diteur de monde ...");
int baseWidth;
int baseHeight;
int width;
int height;
while (true)
{
try
{
while (true) {
try {
String baseWidthStr = JOptionPane.showInputDialog(null, "Veuillez entrez le nombre de cases longueur de votre carte (0 pour annuler) :");
if (baseWidthStr == null)
return false;
@ -222,17 +187,13 @@ public class Main
if (baseWidth == 0)
return false;
break;
}
catch (NumberFormatException ex)
{
} catch (NumberFormatException ex) {
continue;
}
}
while (true)
{
try
{
while (true) {
try {
String baseHeightStr = JOptionPane.showInputDialog("Veuillez entrez le nombre de cases hauteur de votre carte (0 pour annuler) :");
if (baseHeightStr == null)
return false;
@ -242,15 +203,13 @@ public class Main
if (baseHeight == 0)
return false;
break;
}
catch (NumberFormatException ex)
{
} catch (NumberFormatException ex) {
continue;
}
}
width = baseWidth + ((int) baseWidth / 16) + 1;
height = baseHeight + ((int) baseHeight / 16) + 1;
width = baseWidth + (baseWidth / 16) + 1;
height = baseHeight + (baseHeight / 16) + 1;
BufferedImage image = new BufferedImage(width, height, BufferedImage.TYPE_INT_ARGB);
Graphics2D g = image.createGraphics();
@ -259,13 +218,11 @@ public class Main
g.setColor(Color.black);
g.drawLine(0, 0, width, 0);
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);
}
for (int y = 17; y <= height; y += 17)
{
for (int y = 17; y <= height; y += 17) {
g.drawLine(0, y, width, y);
}
@ -279,22 +236,22 @@ public class Main
/**
* 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
* @since 0.1-aplha
*/
public static boolean isInDebugMode()
{
public static boolean isInDebugMode() {
return DEBUG;
}
/**
* Accesseur disant si le jeu est lanc&eacute; en d&eacute;veloppement ou non.
*
* @see #DEV
* @since 0.1-alpha
*/
public static boolean isInDevelopmentMode()
{
public static boolean isInDevelopmentMode() {
return DEV;
}
}

View File

@ -1,5 +1,7 @@
/**
* Ce package comprend uniquement la classe Main, qui lance l'application.
*
* @author ÿnérant
*/
/**
* @author ÿnérant

View File

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

View File

@ -5,40 +5,17 @@ import fr.ynerant.leveleditor.api.editor.RawMap;
import fr.ynerant.leveleditor.api.editor.sprites.Category;
import fr.ynerant.leveleditor.api.editor.sprites.Sprite;
import fr.ynerant.leveleditor.api.editor.sprites.SpriteRegister;
import fr.ynerant.leveleditor.frame.listeners.CollidMapMouseListener;
import fr.ynerant.leveleditor.frame.listeners.CreateMapListener;
import fr.ynerant.leveleditor.frame.listeners.MapMouseListener;
import fr.ynerant.leveleditor.frame.listeners.OpenMapListener;
import fr.ynerant.leveleditor.frame.listeners.SpriteMouseListener;
import fr.ynerant.leveleditor.frame.listeners.*;
import java.awt.BorderLayout;
import java.awt.Color;
import java.awt.Dimension;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.KeyEvent;
import java.awt.event.WindowEvent;
import java.awt.event.WindowListener;
import javax.swing.*;
import javax.swing.event.ChangeEvent;
import javax.swing.event.ChangeListener;
import java.awt.*;
import java.awt.event.*;
import java.awt.image.BufferedImage;
import java.io.File;
import javax.swing.ButtonGroup;
import javax.swing.ImageIcon;
import javax.swing.JFrame;
import javax.swing.JMenu;
import javax.swing.JMenuBar;
import javax.swing.JMenuItem;
import javax.swing.JOptionPane;
import javax.swing.JPanel;
import javax.swing.JRadioButtonMenuItem;
import javax.swing.JScrollPane;
import javax.swing.JTabbedPane;
import javax.swing.KeyStroke;
import javax.swing.event.ChangeEvent;
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 final Map map;
@ -54,7 +31,6 @@ public class EditorFrame extends JFrame implements ChangeListener, ActionListene
private final JMenuItem saveAs = new JMenuItem("Sauvegarder sous ...");
private final JMenuItem exit = new JMenuItem("Quitter");
private final JMenu selectionMode = new JMenu("Mode de s\u00e9lection");
ButtonGroup group = new ButtonGroup();
private final JRadioButtonMenuItem pen = new JRadioButtonMenuItem("Pinceau");
private final JRadioButtonMenuItem pot = new JRadioButtonMenuItem("Pot de peinture");
private final JTabbedPane tabs = new JTabbedPane();
@ -65,11 +41,11 @@ public class EditorFrame extends JFrame implements ChangeListener, ActionListene
private final JPanel couche1 = new JPanel();
private final JPanel couche2 = new JPanel();
private final JPanel couche3 = new JPanel();
ButtonGroup group = new ButtonGroup();
private SpriteComp selectedSprite;
public EditorFrame(Map map)
{
super ("Alice Game Engine");
public EditorFrame(Map map) {
super("Alice Game Engine");
this.map = map;
this.setSize(600, 600);
this.setPreferredSize(getSize());
@ -178,28 +154,23 @@ public class EditorFrame extends JFrame implements ChangeListener, ActionListene
repaint();
}
private void drawResources()
{
private void drawResources() {
couche1.removeAll();
couche2.removeAll();
couche3.removeAll();
if (couche1.getComponents().length > 0)
{
if (couche1.getComponents().length > 0) {
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();
couche3.repaint();
}
for (Category cat : SpriteRegister.getAllCategories())
{
for (Sprite spr : cat.getSprites())
{
for (Category cat : SpriteRegister.getAllCategories()) {
for (Sprite spr : cat.getSprites()) {
SpriteComp sprc1 = new SpriteComp(spr, 0);
SpriteComp sprc2 = new SpriteComp(spr, 1);
SpriteComp sprc3 = new SpriteComp(spr, 2);
@ -220,8 +191,7 @@ public class EditorFrame extends JFrame implements ChangeListener, ActionListene
couche3.repaint();
}
public void resize()
{
public void resize() {
int cursorPos = ((JScrollPane) resources.getSelectedComponent()).getVerticalScrollBar().getValue();
tabs.setPreferredSize(new Dimension(getWidth(), getHeight() / 5));
@ -249,49 +219,37 @@ public class EditorFrame extends JFrame implements ChangeListener, ActionListene
((JScrollPane) resources.getSelectedComponent()).getVerticalScrollBar().setValue(cursorPos);
}
public Map getMap()
{
public Map getMap() {
return map;
}
public SpriteComp getSelectedSprite()
{
public SpriteComp getSelectedSprite() {
return selectedSprite;
}
public void setSelectedSprite(SpriteComp sprite)
{
public void setSelectedSprite(SpriteComp sprite) {
this.selectedSprite = sprite;
}
@Override
public void stateChanged(ChangeEvent event)
{
if (event.getSource() == resources)
{
if (getSelectedLayerIndex() == 0)
{
public void stateChanged(ChangeEvent event) {
if (event.getSource() == resources) {
if (getSelectedLayerIndex() == 0) {
resources.setBackgroundAt(0, 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(2, Color.white);
}
else if (getSelectedLayerIndex() == 2)
{
} else if (getSelectedLayerIndex() == 2) {
resources.setBackgroundAt(0, Color.black);
resources.setBackgroundAt(1, Color.black);
resources.setBackgroundAt(2, Color.white);
}
repaint();
}
else if (event.getSource() == tabs)
{
} else if (event.getSource() == tabs) {
resources.setEnabled(tabs.getSelectedIndex() == 0);
couche1.setEnabled(resources.isEnabled());
couche2.setEnabled(resources.isEnabled());
@ -301,24 +259,17 @@ public class EditorFrame extends JFrame implements ChangeListener, ActionListene
}
}
public int getSelectedLayerIndex()
{
public int getSelectedLayerIndex() {
return resources.getSelectedIndex();
}
@Override
public void actionPerformed(ActionEvent event)
{
if (event.getSource() == save)
{
public void actionPerformed(ActionEvent event) {
if (event.getSource() == save) {
EditorAPI.save(RawMap.create(map));
}
else if (event.getSource() == saveAs)
{
} else if (event.getSource() == saveAs) {
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);
if (result == 0)
@ -329,54 +280,44 @@ public class EditorFrame extends JFrame implements ChangeListener, ActionListene
}
}
public int getSelectedPaintingMode()
{
public int getSelectedPaintingMode() {
return pen.isSelected() ? 0 : pot.isSelected() ? 1 : -1;
}
@Override
public void windowActivated(WindowEvent event)
{
public void windowActivated(WindowEvent event) {
}
@Override
public void windowClosed(WindowEvent event)
{
public void windowClosed(WindowEvent event) {
}
@Override
public void windowClosing(WindowEvent event)
{
public void windowClosing(WindowEvent event) {
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));
}
if (result != 2)
{
if (result != 2) {
dispose();
}
}
@Override
public void windowDeactivated(WindowEvent event)
{
public void windowDeactivated(WindowEvent event) {
}
@Override
public void windowDeiconified(WindowEvent event)
{
public void windowDeiconified(WindowEvent event) {
}
@Override
public void windowIconified(WindowEvent event)
{
public void windowIconified(WindowEvent event) {
}
@Override
public void windowOpened(WindowEvent event)
{
public void windowOpened(WindowEvent event) {
}
}

View File

@ -10,8 +10,7 @@ import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
public class Map
{
public class Map {
@Deprecated
private static List<Case> cases;
private final EditorFrame frame;
@ -20,15 +19,13 @@ public class Map
private java.util.Map<Integer, java.util.Map<Integer, Case>> casesMap = new HashMap<Integer, java.util.Map<Integer, Case>>();
private transient BufferedImage font;
public Map(RawMap raw)
{
public Map(RawMap raw) {
cases = new ArrayList<Case>();
this.width = raw.getWidth();
this.height = raw.getHeight();
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()));
}
@ -39,60 +36,48 @@ public class Map
getFrame().setVisible(true);
}
public EditorFrame getFrame()
{
public EditorFrame getFrame() {
return frame;
}
public int getWidth()
{
public int getWidth() {
return width;
}
public int getHeight()
{
public int getHeight() {
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);
}
public void setCase(int x, int y, Case c)
{
public void setCase(int x, int y, Case c) {
casesMap.get(x).put(y, c);
}
public BufferedImage getFont()
{
public BufferedImage getFont() {
return font;
}
public void setFont(BufferedImage font)
{
public void setFont(BufferedImage font) {
this.font = font;
}
private void reorganizeMap()
{
for (int i = 0; i < width; ++i)
{
private void reorganizeMap() {
for (int i = 0; i < width; ++i) {
casesMap.put(i, new HashMap<Integer, Case>());
}
for (Case c : cases)
{
for (Case c : cases) {
setCase(c.getPosX(), c.getPosY(), c);
}
}
public List<Case> getAllCases()
{
public List<Case> getAllCases() {
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());
}

View File

@ -2,36 +2,30 @@ package fr.ynerant.leveleditor.editor;
import fr.ynerant.leveleditor.api.editor.Case;
import java.awt.Graphics;
import javax.swing.*;
import java.awt.*;
import java.awt.image.BufferedImage;
import javax.swing.JPanel;
public class MapPanel extends JPanel
{
public class MapPanel extends JPanel {
private static final long serialVersionUID = 2629019576253690557L;
private final EditorFrame frame;
public MapPanel(EditorFrame frame)
{
super ();
public MapPanel(EditorFrame frame) {
super();
this.frame = frame;
}
public EditorFrame getFrame()
{
public EditorFrame getFrame() {
return frame;
}
public Map getMap()
{
public Map getMap() {
return frame.getMap();
}
@Override
public void paintComponent(Graphics g)
{
public void paintComponent(Graphics g) {
g.fillRect(0, 0, getWidth(), getHeight());
BufferedImage img = getMap().getFont();
int x = getWidth() / 2 - img.getWidth();
@ -40,12 +34,10 @@ public class MapPanel extends JPanel
int height = img.getHeight() * 2;
g.drawImage(getMap().getFont(), x, y, width, height, null);
for (Case c : getMap().getAllCases())
{
for (Case c : getMap().getAllCases()) {
// 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);
}
/* if (frame.getSelectedLayerIndex() != 0)
@ -54,8 +46,7 @@ public class MapPanel extends JPanel
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);
}
/* if (frame.getSelectedLayerIndex() != 1)
@ -64,8 +55,7 @@ public class MapPanel extends JPanel
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);
}
/* if (frame.getSelectedLayerIndex() != 2)
@ -76,14 +66,11 @@ public class MapPanel extends JPanel
}
}
private boolean isEmpty(BufferedImage image)
{
private boolean isEmpty(BufferedImage image) {
int allrgba = 0;
for (int x = 0; x < image.getWidth(); ++x)
{
for (int y = 0; y < image.getHeight(); ++y)
{
for (int x = 0; x < image.getWidth(); ++x) {
for (int y = 0; y < image.getHeight(); ++y) {
allrgba += image.getRGB(x, y) + 1;
}
}

View File

@ -2,23 +2,18 @@ package fr.ynerant.leveleditor.editor;
import fr.ynerant.leveleditor.api.editor.sprites.Sprite;
import java.awt.Color;
import java.awt.Dimension;
import java.awt.Graphics;
import javax.swing.*;
import java.awt.*;
import javax.swing.JComponent;
public class SpriteComp extends JComponent
{
public class SpriteComp extends JComponent {
private static final long serialVersionUID = -6512257366877053285L;
private Sprite sprite;
private int couche;
private boolean selected;
public SpriteComp(Sprite sprite, int couche)
{
super ();
public SpriteComp(Sprite sprite, int couche) {
super();
this.sprite = sprite;
this.couche = couche;
this.setMinimumSize(new Dimension(32, 32));
@ -29,47 +24,39 @@ public class SpriteComp extends JComponent
repaint();
}
public Sprite getSprite()
{
public Sprite getSprite() {
return sprite;
}
public void setSprite(Sprite s)
{
public void setSprite(Sprite s) {
this.sprite = s;
}
public int getCouche()
{
public int getCouche() {
return couche;
}
public void setCouche(int couche)
{
public void setCouche(int couche) {
this.couche = couche;
}
public boolean isSelected()
{
public boolean isSelected() {
return selected;
}
public void setSelected(boolean selected)
{
public void setSelected(boolean selected) {
this.selected = selected;
}
@Override
public void paintComponent(Graphics g)
{
public void paintComponent(Graphics g) {
super.paintComponent(g);
g.setColor(Color.white);
g.fillRect(0, 0, getWidth(), getHeight());
g.drawImage(sprite.getImage(), 0, 0, 32, 32, Color.white, null);
if (isSelected())
{
if (isSelected()) {
g.setColor(Color.black);
g.drawLine(0, 0, getWidth() - 1, 0);
g.drawLine(0, 0, 0, getHeight() - 1);

View File

@ -1,46 +1,37 @@
package fr.ynerant.leveleditor.editor;
import javax.swing.*;
import java.awt.*;
import javax.swing.JScrollPane;
import javax.swing.SwingUtilities;
public class WrapLayout extends FlowLayout
{
public class WrapLayout extends FlowLayout {
private static final long serialVersionUID = 8777237960365591646L;
public WrapLayout()
{
public WrapLayout() {
super();
}
public WrapLayout(int align)
{
public WrapLayout(int align) {
super(align);
}
public WrapLayout(int align, int hgap, int vgap)
{
public WrapLayout(int align, int hgap, int vgap) {
super(align, hgap, vgap);
}
@Override
public Dimension preferredLayoutSize(Container target)
{
public Dimension preferredLayoutSize(Container target) {
return layoutSize(target, true);
}
@Override
public Dimension minimumLayoutSize(Container target)
{
public Dimension minimumLayoutSize(Container target) {
Dimension minimum = layoutSize(target, false);
minimum.width -= (getHgap() + 1);
return minimum;
}
private Dimension layoutSize(Container target, boolean preferred)
{
synchronized (target.getTreeLock())
{
private Dimension layoutSize(Container target, boolean preferred) {
synchronized (target.getTreeLock()) {
int targetWidth = target.getSize().width;
if (targetWidth == 0)
@ -58,23 +49,19 @@ public class WrapLayout extends FlowLayout
int nmembers = target.getComponentCount();
for (int i = 0; i < nmembers; i++)
{
for (int i = 0; i < nmembers; i++) {
Component m = target.getComponent(i);
if (m.isVisible())
{
if (m.isVisible()) {
Dimension d = preferred ? m.getPreferredSize() : m.getMinimumSize();
if (rowWidth + d.width > maxWidth)
{
if (rowWidth + d.width > maxWidth) {
addRow(dim, rowWidth, rowHeight);
rowWidth = 0;
rowHeight = 0;
}
if (rowWidth != 0)
{
if (rowWidth != 0) {
rowWidth += hgap;
}
@ -89,8 +76,7 @@ public class WrapLayout extends FlowLayout
dim.height += insets.top + insets.bottom + vgap * 2;
Container scrollPane = SwingUtilities.getAncestorOfClass(JScrollPane.class, target);
if (scrollPane != null)
{
if (scrollPane != null) {
dim.width -= (hgap + 1);
}
@ -98,12 +84,10 @@ public class WrapLayout extends FlowLayout
}
}
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);
if (dim.height > 0)
{
if (dim.height > 0) {
dim.height += getVgap();
}

View File

@ -7,32 +7,29 @@ import fr.ynerant.leveleditor.client.main.Main;
import fr.ynerant.leveleditor.frame.listeners.ChangeLAFListener;
import fr.ynerant.leveleditor.frame.listeners.CreateMapListener;
import fr.ynerant.leveleditor.frame.listeners.OpenMapListener;
import java.awt.Dimension;
import java.awt.event.KeyEvent;
import javax.swing.JFrame;
import javax.swing.JMenu;
import javax.swing.JMenuBar;
import javax.swing.JMenuItem;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.core.Logger;
import javax.swing.*;
import java.awt.*;
import java.awt.event.KeyEvent;
/**
* Fen&ecirc;tre principale du jeu
*
* @author ÿnérant
*/
public class MainFrame extends JFrame
{
public class MainFrame extends JFrame {
/**
* ID de s&eacute;rie
*
* @see {@link JFrame}
*/
private static final long serialVersionUID = -3168760121879418534L;
/**
* Instance unique principale
*
* @see #MainFrame()
* @see #getInstance()
*/
@ -40,6 +37,7 @@ public class MainFrame extends JFrame
/**
* Logger de la classe
*
* @see LogManager#getLogger(String)
*/
private static Logger LOGGER = (Logger) LogManager.getLogger("MainFrame");
@ -57,12 +55,12 @@ public class MainFrame extends JFrame
/**
* Constructeur
*
* @see Main#launchFrame()
*/
@SuppressWarnings("JavadocReference")
private MainFrame()
{
super ();
private MainFrame() {
super();
LOGGER.info("Initialisation de la fen\u00eatre");
this.setTitle("Alice Game Engine");
this.setPreferredSize(new Dimension(1000, 800));
@ -98,12 +96,12 @@ public class MainFrame extends JFrame
/**
* Cet accesseur renvoie l'accesseur unique de la classe
*
* @return l'instance unique de la classe
* @see #INSTANCE
* @see #MainFrame()
* @return l'instance unique de la classe
*/
public static MainFrame getInstance()
{
public static MainFrame getInstance() {
if (INSTANCE == null)
return INSTANCE = new MainFrame();

View File

@ -2,64 +2,43 @@ package fr.ynerant.leveleditor.frame.listeners;
import fr.ynerant.leveleditor.frame.MainFrame;
import javax.swing.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import javax.swing.JFrame;
import javax.swing.JMenuItem;
import javax.swing.SwingUtilities;
import javax.swing.UIManager;
public class ChangeLAFListener implements ActionListener
{
public class ChangeLAFListener implements ActionListener {
private final JMenuItem item;
private final JFrame frame;
public ChangeLAFListener(JMenuItem LAF, MainFrame f)
{
public ChangeLAFListener(JMenuItem LAF, MainFrame f) {
this.item = LAF;
this.frame = f;
}
@Override
public void actionPerformed(ActionEvent event)
{
if (item.getText().toLowerCase().contains("sys"))
{
try
{
public void actionPerformed(ActionEvent event) {
if (item.getText().toLowerCase().contains("sys")) {
try {
UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());
}
catch (Exception e)
{
} catch (Exception e) {
new ExceptionInInitializerError("Erreur lors du changement de 'look and feel'").printStackTrace();
System.err.print("Caused by ");
e.printStackTrace();
}
SwingUtilities.updateComponentTreeUI(frame);
}
else if (item.getText().toLowerCase().contains("java"))
{
try
{
} else if (item.getText().toLowerCase().contains("java")) {
try {
UIManager.setLookAndFeel(UIManager.getCrossPlatformLookAndFeelClassName());
}
catch (Exception e)
{
} catch (Exception e) {
new ExceptionInInitializerError("Erreur lors du changement de 'look and feel'").printStackTrace();
System.err.print("Caused by ");
e.printStackTrace();
}
SwingUtilities.updateComponentTreeUI(frame);
}
else if (item.getText().toLowerCase().contains("sombre"))
{
try
{
} else if (item.getText().toLowerCase().contains("sombre")) {
try {
UIManager.setLookAndFeel("com.sun.java.swing.plaf.motif.MotifLookAndFeel");
}
catch (Exception e)
{
} catch (Exception e) {
new ExceptionInInitializerError("Erreur lors du changement de 'look and feel'").printStackTrace();
System.err.print("Caused by ");
e.printStackTrace();

View File

@ -9,33 +9,28 @@ import fr.ynerant.leveleditor.editor.Map;
import java.awt.event.MouseAdapter;
import java.awt.event.MouseEvent;
public class CollidMapMouseListener extends MouseAdapter
{
public class CollidMapMouseListener extends MouseAdapter {
private final EditorFrame frame;
private final CollidPanel panel;
public CollidMapMouseListener(CollidPanel panel, EditorFrame frame)
{
public CollidMapMouseListener(CollidPanel panel, EditorFrame frame) {
this.frame = frame;
this.panel = panel;
}
public EditorFrame getFrame()
{
public EditorFrame getFrame() {
return frame;
}
@Override
public void mouseReleased(MouseEvent event)
{
public void mouseReleased(MouseEvent event) {
Map map = getFrame().getMap();
int x = panel.getWidth() / 2 - map.getFont().getWidth();
int y = panel.getHeight() / 2 - map.getFont().getHeight();
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 newColIndex = colIndex + 1;
if (newColIndex >= Collision.values().length)

View File

@ -12,14 +12,12 @@ import java.awt.event.ActionListener;
/**
* @author ÿnérant
*/
public class CreateMapListener implements ActionListener
{
public class CreateMapListener implements ActionListener {
/* !CodeTemplates.overridecomment.nonjd!
* @see java.awt.event.ActionListener#actionPerformed(java.awt.event.ActionEvent)
*/
@Override
public void actionPerformed(ActionEvent event)
{
public void actionPerformed(ActionEvent event) {
if (Main.launchEditMode())
MainFrame.getInstance().dispose();
}

View File

@ -8,71 +8,74 @@ import fr.ynerant.leveleditor.editor.MapPanel;
import java.awt.event.MouseAdapter;
import java.awt.event.MouseEvent;
public class MapMouseListener extends MouseAdapter
{
public class MapMouseListener extends MouseAdapter {
private final EditorFrame frame;
private final MapPanel panel;
public MapMouseListener(MapPanel panel, EditorFrame frame)
{
public MapMouseListener(MapPanel panel, EditorFrame frame) {
this.frame = frame;
this.panel = panel;
}
public EditorFrame getFrame()
{
public EditorFrame getFrame() {
return frame;
}
@Override
public void mouseClicked(MouseEvent event)
{
if (frame.getSelectedPaintingMode() == 0)
{
public void mouseClicked(MouseEvent event) {
if (frame.getSelectedPaintingMode() == 0) {
Map map = getFrame().getMap();
int x = panel.getWidth() / 2 - map.getFont().getWidth();
int y = panel.getHeight() / 2 - map.getFont().getHeight();
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 (getFrame().getSelectedSprite() != 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 (getFrame().getSelectedSprite() != null) {
Case n;
switch (getFrame().getSelectedSprite().getCouche())
{
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 2 : n = Case.create(c.getPosX(), c.getPosY(), c.getCoucheOne(), c.getCoucheTwo(), getFrame().getSelectedSprite().getSprite(), c.getCollision()); break;
default : n = c; break;
switch (getFrame().getSelectedSprite().getCouche()) {
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 2:
n = Case.create(c.getPosX(), c.getPosY(), c.getCoucheOne(), c.getCoucheTwo(), getFrame().getSelectedSprite().getSprite(), c.getCollision());
break;
default:
n = c;
break;
}
map.setCase(n.getPosX(), n.getPosY(), n);
panel.repaint();
}
}
}
else if (frame.getSelectedPaintingMode() == 1)
{
for (Case c : getFrame().getMap().getAllCases())
{
} else if (frame.getSelectedPaintingMode() == 1) {
for (Case c : getFrame().getMap().getAllCases()) {
Map map = getFrame().getMap();
if (getFrame().getSelectedSprite() != null)
{
if (getFrame().getSelectedSprite() != null) {
if (getFrame().getSelectedSprite().getCouche() - 1 > getFrame().getSelectedLayerIndex())
return;
Case n;
switch (getFrame().getSelectedSprite().getCouche())
{
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 2 : n = Case.create(c.getPosX(), c.getPosY(), c.getCoucheOne(), c.getCoucheTwo(), getFrame().getSelectedSprite().getSprite(), c.getCollision()); break;
default : n = c; break;
switch (getFrame().getSelectedSprite().getCouche()) {
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 2:
n = Case.create(c.getPosX(), c.getPosY(), c.getCoucheOne(), c.getCoucheTwo(), getFrame().getSelectedSprite().getSprite(), c.getCollision());
break;
default:
n = c;
break;
}
map.setCase(n.getPosX(), n.getPosY(), n);
@ -84,10 +87,8 @@ public class MapMouseListener extends MouseAdapter
}
@Override
public void mouseDragged(MouseEvent event)
{
if (frame.getSelectedPaintingMode() == 0)
{
public void mouseDragged(MouseEvent event) {
if (frame.getSelectedPaintingMode() == 0) {
mouseClicked(event);
}
}

View File

@ -6,14 +6,12 @@ import fr.ynerant.leveleditor.frame.MainFrame;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
public class OpenMapListener implements ActionListener
{
public class OpenMapListener implements ActionListener {
/* !CodeTemplates.overridecomment.nonjd!
* @see java.awt.event.ActionListener#actionPerformed(java.awt.event.ActionEvent)
*/
@Override
public void actionPerformed(ActionEvent event)
{
public void actionPerformed(ActionEvent event) {
if (EditorAPI.open() != null)
MainFrame.getInstance().dispose();
}

View File

@ -6,22 +6,18 @@ import fr.ynerant.leveleditor.editor.SpriteComp;
import java.awt.event.MouseAdapter;
import java.awt.event.MouseEvent;
public class SpriteMouseListener extends MouseAdapter
{
public class SpriteMouseListener extends MouseAdapter {
private final SpriteComp sprite;
private final EditorFrame frame;
public SpriteMouseListener(SpriteComp sprc, EditorFrame frame)
{
public SpriteMouseListener(SpriteComp sprc, EditorFrame frame) {
this.sprite = sprc;
this.frame = frame;
}
@Override
public void mouseReleased(MouseEvent event)
{
if (frame.getSelectedSprite() != null)
{
public void mouseReleased(MouseEvent event) {
if (frame.getSelectedSprite() != null) {
frame.getSelectedSprite().setSelected(false);
frame.getSelectedSprite().repaint();
}

View File

@ -1,85 +1,322 @@
{
"blank": [
[0,0]
[
0,
0
]
],
"gazon": [
[0,0],
[0,16],
[0,32],
[0,48],
[0,64],
[0,144],
[0,160],
[0,176],
[16,144],
[32,144],
[16,160],
[32,160],
[32,224],
[48,224],
[64,224],
[80,224],
[96,224],
[112,224],
[112,208],
[159,48],
[160,166],
[176,166],
[128,144],
[128,160],
[144,80],
[48,36],
[64,36],
[54,53],
[70,53],
[48,70],
[16,28],
[16,16],
[16,32],
[16,48],
[16,64],
[16,80],
[32,16],
[32,32],
[32,48],
[32,64],
[32,80],
[48,64],
[48,80],
[64,64],
[64,80],
[80,64],
[80,80],
[96,64],
[96,80],
[112,64],
[112,80],
[128,80],
[128,64],
[112,48],
[128,48],
[112,32],
[128,32],
[112,16],
[128,16],
[64,128],
[80,128],
[96,128],
[48,144],
[64,144],
[80,144],
[96,144],
[48,160],
[96,160],
[48,176],
[96,176],
[32,176],
[112,176],
[64,160],
[80,160],
[64,176],
[80,176],
[64,192],
[80,192]
[
0,
0
],
[
0,
16
],
[
0,
32
],
[
0,
48
],
[
0,
64
],
[
0,
144
],
[
0,
160
],
[
0,
176
],
[
16,
144
],
[
32,
144
],
[
16,
160
],
[
32,
160
],
[
32,
224
],
[
48,
224
],
[
64,
224
],
[
80,
224
],
[
96,
224
],
[
112,
224
],
[
112,
208
],
[
159,
48
],
[
160,
166
],
[
176,
166
],
[
128,
144
],
[
128,
160
],
[
144,
80
],
[
48,
36
],
[
64,
36
],
[
54,
53
],
[
70,
53
],
[
48,
70
],
[
16,
28
],
[
16,
16
],
[
16,
32
],
[
16,
48
],
[
16,
64
],
[
16,
80
],
[
32,
16
],
[
32,
32
],
[
32,
48
],
[
32,
64
],
[
32,
80
],
[
48,
64
],
[
48,
80
],
[
64,
64
],
[
64,
80
],
[
80,
64
],
[
80,
80
],
[
96,
64
],
[
96,
80
],
[
112,
64
],
[
112,
80
],
[
128,
80
],
[
128,
64
],
[
112,
48
],
[
128,
48
],
[
112,
32
],
[
128,
32
],
[
112,
16
],
[
128,
16
],
[
64,
128
],
[
80,
128
],
[
96,
128
],
[
48,
144
],
[
64,
144
],
[
80,
144
],
[
96,
144
],
[
48,
160
],
[
96,
160
],
[
48,
176
],
[
96,
176
],
[
32,
176
],
[
112,
176
],
[
64,
160
],
[
80,
160
],
[
64,
176
],
[
80,
176
],
[
64,
192
],
[
80,
192
]
]
}

View File

@ -1,7 +1,7 @@
<?xml version="1.0" encoding="UTF-8"?>
<Configuration package="log4j.test" status="info">
<Loggers>
<Loggers>
<Root level="info">
</Root>
</Loggers>
</Loggers>
</Configuration>

View File

@ -7,31 +7,27 @@ import junit.framework.TestSuite;
/**
* Unit test for simple App.
*/
public class AppTest extends TestCase
{
public class AppTest extends TestCase {
/**
* Create the test case
*
* @param testName name of the test case
*/
public AppTest(String testName)
{
super (testName);
public AppTest(String testName) {
super(testName);
}
/**
* @return the suite of tests being tested
*/
public static Test suite()
{
public static Test suite() {
return new TestSuite(AppTest.class);
}
/**
* Rigourous Test :-)
*/
public void testApp()
{
public void testApp() {
assertTrue(true);
}
}