mirror of
https://github.com/OMGeeky/ATCS.git
synced 2026-02-23 15:38:23 +01:00
make project file to json
same as with .workspace the .project file now saves as .project.json and falls back to .project
This commit is contained in:
@@ -1,5 +1,6 @@
|
|||||||
package com.gpl.rpg.atcontentstudio.model;
|
package com.gpl.rpg.atcontentstudio.model;
|
||||||
|
|
||||||
|
import com.gpl.rpg.atcontentstudio.io.JsonSerializable;
|
||||||
import com.gpl.rpg.atcontentstudio.model.Project.ResourceSet;
|
import com.gpl.rpg.atcontentstudio.model.Project.ResourceSet;
|
||||||
import com.gpl.rpg.atcontentstudio.model.gamedata.GameDataSet;
|
import com.gpl.rpg.atcontentstudio.model.gamedata.GameDataSet;
|
||||||
import com.gpl.rpg.atcontentstudio.model.maps.TMXMapSet;
|
import com.gpl.rpg.atcontentstudio.model.maps.TMXMapSet;
|
||||||
@@ -24,7 +25,7 @@ import java.io.*;
|
|||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.*;
|
import java.util.*;
|
||||||
|
|
||||||
public class GameSource implements ProjectTreeNode, Serializable {
|
public class GameSource implements ProjectTreeNode, Serializable, JsonSerializable {
|
||||||
|
|
||||||
private static final long serialVersionUID = -1512979360971918158L;
|
private static final long serialVersionUID = -1512979360971918158L;
|
||||||
|
|
||||||
@@ -38,6 +39,22 @@ public class GameSource implements ProjectTreeNode, Serializable {
|
|||||||
public transient WriterModeDataSet writerModeDataSet;
|
public transient WriterModeDataSet writerModeDataSet;
|
||||||
private transient SavedSlotCollection v;
|
private transient SavedSlotCollection v;
|
||||||
|
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Map toMap() {
|
||||||
|
Map map = new HashMap();
|
||||||
|
map.put("type", type.toString());
|
||||||
|
map.put("baseFolder", baseFolder.getPath());
|
||||||
|
return map;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void fromMap(Map map) {
|
||||||
|
if(map==null)return;
|
||||||
|
type = Enum.valueOf(Type.class, (String)map.get("type"));
|
||||||
|
baseFolder = new File((String) map.get("baseFolder"));
|
||||||
|
}
|
||||||
|
|
||||||
public static enum Type {
|
public static enum Type {
|
||||||
source,
|
source,
|
||||||
referenced,
|
referenced,
|
||||||
@@ -52,6 +69,10 @@ public class GameSource implements ProjectTreeNode, Serializable {
|
|||||||
|
|
||||||
public transient Map<String, List<String>> referencedSourceFiles = null;
|
public transient Map<String, List<String>> referencedSourceFiles = null;
|
||||||
|
|
||||||
|
public GameSource(Map json, Project parent) {
|
||||||
|
fromMap(json);
|
||||||
|
refreshTransients(parent);
|
||||||
|
}
|
||||||
public GameSource(File folder, Project parent) {
|
public GameSource(File folder, Project parent) {
|
||||||
this.parent = parent;
|
this.parent = parent;
|
||||||
this.baseFolder = folder;
|
this.baseFolder = folder;
|
||||||
|
|||||||
@@ -2,7 +2,7 @@ package com.gpl.rpg.atcontentstudio.model;
|
|||||||
|
|
||||||
import com.gpl.rpg.atcontentstudio.ATContentStudio;
|
import com.gpl.rpg.atcontentstudio.ATContentStudio;
|
||||||
import com.gpl.rpg.atcontentstudio.Notification;
|
import com.gpl.rpg.atcontentstudio.Notification;
|
||||||
import com.gpl.rpg.atcontentstudio.io.JsonPrettyWriter;
|
import com.gpl.rpg.atcontentstudio.io.JsonSerializable;
|
||||||
import com.gpl.rpg.atcontentstudio.io.SettingsSave;
|
import com.gpl.rpg.atcontentstudio.io.SettingsSave;
|
||||||
import com.gpl.rpg.atcontentstudio.model.GameSource.Type;
|
import com.gpl.rpg.atcontentstudio.model.GameSource.Type;
|
||||||
import com.gpl.rpg.atcontentstudio.model.bookmarks.BookmarksRoot;
|
import com.gpl.rpg.atcontentstudio.model.bookmarks.BookmarksRoot;
|
||||||
@@ -11,13 +11,11 @@ import com.gpl.rpg.atcontentstudio.model.maps.TMXMap;
|
|||||||
import com.gpl.rpg.atcontentstudio.model.maps.TMXMapSet;
|
import com.gpl.rpg.atcontentstudio.model.maps.TMXMapSet;
|
||||||
import com.gpl.rpg.atcontentstudio.model.maps.Worldmap;
|
import com.gpl.rpg.atcontentstudio.model.maps.Worldmap;
|
||||||
import com.gpl.rpg.atcontentstudio.model.maps.WorldmapSegment;
|
import com.gpl.rpg.atcontentstudio.model.maps.WorldmapSegment;
|
||||||
import com.gpl.rpg.atcontentstudio.model.saves.SavedGamesSet;
|
|
||||||
import com.gpl.rpg.atcontentstudio.model.sprites.Spritesheet;
|
import com.gpl.rpg.atcontentstudio.model.sprites.Spritesheet;
|
||||||
import com.gpl.rpg.atcontentstudio.model.tools.writermode.WriterModeData;
|
import com.gpl.rpg.atcontentstudio.model.tools.writermode.WriterModeData;
|
||||||
import com.gpl.rpg.atcontentstudio.ui.DefaultIcons;
|
import com.gpl.rpg.atcontentstudio.ui.DefaultIcons;
|
||||||
import com.gpl.rpg.atcontentstudio.ui.WorkerDialog;
|
import com.gpl.rpg.atcontentstudio.ui.WorkerDialog;
|
||||||
import com.gpl.rpg.atcontentstudio.utils.FileUtils;
|
import com.gpl.rpg.atcontentstudio.utils.FileUtils;
|
||||||
import org.json.simple.JSONArray;
|
|
||||||
import org.w3c.dom.Comment;
|
import org.w3c.dom.Comment;
|
||||||
import org.w3c.dom.Document;
|
import org.w3c.dom.Document;
|
||||||
import org.w3c.dom.Element;
|
import org.w3c.dom.Element;
|
||||||
@@ -42,7 +40,7 @@ import java.nio.file.Paths;
|
|||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.*;
|
import java.util.*;
|
||||||
|
|
||||||
public class Project implements ProjectTreeNode, Serializable {
|
public class Project implements ProjectTreeNode, Serializable, JsonSerializable {
|
||||||
|
|
||||||
private static final long serialVersionUID = 4807454973303366758L;
|
private static final long serialVersionUID = 4807454973303366758L;
|
||||||
private static final String drawablePath = TMXMapSet.DEFAULT_REL_PATH_TO_DRAWABLE.replace("\\", "/");
|
private static final String drawablePath = TMXMapSet.DEFAULT_REL_PATH_TO_DRAWABLE.replace("\\", "/");
|
||||||
@@ -50,6 +48,7 @@ public class Project implements ProjectTreeNode, Serializable {
|
|||||||
|
|
||||||
//Every instance field that is not transient will be saved in this file.
|
//Every instance field that is not transient will be saved in this file.
|
||||||
public static final String SETTINGS_FILE = ".project";
|
public static final String SETTINGS_FILE = ".project";
|
||||||
|
public static final String SETTINGS_FILE_JSON = ".project.json";
|
||||||
|
|
||||||
public String name;
|
public String name;
|
||||||
|
|
||||||
@@ -58,7 +57,6 @@ public class Project implements ProjectTreeNode, Serializable {
|
|||||||
|
|
||||||
public GameSource baseContent; //A.k.a library
|
public GameSource baseContent; //A.k.a library
|
||||||
|
|
||||||
public GameSource referencedContent; //Pointers to base content
|
|
||||||
public transient GameSource alteredContent; //Copied from base content (does not overwrite yet)
|
public transient GameSource alteredContent; //Copied from base content (does not overwrite yet)
|
||||||
public transient GameSource createdContent; //Stand-alone.
|
public transient GameSource createdContent; //Stand-alone.
|
||||||
public transient BookmarksRoot bookmarks;
|
public transient BookmarksRoot bookmarks;
|
||||||
@@ -72,6 +70,29 @@ public class Project implements ProjectTreeNode, Serializable {
|
|||||||
|
|
||||||
public Properties knownSpritesheetsProperties;
|
public Properties knownSpritesheetsProperties;
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Map toMap() {
|
||||||
|
Map map = new HashMap();
|
||||||
|
map.put("name", name.toString());
|
||||||
|
map.put("baseFolder", baseFolder.getPath());
|
||||||
|
map.put("open", open);
|
||||||
|
map.put("baseContent", baseContent.toMap());
|
||||||
|
map.put("sourceSetToUse", sourceSetToUse.toString());
|
||||||
|
return map;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void fromMap(Map map) {
|
||||||
|
if(map==null)return;
|
||||||
|
name = (String) map.get("name");
|
||||||
|
baseFolder = new File((String) map.get("baseFolder"));
|
||||||
|
open = (boolean) map.get("open");
|
||||||
|
|
||||||
|
baseContent = new GameSource((Map) map.get("baseContent"), this);
|
||||||
|
|
||||||
|
sourceSetToUse = Enum.valueOf(ResourceSet.class, (String)map.get("sourceSetToUse"));
|
||||||
|
}
|
||||||
|
|
||||||
public static enum ResourceSet {
|
public static enum ResourceSet {
|
||||||
gameData,
|
gameData,
|
||||||
debugData,
|
debugData,
|
||||||
@@ -80,7 +101,17 @@ public class Project implements ProjectTreeNode, Serializable {
|
|||||||
|
|
||||||
public ResourceSet sourceSetToUse;
|
public ResourceSet sourceSetToUse;
|
||||||
|
|
||||||
public Project(Workspace w, String name, File source, ResourceSet sourceSet) {
|
public Project(Workspace w, File projectFile) {
|
||||||
|
this.parent = w;
|
||||||
|
loadSpritesheetProperties();
|
||||||
|
Map json = FileUtils.mapFromJsonFile(projectFile);
|
||||||
|
this.fromMap(json);
|
||||||
|
|
||||||
|
initializeData();
|
||||||
|
linkAll();
|
||||||
|
save();
|
||||||
|
}
|
||||||
|
public Project(Workspace w, String name, File source, ResourceSet sourceSet){
|
||||||
this.parent = w;
|
this.parent = w;
|
||||||
this.name = name;
|
this.name = name;
|
||||||
this.sourceSetToUse = sourceSet;
|
this.sourceSetToUse = sourceSet;
|
||||||
@@ -93,24 +124,20 @@ public class Project implements ProjectTreeNode, Serializable {
|
|||||||
Notification.addError("Eror creating project root folder: " + e.getMessage());
|
Notification.addError("Eror creating project root folder: " + e.getMessage());
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
}
|
}
|
||||||
open = true;
|
|
||||||
v = new SavedSlotCollection();
|
|
||||||
|
|
||||||
knownSpritesheetsProperties = new Properties();
|
loadSpritesheetProperties();
|
||||||
try {
|
baseContent = new GameSource(source, this);
|
||||||
knownSpritesheetsProperties.load(Project.class.getResourceAsStream("/spritesheets.properties"));
|
open = true;
|
||||||
} catch (IOException e) {
|
initializeData();
|
||||||
Notification.addWarn("Unable to load default spritesheets properties.");
|
linkAll();
|
||||||
e.printStackTrace();
|
save();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void initializeData() {
|
||||||
|
v = new SavedSlotCollection();
|
||||||
|
|
||||||
baseContent = new GameSource(source, this);
|
alteredContent = new GameSource(this, Type.altered);
|
||||||
|
createdContent = new GameSource(this, Type.created);
|
||||||
// referencedContent = new GameSource(this, GameSource.Type.referenced);
|
|
||||||
|
|
||||||
alteredContent = new GameSource(this, GameSource.Type.altered);
|
|
||||||
createdContent = new GameSource(this, GameSource.Type.created);
|
|
||||||
bookmarks = new BookmarksRoot(this);
|
bookmarks = new BookmarksRoot(this);
|
||||||
|
|
||||||
// saves = new SavedGamesSet(this);
|
// saves = new SavedGamesSet(this);
|
||||||
@@ -121,10 +148,6 @@ public class Project implements ProjectTreeNode, Serializable {
|
|||||||
v.add(baseContent);
|
v.add(baseContent);
|
||||||
// v.add(saves);
|
// v.add(saves);
|
||||||
v.add(bookmarks);
|
v.add(bookmarks);
|
||||||
|
|
||||||
linkAll();
|
|
||||||
|
|
||||||
save();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -207,6 +230,11 @@ public class Project implements ProjectTreeNode, Serializable {
|
|||||||
|
|
||||||
public static Project fromFolder(Workspace w, File projRoot) {
|
public static Project fromFolder(Workspace w, File projRoot) {
|
||||||
Project p;
|
Project p;
|
||||||
|
|
||||||
|
File fJson = new File(projRoot, Project.SETTINGS_FILE_JSON);
|
||||||
|
if (fJson.exists()) {
|
||||||
|
p = new Project(w, fJson);
|
||||||
|
} else {
|
||||||
File f = new File(projRoot, Project.SETTINGS_FILE);
|
File f = new File(projRoot, Project.SETTINGS_FILE);
|
||||||
if (!f.exists()) {
|
if (!f.exists()) {
|
||||||
Notification.addError("Unable to find " + SETTINGS_FILE + " for project " + projRoot.getName());
|
Notification.addError("Unable to find " + SETTINGS_FILE + " for project " + projRoot.getName());
|
||||||
@@ -214,6 +242,9 @@ public class Project implements ProjectTreeNode, Serializable {
|
|||||||
} else {
|
} else {
|
||||||
p = (Project) SettingsSave.loadInstance(f, "Project");
|
p = (Project) SettingsSave.loadInstance(f, "Project");
|
||||||
}
|
}
|
||||||
|
p.save();
|
||||||
|
|
||||||
|
}
|
||||||
p.refreshTransients(w);
|
p.refreshTransients(w);
|
||||||
return p;
|
return p;
|
||||||
}
|
}
|
||||||
@@ -223,13 +254,7 @@ public class Project implements ProjectTreeNode, Serializable {
|
|||||||
|
|
||||||
projectElementListeners = new HashMap<Class<? extends GameDataElement>, List<ProjectElementListener>>();
|
projectElementListeners = new HashMap<Class<? extends GameDataElement>, List<ProjectElementListener>>();
|
||||||
|
|
||||||
try {
|
loadSpritesheetProperties();
|
||||||
knownSpritesheetsProperties = new Properties();
|
|
||||||
knownSpritesheetsProperties.load(Project.class.getResourceAsStream("/spritesheets.properties"));
|
|
||||||
} catch (IOException e) {
|
|
||||||
Notification.addWarn("Unable to load default spritesheets properties.");
|
|
||||||
e.printStackTrace();
|
|
||||||
}
|
|
||||||
|
|
||||||
if (sourceSetToUse == null) {
|
if (sourceSetToUse == null) {
|
||||||
sourceSetToUse = ResourceSet.allFiles;
|
sourceSetToUse = ResourceSet.allFiles;
|
||||||
@@ -259,6 +284,16 @@ public class Project implements ProjectTreeNode, Serializable {
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void loadSpritesheetProperties() {
|
||||||
|
knownSpritesheetsProperties = new Properties();
|
||||||
|
try {
|
||||||
|
knownSpritesheetsProperties.load(Project.class.getResourceAsStream("/spritesheets.properties"));
|
||||||
|
} catch (IOException e) {
|
||||||
|
Notification.addWarn("Unable to load default spritesheets properties.");
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
public void linkAll() {
|
public void linkAll() {
|
||||||
for (ProjectTreeNode node : baseContent.gameData.v.getNonEmptyIterable()) {
|
for (ProjectTreeNode node : baseContent.gameData.v.getNonEmptyIterable()) {
|
||||||
if (node instanceof GameDataCategory<?>) {
|
if (node instanceof GameDataCategory<?>) {
|
||||||
@@ -303,7 +338,7 @@ public class Project implements ProjectTreeNode, Serializable {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public void save() {
|
public void save() {
|
||||||
SettingsSave.saveInstance(this, new File(baseFolder, Project.SETTINGS_FILE), "Project " + this.name);
|
FileUtils.writeStringToFile(FileUtils.toJsonString(toMap()),new File(baseFolder, Project.SETTINGS_FILE_JSON), "Project " + this.name);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -111,7 +111,7 @@ public class Workspace implements ProjectTreeNode, Serializable, JsonSerializabl
|
|||||||
public static void setActive(File workspaceRoot) {
|
public static void setActive(File workspaceRoot) {
|
||||||
Workspace w;
|
Workspace w;
|
||||||
File f2 = new File(workspaceRoot, WS_SETTINGS_FILE_JSON);
|
File f2 = new File(workspaceRoot, WS_SETTINGS_FILE_JSON);
|
||||||
if (workspaceRoot.exists() && f2.exists()) {
|
if (f2.exists()) {
|
||||||
w = loadWorkspaceFromJson(workspaceRoot, f2);
|
w = loadWorkspaceFromJson(workspaceRoot, f2);
|
||||||
w.refreshTransients();
|
w.refreshTransients();
|
||||||
} else {
|
} else {
|
||||||
@@ -134,12 +134,9 @@ public class Workspace implements ProjectTreeNode, Serializable, JsonSerializabl
|
|||||||
|
|
||||||
private static Workspace loadWorkspaceFromJson(File workspaceRoot, File settingsFile) {
|
private static Workspace loadWorkspaceFromJson(File workspaceRoot, File settingsFile) {
|
||||||
Workspace w = w = new Workspace(workspaceRoot);
|
Workspace w = w = new Workspace(workspaceRoot);
|
||||||
String json = FileUtils.readFileToString(settingsFile);
|
Map json = FileUtils.mapFromJsonFile(settingsFile);
|
||||||
if (json!= null) {
|
if (json!= null) {
|
||||||
Map map = (Map)FileUtils.fromJsonString(json);
|
w.fromMap(json);
|
||||||
if(map!= null){
|
|
||||||
w.fromMap(map);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
return w;
|
return w;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -53,6 +53,15 @@ public class FileUtils {
|
|||||||
return o;
|
return o;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static Map mapFromJsonFile(File file){
|
||||||
|
String json = readFileToString(file);
|
||||||
|
if (json == null) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
Map map = (Map)FileUtils.fromJsonString(json);
|
||||||
|
return map;
|
||||||
|
}
|
||||||
|
|
||||||
public static boolean writeStringToFile(String toWrite, File file, String type) {
|
public static boolean writeStringToFile(String toWrite, File file, String type) {
|
||||||
return writeStringToFile(toWrite, file, type, true);
|
return writeStringToFile(toWrite, file, type, true);
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user