From feb05838f8a8a7446f6dd6d91ec034087b3c6163 Mon Sep 17 00:00:00 2001 From: Oskar Wiksten Date: Wed, 30 Jan 2013 00:31:03 +0100 Subject: [PATCH] Refactor content editor - work in progress on editor for dialogue. --- AndorsTrailEdit/controllers.js | 30 +++++- AndorsTrailEdit/datastore.js | 8 +- AndorsTrailEdit/defaults.js | 3 + AndorsTrailEdit/edit_dialogue.html | 147 ++++++++++++++++++++++++++- AndorsTrailEdit/edit_item.html | 4 +- AndorsTrailEdit/editor.html | 156 ----------------------------- AndorsTrailEdit/iconselector.js | 28 ------ AndorsTrailEdit/import.html | 2 +- AndorsTrailEdit/importexport.js | 30 ++++++ 9 files changed, 213 insertions(+), 195 deletions(-) delete mode 100644 AndorsTrailEdit/iconselector.js diff --git a/AndorsTrailEdit/controllers.js b/AndorsTrailEdit/controllers.js index b30ff476e..98c3f324b 100644 --- a/AndorsTrailEdit/controllers.js +++ b/AndorsTrailEdit/controllers.js @@ -23,7 +23,7 @@ var ATEditor = (function(ATEditor, model, importExport, exampleData) { }; $scope.clear = function(section) { if(!confirm("Are you sure you want to clear all " + section.name + " ?")) return; - section.items = []; + section.clear(); }; $scope.getName = function(section, obj) { return section.getName(obj); @@ -173,7 +173,33 @@ var ATEditor = (function(ATEditor, model, importExport, exampleData) { }; controllers.DialogueController = function($scope, $routeParams) { $scope.datasource = model.dialogue; - $scope.obj = $scope.datasource.findById($routeParams.id); + $scope.rootPhrase = $scope.datasource.findById($routeParams.id); + + $scope.phrase = $scope.rootPhrase; + $scope.reply = null; + $scope.removeReward = function(phrase, reward) { + var idx = phrase.rewards.indexOf(reward); + phrase.rewards.splice(idx, 1); + }; + $scope.addReward = function(phrase) { + phrase.rewards.push({}); + }; + $scope.followNextReply = function(nextPhraseID) { + }; + $scope.selectReply = function(reply) { + $scope.reply = reply; + }; + $scope.removeReply = function(phrase, reply) { + var idx = phrase.replies.indexOf(reply); + phrase.replies.splice(idx, 1); + if ($scope.reply === reply) { $scope.reply = null; } + }; + $scope.addReply = function(phrase) { + var reply = {}; + ATEditor.defaults.addDefaults('reply', reply); + phrase.replies.push(reply); + $scope.reply = reply; + }; }; controllers.MonsterController = function($scope, $routeParams) { $scope.datasource = model.monsters; diff --git a/AndorsTrailEdit/datastore.js b/AndorsTrailEdit/datastore.js index 7a2e11a65..f203fa0b4 100644 --- a/AndorsTrailEdit/datastore.js +++ b/AndorsTrailEdit/datastore.js @@ -28,7 +28,9 @@ var ATEditor = (function(ATEditor, _) { this.addNew = function() { var obj = { }; obj[options.idField] = 'new_' + options.id; - obj[options.nameField] = 'New ' + options.id; + if (options.idField != options.nameField) { + obj[options.nameField] = 'New ' + options.id; + } this.ensureUniqueId(obj); items.push(obj); return obj; @@ -48,6 +50,10 @@ var ATEditor = (function(ATEditor, _) { items.splice(idx, 1); } }; + this.clear = function() { + items = []; + this.items = items; + }; this.findFirstFreeId = function(id) { if(!this.hasObjectWithId(id)) { diff --git a/AndorsTrailEdit/defaults.js b/AndorsTrailEdit/defaults.js index b0b7f99f3..a0902e4f9 100644 --- a/AndorsTrailEdit/defaults.js +++ b/AndorsTrailEdit/defaults.js @@ -43,6 +43,9 @@ var ATEditor = (function(ATEditor, _) { ,inventorySlot: -1 ,size: 0 } + ,reply: { + requires: { item: { requireType: 0 } } + } }; ATEditor.defaults = { diff --git a/AndorsTrailEdit/edit_dialogue.html b/AndorsTrailEdit/edit_dialogue.html index 5ebda8664..35f5228e5 100644 --- a/AndorsTrailEdit/edit_dialogue.html +++ b/AndorsTrailEdit/edit_dialogue.html @@ -1,5 +1,142 @@ -
-

id: {{obj.id}}

-
-
-
+

Dialogue

+
+ Conversation flow +
+ +
+ +
+ NPC phrase +
+ + +
+
+ + +

+ Since this phrase does not have any displayed
+ text, it will not be shown to the player.
+ Instead, the first reply that matches all
+ requirements will be automatically followed. +

+
+
+ +
+
+ + + + + + + + + + + + + + + + +
TypeIDValue
+ +
+ +
+
+ +
+ Replies +
+ +
+
+ +
+ + + Go + +
+
+
+ + + + + + + + + + + + +
Reply
{{reply.text.substring(0, 40)}}
+ +
+
+ +
+ Player reply +
+ + +
+
+ + +
+
+ +
+ + + Go + +
+
+
+ +
+
+ + +
+
+ + +
+
+ + +
+
+ +
+
+ + +
+ +
+
diff --git a/AndorsTrailEdit/edit_item.html b/AndorsTrailEdit/edit_item.html index 89981254e..4f75822fd 100644 --- a/AndorsTrailEdit/edit_item.html +++ b/AndorsTrailEdit/edit_item.html @@ -90,7 +90,7 @@ -
+
@@ -110,7 +110,7 @@
-
+
diff --git a/AndorsTrailEdit/editor.html b/AndorsTrailEdit/editor.html index 8c4ca1f03..7b16d392b 100644 --- a/AndorsTrailEdit/editor.html +++ b/AndorsTrailEdit/editor.html @@ -98,161 +98,6 @@
- - @@ -268,7 +113,6 @@ - diff --git a/AndorsTrailEdit/iconselector.js b/AndorsTrailEdit/iconselector.js deleted file mode 100644 index 0f83d59bd..000000000 --- a/AndorsTrailEdit/iconselector.js +++ /dev/null @@ -1,28 +0,0 @@ -var ATEditor = (function(ATEditor, tilesets) { - - this.setImage = function(imageElem, imageID, scale) { - if (!scale) scale = 1; - var img = tilesets.parseImageID(imageID); - var tilesetImage = tilesets.getTileset(img.name); - var c = tilesetImage.localIDToCoords(img.localID); - imageElem.css({ - "background-image": "url(" +img.path + img.name + ".png)", - "background-position": (-c.x)*scale+"px " + (-c.y)*scale+"px", - "width": tilesetImage._tileSize.x * scale + "px", - "height": tilesetImage._tileSize.y * scale + "px", - "cursor": "pointer" - }); - if (scale && (scale !== 1)) { - imageElem.css({ - "background-size": - tilesetImage._tileSize.x * tilesetImage._numTiles.x * scale + "px " - + tilesetImage._tileSize.y * tilesetImage._numTiles.y * scale + "px " - }); - } - } - - ATEditor.iconselector = { - setImage: setImage - }; - return ATEditor; -})(ATEditor, ATEditor.tilesets); diff --git a/AndorsTrailEdit/import.html b/AndorsTrailEdit/import.html index 21f017acb..934ccde9a 100644 --- a/AndorsTrailEdit/import.html +++ b/AndorsTrailEdit/import.html @@ -17,7 +17,7 @@

- +

diff --git a/AndorsTrailEdit/importexport.js b/AndorsTrailEdit/importexport.js index 6c5384183..22fd752b7 100644 --- a/AndorsTrailEdit/importexport.js +++ b/AndorsTrailEdit/importexport.js @@ -17,6 +17,20 @@ var ATEditor = (function(ATEditor, _) { prep.droplist = function(o) { }; prep.dialogue = function(o) { + o.hasRewards = ATEditor.utils.hasValues(o.rewards); + if (o.replies.length === 1 && o.replies[0].text === "N") { + o.nextPhraseID = o.replies[0].nextPhraseID; + o.hasOnlyNextReply = true; + } else { + o.nextPhraseID = ""; + o.hasOnlyNextReply = false; + } + _.each(o.replies, function(reply) { + ATEditor.defaults.addDefaults('reply', reply); + if (reply.nextPhraseID && reply.nextPhraseID.length === 1) { reply.replyLeadsTo = reply.nextPhraseID; } + reply.requiresItems = ATEditor.utils.hasValues(reply.requires.item); + reply.requiresQuest = _.toBool(reply.requires.progress); + }); }; prep.monster = function(o) { o.hasConversation = _.toBool(o.phraseID); @@ -70,6 +84,22 @@ var ATEditor = (function(ATEditor, _) { unprep.droplist = function(o) { }; unprep.dialogue = function(o) { + if (!o.hasRewards) { delete o.rewards; } + delete o.hasRewards; + _.each(o.replies, function(reply) { + if (reply.replyLeadsTo) { reply.text = reply.replyLeadsTo; } + delete reply.replyLeadsTo; + var requires = reply.requires; + if (!reply.requiresItems) { delete requires.item; } + delete reply.requiresItems; + if (!reply.requiresQuest) { delete requires.progress; } + delete reply.requiresQuest; + }); + if (o.hasOnlyNextReply) { + o.replies = [ { text: "N", nextPhraseID: o.nextPhraseID } ]; + } + delete o.nextPhraseID; + delete o.hasOnlyNextReply; }; unprep.monster = function(o) { if (!o.hasCritical) {