From b1d0175a9de033540053243e344a0a9237d2aee8 Mon Sep 17 00:00:00 2001 From: Zukero Date: Fri, 16 Dec 2016 09:41:04 +0100 Subject: [PATCH] Progress on Dialogue Sketch to JSON Data conversion. Opportunistic bug fix in JSON import wizard. --- .../rpg/atcontentstudio/model/Project.java | 30 ++++++++++++++++++- .../model/gamedata/Dialogue.java | 5 +--- .../tools/writermode/WriterModeData.java | 19 ++++++++---- .../atcontentstudio/ui/JSONImportWizard.java | 7 ++--- .../atcontentstudio/ui/WorkspaceActions.java | 7 +---- 5 files changed, 46 insertions(+), 22 deletions(-) diff --git a/src/com/gpl/rpg/atcontentstudio/model/Project.java b/src/com/gpl/rpg/atcontentstudio/model/Project.java index e54aac3..f3e97ff 100644 --- a/src/com/gpl/rpg/atcontentstudio/model/Project.java +++ b/src/com/gpl/rpg/atcontentstudio/model/Project.java @@ -801,7 +801,7 @@ public class Project implements ProjectTreeNode, Serializable { /** * - * @param node. Before calling this method, make sure that no other node with the same class exist in either created or altered. + * @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 createElement(JSONElement node) { node.writable = true; @@ -823,6 +823,34 @@ public class Project implements ProjectTreeNode, Serializable { fireElementAdded(node, getNodeIndex(node)); } + /** + * + * @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 nodes) { + for (JSONElement node : nodes) { + //Already added. + if (node.getProject() != null) continue; + node.writable = true; + if (getGameDataElement(node.getClass(), node.id) != null) { + GameDataElement existingNode = getGameDataElement(node.getClass(), node.id); + for (GameDataElement backlink : existingNode.getBacklinks()) { + backlink.elementChanged(existingNode, node); + } + existingNode.getBacklinks().clear(); + node.writable = true; + alteredContent.gameData.addElement(node); + } else { + createdContent.gameData.addElement(node); + } + } + for (JSONElement node : nodes) { + node.link(); + node.state = GameDataElement.State.created; + fireElementAdded(node, getNodeIndex(node)); + } + } + public void moveToCreated(JSONElement target) { target.childrenRemoved(new ArrayList()); diff --git a/src/com/gpl/rpg/atcontentstudio/model/gamedata/Dialogue.java b/src/com/gpl/rpg/atcontentstudio/model/gamedata/Dialogue.java index 87bf3a0..0f64e2c 100644 --- a/src/com/gpl/rpg/atcontentstudio/model/gamedata/Dialogue.java +++ b/src/com/gpl/rpg/atcontentstudio/model/gamedata/Dialogue.java @@ -224,10 +224,7 @@ public class Dialogue extends JSONElement { if (replies != null) { for (Reply reply : replies) { if (reply.next_phrase_id != null) { - if (!reply.next_phrase_id.equals(Reply.EXIT_PHRASE_ID) - && !reply.next_phrase_id.equals(Reply.FIGHT_PHRASE_ID) - && !reply.next_phrase_id.equals(Reply.SHOP_PHRASE_ID) - && !reply.next_phrase_id.equals(Reply.REMOVE_PHRASE_ID)) { + if (!Reply.KEY_PHRASE_ID.contains(reply.next_phrase_id)) { reply.next_phrase = proj.getDialogue(reply.next_phrase_id); } } diff --git a/src/com/gpl/rpg/atcontentstudio/model/tools/writermode/WriterModeData.java b/src/com/gpl/rpg/atcontentstudio/model/tools/writermode/WriterModeData.java index 5fd5563..a201ad6 100644 --- a/src/com/gpl/rpg/atcontentstudio/model/tools/writermode/WriterModeData.java +++ b/src/com/gpl/rpg/atcontentstudio/model/tools/writermode/WriterModeData.java @@ -5,9 +5,9 @@ import java.io.File; 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.ArrayList; import java.util.List; import java.util.Map; @@ -78,7 +78,7 @@ public class WriterModeData extends GameDataElement { public int index; public List replies = new ArrayList(); public List parents = new ArrayList(); - + public Dialogue dialogue; public WriterDialogue() {} @@ -137,10 +137,14 @@ public class WriterModeData extends GameDataElement { public Dialogue toDialogue(Map visited){ if (visited.get(this) != null) return visited.get(this); - Dialogue dialogue = new Dialogue(); - dialogue.state = GameDataElement.State.parsed; + if (dialogue == null) { + dialogue = new Dialogue(); + dialogue.id = getID(); + dialogue.state = GameDataElement.State.parsed; + } else { + dialogue.state = GameDataElement.State.modified; + } visited.put(this, dialogue); - dialogue.id = getID(); dialogue.message = this.text; if (this.replies != null && !this.replies.isEmpty()) { dialogue.replies = new ArrayList(); @@ -182,6 +186,7 @@ public class WriterModeData extends GameDataElement { public WriterDialogue parent; public String next_dialogue_id; public WriterDialogue next_dialogue; + public Dialogue.Reply reply; public WriterReply() {} @@ -220,7 +225,9 @@ public class WriterModeData extends GameDataElement { public boolean isSpecial() {return false;} public Dialogue.Reply toReply(Map visited) { - Dialogue.Reply reply = new Dialogue.Reply(); + if (reply == null) { + reply = new Dialogue.Reply(); + } reply.text = this.text; if (this.next_dialogue != null) { this.next_dialogue.toDialogue(visited); diff --git a/src/com/gpl/rpg/atcontentstudio/ui/JSONImportWizard.java b/src/com/gpl/rpg/atcontentstudio/ui/JSONImportWizard.java index 6cfeb9f..4990d4a 100644 --- a/src/com/gpl/rpg/atcontentstudio/ui/JSONImportWizard.java +++ b/src/com/gpl/rpg/atcontentstudio/ui/JSONImportWizard.java @@ -404,11 +404,8 @@ public class JSONImportWizard extends JDialog { okListener = new ActionListener() { @Override public void actionPerformed(ActionEvent e) { - JSONElement lastNode = null; - for (JSONElement node : created) { - proj.createElement(node); - lastNode = node; - } + proj.createElements(created); + JSONElement lastNode = created.get(created.size() - 1); if (lastNode != null) { lastNode.save(); ATContentStudio.frame.selectInTree(lastNode); diff --git a/src/com/gpl/rpg/atcontentstudio/ui/WorkspaceActions.java b/src/com/gpl/rpg/atcontentstudio/ui/WorkspaceActions.java index 208bd6e..3d55c08 100644 --- a/src/com/gpl/rpg/atcontentstudio/ui/WorkspaceActions.java +++ b/src/com/gpl/rpg/atcontentstudio/ui/WorkspaceActions.java @@ -342,12 +342,7 @@ public class WorkspaceActions { if (selectedNode == null || selectedNode.getProject() == null || !(selectedNode instanceof WriterModeData)) return; WriterModeData wData = (WriterModeData)selectedNode; Collection exported = wData.toDialogue(); - for (Dialogue dialogue : exported) { - selectedNode.getProject().createElement(dialogue); - } - for (Dialogue dialogue : exported) { - dialogue.link(); - } + selectedNode.getProject().createElements(new ArrayList(exported)); }; public void selectionChanged(ProjectTreeNode selectedNode, TreePath[] selectedPaths) { setEnabled(selectedNode != null && selectedNode instanceof WriterModeData);