mirror of
https://github.com/OMGeeky/ATCS.git
synced 2026-01-17 08:56:47 +01:00
Warning hunt. Dialogue sketch I/O progress. Sketch creation from
existing Dialogue begins.
This commit is contained in:
@@ -9,7 +9,6 @@ import java.io.Serializable;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Enumeration;
|
||||
import java.util.LinkedHashMap;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
|
||||
@@ -11,7 +11,6 @@ import java.util.Enumeration;
|
||||
import java.util.HashMap;
|
||||
import java.util.LinkedHashMap;
|
||||
import java.util.LinkedHashSet;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Properties;
|
||||
@@ -827,7 +826,7 @@ public class Project implements ProjectTreeNode, Serializable {
|
||||
*
|
||||
* @param node. Before calling this method, make sure that no other node with the same class and id exist in either created or altered.
|
||||
*/
|
||||
public void createElements(List<JSONElement> nodes) {
|
||||
public void createElements(List<? extends JSONElement> nodes) {
|
||||
for (JSONElement node : nodes) {
|
||||
//Already added.
|
||||
if (node.getProject() != null) continue;
|
||||
@@ -892,7 +891,6 @@ public class Project implements ProjectTreeNode, Serializable {
|
||||
public void createWriterSketch(WriterModeData node) {
|
||||
node.writable = true;
|
||||
createdContent.writerModeDataSet.add(node);
|
||||
node.state = GameDataElement.State.created;
|
||||
node.link();
|
||||
fireElementAdded(node, getNodeIndex(node));
|
||||
}
|
||||
|
||||
@@ -9,7 +9,6 @@ import java.util.Collections;
|
||||
import java.util.Enumeration;
|
||||
import java.util.HashMap;
|
||||
import java.util.HashSet;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
@@ -26,13 +25,13 @@ import com.gpl.rpg.atcontentstudio.ui.ProjectsTree.ProjectsTreeModel;
|
||||
import com.gpl.rpg.atcontentstudio.ui.WorkerDialog;
|
||||
|
||||
public class Workspace implements ProjectTreeNode, Serializable {
|
||||
|
||||
|
||||
private static final long serialVersionUID = 7938633033601384956L;
|
||||
|
||||
public static final String WS_SETTINGS_FILE = ".workspace";
|
||||
|
||||
|
||||
public static Workspace activeWorkspace;
|
||||
|
||||
|
||||
public Preferences preferences = new Preferences();
|
||||
public File baseFolder;
|
||||
public File settingsFile;
|
||||
@@ -40,16 +39,17 @@ public class Workspace implements ProjectTreeNode, Serializable {
|
||||
public Set<String> projectsName = new HashSet<String>();
|
||||
public Map<String, Boolean> projectsOpenByName = new HashMap<String, Boolean>();
|
||||
public Set<File> knownMapSourcesFolders = new HashSet<File>();
|
||||
|
||||
|
||||
public transient ProjectsTreeModel projectsTreeModel = null;
|
||||
|
||||
|
||||
public Workspace(File workspaceRoot) {
|
||||
baseFolder = workspaceRoot;
|
||||
if (!workspaceRoot.exists()) {
|
||||
try {
|
||||
workspaceRoot.mkdir();
|
||||
} catch (SecurityException e) {
|
||||
Notification.addError("Error creating workspace directory: "+e.getMessage());
|
||||
Notification.addError("Error creating workspace directory: "
|
||||
+ e.getMessage());
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
@@ -58,14 +58,15 @@ public class Workspace implements ProjectTreeNode, Serializable {
|
||||
try {
|
||||
settingsFile.createNewFile();
|
||||
} catch (IOException e) {
|
||||
Notification.addError("Error creating workspace datafile: "+e.getMessage());
|
||||
Notification.addError("Error creating workspace datafile: "
|
||||
+ e.getMessage());
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
Notification.addSuccess("New workspace created: "+workspaceRoot.getAbsolutePath());
|
||||
Notification.addSuccess("New workspace created: "
|
||||
+ workspaceRoot.getAbsolutePath());
|
||||
save();
|
||||
}
|
||||
|
||||
|
||||
public static void setActive(File workspaceRoot) {
|
||||
Workspace w = null;
|
||||
@@ -82,11 +83,11 @@ public class Workspace implements ProjectTreeNode, Serializable {
|
||||
}
|
||||
activeWorkspace = w;
|
||||
}
|
||||
|
||||
|
||||
public static void saveActive() {
|
||||
activeWorkspace.save();
|
||||
}
|
||||
|
||||
|
||||
public void save() {
|
||||
SettingsSave.saveInstance(this, settingsFile, "Workspace");
|
||||
}
|
||||
@@ -95,82 +96,104 @@ public class Workspace implements ProjectTreeNode, Serializable {
|
||||
public Enumeration<ProjectTreeNode> children() {
|
||||
return Collections.enumeration(projects);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean getAllowsChildren() {
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public TreeNode getChildAt(int arg0) {
|
||||
return projects.get(arg0);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getChildCount() {
|
||||
return projects.size();
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getIndex(TreeNode arg0) {
|
||||
return projects.indexOf(arg0);
|
||||
}
|
||||
|
||||
@Override
|
||||
public TreeNode getParent() {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isLeaf() {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void childrenAdded(List<ProjectTreeNode> path) {
|
||||
path.add(0, this);
|
||||
if (projectsTreeModel != null) projectsTreeModel.insertNode(new TreePath(path.toArray()));
|
||||
if (projectsTreeModel != null)
|
||||
projectsTreeModel.insertNode(new TreePath(path.toArray()));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void childrenChanged(List<ProjectTreeNode> path) {
|
||||
path.add(0, this);
|
||||
if (projectsTreeModel != null) projectsTreeModel.changeNode(new TreePath(path.toArray()));
|
||||
ATContentStudio.frame.editorChanged(path.get(path.size() - 1));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void childrenRemoved(List<ProjectTreeNode> path) {
|
||||
path.add(0, this);
|
||||
if (projectsTreeModel != null) projectsTreeModel.removeNode(new TreePath(path.toArray()));
|
||||
if (projectsTreeModel != null)
|
||||
projectsTreeModel.removeNode(new TreePath(path.toArray()));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void notifyCreated() {
|
||||
childrenAdded(new ArrayList<ProjectTreeNode>());
|
||||
for (ProjectTreeNode node : projects) {
|
||||
if (node != null) node.notifyCreated();
|
||||
if (node != null)
|
||||
node.notifyCreated();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getDesc() {
|
||||
return "Workspace: "+baseFolder.getAbsolutePath();
|
||||
return "Workspace: " + baseFolder.getAbsolutePath();
|
||||
}
|
||||
|
||||
|
||||
public static void createProject(final String projectName, final File gameSourceFolder, final Project.ResourceSet sourceSet) {
|
||||
WorkerDialog.showTaskMessage("Creating project "+projectName+"...", ATContentStudio.frame, new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
if (activeWorkspace.projectsName.contains(projectName)) {
|
||||
Notification.addError("A project named "+projectName+" already exists in this workspace.");
|
||||
return;
|
||||
}
|
||||
Project p = new Project(activeWorkspace, projectName, gameSourceFolder, sourceSet);
|
||||
activeWorkspace.projects.add(p);
|
||||
activeWorkspace.projectsName.add(projectName);
|
||||
activeWorkspace.projectsOpenByName.put(projectName, p.open);
|
||||
activeWorkspace.knownMapSourcesFolders.add(gameSourceFolder);
|
||||
p.notifyCreated();
|
||||
Notification.addSuccess("Project "+projectName+" successfully created");
|
||||
saveActive();
|
||||
}
|
||||
});
|
||||
public static void createProject(final String projectName,
|
||||
final File gameSourceFolder, final Project.ResourceSet sourceSet) {
|
||||
WorkerDialog.showTaskMessage("Creating project " + projectName + "...",
|
||||
ATContentStudio.frame, new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
if (activeWorkspace.projectsName.contains(projectName)) {
|
||||
Notification.addError("A project named "
|
||||
+ projectName
|
||||
+ " already exists in this workspace.");
|
||||
return;
|
||||
}
|
||||
Project p = new Project(activeWorkspace, projectName,
|
||||
gameSourceFolder, sourceSet);
|
||||
activeWorkspace.projects.add(p);
|
||||
activeWorkspace.projectsName.add(projectName);
|
||||
activeWorkspace.projectsOpenByName.put(projectName,
|
||||
p.open);
|
||||
activeWorkspace.knownMapSourcesFolders
|
||||
.add(gameSourceFolder);
|
||||
p.notifyCreated();
|
||||
Notification.addSuccess("Project " + projectName
|
||||
+ " successfully created");
|
||||
saveActive();
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
public static void closeProject(Project p) {
|
||||
int index = activeWorkspace.projects.indexOf(p);
|
||||
if (index < 0) {
|
||||
Notification.addError("Cannot close unknown project "+p.name);
|
||||
Notification.addError("Cannot close unknown project " + p.name);
|
||||
return;
|
||||
}
|
||||
p.close();
|
||||
@@ -180,27 +203,31 @@ public class Workspace implements ProjectTreeNode, Serializable {
|
||||
cp.notifyCreated();
|
||||
saveActive();
|
||||
}
|
||||
|
||||
|
||||
public static void openProject(final ClosedProject cp) {
|
||||
WorkerDialog.showTaskMessage("Opening project "+cp.name+"...", ATContentStudio.frame, new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
int index = activeWorkspace.projects.indexOf(cp);
|
||||
if (index < 0) {
|
||||
Notification.addError("Cannot open unknown project "+cp.name);
|
||||
return;
|
||||
}
|
||||
cp.childrenRemoved(new ArrayList<ProjectTreeNode>());
|
||||
Project p = Project.fromFolder(activeWorkspace, new File(activeWorkspace.baseFolder, cp.name));
|
||||
p.open();
|
||||
activeWorkspace.projects.set(index, p);
|
||||
activeWorkspace.projectsOpenByName.put(p.name, true);
|
||||
p.notifyCreated();
|
||||
saveActive();
|
||||
}
|
||||
});
|
||||
WorkerDialog.showTaskMessage("Opening project " + cp.name + "...",
|
||||
ATContentStudio.frame, new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
int index = activeWorkspace.projects.indexOf(cp);
|
||||
if (index < 0) {
|
||||
Notification
|
||||
.addError("Cannot open unknown project "
|
||||
+ cp.name);
|
||||
return;
|
||||
}
|
||||
cp.childrenRemoved(new ArrayList<ProjectTreeNode>());
|
||||
Project p = Project.fromFolder(activeWorkspace,
|
||||
new File(activeWorkspace.baseFolder, cp.name));
|
||||
p.open();
|
||||
activeWorkspace.projects.set(index, p);
|
||||
activeWorkspace.projectsOpenByName.put(p.name, true);
|
||||
p.notifyCreated();
|
||||
saveActive();
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
public void refreshTransients() {
|
||||
this.projects = new ArrayList<ProjectTreeNode>();
|
||||
Set<String> projectsFailed = new HashSet<String>();
|
||||
@@ -212,11 +239,16 @@ public class Workspace implements ProjectTreeNode, Serializable {
|
||||
if (p != null) {
|
||||
projects.add(p);
|
||||
} else {
|
||||
Notification.addError("Failed to open project "+projectName+". Removing it from workspace (not from filesystem though).");
|
||||
Notification
|
||||
.addError("Failed to open project "
|
||||
+ projectName
|
||||
+ ". Removing it from workspace (not from filesystem though).");
|
||||
projectsFailed.add(projectName);
|
||||
}
|
||||
} else {
|
||||
Notification.addError("Unable to find project "+projectName+"'s root folder. Removing it from workspace");
|
||||
Notification.addError("Unable to find project "
|
||||
+ projectName
|
||||
+ "'s root folder. Removing it from workspace");
|
||||
projectsFailed.add(projectName);
|
||||
}
|
||||
} else {
|
||||
@@ -229,21 +261,31 @@ public class Workspace implements ProjectTreeNode, Serializable {
|
||||
}
|
||||
notifyCreated();
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public Project getProject() {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Image getIcon() {return null;}
|
||||
@Override
|
||||
public Image getClosedIcon() {return null;}
|
||||
@Override
|
||||
public Image getLeafIcon() {return null;}
|
||||
@Override
|
||||
public Image getOpenIcon() {return null;}
|
||||
|
||||
@Override
|
||||
public Image getIcon() {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Image getClosedIcon() {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Image getLeafIcon() {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Image getOpenIcon() {
|
||||
return null;
|
||||
}
|
||||
|
||||
public static void deleteProject(ClosedProject cp) {
|
||||
cp.childrenRemoved(new ArrayList<ProjectTreeNode>());
|
||||
@@ -251,37 +293,41 @@ public class Workspace implements ProjectTreeNode, Serializable {
|
||||
activeWorkspace.projectsOpenByName.remove(cp.name);
|
||||
activeWorkspace.projectsName.remove(cp.name);
|
||||
if (delete(new File(activeWorkspace.baseFolder, cp.name))) {
|
||||
Notification.addSuccess("Closed project "+cp.name+" successfully deleted.");
|
||||
Notification.addSuccess("Closed project " + cp.name
|
||||
+ " successfully deleted.");
|
||||
} else {
|
||||
Notification.addError("Error while deleting closed project "+cp.name+". Files may remain in the workspace.");
|
||||
Notification.addError("Error while deleting closed project "
|
||||
+ cp.name + ". Files may remain in the workspace.");
|
||||
}
|
||||
cp = null;
|
||||
saveActive();
|
||||
}
|
||||
|
||||
|
||||
public static void deleteProject(Project p) {
|
||||
p.childrenRemoved(new ArrayList<ProjectTreeNode>());
|
||||
activeWorkspace.projects.remove(p);
|
||||
activeWorkspace.projectsOpenByName.remove(p.name);
|
||||
activeWorkspace.projectsName.remove(p.name);
|
||||
if (delete(p.baseFolder)) {
|
||||
Notification.addSuccess("Project "+p.name+" successfully deleted.");
|
||||
Notification.addSuccess("Project " + p.name
|
||||
+ " successfully deleted.");
|
||||
} else {
|
||||
Notification.addError("Error while deleting project "+p.name+". Files may remain in the workspace.");
|
||||
Notification.addError("Error while deleting project " + p.name
|
||||
+ ". Files may remain in the workspace.");
|
||||
}
|
||||
p = null;
|
||||
saveActive();
|
||||
}
|
||||
|
||||
|
||||
private static boolean delete(File f) {
|
||||
boolean b = true;
|
||||
if (f.isDirectory()) {
|
||||
for (File c : f.listFiles())
|
||||
b &= delete(c);
|
||||
}
|
||||
return b&= f.delete();
|
||||
return b &= f.delete();
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public GameDataSet getDataSet() {
|
||||
return null;
|
||||
@@ -291,11 +337,10 @@ public class Workspace implements ProjectTreeNode, Serializable {
|
||||
public Type getDataType() {
|
||||
return null;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public boolean isEmpty() {
|
||||
return projects.isEmpty();
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
@@ -8,7 +8,6 @@ import java.io.IOException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.LinkedHashMap;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
|
||||
@@ -5,8 +5,8 @@ import java.io.File;
|
||||
import java.io.FileNotFoundException;
|
||||
import java.io.FileReader;
|
||||
import java.io.IOException;
|
||||
import java.util.LinkedHashMap;
|
||||
import java.util.ArrayList;
|
||||
import java.util.LinkedHashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
|
||||
@@ -10,7 +10,6 @@ import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
import java.util.Enumeration;
|
||||
import java.util.LinkedHashMap;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
|
||||
@@ -5,8 +5,8 @@ import java.io.File;
|
||||
import java.io.FileNotFoundException;
|
||||
import java.io.FileReader;
|
||||
import java.io.IOException;
|
||||
import java.util.LinkedHashMap;
|
||||
import java.util.ArrayList;
|
||||
import java.util.LinkedHashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
|
||||
@@ -5,8 +5,8 @@ import java.io.File;
|
||||
import java.io.FileNotFoundException;
|
||||
import java.io.FileReader;
|
||||
import java.io.IOException;
|
||||
import java.util.LinkedHashMap;
|
||||
import java.util.ArrayList;
|
||||
import java.util.LinkedHashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
|
||||
@@ -5,8 +5,8 @@ import java.io.File;
|
||||
import java.io.FileNotFoundException;
|
||||
import java.io.FileReader;
|
||||
import java.io.IOException;
|
||||
import java.util.LinkedHashMap;
|
||||
import java.util.ArrayList;
|
||||
import java.util.LinkedHashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
package com.gpl.rpg.atcontentstudio.model.gamedata;
|
||||
|
||||
import java.util.LinkedHashMap;
|
||||
import java.util.ArrayList;
|
||||
import java.util.LinkedHashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
|
||||
@@ -10,7 +10,6 @@ import java.io.StringReader;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Enumeration;
|
||||
import java.util.HashSet;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
|
||||
|
||||
@@ -6,7 +6,6 @@ import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
import java.util.Comparator;
|
||||
import java.util.Enumeration;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import javax.swing.tree.TreeNode;
|
||||
|
||||
@@ -11,7 +11,6 @@ import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
import java.util.Enumeration;
|
||||
import java.util.LinkedHashMap;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
|
||||
@@ -3,8 +3,8 @@ package com.gpl.rpg.atcontentstudio.model.maps;
|
||||
import java.awt.Image;
|
||||
import java.awt.Point;
|
||||
import java.io.ByteArrayOutputStream;
|
||||
import java.util.LinkedHashMap;
|
||||
import java.util.ArrayList;
|
||||
import java.util.LinkedHashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
|
||||
@@ -5,7 +5,6 @@ import java.io.File;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
import java.util.Enumeration;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import javax.swing.tree.TreeNode;
|
||||
|
||||
@@ -6,10 +6,11 @@ import java.io.FileNotFoundException;
|
||||
import java.io.FileReader;
|
||||
import java.io.IOException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collection;
|
||||
import java.util.LinkedHashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.regex.Matcher;
|
||||
import java.util.regex.Pattern;
|
||||
|
||||
import org.json.simple.parser.JSONParser;
|
||||
import org.json.simple.parser.ParseException;
|
||||
@@ -17,6 +18,7 @@ import org.json.simple.parser.ParseException;
|
||||
import com.gpl.rpg.atcontentstudio.Notification;
|
||||
import com.gpl.rpg.atcontentstudio.model.GameDataElement;
|
||||
import com.gpl.rpg.atcontentstudio.model.Project;
|
||||
import com.gpl.rpg.atcontentstudio.model.ProjectTreeNode;
|
||||
import com.gpl.rpg.atcontentstudio.model.SaveEvent;
|
||||
import com.gpl.rpg.atcontentstudio.model.gamedata.Dialogue;
|
||||
import com.gpl.rpg.atcontentstudio.model.gamedata.GameDataSet;
|
||||
@@ -43,15 +45,21 @@ public class WriterModeData extends GameDataElement {
|
||||
public WriterModeData(String id_prefix){
|
||||
this.id = id_prefix;
|
||||
}
|
||||
|
||||
|
||||
@SuppressWarnings("rawtypes")
|
||||
public WriterModeData(WriterModeDataSet parent, @SuppressWarnings("rawtypes") Map jsonObj) {
|
||||
public WriterModeData(WriterModeDataSet parent, Map jsonObj) {
|
||||
this.parent = parent;
|
||||
this.jsonFile = parent.writerFile;
|
||||
this.parse(jsonObj);
|
||||
this.state = State.parsed;
|
||||
}
|
||||
|
||||
public WriterModeData(String id_prefix, Dialogue imported) {
|
||||
this.id = id_prefix;
|
||||
this.begin = new WriterDialogue(imported);
|
||||
this.state = State.linked;
|
||||
}
|
||||
|
||||
public int getNextIndex(String id_prefix) {
|
||||
Integer index = threadsNextIndex.get(id_prefix);
|
||||
if (index == null) index = 0;
|
||||
@@ -81,6 +89,30 @@ public class WriterModeData extends GameDataElement {
|
||||
|
||||
public WriterDialogue() {}
|
||||
|
||||
public WriterDialogue(Dialogue dialogue) {
|
||||
this.dialogue = dialogue;
|
||||
this.text = dialogue.message;
|
||||
this.id = this.dialogue_id = dialogue.id;
|
||||
Pattern p = Pattern.compile("(.*)([0-9]+)");
|
||||
Matcher m = p.matcher(dialogue.id);
|
||||
if (m.matches()) {
|
||||
this.id_prefix = m.group(1);
|
||||
this.index = Integer.parseInt(m.group(2));
|
||||
} else {
|
||||
this.id_prefix = this.id+"_";
|
||||
}
|
||||
nodesById.put(this.id, this);
|
||||
if (dialogue.replies != null) {
|
||||
for (Dialogue.Reply reply : dialogue.replies) {
|
||||
if (Dialogue.Reply.GO_NEXT_TEXT.equals(reply.text)) {
|
||||
replies.add(new EmptyReply(this, reply));
|
||||
} else {
|
||||
replies.add(new WriterReply(this, reply));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public WriterDialogue(String id_prefix) {
|
||||
text = "";
|
||||
this.id_prefix = id_prefix;
|
||||
@@ -89,7 +121,7 @@ public class WriterModeData extends GameDataElement {
|
||||
|
||||
@Override
|
||||
public String getTitle() {
|
||||
return "Dialogue "+id_prefix+index;
|
||||
return "Dialogue "+getID();
|
||||
}
|
||||
|
||||
public String getID() {
|
||||
@@ -146,22 +178,50 @@ public class WriterModeData extends GameDataElement {
|
||||
public boolean isSpecial() {return false;}
|
||||
|
||||
|
||||
public Dialogue toDialogue(Map<WriterDialogue, Dialogue> visited) {
|
||||
public Dialogue toDialogue(Map<WriterDialogue, Dialogue> visited, List<Dialogue> created, List<Dialogue> modified) {
|
||||
if (visited.get(this) != null) return visited.get(this);
|
||||
//Creating a new Dialogue
|
||||
if (dialogue == null) {
|
||||
dialogue = new Dialogue();
|
||||
dialogue.id = getID();
|
||||
dialogue.state = GameDataElement.State.parsed;
|
||||
created.add(dialogue);
|
||||
} else {
|
||||
if (hasChanged()) dialogue.state = GameDataElement.State.modified;
|
||||
if (hasChanged()) {
|
||||
if (dialogue.writable) {
|
||||
//Modifying a created or altered Dialogue
|
||||
dialogue.state = GameDataElement.State.modified;
|
||||
modified.add(dialogue);
|
||||
} else {
|
||||
//Altering a game source Dialogue
|
||||
Dialogue clone = (Dialogue) dialogue.clone();
|
||||
if (this.replies != null) {
|
||||
for (WriterReply wReply : this.replies) {
|
||||
if (wReply.reply != null) {
|
||||
wReply.reply = clone.replies.get(dialogue.replies.indexOf(wReply.reply));
|
||||
}
|
||||
}
|
||||
}
|
||||
dialogue = clone;
|
||||
dialogue.state = GameDataElement.State.parsed;
|
||||
created.add(dialogue);
|
||||
}
|
||||
}
|
||||
}
|
||||
visited.put(this, dialogue);
|
||||
dialogue.message = this.text;
|
||||
if (this.replies != null && !this.replies.isEmpty()) {
|
||||
dialogue.replies = new ArrayList<Dialogue.Reply>();
|
||||
for (WriterReply wReply : this.replies) {
|
||||
dialogue.replies.add(wReply.toReply(visited));
|
||||
if (dialogue.replies == null) {
|
||||
dialogue.replies = new ArrayList<Dialogue.Reply>();
|
||||
} else {
|
||||
dialogue.replies.clear();
|
||||
}
|
||||
for (WriterReply wReply : this.replies) {
|
||||
//if (wReply.reply != null && dialogue.replies)
|
||||
dialogue.replies.add(wReply.toReply(visited, created, modified));
|
||||
}
|
||||
} else {
|
||||
dialogue.replies = null;
|
||||
}
|
||||
return dialogue;
|
||||
}
|
||||
@@ -194,19 +254,19 @@ public class WriterModeData extends GameDataElement {
|
||||
public SpecialDialogue duplicate() {return new SelectorDialogue();}
|
||||
}
|
||||
public class ShopDialogue extends SpecialDialogue {
|
||||
public static final String id = "S";
|
||||
public static final String id = Dialogue.Reply.SHOP_PHRASE_ID;
|
||||
public SpecialDialogue duplicate() {return new ShopDialogue();}
|
||||
}
|
||||
public class FightDialogue extends SpecialDialogue {
|
||||
public static final String id = "F";
|
||||
public static final String id = Dialogue.Reply.FIGHT_PHRASE_ID;
|
||||
public SpecialDialogue duplicate() {return new FightDialogue();}
|
||||
}
|
||||
public class EndDialogue extends SpecialDialogue {
|
||||
public static final String id = "X";
|
||||
public static final String id = Dialogue.Reply.EXIT_PHRASE_ID;
|
||||
public SpecialDialogue duplicate() {return new EndDialogue();}
|
||||
}
|
||||
public class RemoveNPCDialogue extends SpecialDialogue {
|
||||
public static final String id = "R";
|
||||
public static final String id = Dialogue.Reply.REMOVE_PHRASE_ID;
|
||||
public SpecialDialogue duplicate() {return new RemoveNPCDialogue();}
|
||||
}
|
||||
|
||||
@@ -224,6 +284,18 @@ public class WriterModeData extends GameDataElement {
|
||||
parent.replies.add(this);
|
||||
}
|
||||
|
||||
public WriterReply(WriterDialogue parent, Dialogue.Reply reply) {
|
||||
this.parent = parent;
|
||||
this.reply = reply;
|
||||
this.text = reply.text;
|
||||
this.next_dialogue_id = reply.next_phrase_id;
|
||||
if (nodesById.get(this.next_dialogue_id) != null) {
|
||||
this.next_dialogue = nodesById.get(this.next_dialogue_id);
|
||||
} else if (reply.next_phrase != null ){
|
||||
this.next_dialogue = new WriterDialogue(reply.next_phrase);
|
||||
}
|
||||
}
|
||||
|
||||
@SuppressWarnings("rawtypes")
|
||||
public WriterReply(WriterDialogue parent, Map json) {
|
||||
this.parent = parent;
|
||||
@@ -252,18 +324,18 @@ public class WriterModeData extends GameDataElement {
|
||||
|
||||
public boolean isSpecial() {return false;}
|
||||
|
||||
public Dialogue.Reply toReply(Map<WriterDialogue, Dialogue> visited) {
|
||||
public Dialogue.Reply toReply(Map<WriterDialogue, Dialogue> visited, List<Dialogue> created, List<Dialogue> modified) {
|
||||
if (reply == null) {
|
||||
reply = new Dialogue.Reply();
|
||||
}
|
||||
reply.text = this.text;
|
||||
if (this.next_dialogue != null) {
|
||||
this.next_dialogue.toDialogue(visited);
|
||||
this.next_dialogue.toDialogue(visited, created, modified);
|
||||
reply.next_phrase_id = this.next_dialogue.getID();
|
||||
} else if (this.next_dialogue_id != null) {
|
||||
reply.next_phrase_id = this.next_dialogue_id;
|
||||
} else {
|
||||
reply.next_phrase_id = "X";
|
||||
reply.next_phrase_id = Dialogue.Reply.EXIT_PHRASE_ID;
|
||||
}
|
||||
return reply;
|
||||
}
|
||||
@@ -289,6 +361,10 @@ public class WriterModeData extends GameDataElement {
|
||||
|
||||
public boolean isSpecial() {return true;}
|
||||
|
||||
public SpecialReply(WriterDialogue parent, Dialogue.Reply reply) {
|
||||
super(parent, reply);
|
||||
}
|
||||
|
||||
public SpecialReply(WriterDialogue parent) {
|
||||
super(parent);
|
||||
}
|
||||
@@ -298,15 +374,20 @@ public class WriterModeData extends GameDataElement {
|
||||
}
|
||||
}
|
||||
public class EmptyReply extends SpecialReply {
|
||||
|
||||
public EmptyReply(WriterDialogue parent, Dialogue.Reply reply) {
|
||||
super(parent, reply);
|
||||
text = Dialogue.Reply.GO_NEXT_TEXT;
|
||||
}
|
||||
|
||||
public EmptyReply(WriterDialogue parent) {
|
||||
super(parent);
|
||||
text="N";
|
||||
text = Dialogue.Reply.GO_NEXT_TEXT;
|
||||
}
|
||||
|
||||
public EmptyReply(WriterDialogue parent, Map json) {
|
||||
super(parent, json);
|
||||
text="N";
|
||||
text = Dialogue.Reply.GO_NEXT_TEXT;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -471,6 +552,35 @@ public class WriterModeData extends GameDataElement {
|
||||
reply.next_dialogue = nodesById.get(reply.next_dialogue_id);
|
||||
}
|
||||
}
|
||||
//TODO Seriously, this is failure-prone by design. Can't do much better though...
|
||||
List<Dialogue.Reply> linked = new ArrayList<Dialogue.Reply>(dialogue.dialogue.replies.size());
|
||||
if (dialogue.dialogue != null && dialogue.dialogue.replies != null) {
|
||||
//Try to hook to existing replies... not as easy when there's no ID.
|
||||
Dialogue.Reply best = null;
|
||||
int score, maxScore = 0;
|
||||
for (Dialogue.Reply dReply : dialogue.dialogue.replies) {
|
||||
//Never link twice to the same...
|
||||
if (linked.contains(dReply)) continue;
|
||||
score = 0;
|
||||
//Arbitrary values... hopefully this gives good results.
|
||||
//Same target gives good hope of preserving at least the structure.
|
||||
if (dReply.next_phrase_id != null && dReply.next_phrase_id.equals(reply.next_dialogue_id)) score +=50;
|
||||
//Same text is almost as good as an ID, but there may be duplicates due to requirements system...
|
||||
if (dReply.text != null && dReply.text.equals(reply.text)) score +=40;
|
||||
//Same slot in the list. That's not so bad if all else fails, and could help sort duplicates with same text.
|
||||
if (dialogue.dialogue.replies.indexOf(dReply) == dialogue.replies.indexOf(reply)) score +=20;
|
||||
//Both have null text. It's not much, but it's something....
|
||||
if (dReply.text == null && reply.text == null) score += 10;
|
||||
if (score > maxScore) {
|
||||
maxScore = score;
|
||||
best = dReply;
|
||||
}
|
||||
}
|
||||
if (maxScore > 0) {
|
||||
reply.reply = best;
|
||||
linked.add(best);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
for (String rootId : rootsId) {
|
||||
@@ -504,10 +614,15 @@ public class WriterModeData extends GameDataElement {
|
||||
return null;
|
||||
}
|
||||
|
||||
public Collection<Dialogue> toDialogue(){
|
||||
public List<Dialogue> toDialogue(){
|
||||
Map<WriterModeData.WriterDialogue, Dialogue> visited = new LinkedHashMap<WriterModeData.WriterDialogue, Dialogue>();
|
||||
begin.toDialogue(visited);
|
||||
return visited.values();
|
||||
List<Dialogue> created = new ArrayList<Dialogue>();
|
||||
List<Dialogue> modified = new ArrayList<Dialogue>();
|
||||
begin.toDialogue(visited, created, modified);
|
||||
for (Dialogue modifiedDialogue : modified) {
|
||||
modifiedDialogue.childrenChanged(new ArrayList<ProjectTreeNode>());
|
||||
}
|
||||
return created;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -11,7 +11,6 @@ import java.io.StringWriter;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
import java.util.Enumeration;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user