Naive attempt at Tiled integration. Very primitive yet. Requires Java7

!! for symlink creation.
This commit is contained in:
Zukero
2017-01-20 18:38:44 +01:00
parent 900d0bc9b5
commit 291808a564
3 changed files with 47 additions and 12 deletions

View File

@@ -2,6 +2,10 @@ package com.gpl.rpg.atcontentstudio.model.maps;
import java.awt.Image;
import java.io.File;
import java.io.IOException;
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.Paths;
import java.util.ArrayList;
import java.util.Collections;
import java.util.Comparator;
@@ -17,12 +21,14 @@ import com.gpl.rpg.atcontentstudio.model.Project;
import com.gpl.rpg.atcontentstudio.model.Project.ResourceSet;
import com.gpl.rpg.atcontentstudio.model.ProjectTreeNode;
import com.gpl.rpg.atcontentstudio.model.gamedata.GameDataSet;
import com.gpl.rpg.atcontentstudio.model.sprites.SpriteSheetSet;
import com.gpl.rpg.atcontentstudio.ui.DefaultIcons;
public class TMXMapSet implements ProjectTreeNode {
public static final String DEFAULT_REL_PATH_IN_SOURCE = "res/xml/";
public static final String DEFAULT_REL_PATH_IN_PROJECT = "maps/";
public static final String DEFAULT_REL_PATH_IN_SOURCE = "res"+File.separator+"xml"+File.separator;
public static final String DEFAULT_REL_PATH_IN_PROJECT = "maps"+File.separator;
public static final String DEFAULT_REL_PATH_TO_DRAWABLE = ".."+File.separator+"drawable"+File.separator;
public static final String GAME_MAPS_ARRAY_NAME = "loadresource_maps";
public static final String DEBUG_SUFFIX = "_debug";
@@ -44,6 +50,15 @@ public class TMXMapSet implements ProjectTreeNode {
if (!this.mapFolder.exists()) {
this.mapFolder.mkdirs();
}
Path target = Paths.get(getProject().baseContent.gameSprites.drawableFolder.getAbsolutePath());
Path link = Paths.get(new File(mapFolder.getAbsolutePath()+File.separator+DEFAULT_REL_PATH_TO_DRAWABLE).getAbsolutePath());
if (!Files.exists(link)) {
try {
Files.createSymbolicLink(link, target);
} catch (IOException e) {
e.printStackTrace();
}
}
}
this.tmxMaps = new ArrayList<TMXMap>();

View File

@@ -429,20 +429,24 @@ public class WorkspaceActions {
}
@Override
public synchronized void putValue(String key, Object value) {
public void putValue(String key, Object value) {
PropertyChangeEvent event = new PropertyChangeEvent(this, key, values.get(key), value);
values.put(key, value);
for (PropertyChangeListener l : listeners) {
l.propertyChange(event);
synchronized(listeners) {
for (PropertyChangeListener l : listeners) {
l.propertyChange(event);
}
}
}
@Override
public synchronized void setEnabled(boolean b) {
public void setEnabled(boolean b) {
PropertyChangeEvent event = new PropertyChangeEvent(this, "enabled", isEnabled(), b);
enabled = b;
for (PropertyChangeListener l : listeners) {
l.propertyChange(event);
synchronized(listeners) {
for (PropertyChangeListener l : listeners) {
l.propertyChange(event);
}
}
}
@@ -454,13 +458,17 @@ public class WorkspaceActions {
private Set<PropertyChangeListener> listeners = new HashSet<PropertyChangeListener>();
@Override
public synchronized void addPropertyChangeListener(PropertyChangeListener listener) {
listeners.add(listener);
public void addPropertyChangeListener(PropertyChangeListener listener) {
synchronized(listeners) {
listeners.add(listener);
}
}
@Override
public synchronized void removePropertyChangeListener(PropertyChangeListener listener) {
listeners.remove(listener);
public void removePropertyChangeListener(PropertyChangeListener listener) {
synchronized(listeners) {
listeners.remove(listener);
}
}
}

View File

@@ -18,6 +18,7 @@ import java.awt.event.MouseAdapter;
import java.awt.event.MouseEvent;
import java.awt.event.MouseMotionAdapter;
import java.awt.event.MouseMotionListener;
import java.io.IOException;
import java.util.ArrayList;
import java.util.LinkedHashMap;
import java.util.List;
@@ -1604,6 +1605,17 @@ public class TMXMapEditor extends Editor {
savePane.add(gdeIcon, JideBoxLayout.FIX);
savePane.setLayout(new JideBoxLayout(savePane, JideBoxLayout.LINE_AXIS, 6));
if (map.writable) {
gdeIcon.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
try {
Runtime.getRuntime().exec(new String[]{"tiled",map.tmxFile.getAbsolutePath()});
} catch (IOException e1) {
e1.printStackTrace();
}
}
});
if (map.getDataType() == GameSource.Type.altered) {
savePane.add(message = new JLabel(ALTERED_MESSAGE), JideBoxLayout.FIX);
} else if (map.getDataType() == GameSource.Type.created) {