diff --git a/AndorsTrailEdit/js/controllers/dialogue.js b/AndorsTrailEdit/js/controllers/dialogue.js index 48b4c0248..188f5d573 100644 --- a/AndorsTrailEdit/js/controllers/dialogue.js +++ b/AndorsTrailEdit/js/controllers/dialogue.js @@ -1,4 +1,4 @@ -var ATEditor = (function(ATEditor, model, defaults, _) { +var ATEditor = (function(ATEditor, model, defaults, importExport, _) { function DialogueController($scope, $routeParams) { $scope.datasource = model.dialogue; @@ -6,92 +6,6 @@ var ATEditor = (function(ATEditor, model, defaults, _) { $scope.phrase = $scope.rootPhrase; $scope.reply = null; - function rebuildTree(rootPhrase) { - console.log("rebuilding tree for " + rootPhrase.id); - rootPhrase.tree = rootPhrase.tree || {}; - rootPhrase.tree.dirty = true; - rebuildPhraseTree(rootPhrase, {}); - } - - function rebuildPhraseTree(phrase, visitedPhraseIDs) { - if (visitedPhraseIDs[phrase.id]) { - var phraseNode = {}; - phraseNode.image = 'imgphrase.png'; - phraseNode.text = "(conversation loop)"; - phraseNode.phrase = phrase; - phraseNode.reply = null; - phraseNode.children = []; - return phraseNode; - } - visitedPhraseIDs[phrase.id] = true; - if (_.keys(visitedPhraseIDs).length > 1000) { return {}; } - - if (phrase.tree && !phrase.tree.dirty) { return phrase.tree; } - console.log("Constructing " + phrase.id); - var phraseNode = {}; - phraseNode.dirty = false; - phraseNode.image = 'imgphrase.png'; - phraseNode.text = phrase.message || '(no text)'; - phraseNode.phrase = phrase; - phraseNode.reply = null; - phraseNode.children = []; - phrase.tree = phraseNode; - - if (phrase.hasOnlyNextReply) { - var nextPhrase = model.dialogue.findById(phrase.nextPhraseID); - if (nextPhrase) { - var childNode = rebuildPhraseTree(nextPhrase, visitedPhraseIDs); - phraseNode.children = [ childNode ]; - } - } else { - _.each(phrase.replies, function(reply) { - var replyNode = {} - replyNode.image = 'imgreply.png'; - replyNode.text = reply.text || '(no text)'; - replyNode.phrase = phrase; - replyNode.reply = reply; - replyNode.children = []; - phraseNode.children.push(replyNode); - if (reply.nextPhraseID) { - var nextPhrase = model.dialogue.findById(reply.nextPhraseID); - if (nextPhrase) { - var childNode = rebuildPhraseTree(nextPhrase, visitedPhraseIDs); - replyNode.children.push(childNode); - } - } - }); - } - return phraseNode; - } - - $scope.onclick = function(node) { - $scope.phrase = node.phrase; - $scope.reply = node.reply; - }; - - $scope.$watch('phrase.message' - +' + phrase.nextPhraseID' - +' + phrase.hasOnlyNextReply' - +' + reply.text' - +' + reply.nextPhraseID' - , function() { - rebuildTree($scope.phrase); - $scope.node = $scope.rootPhrase.tree; - }); - - $scope.refreshTree = function() { - function setDirty(node) { - if (node) { - node.dirty = true; - _.each(node.children, function(c) { - setDirty(c); - }); - } - } - setDirty($scope.rootPhrase.tree); - rebuildTree($scope.rootPhrase); - }; - $scope.removeReward = function(phrase, reward) { var idx = phrase.rewards.indexOf(reward); phrase.rewards.splice(idx, 1); @@ -99,7 +13,25 @@ var ATEditor = (function(ATEditor, model, defaults, _) { $scope.addReward = function(phrase) { phrase.rewards.push({}); }; - $scope.followNextReply = function(nextPhraseID) { + $scope.proceedToPhrase = function(obj, prop) { + var phraseId = obj[prop]; + if (phraseId) { + var nextPhrase = model.dialogue.findById(phraseId); + if (nextPhrase) { + window.location = "#/" + model.dialogue.id + "/edit/" + phraseId; + return; + } + } else { + phraseId = $scope.phrase.id; + } + var newPhrase = model.dialogue.addNew(phraseId); + importExport.prepareObjectsForEditor(model.dialogue, [ newPhrase ]); + newPhrase.hasOnlyNextReply = true; + + phraseId = newPhrase.id; + obj[prop] = phraseId; + + window.location = "#/" + model.dialogue.id + "/edit/" + phraseId; }; $scope.selectReply = function(reply) { $scope.reply = reply; @@ -121,4 +53,4 @@ var ATEditor = (function(ATEditor, model, defaults, _) { ATEditor.controllers.DialogueController = DialogueController; return ATEditor; -})(ATEditor, ATEditor.model, ATEditor.defaults, _); +})(ATEditor, ATEditor.model, ATEditor.defaults, ATEditor.importExport, _); diff --git a/AndorsTrailEdit/js/datastore.js b/AndorsTrailEdit/js/datastore.js index f203fa0b4..89933d9bd 100644 --- a/AndorsTrailEdit/js/datastore.js +++ b/AndorsTrailEdit/js/datastore.js @@ -25,9 +25,10 @@ var ATEditor = (function(ATEditor, _) { this.getName = function(obj) { return obj[options.nameField]; }; - this.addNew = function() { + this.addNew = function(suggestedId) { var obj = { }; - obj[options.idField] = 'new_' + options.id; + if (!suggestedId) { suggestedId = 'new_' + options.id; } + obj[options.idField] = suggestedId; if (options.idField != options.nameField) { obj[options.nameField] = 'New ' + options.id; } diff --git a/AndorsTrailEdit/js/directives.js b/AndorsTrailEdit/js/directives.js index 3fcac11e5..9534336a3 100644 --- a/AndorsTrailEdit/js/directives.js +++ b/AndorsTrailEdit/js/directives.js @@ -84,22 +84,6 @@ var ATEditor = (function(ATEditor, app, tilesets, $) { } }); - // http://jsfiddle.net/ag5zC/22/ - app.directive('treenode', function ($compile) { - var link; - return { - restrict: 'E', - terminal: true, - scope: { node: '=', onclick: '=' }, - link: function (scope, element, attrs) { - if(!link) { - link = $compile(element.html()); - } - element.replaceWith(link(scope.$new(), function(clone) { })); - } - } - }); - return ATEditor; })(ATEditor, ATEditor.app, ATEditor.tilesets, jQuery); diff --git a/AndorsTrailEdit/partials/edit_dialogue.html b/AndorsTrailEdit/partials/edit_dialogue.html index deaa77cbe..6aa17a5b0 100644 --- a/AndorsTrailEdit/partials/edit_dialogue.html +++ b/AndorsTrailEdit/partials/edit_dialogue.html @@ -1,24 +1,5 @@

Dialogue

-
- Conversation flow -
-
- Refresh -
-
- - - {{node.text}} -
-
    -
  • -
-
-
- -
-
NPC phrase
@@ -28,7 +9,7 @@
-

+

Since this phrase does not have any displayed
text, it will not be shown to the player.
Instead, the first reply that matches all
@@ -77,8 +58,9 @@

@@ -88,11 +70,16 @@ Reply + - {{reply.text.substring(0, 40)}} - + + {{reply.text.substring(0, 40)}} + (conditional evaluation) + + + Go @@ -120,8 +107,9 @@
diff --git a/AndorsTrailEdit/styles.css b/AndorsTrailEdit/styles.css index 2c92ae9e0..c0cb2d100 100644 --- a/AndorsTrailEdit/styles.css +++ b/AndorsTrailEdit/styles.css @@ -43,6 +43,7 @@ html, body { margin:0; padding:0; } #dialogueTree ul { list-style: none; margin-left: 10px; } #dialogueTree li { } #dialogueTree .selected { background-color: #d7d7ff; } +.dialogueConditional { color: #855; } .tools-buttons { padding-bottom: 10px; } #importExportTextArea { width: 500px; }