Fixed formatting, more IDEA removal.
This commit is contained in:
1
.gitignore
vendored
1
.gitignore
vendored
@@ -7,6 +7,7 @@ target/
|
|||||||
|
|
||||||
bin/
|
bin/
|
||||||
.idea/
|
.idea/
|
||||||
|
*.iml
|
||||||
|
|
||||||
# User-specific stuff:
|
# User-specific stuff:
|
||||||
.idea/**/workspace.xml
|
.idea/**/workspace.xml
|
||||||
|
|||||||
112
pom.xml
112
pom.xml
@@ -1,61 +1,61 @@
|
|||||||
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
<project xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://maven.apache.org/POM/4.0.0"
|
||||||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
|
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
|
||||||
<modelVersion>4.0.0</modelVersion>
|
<modelVersion>4.0.0</modelVersion>
|
||||||
<groupId>com.aargonian.editor</groupId>
|
<groupId>com.aargonian.editor</groupId>
|
||||||
<artifactId>tile-editor</artifactId>
|
<artifactId>tile-editor</artifactId>
|
||||||
<packaging>jar</packaging>
|
<packaging>jar</packaging>
|
||||||
<version>0.1.0-SNAPSHOT</version>
|
<version>0.1.0-SNAPSHOT</version>
|
||||||
<name>TileGameEditor</name>
|
<name>TileGameEditor</name>
|
||||||
|
|
||||||
<properties>
|
<properties>
|
||||||
<maven.compiler.source>1.8</maven.compiler.source>
|
<maven.compiler.source>1.8</maven.compiler.source>
|
||||||
<maven.compiler.target>1.8</maven.compiler.target>
|
<maven.compiler.target>1.8</maven.compiler.target>
|
||||||
</properties>
|
</properties>
|
||||||
|
|
||||||
<build>
|
<build>
|
||||||
<plugins>
|
<plugins>
|
||||||
<plugin>
|
<plugin>
|
||||||
<groupId>org.apache.maven.plugins</groupId>
|
<groupId>org.apache.maven.plugins</groupId>
|
||||||
<artifactId>maven-jar-plugin</artifactId>
|
<artifactId>maven-jar-plugin</artifactId>
|
||||||
<version>3.0.2</version>
|
<version>3.0.2</version>
|
||||||
<configuration>
|
<configuration>
|
||||||
<archive>
|
<archive>
|
||||||
<manifest>
|
<manifest>
|
||||||
<addClasspath>true</addClasspath>
|
<addClasspath>true</addClasspath>
|
||||||
<classpathPrefix>lib/</classpathPrefix>
|
<classpathPrefix>lib/</classpathPrefix>
|
||||||
<mainClass>com.aargonian.editor.GameFrame</mainClass>
|
<mainClass>com.aargonian.editor.GameFrame</mainClass>
|
||||||
</manifest>
|
</manifest>
|
||||||
</archive>
|
</archive>
|
||||||
</configuration>
|
</configuration>
|
||||||
</plugin>
|
</plugin>
|
||||||
<plugin>
|
<plugin>
|
||||||
<groupId>org.apache.maven.plugins</groupId>
|
<groupId>org.apache.maven.plugins</groupId>
|
||||||
<artifactId>maven-shade-plugin</artifactId>
|
<artifactId>maven-shade-plugin</artifactId>
|
||||||
<version>3.0.0</version>
|
<version>3.0.0</version>
|
||||||
<executions>
|
<executions>
|
||||||
<execution>
|
<execution>
|
||||||
<phase>package</phase>
|
<phase>package</phase>
|
||||||
<goals>
|
<goals>
|
||||||
<goal>shade</goal>
|
<goal>shade</goal>
|
||||||
</goals>
|
</goals>
|
||||||
</execution>
|
</execution>
|
||||||
</executions>
|
</executions>
|
||||||
</plugin>
|
</plugin>
|
||||||
</plugins>
|
</plugins>
|
||||||
</build>
|
</build>
|
||||||
|
|
||||||
<dependencies>
|
<dependencies>
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>junit</groupId>
|
<groupId>junit</groupId>
|
||||||
<artifactId>junit</artifactId>
|
<artifactId>junit</artifactId>
|
||||||
<version>3.8.1</version>
|
<version>3.8.1</version>
|
||||||
<scope>test</scope>
|
<scope>test</scope>
|
||||||
</dependency>
|
</dependency>
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>org.pcollections</groupId>
|
<groupId>org.pcollections</groupId>
|
||||||
<artifactId>pcollections</artifactId>
|
<artifactId>pcollections</artifactId>
|
||||||
<version>2.1.2</version>
|
<version>2.1.2</version>
|
||||||
</dependency>
|
</dependency>
|
||||||
</dependencies>
|
</dependencies>
|
||||||
|
|
||||||
</project>
|
</project>
|
||||||
|
|||||||
@@ -14,25 +14,22 @@ import java.util.List;
|
|||||||
* keep each tile instance as a subimage within a larger sheet, unless written out by a TileSheetWriter. Instead,
|
* keep each tile instance as a subimage within a larger sheet, unless written out by a TileSheetWriter. Instead,
|
||||||
* individual tile images can be added or removed from the set at will.
|
* individual tile images can be added or removed from the set at will.
|
||||||
*/
|
*/
|
||||||
public class EditableTileSheet
|
public class EditableTileSheet {
|
||||||
{
|
|
||||||
/*
|
/*
|
||||||
* An EditableTileSheet is the backing model for the TileSheets dock of the editor, and as such implements the
|
* An EditableTileSheet is the backing model for the TileSheets dock of the editor, and as such implements the
|
||||||
* Observer
|
* Observer
|
||||||
* pattern for the sake of a cleaner MVC implementation.
|
* pattern for the sake of a cleaner MVC implementation.
|
||||||
*/
|
*/
|
||||||
private final List<Image> tileImages;
|
private final List<Image> tileImages;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Creates an empty EditableTileSheet.
|
* Creates an empty EditableTileSheet.
|
||||||
*/
|
*/
|
||||||
public EditableTileSheet()
|
public EditableTileSheet() {
|
||||||
{
|
|
||||||
this.tileImages = new ArrayList<>();
|
this.tileImages = new ArrayList<>();
|
||||||
}
|
}
|
||||||
|
|
||||||
public EditableTileSheet(List<Image> tileImages)
|
public EditableTileSheet(List<Image> tileImages) {
|
||||||
{
|
|
||||||
this.tileImages = tileImages;
|
this.tileImages = tileImages;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -10,71 +10,57 @@ import java.awt.event.*;
|
|||||||
* model, and receives input events from the TileMapDisplay. It is the job of the EditorTool to translate these input
|
* model, and receives input events from the TileMapDisplay. It is the job of the EditorTool to translate these input
|
||||||
* events into corresponding actions on the underlying TileMap or in the TileMapDisplay.
|
* events into corresponding actions on the underlying TileMap or in the TileMapDisplay.
|
||||||
*/
|
*/
|
||||||
public class EditorTool implements MouseListener, MouseMotionListener, KeyListener
|
public class EditorTool implements MouseListener, MouseMotionListener, KeyListener {
|
||||||
{
|
|
||||||
private final TileMapDisplay display;
|
private final TileMapDisplay display;
|
||||||
|
|
||||||
protected EditorTool(TileMapDisplay display)
|
protected EditorTool(TileMapDisplay display) {
|
||||||
{
|
if (display == null) {
|
||||||
if(display == null)
|
|
||||||
{
|
|
||||||
throw new NullPointerException("Given TileMapDisplay was Null!");
|
throw new NullPointerException("Given TileMapDisplay was Null!");
|
||||||
}
|
}
|
||||||
this.display = display;
|
this.display = display;
|
||||||
}
|
}
|
||||||
|
|
||||||
protected TileMapDisplay getCurrentDisplay()
|
protected TileMapDisplay getCurrentDisplay() {
|
||||||
{
|
|
||||||
return this.display;
|
return this.display;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void keyTyped(KeyEvent e)
|
public void keyTyped(KeyEvent e) {
|
||||||
{
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void keyPressed(KeyEvent e)
|
public void keyPressed(KeyEvent e) {
|
||||||
{
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void keyReleased(KeyEvent e)
|
public void keyReleased(KeyEvent e) {
|
||||||
{
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void mousePressed(MouseEvent e)
|
public void mousePressed(MouseEvent e) {
|
||||||
{
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void mouseClicked(MouseEvent e)
|
public void mouseClicked(MouseEvent e) {
|
||||||
{
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void mouseReleased(MouseEvent e)
|
public void mouseReleased(MouseEvent e) {
|
||||||
{
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void mouseEntered(MouseEvent e)
|
public void mouseEntered(MouseEvent e) {
|
||||||
{
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void mouseExited(MouseEvent e)
|
public void mouseExited(MouseEvent e) {
|
||||||
{
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void mouseDragged(MouseEvent e)
|
public void mouseDragged(MouseEvent e) {
|
||||||
{
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void mouseMoved(MouseEvent e)
|
public void mouseMoved(MouseEvent e) {
|
||||||
{
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -11,56 +11,47 @@ import java.util.ArrayList;
|
|||||||
/**
|
/**
|
||||||
* Created by aargonian on 7/8/17.
|
* Created by aargonian on 7/8/17.
|
||||||
*/
|
*/
|
||||||
public class GameFrame
|
public class GameFrame {
|
||||||
{
|
|
||||||
private static final String PROG_TITLE = "TileEditor 0.1.0";
|
private static final String PROG_TITLE = "TileEditor 0.1.0";
|
||||||
|
|
||||||
public static void main(String[] args)
|
public static void main(String[] args) {
|
||||||
{
|
|
||||||
EventQueue.invokeLater(GameFrame::setupUI);
|
EventQueue.invokeLater(GameFrame::setupUI);
|
||||||
}
|
}
|
||||||
|
|
||||||
//TODO: Add an Icon Image
|
//TODO: Add an Icon Image
|
||||||
private static JFrame setupFrame()
|
private static JFrame setupFrame() {
|
||||||
{
|
|
||||||
JFrame frame = new JFrame(PROG_TITLE);
|
JFrame frame = new JFrame(PROG_TITLE);
|
||||||
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
|
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
|
||||||
|
|
||||||
Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize();
|
Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize();
|
||||||
if(screenSize.width <= 1024 || screenSize.height <= 800)
|
if (screenSize.width <= 1024 || screenSize.height <= 800) {
|
||||||
{
|
|
||||||
frame.setExtendedState(JFrame.MAXIMIZED_BOTH); //maximize by default if the screen is really small
|
frame.setExtendedState(JFrame.MAXIMIZED_BOTH); //maximize by default if the screen is really small
|
||||||
}
|
} else {
|
||||||
else
|
|
||||||
{
|
|
||||||
frame.setSize((int) Math.round(screenSize.width * 0.8), (int) Math.round(screenSize.height * 0.8));
|
frame.setSize((int) Math.round(screenSize.width * 0.8), (int) Math.round(screenSize.height * 0.8));
|
||||||
frame.setLocationRelativeTo(null); //Centers the frame
|
frame.setLocationRelativeTo(null); //Centers the frame
|
||||||
}
|
}
|
||||||
return frame;
|
return frame;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Creates the pane that holds the different tile implementations the user may choose to put into the editor.
|
* Creates the pane that holds the different tile implementations the user may choose to put into the editor.
|
||||||
*
|
*
|
||||||
* @return The Tile Pane Component, Fully Constructed
|
* @return The Tile Pane Component, Fully Constructed
|
||||||
*/
|
*/
|
||||||
private static JComponent setupTilesPanel()
|
private static JComponent setupTilesPanel() {
|
||||||
{
|
|
||||||
throw new UnsupportedOperationException("Not Supported Yet.");
|
throw new UnsupportedOperationException("Not Supported Yet.");
|
||||||
}
|
}
|
||||||
|
|
||||||
private static void createTools(TileMapDisplay tileMapDisplay, TilesetDisplay tilesetDisplay)
|
private static void createTools(TileMapDisplay tileMapDisplay, TilesetDisplay tilesetDisplay) {
|
||||||
{
|
|
||||||
PencilTool pencil = new PencilTool(tileMapDisplay, tilesetDisplay);
|
PencilTool pencil = new PencilTool(tileMapDisplay, tilesetDisplay);
|
||||||
tileMapDisplay.setCurrentActiveTool(pencil);
|
tileMapDisplay.setCurrentActiveTool(pencil);
|
||||||
}
|
}
|
||||||
|
|
||||||
private static void setupUI()
|
private static void setupUI() {
|
||||||
{
|
|
||||||
JFrame frame = setupFrame();
|
JFrame frame = setupFrame();
|
||||||
|
|
||||||
TileMap map = new TileMap(10, 10);
|
TileMap map = new TileMap(10, 10);
|
||||||
|
|
||||||
//Create TileMap Display
|
//Create TileMap Display
|
||||||
TileMapDisplay.OptionsBuilder displayOptions = new TileMapDisplay.OptionsBuilder();
|
TileMapDisplay.OptionsBuilder displayOptions = new TileMapDisplay.OptionsBuilder();
|
||||||
displayOptions = displayOptions.tileSize(32, 32).displaySize(640, 480).borderColor(Color.black);
|
displayOptions = displayOptions.tileSize(32, 32).displaySize(640, 480).borderColor(Color.black);
|
||||||
@@ -68,24 +59,24 @@ public class GameFrame
|
|||||||
currentTileMapDisplay.setCurrentTileMap(map);
|
currentTileMapDisplay.setCurrentTileMap(map);
|
||||||
currentTileMapDisplay.setCurrentActiveTool(new TileSelectTool(currentTileMapDisplay));
|
currentTileMapDisplay.setCurrentActiveTool(new TileSelectTool(currentTileMapDisplay));
|
||||||
frame.add(BorderLayout.CENTER, currentTileMapDisplay);
|
frame.add(BorderLayout.CENTER, currentTileMapDisplay);
|
||||||
|
|
||||||
//Create TilesetDisplay
|
//Create TilesetDisplay
|
||||||
ArrayList<ImageResource> images = new ArrayList<>();
|
ArrayList<ImageResource> images = new ArrayList<>();
|
||||||
images.add(ResourceLoader.loadImage("res/Water.png"));
|
images.add(ResourceLoader.loadImage("res/Water.png"));
|
||||||
images.add(ResourceLoader.loadImage("res/Grass.png"));
|
images.add(ResourceLoader.loadImage("res/Grass.png"));
|
||||||
TilesetDisplay tileDisplay = new TilesetDisplay(32, images);
|
TilesetDisplay tileDisplay = new TilesetDisplay(32, images);
|
||||||
frame.add(BorderLayout.WEST, tileDisplay);
|
frame.add(BorderLayout.WEST, tileDisplay);
|
||||||
|
|
||||||
//CREATE ALL TOOLS with their necessary connections
|
//CREATE ALL TOOLS with their necessary connections
|
||||||
createTools(currentTileMapDisplay, tileDisplay);
|
createTools(currentTileMapDisplay, tileDisplay);
|
||||||
|
|
||||||
//Create TileInfoDisplay
|
//Create TileInfoDisplay
|
||||||
|
|
||||||
//Set the Tile Pencil Tool as the Current Active Tool
|
//Set the Tile Pencil Tool as the Current Active Tool
|
||||||
|
|
||||||
frame.pack();
|
frame.pack();
|
||||||
frame.setLocationRelativeTo(null);
|
frame.setLocationRelativeTo(null);
|
||||||
frame.setVisible(true);
|
frame.setVisible(true);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -8,31 +8,26 @@ import java.awt.event.MouseEvent;
|
|||||||
/**
|
/**
|
||||||
* Created by aargonian on 7/23/17.
|
* Created by aargonian on 7/23/17.
|
||||||
*/
|
*/
|
||||||
public class PencilTool extends EditorTool implements TilesetDisplay.TilesetListener
|
public class PencilTool extends EditorTool implements TilesetDisplay.TilesetListener {
|
||||||
{
|
|
||||||
private ImageResource currentImage;
|
private ImageResource currentImage;
|
||||||
|
|
||||||
public PencilTool(TileMapDisplay display, TilesetDisplay tilesetDisplay)
|
public PencilTool(TileMapDisplay display, TilesetDisplay tilesetDisplay) {
|
||||||
{
|
|
||||||
super(display);
|
super(display);
|
||||||
tilesetDisplay.addSetListener(this);
|
tilesetDisplay.addSetListener(this);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void imageSelected(ImageResource resource)
|
public void imageSelected(ImageResource resource) {
|
||||||
{
|
|
||||||
this.currentImage = resource;
|
this.currentImage = resource;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void mouseClicked(MouseEvent e)
|
public void mouseClicked(MouseEvent e) {
|
||||||
{
|
if (this.currentImage != null) {
|
||||||
if(this.currentImage != null)
|
|
||||||
{
|
|
||||||
int tileX = e.getX() / super.getCurrentDisplay().getOptions().tileWidth();
|
int tileX = e.getX() / super.getCurrentDisplay().getOptions().tileWidth();
|
||||||
int tileY = e.getY() / super.getCurrentDisplay().getOptions().tileHeight();
|
int tileY = e.getY() / super.getCurrentDisplay().getOptions().tileHeight();
|
||||||
this.getCurrentDisplay().getCurrentTileMap()
|
this.getCurrentDisplay().getCurrentTileMap()
|
||||||
.setTileResourceAt(TileImpl.PROPERTY_IMG, this.currentImage, tileX, tileY);
|
.setTileResourceAt(TileImpl.PROPERTY_IMG, this.currentImage, tileX, tileY);
|
||||||
this.getCurrentDisplay().repaint();
|
this.getCurrentDisplay().repaint();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -12,205 +12,170 @@ import java.util.List;
|
|||||||
/**
|
/**
|
||||||
* Created by aargonian on 7/8/17.
|
* Created by aargonian on 7/8/17.
|
||||||
*/
|
*/
|
||||||
public class TileMapDisplay extends JComponent
|
public class TileMapDisplay extends JComponent {
|
||||||
{
|
|
||||||
private static final OptionsBuilder DEFAULT_OPTIONS =
|
private static final OptionsBuilder DEFAULT_OPTIONS =
|
||||||
new OptionsBuilder().borderColor(Color.black).displaySize(640, 480).tileSize(32, 32);
|
new OptionsBuilder().borderColor(Color.black).displaySize(640, 480).tileSize(32, 32);
|
||||||
private final OptionsBuilder options;
|
private final OptionsBuilder options;
|
||||||
private TileMap tileMap;
|
private TileMap tileMap;
|
||||||
private EditorTool currentActiveTool;
|
private EditorTool currentActiveTool;
|
||||||
private List<Pair<Integer, Integer>> selectedTiles;
|
private List<Pair<Integer, Integer>> selectedTiles;
|
||||||
|
|
||||||
public TileMapDisplay()
|
public TileMapDisplay() {
|
||||||
{
|
|
||||||
this.options = DEFAULT_OPTIONS;
|
this.options = DEFAULT_OPTIONS;
|
||||||
}
|
}
|
||||||
|
|
||||||
public TileMapDisplay(OptionsBuilder options)
|
public TileMapDisplay(OptionsBuilder options) {
|
||||||
{
|
|
||||||
this.options = options;
|
this.options = options;
|
||||||
this.setPreferredSize(new Dimension(options.displayWidth(), options.displayHeight()));
|
this.setPreferredSize(new Dimension(options.displayWidth(), options.displayHeight()));
|
||||||
}
|
}
|
||||||
|
|
||||||
public OptionsBuilder getOptions()
|
public OptionsBuilder getOptions() {
|
||||||
{
|
|
||||||
return this.options;
|
return this.options;
|
||||||
}
|
}
|
||||||
|
|
||||||
public TileMap getCurrentTileMap()
|
public TileMap getCurrentTileMap() {
|
||||||
{
|
|
||||||
return this.tileMap;
|
return this.tileMap;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setCurrentTileMap(TileMap map)
|
public void setCurrentTileMap(TileMap map) {
|
||||||
{
|
|
||||||
this.tileMap = map;
|
this.tileMap = map;
|
||||||
}
|
}
|
||||||
|
|
||||||
public List<Pair<Integer, Integer>> getSelectedTiles()
|
public List<Pair<Integer, Integer>> getSelectedTiles() {
|
||||||
{
|
|
||||||
return this.selectedTiles;
|
return this.selectedTiles;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setSelectedTiles(List<Pair<Integer, Integer>> tiles)
|
public void setSelectedTiles(List<Pair<Integer, Integer>> tiles) {
|
||||||
{
|
|
||||||
this.selectedTiles = tiles;
|
this.selectedTiles = tiles;
|
||||||
this.repaint();
|
this.repaint();
|
||||||
}
|
}
|
||||||
|
|
||||||
public EditorTool getCurrentActiveTool()
|
public EditorTool getCurrentActiveTool() {
|
||||||
{
|
|
||||||
return this.currentActiveTool;
|
return this.currentActiveTool;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setCurrentActiveTool(EditorTool tool)
|
public void setCurrentActiveTool(EditorTool tool) {
|
||||||
{
|
if (this.currentActiveTool != null) {
|
||||||
if(this.currentActiveTool != null)
|
|
||||||
{
|
|
||||||
this.removeMouseListener(this.currentActiveTool);
|
this.removeMouseListener(this.currentActiveTool);
|
||||||
this.removeMouseMotionListener(this.currentActiveTool);
|
this.removeMouseMotionListener(this.currentActiveTool);
|
||||||
this.removeKeyListener(this.currentActiveTool);
|
this.removeKeyListener(this.currentActiveTool);
|
||||||
}
|
}
|
||||||
|
|
||||||
this.currentActiveTool = tool;
|
this.currentActiveTool = tool;
|
||||||
this.addMouseListener(tool);
|
this.addMouseListener(tool);
|
||||||
this.addMouseMotionListener(tool);
|
this.addMouseMotionListener(tool);
|
||||||
this.addKeyListener(tool);
|
this.addKeyListener(tool);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void paintComponent(Graphics g)
|
public void paintComponent(Graphics g) {
|
||||||
{
|
|
||||||
Graphics2D g2 = (Graphics2D) g;
|
Graphics2D g2 = (Graphics2D) g;
|
||||||
g2.setColor(this.options.borderColor());
|
g2.setColor(this.options.borderColor());
|
||||||
g2.fillRect(0, 0, this.getWidth(), this.getHeight());
|
g2.fillRect(0, 0, this.getWidth(), this.getHeight());
|
||||||
for(int x = 0; x < this.tileMap.getColumns(); x++)
|
for (int x = 0; x < this.tileMap.getColumns(); x++) {
|
||||||
{
|
for (int y = 0; y < this.tileMap.getRows(); y++) {
|
||||||
for(int y = 0; y < this.tileMap.getRows(); y++)
|
|
||||||
{
|
|
||||||
final int tileXLoc = x * this.options.tileWidth();
|
final int tileXLoc = x * this.options.tileWidth();
|
||||||
final int tileYLoc = y * this.options.tileHeight();
|
final int tileYLoc = y * this.options.tileHeight();
|
||||||
|
|
||||||
ImageResource imgRes = (ImageResource) this.tileMap.getTileResourceAt(TileImpl.PROPERTY_IMG, x, y);
|
ImageResource imgRes = (ImageResource) this.tileMap.getTileResourceAt(TileImpl.PROPERTY_IMG, x, y);
|
||||||
Image img = imgRes == null ? null : imgRes.getImage();
|
Image img = imgRes == null ? null : imgRes.getImage();
|
||||||
if(img != null)
|
if (img != null) {
|
||||||
{
|
|
||||||
g2.drawImage(img, tileXLoc, tileYLoc, this.options.tileWidth(), this.options.tileHeight(), null);
|
g2.drawImage(img, tileXLoc, tileYLoc, this.options.tileWidth(), this.options.tileHeight(), null);
|
||||||
}
|
} else {
|
||||||
else
|
|
||||||
{
|
|
||||||
final int HALF_WIDTH = this.options.tileWidth() / 2;
|
final int HALF_WIDTH = this.options.tileWidth() / 2;
|
||||||
final int HALF_HEIGHT = this.options.tileHeight() / 2;
|
final int HALF_HEIGHT = this.options.tileHeight() / 2;
|
||||||
|
|
||||||
g2.setColor(Color.lightGray);
|
g2.setColor(Color.lightGray);
|
||||||
g2.fillRect(tileXLoc, tileYLoc, HALF_WIDTH, HALF_HEIGHT);
|
g2.fillRect(tileXLoc, tileYLoc, HALF_WIDTH, HALF_HEIGHT);
|
||||||
g2.fillRect(tileXLoc + HALF_WIDTH, tileYLoc + HALF_HEIGHT, HALF_WIDTH, HALF_HEIGHT);
|
g2.fillRect(tileXLoc + HALF_WIDTH, tileYLoc + HALF_HEIGHT, HALF_WIDTH, HALF_HEIGHT);
|
||||||
|
|
||||||
g2.setColor(Color.gray);
|
g2.setColor(Color.gray);
|
||||||
g2.fillRect(tileXLoc, tileYLoc + HALF_HEIGHT, HALF_WIDTH, HALF_HEIGHT);
|
g2.fillRect(tileXLoc, tileYLoc + HALF_HEIGHT, HALF_WIDTH, HALF_HEIGHT);
|
||||||
g2.fillRect(tileXLoc + HALF_WIDTH, tileYLoc, HALF_WIDTH, HALF_HEIGHT);
|
g2.fillRect(tileXLoc + HALF_WIDTH, tileYLoc, HALF_WIDTH, HALF_HEIGHT);
|
||||||
}
|
}
|
||||||
|
|
||||||
if(this.selectedTiles != null)
|
if (this.selectedTiles != null) {
|
||||||
{
|
for (Pair<Integer, Integer> selectedTile : this.selectedTiles) {
|
||||||
for(Pair<Integer, Integer> selectedTile : this.selectedTiles)
|
if (selectedTile.getFirst() == x && selectedTile.getSecond() == y) {
|
||||||
{
|
|
||||||
if(selectedTile.getFirst() == x && selectedTile.getSecond() == y)
|
|
||||||
{
|
|
||||||
g2.setColor(Color.YELLOW);
|
g2.setColor(Color.YELLOW);
|
||||||
g2.fillRect(tileXLoc, tileYLoc, this.options.tileWidth(), this.options.tileHeight());
|
g2.fillRect(tileXLoc, tileYLoc, this.options.tileWidth(), this.options.tileHeight());
|
||||||
g2.setColor(Color.YELLOW.brighter());
|
g2.setColor(Color.YELLOW.brighter());
|
||||||
g2.fillRect(tileXLoc + 2, tileYLoc + 2, this.options.tileWidth() - 2,
|
g2.fillRect(tileXLoc + 2, tileYLoc + 2, this.options.tileWidth() - 2,
|
||||||
this.options.tileHeight() - 2);
|
this.options.tileHeight() - 2);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public static final class OptionsBuilder
|
public static final class OptionsBuilder {
|
||||||
{
|
|
||||||
private int tileWidth = 32;
|
private int tileWidth = 32;
|
||||||
private int tileHeight = 32;
|
private int tileHeight = 32;
|
||||||
private int displayWidth = 640;
|
private int displayWidth = 640;
|
||||||
private int displayHeight = 480;
|
private int displayHeight = 480;
|
||||||
private Color borderColor = Color.black;
|
private Color borderColor = Color.black;
|
||||||
private boolean fullscreen = false;
|
private boolean fullscreen = false;
|
||||||
|
|
||||||
public OptionsBuilder tileWidth(int width)
|
public OptionsBuilder tileWidth(int width) {
|
||||||
{
|
|
||||||
this.tileWidth = width <= 0 ? 0 : width;
|
this.tileWidth = width <= 0 ? 0 : width;
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
public OptionsBuilder tileHeight(int height)
|
public OptionsBuilder tileHeight(int height) {
|
||||||
{
|
|
||||||
this.tileHeight = height <= 0 ? 0 : height;
|
this.tileHeight = height <= 0 ? 0 : height;
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
public OptionsBuilder tileSize(int width, int height)
|
public OptionsBuilder tileSize(int width, int height) {
|
||||||
{
|
|
||||||
return this.tileWidth(width).tileHeight(height);
|
return this.tileWidth(width).tileHeight(height);
|
||||||
}
|
}
|
||||||
|
|
||||||
public OptionsBuilder borderColor(Color c)
|
public OptionsBuilder borderColor(Color c) {
|
||||||
{
|
|
||||||
this.borderColor = c;
|
this.borderColor = c;
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
public OptionsBuilder displayWidth(int width)
|
public OptionsBuilder displayWidth(int width) {
|
||||||
{
|
|
||||||
this.displayWidth = width <= 0 ? 0 : width;
|
this.displayWidth = width <= 0 ? 0 : width;
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
public OptionsBuilder displayHeight(int height)
|
public OptionsBuilder displayHeight(int height) {
|
||||||
{
|
|
||||||
this.displayHeight = height <= 0 ? 0 : height;
|
this.displayHeight = height <= 0 ? 0 : height;
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
public OptionsBuilder displaySize(int width, int height)
|
public OptionsBuilder displaySize(int width, int height) {
|
||||||
{
|
|
||||||
return this.displayWidth(width).displayHeight(height);
|
return this.displayWidth(width).displayHeight(height);
|
||||||
}
|
}
|
||||||
|
|
||||||
public OptionsBuilder fullscreen(boolean value)
|
public OptionsBuilder fullscreen(boolean value) {
|
||||||
{
|
|
||||||
this.fullscreen = value;
|
this.fullscreen = value;
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
public int tileWidth()
|
public int tileWidth() {
|
||||||
{
|
|
||||||
return this.tileWidth;
|
return this.tileWidth;
|
||||||
}
|
}
|
||||||
|
|
||||||
public int tileHeight()
|
public int tileHeight() {
|
||||||
{
|
|
||||||
return this.tileHeight;
|
return this.tileHeight;
|
||||||
}
|
}
|
||||||
|
|
||||||
public int displayWidth()
|
public int displayWidth() {
|
||||||
{
|
|
||||||
return this.displayWidth;
|
return this.displayWidth;
|
||||||
}
|
}
|
||||||
|
|
||||||
public int displayHeight()
|
public int displayHeight() {
|
||||||
{
|
|
||||||
return this.displayHeight;
|
return this.displayHeight;
|
||||||
}
|
}
|
||||||
|
|
||||||
public Color borderColor()
|
public Color borderColor() {
|
||||||
{
|
|
||||||
return this.borderColor;
|
return this.borderColor;
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean fulllscreen()
|
public boolean fulllscreen() {
|
||||||
{
|
|
||||||
return this.fullscreen;
|
return this.fullscreen;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -8,35 +8,30 @@ import java.awt.event.MouseEvent;
|
|||||||
/**
|
/**
|
||||||
* Created by aargonian on 7/16/17.
|
* Created by aargonian on 7/16/17.
|
||||||
*/
|
*/
|
||||||
public class TileSelectTool extends EditorTool
|
public class TileSelectTool extends EditorTool {
|
||||||
{
|
|
||||||
private int currentTileX = 0;
|
private int currentTileX = 0;
|
||||||
private int currentTileY = 0;
|
private int currentTileY = 0;
|
||||||
|
|
||||||
public TileSelectTool(TileMapDisplay display)
|
public TileSelectTool(TileMapDisplay display) {
|
||||||
{
|
|
||||||
super(display);
|
super(display);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void mouseClicked(MouseEvent e)
|
public void mouseClicked(MouseEvent e) {
|
||||||
{
|
|
||||||
int tileX = e.getX() / super.getCurrentDisplay().getOptions().tileWidth();
|
int tileX = e.getX() / super.getCurrentDisplay().getOptions().tileWidth();
|
||||||
int tileY = e.getY() / super.getCurrentDisplay().getOptions().tileHeight();
|
int tileY = e.getY() / super.getCurrentDisplay().getOptions().tileHeight();
|
||||||
//getCurrentDisplay().setSelectedTiles(Arrays.asList(new Pair<Integer, Integer>(tileX, tileY)));
|
//getCurrentDisplay().setSelectedTiles(Arrays.asList(new Pair<Integer, Integer>(tileX, tileY)));
|
||||||
this.getCurrentDisplay().getCurrentTileMap()
|
this.getCurrentDisplay().getCurrentTileMap()
|
||||||
.setTileResourceAt(TileImpl.PROPERTY_IMG, new ImageResource("res/Water.png"), tileX, tileY);
|
.setTileResourceAt(TileImpl.PROPERTY_IMG, new ImageResource("res/Water.png"), tileX, tileY);
|
||||||
this.getCurrentDisplay().repaint();
|
this.getCurrentDisplay().repaint();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void mouseMoved(MouseEvent e)
|
public void mouseMoved(MouseEvent e) {
|
||||||
{
|
|
||||||
int tileX = e.getX() / super.getCurrentDisplay().getOptions().tileWidth();
|
int tileX = e.getX() / super.getCurrentDisplay().getOptions().tileWidth();
|
||||||
int tileY = e.getY() / super.getCurrentDisplay().getOptions().tileHeight();
|
int tileY = e.getY() / super.getCurrentDisplay().getOptions().tileHeight();
|
||||||
|
|
||||||
if(tileX != this.currentTileX || tileY != this.currentTileY)
|
if (tileX != this.currentTileX || tileY != this.currentTileY) {
|
||||||
{
|
|
||||||
this.currentTileX = tileX;
|
this.currentTileX = tileX;
|
||||||
this.currentTileY = tileY;
|
this.currentTileY = tileY;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -13,131 +13,109 @@ import java.util.ArrayList;
|
|||||||
* <p>
|
* <p>
|
||||||
* This class implements a display for a set of tiles.
|
* This class implements a display for a set of tiles.
|
||||||
*/
|
*/
|
||||||
public final class TilesetDisplay extends JComponent implements MouseListener
|
public final class TilesetDisplay extends JComponent implements MouseListener {
|
||||||
{
|
|
||||||
private final ArrayList<ImageResource> images;
|
private final ArrayList<ImageResource> images;
|
||||||
private final ArrayList<TilesetListener> listeners;
|
private final ArrayList<TilesetListener> listeners;
|
||||||
private int currentlySelectedImage = 0;
|
private int currentlySelectedImage = 0;
|
||||||
private int tileSize = 0;
|
private int tileSize = 0;
|
||||||
|
|
||||||
public TilesetDisplay(int tileSize, ArrayList<ImageResource> tileImages)
|
public TilesetDisplay(int tileSize, ArrayList<ImageResource> tileImages) {
|
||||||
{
|
if (tileImages == null) {
|
||||||
if(tileImages == null)
|
|
||||||
{
|
|
||||||
throw new NullPointerException("Passed Image Set is Null.");
|
throw new NullPointerException("Passed Image Set is Null.");
|
||||||
}
|
}
|
||||||
if(tileSize < 0)
|
if (tileSize < 0) {
|
||||||
{
|
|
||||||
throw new IllegalArgumentException("Tilesize Cannot Be Negative!");
|
throw new IllegalArgumentException("Tilesize Cannot Be Negative!");
|
||||||
}
|
}
|
||||||
this.images = tileImages;
|
this.images = tileImages;
|
||||||
this.tileSize = tileSize;
|
this.tileSize = tileSize;
|
||||||
this.listeners = new ArrayList<>();
|
this.listeners = new ArrayList<>();
|
||||||
|
|
||||||
this.addMouseListener(this);
|
this.addMouseListener(this);
|
||||||
//TODO: Remove this later?
|
//TODO: Remove this later?
|
||||||
int squareSize = ((int) (Math.sqrt(tileImages.size()))) * tileSize;
|
int squareSize = ((int) (Math.sqrt(tileImages.size()))) * tileSize;
|
||||||
this.setPreferredSize(new Dimension(squareSize, squareSize));
|
this.setPreferredSize(new Dimension(squareSize, squareSize));
|
||||||
}
|
}
|
||||||
|
|
||||||
public void addSetListener(TilesetListener listener)
|
public void addSetListener(TilesetListener listener) {
|
||||||
{
|
|
||||||
this.listeners.add(listener);
|
this.listeners.add(listener);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void removeSetListener(TilesetListener listener)
|
public void removeSetListener(TilesetListener listener) {
|
||||||
{
|
|
||||||
this.listeners.remove(listener);
|
this.listeners.remove(listener);
|
||||||
}
|
}
|
||||||
|
|
||||||
private void setCurrentlySelectedImage(int index)
|
private void setCurrentlySelectedImage(int index) {
|
||||||
{
|
|
||||||
this.currentlySelectedImage = index;
|
this.currentlySelectedImage = index;
|
||||||
if(index < this.images.size() && index >= 0)
|
if (index < this.images.size() && index >= 0) {
|
||||||
{
|
for (TilesetListener listener : this.listeners) {
|
||||||
for(TilesetListener listener : this.listeners)
|
|
||||||
{
|
|
||||||
listener.imageSelected(this.images.get(index));
|
listener.imageSelected(this.images.get(index));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public ImageResource getCurrentlySelectedImage(ImageResource res)
|
public ImageResource getCurrentlySelectedImage(ImageResource res) {
|
||||||
{
|
if (this.currentlySelectedImage >= 0 && this.currentlySelectedImage < this.images.size()) {
|
||||||
if(this.currentlySelectedImage >= 0 && this.currentlySelectedImage < this.images.size())
|
|
||||||
{
|
|
||||||
return this.images.get(this.currentlySelectedImage);
|
return this.images.get(this.currentlySelectedImage);
|
||||||
}
|
}
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void addImageToDisplay(ImageResource img)
|
public void addImageToDisplay(ImageResource img) {
|
||||||
{
|
|
||||||
this.images.add(img);
|
this.images.add(img);
|
||||||
this.repaint();
|
this.repaint();
|
||||||
}
|
}
|
||||||
|
|
||||||
public void removeImageFromDisplay(ImageResource img)
|
public void removeImageFromDisplay(ImageResource img) {
|
||||||
{
|
|
||||||
this.images.remove(img);
|
this.images.remove(img);
|
||||||
this.repaint();
|
this.repaint();
|
||||||
}
|
}
|
||||||
|
|
||||||
//Todo: Update this to use a scrollpane and avoid divide by zero.
|
//Todo: Update this to use a scrollpane and avoid divide by zero.
|
||||||
@Override
|
@Override
|
||||||
public void paintComponent(Graphics g)
|
public void paintComponent(Graphics g) {
|
||||||
{
|
|
||||||
int columns = this.getWidth() / this.tileSize;
|
int columns = this.getWidth() / this.tileSize;
|
||||||
if(columns != 0) // Avoid divide by zero and simply display nothing.
|
if (columns != 0) // Avoid divide by zero and simply display nothing.
|
||||||
{
|
{
|
||||||
for(int i = 0; i < this.images.size(); i++)
|
for (int i = 0; i < this.images.size(); i++) {
|
||||||
{
|
|
||||||
g.drawImage(this.images.get(i).getImage(), (i % columns) * this.tileSize, i / columns * this.tileSize,
|
g.drawImage(this.images.get(i).getImage(), (i % columns) * this.tileSize, i / columns * this.tileSize,
|
||||||
this.tileSize, this.tileSize, null);
|
this.tileSize, this.tileSize, null);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void mouseClicked(MouseEvent e)
|
public void mouseClicked(MouseEvent e) {
|
||||||
{
|
if (this.images.size() < 1) {
|
||||||
if(this.images.size() < 1)
|
|
||||||
{
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
int columns = this.getWidth() / this.tileSize;
|
int columns = this.getWidth() / this.tileSize;
|
||||||
int tileX = e.getX() / this.tileSize;
|
int tileX = e.getX() / this.tileSize;
|
||||||
int tileY = e.getY() / this.tileSize;
|
int tileY = e.getY() / this.tileSize;
|
||||||
this.setCurrentlySelectedImage(tileY * columns + tileX);
|
this.setCurrentlySelectedImage(tileY * columns + tileX);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void mousePressed(MouseEvent e)
|
public void mousePressed(MouseEvent e) {
|
||||||
{
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void mouseReleased(MouseEvent e)
|
public void mouseReleased(MouseEvent e) {
|
||||||
{
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void mouseEntered(MouseEvent e)
|
public void mouseEntered(MouseEvent e) {
|
||||||
{
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void mouseExited(MouseEvent e)
|
public void mouseExited(MouseEvent e) {
|
||||||
{
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public interface TilesetListener
|
public interface TilesetListener {
|
||||||
{
|
|
||||||
void imageSelected(ImageResource image);
|
void imageSelected(ImageResource image);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -12,87 +12,66 @@ import java.util.Arrays;
|
|||||||
* This is a simple extension to the existing BufferedImage class that provides an implementation of equals() and
|
* This is a simple extension to the existing BufferedImage class that provides an implementation of equals() and
|
||||||
* hashCode().
|
* hashCode().
|
||||||
*/
|
*/
|
||||||
public class ImageResource extends Resource
|
public class ImageResource extends Resource {
|
||||||
{
|
|
||||||
private final BufferedImage res;
|
private final BufferedImage res;
|
||||||
private int hash = 0;
|
private int hash = 0;
|
||||||
|
|
||||||
public ImageResource(String imagePath)
|
public ImageResource(String imagePath) {
|
||||||
{
|
|
||||||
super(imagePath, ResourceType.IMAGE);
|
super(imagePath, ResourceType.IMAGE);
|
||||||
|
|
||||||
BufferedImage temp = null;
|
BufferedImage temp = null;
|
||||||
if(imagePath != null && !imagePath.isEmpty())
|
if (imagePath != null && !imagePath.isEmpty()) {
|
||||||
{
|
try {
|
||||||
try
|
|
||||||
{
|
|
||||||
File imageFile = new File(imagePath);
|
File imageFile = new File(imagePath);
|
||||||
if(imageFile.exists())
|
if (imageFile.exists()) {
|
||||||
{
|
|
||||||
temp = ImageIO.read(imageFile);
|
temp = ImageIO.read(imageFile);
|
||||||
}
|
} else {
|
||||||
else
|
|
||||||
{
|
|
||||||
throw new IOException("Image File Does Not Exist: " + imagePath);
|
throw new IOException("Image File Does Not Exist: " + imagePath);
|
||||||
}
|
}
|
||||||
}
|
} catch (IOException ex) {
|
||||||
catch(IOException ex)
|
|
||||||
{
|
|
||||||
ex.printStackTrace();
|
ex.printStackTrace();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
this.res = temp;
|
this.res = temp;
|
||||||
}
|
}
|
||||||
|
|
||||||
public BufferedImage getImage()
|
public BufferedImage getImage() {
|
||||||
{
|
|
||||||
return this.res;
|
return this.res;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public int hashCode()
|
public int hashCode() {
|
||||||
{
|
if (this.hash == 0 && this.res != null) {
|
||||||
if(this.hash == 0 && this.res != null)
|
|
||||||
{
|
|
||||||
int[] data = new int[this.res.getWidth() * this.res.getHeight()];
|
int[] data = new int[this.res.getWidth() * this.res.getHeight()];
|
||||||
this.res.getRGB(0, 0, this.res.getWidth(), this.res.getHeight(), data, 0, 0);
|
this.res.getRGB(0, 0, this.res.getWidth(), this.res.getHeight(), data, 0, 0);
|
||||||
this.hash = Arrays.hashCode(data);
|
this.hash = Arrays.hashCode(data);
|
||||||
}
|
}
|
||||||
return this.hash;
|
return this.hash;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean equals(Object o)
|
public boolean equals(Object o) {
|
||||||
{
|
if (this == o) {
|
||||||
if(this == o)
|
|
||||||
{
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
if(o == null)
|
if (o == null) {
|
||||||
{
|
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
if(o.getClass() != this.getClass())
|
if (o.getClass() != this.getClass()) {
|
||||||
{
|
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
ImageResource other = (ImageResource) o;
|
ImageResource other = (ImageResource) o;
|
||||||
if(this.res.getWidth() != other.res.getWidth())
|
if (this.res.getWidth() != other.res.getWidth()) {
|
||||||
{
|
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
if(this.res.getHeight() != other.res.getHeight())
|
if (this.res.getHeight() != other.res.getHeight()) {
|
||||||
{
|
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
for(int x = 0; x < this.res.getHeight(); x++)
|
for (int x = 0; x < this.res.getHeight(); x++) {
|
||||||
{
|
for (int y = 0; y < this.res.getWidth(); y++) {
|
||||||
for(int y = 0; y < this.res.getWidth(); y++)
|
if (this.res.getRGB(x, y) != other.res.getRGB(x, y)) {
|
||||||
{
|
|
||||||
if(this.res.getRGB(x, y) != other.res.getRGB(x, y))
|
|
||||||
{
|
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -7,36 +7,31 @@ package com.aargonian.resource;
|
|||||||
* or anything else that may be limited or is unique in some fashion. Resources are named entities, and are cacheable
|
* or anything else that may be limited or is unique in some fashion. Resources are named entities, and are cacheable
|
||||||
* and ownable. Resources are required to override the equals() and hashCode() methods, for convenience.
|
* and ownable. Resources are required to override the equals() and hashCode() methods, for convenience.
|
||||||
*/
|
*/
|
||||||
abstract public class Resource
|
abstract public class Resource {
|
||||||
{
|
|
||||||
private final String name;
|
private final String name;
|
||||||
private final ResourceType type;
|
private final ResourceType type;
|
||||||
|
|
||||||
protected Resource(String name, ResourceType type)
|
protected Resource(String name, ResourceType type) {
|
||||||
{
|
|
||||||
this.name = name;
|
this.name = name;
|
||||||
this.type = type;
|
this.type = type;
|
||||||
}
|
}
|
||||||
|
|
||||||
public String getName()
|
public String getName() {
|
||||||
{
|
|
||||||
return this.name;
|
return this.name;
|
||||||
}
|
}
|
||||||
|
|
||||||
public ResourceType getType()
|
public ResourceType getType() {
|
||||||
{
|
|
||||||
return this.type;
|
return this.type;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
abstract public boolean equals(Object o);
|
abstract public boolean equals(Object o);
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
abstract public int hashCode();
|
abstract public int hashCode();
|
||||||
|
|
||||||
//We know at compile-time what sort of resources exist, so they are enumerated here for checking
|
//We know at compile-time what sort of resources exist, so they are enumerated here for checking
|
||||||
public enum ResourceType
|
public enum ResourceType {
|
||||||
{
|
|
||||||
FILE, IMAGE, SOUND, SCRIPT, SOCKET
|
FILE, IMAGE, SOUND, SCRIPT, SOCKET
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -9,22 +9,15 @@ import java.util.Map;
|
|||||||
* A utility class for loading and caching common resources used by the editor. Primarily used to load images and sound
|
* A utility class for loading and caching common resources used by the editor. Primarily used to load images and sound
|
||||||
* files.
|
* files.
|
||||||
*/
|
*/
|
||||||
public final class ResourceLoader
|
public final class ResourceLoader {
|
||||||
{
|
|
||||||
private static final Map<String, Resource> resourceCache = new HashMap<>(100);
|
private static final Map<String, Resource> resourceCache = new HashMap<>(100);
|
||||||
|
|
||||||
public static ImageResource loadImage(String imagePath)
|
public static ImageResource loadImage(String imagePath) {
|
||||||
{
|
if (imagePath == null || imagePath.isEmpty()) {
|
||||||
if(imagePath == null || imagePath.isEmpty())
|
|
||||||
{
|
|
||||||
return null;
|
return null;
|
||||||
}
|
} else if (resourceCache.containsKey(imagePath) && resourceCache.get(imagePath) != null) {
|
||||||
else if(resourceCache.containsKey(imagePath) && resourceCache.get(imagePath) != null)
|
|
||||||
{
|
|
||||||
return (ImageResource) resourceCache.get(imagePath);
|
return (ImageResource) resourceCache.get(imagePath);
|
||||||
}
|
} else {
|
||||||
else
|
|
||||||
{
|
|
||||||
ImageResource resource = new ImageResource(imagePath);
|
ImageResource resource = new ImageResource(imagePath);
|
||||||
resourceCache.put(imagePath, resource);
|
resourceCache.put(imagePath, resource);
|
||||||
return resource;
|
return resource;
|
||||||
|
|||||||
@@ -9,8 +9,7 @@ import java.util.Map;
|
|||||||
/**
|
/**
|
||||||
* Created by aargonian on 7/4/17.
|
* Created by aargonian on 7/4/17.
|
||||||
*/
|
*/
|
||||||
public class TileImpl
|
public class TileImpl {
|
||||||
{
|
|
||||||
/**
|
/**
|
||||||
* Very important magic string values used by the tile class for common properties/values
|
* Very important magic string values used by the tile class for common properties/values
|
||||||
*/
|
*/
|
||||||
@@ -18,132 +17,105 @@ public class TileImpl
|
|||||||
public static final String PROPERTY_IMG = "ImageRef";
|
public static final String PROPERTY_IMG = "ImageRef";
|
||||||
public static final String VALUE_TRUE = "True";
|
public static final String VALUE_TRUE = "True";
|
||||||
public static final String VALUE_FALSE = "False";
|
public static final String VALUE_FALSE = "False";
|
||||||
|
|
||||||
private final HashPMap<String, String> properties;
|
private final HashPMap<String, String> properties;
|
||||||
private final HashPMap<String, Resource> resources;
|
private final HashPMap<String, Resource> resources;
|
||||||
private int hash = 0;
|
private int hash = 0;
|
||||||
|
|
||||||
public TileImpl(Map<String, String> startingProperties, Map<String, Resource> startingResources)
|
public TileImpl(Map<String, String> startingProperties, Map<String, Resource> startingResources) {
|
||||||
{
|
if (startingProperties != null && startingProperties.size() > 0) {
|
||||||
if(startingProperties != null && startingProperties.size() > 0)
|
|
||||||
{
|
|
||||||
this.properties = HashTreePMap.from(startingProperties);
|
this.properties = HashTreePMap.from(startingProperties);
|
||||||
}
|
} else {
|
||||||
else
|
|
||||||
{
|
|
||||||
this.properties = null;
|
this.properties = null;
|
||||||
}
|
}
|
||||||
|
|
||||||
if(startingResources != null && startingResources.size() > 0)
|
if (startingResources != null && startingResources.size() > 0) {
|
||||||
{
|
|
||||||
this.resources = HashTreePMap.from(startingResources);
|
this.resources = HashTreePMap.from(startingResources);
|
||||||
}
|
} else {
|
||||||
else
|
|
||||||
{
|
|
||||||
this.resources = null;
|
this.resources = null;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private TileImpl(HashPMap<String, String> implProperties, HashPMap<String, Resource> implResources)
|
private TileImpl(HashPMap<String, String> implProperties, HashPMap<String, Resource> implResources) {
|
||||||
{
|
|
||||||
this.properties = implProperties;
|
this.properties = implProperties;
|
||||||
this.resources = implResources;
|
this.resources = implResources;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean equals(Object o)
|
public boolean equals(Object o) {
|
||||||
{
|
if (this == o) {
|
||||||
if(this == o)
|
|
||||||
{
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
if(o == null || this.getClass() != o.getClass())
|
if (o == null || this.getClass() != o.getClass()) {
|
||||||
{
|
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
TileImpl tile = (TileImpl) o;
|
TileImpl tile = (TileImpl) o;
|
||||||
|
|
||||||
return (this.properties != null ? this.properties.equals(tile.properties) : tile.properties == null) &&
|
return (this.properties != null ? this.properties.equals(tile.properties) : tile.properties == null) &&
|
||||||
(this.resources != null ? this.resources.equals(tile.resources) : tile.resources == null);
|
(this.resources != null ? this.resources.equals(tile.resources) : tile.resources == null);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public int hashCode()
|
public int hashCode() {
|
||||||
{
|
if (this.hash == 0) {
|
||||||
if(this.hash == 0)
|
|
||||||
{
|
|
||||||
int result = this.properties != null ? this.properties.hashCode() : 0;
|
int result = this.properties != null ? this.properties.hashCode() : 0;
|
||||||
result = 31 * result + (this.resources != null ? this.resources.hashCode() : 0);
|
result = 31 * result + (this.resources != null ? this.resources.hashCode() : 0);
|
||||||
this.hash = result;
|
this.hash = result;
|
||||||
}
|
}
|
||||||
return this.hash;
|
return this.hash;
|
||||||
}
|
}
|
||||||
|
|
||||||
public TileImpl removeProperty(String property)
|
public TileImpl removeProperty(String property) {
|
||||||
{
|
if (this.properties == null) {
|
||||||
if(this.properties == null)
|
|
||||||
{
|
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
return new TileImpl(this.properties.minus(property), this.resources);
|
return new TileImpl(this.properties.minus(property), this.resources);
|
||||||
}
|
}
|
||||||
|
|
||||||
public String getProperty(String property)
|
public String getProperty(String property) {
|
||||||
{
|
if (this.properties == null) {
|
||||||
if(this.properties == null)
|
|
||||||
{
|
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
return this.properties.get(property);
|
return this.properties.get(property);
|
||||||
}
|
}
|
||||||
|
|
||||||
public TileImpl setProperty(String property, String value)
|
public TileImpl setProperty(String property, String value) {
|
||||||
{
|
if (this.properties == null) {
|
||||||
if(this.properties == null)
|
|
||||||
{
|
|
||||||
return new TileImpl(HashTreePMap.singleton(property, value), this.resources);
|
return new TileImpl(HashTreePMap.singleton(property, value), this.resources);
|
||||||
}
|
}
|
||||||
return new TileImpl(this.properties.plus(property, value), this.resources);
|
return new TileImpl(this.properties.plus(property, value), this.resources);
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean hasProperty(String property)
|
public boolean hasProperty(String property) {
|
||||||
{
|
|
||||||
return this.properties != null && this.properties.containsKey(property) &&
|
return this.properties != null && this.properties.containsKey(property) &&
|
||||||
this.properties.get(property) != null;
|
this.properties.get(property) != null;
|
||||||
}
|
}
|
||||||
|
|
||||||
public TileImpl removeResource(String resource)
|
public TileImpl removeResource(String resource) {
|
||||||
{
|
if (this.resources == null) {
|
||||||
if(this.resources == null)
|
|
||||||
{
|
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
return new TileImpl(this.properties, this.resources.minus(resource));
|
return new TileImpl(this.properties, this.resources.minus(resource));
|
||||||
}
|
}
|
||||||
|
|
||||||
public Resource getResource(String resource)
|
public Resource getResource(String resource) {
|
||||||
{
|
if (this.resources == null) {
|
||||||
if(this.resources == null)
|
|
||||||
{
|
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
return this.resources.get(resource);
|
return this.resources.get(resource);
|
||||||
}
|
}
|
||||||
|
|
||||||
public TileImpl setResource(String resourceKey, Resource resource)
|
public TileImpl setResource(String resourceKey, Resource resource) {
|
||||||
{
|
if (this.resources == null) {
|
||||||
if(this.resources == null)
|
|
||||||
{
|
|
||||||
return new TileImpl(this.properties, HashTreePMap.singleton(resourceKey, resource));
|
return new TileImpl(this.properties, HashTreePMap.singleton(resourceKey, resource));
|
||||||
}
|
}
|
||||||
return new TileImpl(this.properties, this.resources.plus(resourceKey, resource));
|
return new TileImpl(this.properties, this.resources.plus(resourceKey, resource));
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean hasResource(String resourceKey)
|
public boolean hasResource(String resourceKey) {
|
||||||
{
|
|
||||||
return this.resources != null && this.resources.containsKey(resourceKey) &&
|
return this.resources != null && this.resources.containsKey(resourceKey) &&
|
||||||
this.resources.get(resourceKey) != null;
|
this.resources.get(resourceKey) != null;
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -7,55 +7,44 @@ import java.util.ArrayList;
|
|||||||
/**
|
/**
|
||||||
* Created by aargonian on 7/4/17.
|
* Created by aargonian on 7/4/17.
|
||||||
*/
|
*/
|
||||||
public class TileMap
|
public class TileMap {
|
||||||
{
|
|
||||||
private final ArrayList<TileImpl> tilesImplementations;
|
private final ArrayList<TileImpl> tilesImplementations;
|
||||||
private final Tile[] tiles;
|
private final Tile[] tiles;
|
||||||
private final int rows;
|
private final int rows;
|
||||||
private final int columns;
|
private final int columns;
|
||||||
|
|
||||||
public TileMap(int columns, int rows)
|
public TileMap(int columns, int rows) {
|
||||||
{
|
|
||||||
this.columns = columns;
|
this.columns = columns;
|
||||||
this.rows = rows;
|
this.rows = rows;
|
||||||
this.tilesImplementations = new ArrayList<>();
|
this.tilesImplementations = new ArrayList<>();
|
||||||
this.tilesImplementations.add(new TileImpl(null, null));
|
this.tilesImplementations.add(new TileImpl(null, null));
|
||||||
this.tilesImplementations.get(0).setProperty(TileImpl.PROPERTY_TILETYPE, "EmptyTile");
|
this.tilesImplementations.get(0).setProperty(TileImpl.PROPERTY_TILETYPE, "EmptyTile");
|
||||||
this.tiles = new Tile[columns * rows];
|
this.tiles = new Tile[columns * rows];
|
||||||
for(int i = 0; i < this.tiles.length; i++)
|
for (int i = 0; i < this.tiles.length; i++) {
|
||||||
{
|
|
||||||
this.tiles[i] = new Tile(this.tilesImplementations.get(0));
|
this.tiles[i] = new Tile(this.tilesImplementations.get(0));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public void addTileImplementation(TileImpl impl)
|
public void addTileImplementation(TileImpl impl) {
|
||||||
{
|
|
||||||
this.tilesImplementations.add(impl);
|
this.tilesImplementations.add(impl);
|
||||||
}
|
}
|
||||||
|
|
||||||
public ArrayList<TileImpl> getTileImplementations()
|
public ArrayList<TileImpl> getTileImplementations() {
|
||||||
{
|
|
||||||
return this.tilesImplementations;
|
return this.tilesImplementations;
|
||||||
}
|
}
|
||||||
|
|
||||||
public int getRows()
|
public int getRows() {
|
||||||
{
|
|
||||||
return this.rows;
|
return this.rows;
|
||||||
}
|
}
|
||||||
|
|
||||||
public int getColumns()
|
public int getColumns() {
|
||||||
{
|
|
||||||
return this.columns;
|
return this.columns;
|
||||||
}
|
}
|
||||||
|
|
||||||
private void setTileImplementation(Tile tile, TileImpl newImpl)
|
private void setTileImplementation(Tile tile, TileImpl newImpl) {
|
||||||
{
|
for (TileImpl implementation : this.tilesImplementations) {
|
||||||
for(TileImpl implementation : this.tilesImplementations)
|
if (implementation.hashCode() == newImpl.hashCode()) {
|
||||||
{
|
if (implementation.equals(newImpl)) {
|
||||||
if(implementation.hashCode() == newImpl.hashCode())
|
|
||||||
{
|
|
||||||
if(implementation.equals(newImpl))
|
|
||||||
{
|
|
||||||
tile.setTileImplementation(implementation);
|
tile.setTileImplementation(implementation);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@@ -65,91 +54,74 @@ public class TileMap
|
|||||||
this.tilesImplementations.add(newImpl);
|
this.tilesImplementations.add(newImpl);
|
||||||
tile.setTileImplementation(newImpl);
|
tile.setTileImplementation(newImpl);
|
||||||
}
|
}
|
||||||
|
|
||||||
private boolean inBounds(int x, int y)
|
private boolean inBounds(int x, int y) {
|
||||||
{
|
|
||||||
return !(x < 0 || x >= this.columns || y < 0 || y >= this.rows);
|
return !(x < 0 || x >= this.columns || y < 0 || y >= this.rows);
|
||||||
}
|
}
|
||||||
|
|
||||||
public String getTilePropertyAt(String property, int x, int y)
|
public String getTilePropertyAt(String property, int x, int y) {
|
||||||
{
|
if (this.inBounds(x, y)) {
|
||||||
if(this.inBounds(x, y))
|
|
||||||
{
|
|
||||||
return this.tiles[(y * this.columns) + x].getTileImplementation().getProperty(property);
|
return this.tiles[(y * this.columns) + x].getTileImplementation().getProperty(property);
|
||||||
}
|
}
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setTilePropertyAt(String property, String value, int x, int y)
|
public void setTilePropertyAt(String property, String value, int x, int y) {
|
||||||
{
|
if (!this.inBounds(x, y)) {
|
||||||
if(!this.inBounds(x, y))
|
|
||||||
{
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
Tile tile = this.tiles[(y * this.columns) + x];
|
Tile tile = this.tiles[(y * this.columns) + x];
|
||||||
TileImpl newImpl = tile.getTileImplementation().setProperty(property, value);
|
TileImpl newImpl = tile.getTileImplementation().setProperty(property, value);
|
||||||
this.setTileImplementation(tile, newImpl);
|
this.setTileImplementation(tile, newImpl);
|
||||||
}
|
}
|
||||||
|
|
||||||
public Resource getTileResourceAt(String resource, int x, int y)
|
public Resource getTileResourceAt(String resource, int x, int y) {
|
||||||
{
|
if (!this.inBounds(x, y)) {
|
||||||
if(!this.inBounds(x, y))
|
|
||||||
{
|
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
return this.tiles[(y * this.columns) + x].getTileImplementation().getResource(resource);
|
return this.tiles[(y * this.columns) + x].getTileImplementation().getResource(resource);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setTileResourceAt(String resourceKey, Resource resource, int x, int y)
|
public void setTileResourceAt(String resourceKey, Resource resource, int x, int y) {
|
||||||
{
|
if (!this.inBounds(x, y)) {
|
||||||
if(!this.inBounds(x, y))
|
|
||||||
{
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
Tile tile = this.tiles[(y * this.columns) + x];
|
Tile tile = this.tiles[(y * this.columns) + x];
|
||||||
TileImpl newImpl = tile.getTileImplementation().setResource(resourceKey, resource);
|
TileImpl newImpl = tile.getTileImplementation().setResource(resourceKey, resource);
|
||||||
this.setTileImplementation(tile, newImpl);
|
this.setTileImplementation(tile, newImpl);
|
||||||
}
|
}
|
||||||
|
|
||||||
private final class Tile
|
private final class Tile {
|
||||||
{
|
|
||||||
private TileImpl implementation;
|
private TileImpl implementation;
|
||||||
|
|
||||||
private Tile(TileImpl impl)
|
private Tile(TileImpl impl) {
|
||||||
{
|
|
||||||
this.implementation = impl;
|
this.implementation = impl;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean equals(Object o)
|
public boolean equals(Object o) {
|
||||||
{
|
if (this == o) {
|
||||||
if(this == o)
|
|
||||||
{
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
if(o == null || this.getClass() != o.getClass())
|
if (o == null || this.getClass() != o.getClass()) {
|
||||||
{
|
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
Tile tile = (Tile) o;
|
Tile tile = (Tile) o;
|
||||||
|
|
||||||
return this.implementation.equals(tile.implementation);
|
return this.implementation.equals(tile.implementation);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public int hashCode()
|
public int hashCode() {
|
||||||
{
|
|
||||||
return this.implementation.hashCode();
|
return this.implementation.hashCode();
|
||||||
}
|
}
|
||||||
|
|
||||||
private TileImpl getTileImplementation()
|
private TileImpl getTileImplementation() {
|
||||||
{
|
|
||||||
return this.implementation;
|
return this.implementation;
|
||||||
}
|
}
|
||||||
|
|
||||||
private void setTileImplementation(TileImpl impl)
|
private void setTileImplementation(TileImpl impl) {
|
||||||
{
|
|
||||||
this.implementation = impl;
|
this.implementation = impl;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -3,34 +3,28 @@ package com.aargonian.util;
|
|||||||
/**
|
/**
|
||||||
* Created by aargonian on 7/17/17.
|
* Created by aargonian on 7/17/17.
|
||||||
*/
|
*/
|
||||||
public class Pair<K, T>
|
public class Pair<K, T> {
|
||||||
{
|
|
||||||
private K first;
|
private K first;
|
||||||
private T second;
|
private T second;
|
||||||
|
|
||||||
public Pair(K first, T second)
|
public Pair(K first, T second) {
|
||||||
{
|
|
||||||
this.first = first;
|
this.first = first;
|
||||||
this.second = second;
|
this.second = second;
|
||||||
}
|
}
|
||||||
|
|
||||||
public K getFirst()
|
public K getFirst() {
|
||||||
{
|
|
||||||
return this.first;
|
return this.first;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setFirst(K first)
|
public void setFirst(K first) {
|
||||||
{
|
|
||||||
this.first = first;
|
this.first = first;
|
||||||
}
|
}
|
||||||
|
|
||||||
public T getSecond()
|
public T getSecond() {
|
||||||
{
|
|
||||||
return this.second;
|
return this.second;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setSecond(T second)
|
public void setSecond(T second) {
|
||||||
{
|
|
||||||
this.second = second;
|
this.second = second;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user