From 291808a56487683e5762b8fd5451f82faf5f64de Mon Sep 17 00:00:00 2001 From: Zukero Date: Fri, 20 Jan 2017 18:38:44 +0100 Subject: [PATCH] Naive attempt at Tiled integration. Very primitive yet. Requires Java7 !! for symlink creation. --- .../atcontentstudio/model/maps/TMXMapSet.java | 19 +++++++++++-- .../atcontentstudio/ui/WorkspaceActions.java | 28 ++++++++++++------- .../atcontentstudio/ui/map/TMXMapEditor.java | 12 ++++++++ 3 files changed, 47 insertions(+), 12 deletions(-) diff --git a/src/com/gpl/rpg/atcontentstudio/model/maps/TMXMapSet.java b/src/com/gpl/rpg/atcontentstudio/model/maps/TMXMapSet.java index 64ab8a1..f852f86 100644 --- a/src/com/gpl/rpg/atcontentstudio/model/maps/TMXMapSet.java +++ b/src/com/gpl/rpg/atcontentstudio/model/maps/TMXMapSet.java @@ -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(); diff --git a/src/com/gpl/rpg/atcontentstudio/ui/WorkspaceActions.java b/src/com/gpl/rpg/atcontentstudio/ui/WorkspaceActions.java index ff48fb6..26db950 100644 --- a/src/com/gpl/rpg/atcontentstudio/ui/WorkspaceActions.java +++ b/src/com/gpl/rpg/atcontentstudio/ui/WorkspaceActions.java @@ -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 listeners = new HashSet(); @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); + } } } diff --git a/src/com/gpl/rpg/atcontentstudio/ui/map/TMXMapEditor.java b/src/com/gpl/rpg/atcontentstudio/ui/map/TMXMapEditor.java index 1f846fe..850afd8 100644 --- a/src/com/gpl/rpg/atcontentstudio/ui/map/TMXMapEditor.java +++ b/src/com/gpl/rpg/atcontentstudio/ui/map/TMXMapEditor.java @@ -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) {