Remove warnings

This commit is contained in:
Yohann D'ANELLO 2020-02-25 00:48:55 +01:00
parent d36800ab13
commit 94ee23c881
17 changed files with 58 additions and 154 deletions

View File

@ -19,7 +19,7 @@ public class EditorAPI {
private static File LAST_FILE;
public static RawMap toRawMap(int width, int height) {
List<RawCase> cases = new ArrayList<RawCase>();
List<RawCase> cases = new ArrayList<>();
for (int y = 1; y < height; y += 16) {
for (int x = 1; x < width; x += 16) {
@ -48,7 +48,7 @@ public class EditorAPI {
jfc.setFileHidingEnabled(true);
jfc.setFileSelectionMode(JFileChooser.FILES_ONLY);
File dir = new File("maps");
dir.mkdirs();
assert dir.mkdirs();
jfc.setCurrentDirectory(dir);
return jfc;
@ -56,7 +56,7 @@ public class EditorAPI {
public static void saveAs(RawMap map) {
JFileChooser jfc = createJFC();
File file = null;
File file;
jfc.showSaveDialog(null);
file = jfc.getSelectedFile();
@ -83,7 +83,7 @@ public class EditorAPI {
String json = createGson().toJson(map);
try {
file.createNewFile();
assert file.createNewFile();
BufferedOutputStream bos = new BufferedOutputStream(new GZIPOutputStream(new FileOutputStream(file)));
bos.write(json.getBytes(StandardCharsets.UTF_8));
@ -96,7 +96,7 @@ public class EditorAPI {
public static Map open() {
JFileChooser jfc = createJFC();
File file = null;
File file;
jfc.showOpenDialog(null);
file = jfc.getSelectedFile();
@ -114,15 +114,14 @@ public class EditorAPI {
try {
GZIPInputStream gis = new GZIPInputStream(new BufferedInputStream(new FileInputStream(f)));
byte[] bytes = new byte[512 * 1024];
int count = 0;
String text = "";
int count;
StringBuilder text = new StringBuilder();
while ((count = gis.read(bytes)) != -1) {
text += new String(bytes, 0, count, StandardCharsets.UTF_8);
text.append(new String(bytes, 0, count, StandardCharsets.UTF_8));
}
gis.close();
bytes = null;
json = text;
json = text.toString();
} catch (IOException e) {
e.printStackTrace();
}

View File

@ -24,7 +24,7 @@ public class RawMap {
RawMap raw = new RawMap();
raw.width = map.getWidth();
raw.height = map.getHeight();
raw.cases = new ArrayList<RawCase>();
raw.cases = new ArrayList<>();
for (Case c : map.getAllCases()) {
RawCase rc = RawCase.create(c);
raw.cases.add(rc);

View File

@ -5,16 +5,14 @@ import java.util.List;
public class Category {
private List<Sprite> sprites;
private String name;
private int index;
private Category() {
}
public static Category create(String name, int index, List<Sprite> sprites) {
public static Category create(String name, List<Sprite> sprites) {
Category c = new Category();
c.name = name;
c.index = index;
c.sprites = sprites;
return c;
@ -28,7 +26,4 @@ public class Category {
return sprites;
}
public int getIndex() {
return index;
}
}

View File

@ -5,7 +5,7 @@ import java.awt.image.BufferedImage;
import java.util.ArrayList;
public class Sprite {
public static final Sprite BLANK = new Sprite(new BufferedImage(16, 16, BufferedImage.TYPE_INT_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", new ArrayList<>()), 0);
static {
Graphics2D g = BLANK.getImage().createGraphics();

View File

@ -17,7 +17,7 @@ import java.util.jar.JarFile;
public class SpriteRegister {
private static Map<String, List<List<Double>>> nameToCoords;
private static Map<String, Category> sprites = new HashMap<String, Category>();
private static final Map<String, Category> sprites = new HashMap<>();
public static void unpack() throws IOException, URISyntaxException {
if (Main.isInDevelopmentMode()) {
@ -38,7 +38,7 @@ public class SpriteRegister {
if (name.startsWith("assets/")) {
File f = new File(name);
if (name.endsWith("/"))
f.mkdirs();
assert f.mkdirs();
else if (!f.isFile())
Files.copy(jar.getInputStream(je), Paths.get(f.toURI()));
}
@ -49,7 +49,7 @@ public class SpriteRegister {
}
private static void unpackDir(File dir) throws IOException {
for (File f : dir.listFiles()) {
for (File f : Objects.requireNonNull(dir.listFiles())) {
if (f.isDirectory()) {
unpackDir(f);
continue;
@ -57,9 +57,8 @@ public class SpriteRegister {
String path = f.getAbsolutePath().substring(f.getAbsolutePath().indexOf(File.separatorChar + "assets") + 1);
File local = new File(path);
local.getParentFile().mkdirs();
if (local.exists())
local.delete();
assert local.getParentFile().mkdirs();
assert !local.exists() || local.delete();
Files.copy(Paths.get(f.toURI()), Paths.get(local.toURI()));
}
}
@ -71,16 +70,16 @@ public class SpriteRegister {
}
File assetsDir = new File("assets");
List<String> assets = new ArrayList<String>();
List<String> assets = new ArrayList<>();
for (File dir : assetsDir.listFiles()) {
for (File dir : Objects.requireNonNull(assetsDir.listFiles())) {
assets.add(dir.getName());
}
for (String asset : assets) {
try {
File f = new File(assetsDir.getAbsolutePath() + "/" + asset + "/textures/sprites");
f.mkdirs();
assert f.mkdirs();
BufferedReader br = new BufferedReader(new InputStreamReader(new FileInputStream(new File(f, "sprites.json"))));
nameToCoords = new Gson().fromJson(br, Map.class);
br.close();
@ -90,7 +89,7 @@ public class SpriteRegister {
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>());
Category cat = Category.create(key, new ArrayList<>());
for (List<Double> list : nameToCoords.get(key)) {
int x = list.get(0).intValue();
@ -102,7 +101,6 @@ public class SpriteRegister {
sprites.put(key, cat);
} catch (Throwable t) {
LogManager.getLogger("SpriteRegister").fatal("Erreur lors de la lecture du sprite '" + key + "'", t);
continue;
}
}
} catch (IOException e) {
@ -115,21 +113,8 @@ public class SpriteRegister {
return sprites.get(name);
}
public static Category getCategory(int index) {
return getCategory(new ArrayList<String>(sprites.keySet()).get(index));
}
public static List<Category> getAllCategories() {
return new ArrayList<Category>(sprites.values());
return new ArrayList<>(sprites.values());
}
public static List<Sprite> getAllSprites() {
List<Sprite> list = new ArrayList<Sprite>();
for (Category c : sprites.values()) {
list.addAll(c.getSprites());
}
return list;
}
}

View File

@ -1,6 +1,3 @@
/**
* @author ÿnérant
*/
package fr.ynerant.leveleditor.client.main;
import fr.ynerant.leveleditor.api.editor.EditorAPI;
@ -33,15 +30,6 @@ import java.util.Map;
* @see #main(String...)
*/
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
*/
private static boolean DEBUG;
/**
* Variable disant si le jeu est lanc&eacute; en d&eacute;veloppement ou non.
*
@ -87,7 +75,6 @@ public class Main {
OptionParser parser = new OptionParser();
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<String> help = parser.accepts("help", "Affiche ce menu d'aide").withOptionalArg().forHelp();
OptionSet set = parser.parse(args);
@ -102,14 +89,6 @@ public class Main {
}
}
if (set.has(debug)) {
DEBUG = set.valueOf(debug);
if (DEBUG) {
LOGGER.setLevel(Level.ALL);
}
}
try {
SpriteRegister.unpack();
} catch (IOException | URISyntaxException e) {
@ -165,7 +144,6 @@ public class Main {
/**
* Permet de lancer l'&eacute;diteur de carte
*
* @return
* @see #main(String...)
* @see #launchFrame()
* @since 0.1-aplha
@ -187,8 +165,7 @@ public class Main {
if (baseWidth == 0)
return false;
break;
} catch (NumberFormatException ex) {
continue;
} catch (NumberFormatException ignored) {
}
}
@ -203,8 +180,7 @@ public class Main {
if (baseHeight == 0)
return false;
break;
} catch (NumberFormatException ex) {
continue;
} catch (NumberFormatException ignored) {
}
}
@ -234,17 +210,6 @@ public class Main {
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.
*
* @see #DEBUG
* @since 0.1-aplha
*/
public static boolean isInDebugMode() {
return DEBUG;
}
/**
* Accesseur disant si le jeu est lanc&eacute; en d&eacute;veloppement ou non.
*

View File

@ -3,7 +3,4 @@
*
* @author ÿnérant
*/
/**
* @author ÿnérant
*/
package fr.ynerant.leveleditor.client.main;

View File

@ -17,10 +17,6 @@ public class CollidPanel extends JPanel {
this.frame = frame;
}
public EditorFrame getFrame() {
return frame;
}
public Map getMap() {
return frame.getMap();
}

View File

@ -20,32 +20,23 @@ public class EditorFrame extends JFrame implements ChangeListener, ActionListene
private final Map map;
private final JPanel content = new JPanel();
private final JMenuBar menuBar = new JMenuBar();
private final JMenu fichier = new JMenu("Fichier");
private final JMenu tools = new JMenu("Outils");
private final JMenuItem nouveau = new JMenuItem("Nouveau");
private final JMenuItem open = new JMenuItem("Ouvrir");
private final JMenuItem save = new JMenuItem("Sauvegarder");
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");
private final JRadioButtonMenuItem pen = new JRadioButtonMenuItem("Pinceau");
private final JRadioButtonMenuItem pot = new JRadioButtonMenuItem("Pot de peinture");
private final JTabbedPane tabs = new JTabbedPane();
private final JPanel tabEvents = new JPanel();
private final CollidPanel tabColl;
private final MapPanel mapPanel;
private final JTabbedPane resources = new JTabbedPane();
private final JPanel couche1 = new JPanel();
private final JPanel couche2 = new JPanel();
private final JPanel couche3 = new JPanel();
ButtonGroup group = new ButtonGroup();
final ButtonGroup group = new ButtonGroup();
private SpriteComp selectedSprite;
public EditorFrame(Map map) {
super("Alice Game Engine");
super("Level Editor");
this.map = map;
this.setSize(600, 600);
this.setPreferredSize(getSize());
@ -53,17 +44,21 @@ public class EditorFrame extends JFrame implements ChangeListener, ActionListene
this.setExtendedState(JFrame.MAXIMIZED_BOTH);
this.setLocationRelativeTo(null);
this.addWindowListener(this);
JPanel content = new JPanel();
content.setLayout(new BorderLayout());
this.setContentPane(content);
this.setVisible(true);
this.setVisible(false);
JMenu fichier = new JMenu("Fichier");
fichier.setMnemonic(KeyEvent.VK_F + KeyEvent.ALT_DOWN_MASK);
JMenuItem nouveau = new JMenuItem("Nouveau");
nouveau.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_N, KeyEvent.CTRL_DOWN_MASK, true));
nouveau.addActionListener(new CreateMapListener());
fichier.add(nouveau);
JMenuItem open = new JMenuItem("Ouvrir");
open.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_O, KeyEvent.CTRL_DOWN_MASK, true));
open.addActionListener(new OpenMapListener());
fichier.add(open);
@ -84,6 +79,7 @@ public class EditorFrame extends JFrame implements ChangeListener, ActionListene
exit.addActionListener(this);
fichier.add(exit);
JMenuBar menuBar = new JMenuBar();
menuBar.add(fichier);
pen.setSelected(true);
@ -91,9 +87,11 @@ public class EditorFrame extends JFrame implements ChangeListener, ActionListene
pot.addActionListener(this);
group.add(pen);
group.add(pot);
JMenu selectionMode = new JMenu("Mode de s\u00e9lection");
selectionMode.add(pen);
selectionMode.add(pot);
JMenu tools = new JMenu("Outils");
tools.setMnemonic(KeyEvent.VK_O + KeyEvent.ALT_DOWN_MASK);
tools.add(selectionMode);
@ -118,6 +116,7 @@ public class EditorFrame extends JFrame implements ChangeListener, ActionListene
scrollCollidMap.getVerticalScrollBar().setUnitIncrement(34);
tabs.addTab("Carte", scrollMap);
JPanel tabEvents = new JPanel();
tabs.addTab("\u00c9vennments", new JScrollPane(tabEvents));
tabs.addTab("Collisions", scrollCollidMap);
tabs.addChangeListener(this);

View File

@ -14,13 +14,13 @@ public class Map {
@Deprecated
private static List<Case> cases;
private final EditorFrame frame;
private int width;
private int height;
private java.util.Map<Integer, java.util.Map<Integer, Case>> casesMap = new HashMap<Integer, java.util.Map<Integer, Case>>();
private transient BufferedImage font;
private final int width;
private final int height;
private final java.util.Map<Integer, java.util.Map<Integer, Case>> casesMap = new HashMap<>();
private final transient BufferedImage font;
public Map(RawMap raw) {
cases = new ArrayList<Case>();
cases = new ArrayList<>();
this.width = raw.getWidth();
this.height = raw.getHeight();
this.font = raw.getFont();
@ -49,7 +49,7 @@ public class Map {
}
public Case getCase(int x, int y) {
return casesMap.getOrDefault(x, new HashMap<Integer, Case>()).get(y);
return casesMap.getOrDefault(x, new HashMap<>()).get(y);
}
public void setCase(int x, int y, Case c) {
@ -60,13 +60,9 @@ public class Map {
return font;
}
public void setFont(BufferedImage font) {
this.font = font;
}
private void reorganizeMap() {
for (int i = 0; i < width; ++i) {
casesMap.put(i, new HashMap<Integer, Case>());
casesMap.put(i, new HashMap<>());
}
for (Case c : cases) {
@ -75,7 +71,7 @@ public class Map {
}
public List<Case> getAllCases() {
List<Case> list = new ArrayList<Case>();
List<Case> list = new ArrayList<>();
for (java.util.Map<Integer, Case> l : casesMap.values()) {
list.addAll(l.values());

View File

@ -16,10 +16,6 @@ public class MapPanel extends JPanel {
this.frame = frame;
}
public EditorFrame getFrame() {
return frame;
}
public Map getMap() {
return frame.getMap();
}
@ -66,6 +62,7 @@ public class MapPanel extends JPanel {
}
}
@SuppressWarnings("BooleanMethodIsAlwaysInverted")
private boolean isEmpty(BufferedImage image) {
int allrgba = 0;

View File

@ -8,8 +8,8 @@ import java.awt.*;
public class SpriteComp extends JComponent {
private static final long serialVersionUID = -6512257366877053285L;
private Sprite sprite;
private int couche;
private final Sprite sprite;
private final int couche;
private boolean selected;
public SpriteComp(Sprite sprite, int couche) {
@ -28,18 +28,10 @@ public class SpriteComp extends JComponent {
return sprite;
}
public void setSprite(Sprite s) {
this.sprite = s;
}
public int getCouche() {
return couche;
}
public void setCouche(int couche) {
this.couche = couche;
}
public boolean isSelected() {
return selected;
}

View File

@ -6,18 +6,10 @@ import java.awt.*;
public class WrapLayout extends FlowLayout {
private static final long serialVersionUID = 8777237960365591646L;
public WrapLayout() {
super();
}
public WrapLayout(int align) {
super(align);
}
public WrapLayout(int align, int hgap, int vgap) {
super(align, hgap, vgap);
}
@Override
public Dimension preferredLayoutSize(Container target) {
return layoutSize(target, true);

View File

@ -1,6 +1,3 @@
/**
* @author ÿnérant
*/
package fr.ynerant.leveleditor.frame;
import fr.ynerant.leveleditor.client.main.Main;
@ -22,8 +19,6 @@ import java.awt.event.KeyEvent;
public class MainFrame extends JFrame {
/**
* ID de s&eacute;rie
*
* @see {@link JFrame}
*/
private static final long serialVersionUID = -3168760121879418534L;
@ -40,18 +35,7 @@ public class MainFrame extends JFrame {
*
* @see LogManager#getLogger(String)
*/
private static Logger LOGGER = (Logger) LogManager.getLogger("MainFrame");
private JMenuBar menuBar = new JMenuBar();
private JMenu fichier = new JMenu("Fichier");
private JMenu display = new JMenu("Affichage");
private JMenu editMaps = new JMenu("Cartes");
private JMenu changeLAF = new JMenu("Modfier l'apparence");
private JMenuItem createMap = new JMenuItem("Cr\u00e9er");
private JMenuItem openMap = new JMenuItem("Ouvrir");
private JMenuItem systemLAF = new JMenuItem("Apparence syst\u00e8me");
private JMenuItem javaLAF = new JMenuItem("Apparence Java");
private JMenuItem darkLAF = new JMenuItem("Apparence sombre");
private static final Logger LOGGER = (Logger) LogManager.getLogger("MainFrame");
/**
* Constructeur
@ -69,25 +53,35 @@ public class MainFrame extends JFrame {
this.setExtendedState(JFrame.MAXIMIZED_BOTH);
this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
JMenu fichier = new JMenu("Fichier");
fichier.setMnemonic(KeyEvent.VK_F + KeyEvent.ALT_DOWN_MASK);
JMenu display = new JMenu("Affichage");
display.setMnemonic(KeyEvent.VK_A + KeyEvent.ALT_DOWN_MASK);
JMenuItem createMap = new JMenuItem("Cr\u00e9er");
createMap.addActionListener(new CreateMapListener());
JMenu editMaps = new JMenu("Cartes");
editMaps.add(createMap);
JMenuItem openMap = new JMenuItem("Ouvrir");
openMap.addActionListener(new OpenMapListener());
editMaps.add(openMap);
fichier.add(editMaps);
JMenuItem systemLAF = new JMenuItem("Apparence syst\u00e8me");
systemLAF.addActionListener(new ChangeLAFListener(systemLAF, this));
JMenu changeLAF = new JMenu("Modfier l'apparence");
changeLAF.add(systemLAF);
JMenuItem javaLAF = new JMenuItem("Apparence Java");
javaLAF.addActionListener(new ChangeLAFListener(javaLAF, this));
changeLAF.add(javaLAF);
JMenuItem darkLAF = new JMenuItem("Apparence sombre");
darkLAF.addActionListener(new ChangeLAFListener(darkLAF, this));
changeLAF.add(darkLAF);
display.add(changeLAF);
JMenuBar menuBar = new JMenuBar();
menuBar.add(fichier);
menuBar.add(display);

View File

@ -28,7 +28,7 @@ public class CollidMapMouseListener extends MouseAdapter {
int x = panel.getWidth() / 2 - map.getFont().getWidth();
int y = panel.getHeight() / 2 - map.getFont().getHeight();
Case c = null;
Case c;
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();

View File

@ -1,6 +1,3 @@
/**
* @author ÿnérant
*/
package fr.ynerant.leveleditor.frame.listeners;
import fr.ynerant.leveleditor.client.main.Main;

View File

@ -28,7 +28,7 @@ public class MapMouseListener extends MouseAdapter {
int x = panel.getWidth() / 2 - map.getFont().getWidth();
int y = panel.getHeight() / 2 - map.getFont().getHeight();
Case c = null;
Case c;
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) {