mirror of
https://github.com/OMGeeky/andors-trail.git
synced 2025-12-27 06:29:37 +01:00
Refactor content editor - Add support for loading actual content with http get.
This commit is contained in:
@@ -1,8 +1,8 @@
|
||||
var ATEditor = (function(ATEditor, model, importExport) {
|
||||
var ATEditor = (function(ATEditor, model, importExport, exampleData) {
|
||||
|
||||
var controllers = {};
|
||||
|
||||
controllers.NavigationController = function($scope, $routeParams) {
|
||||
controllers.NavigationController = function($scope, $routeParams, $http) {
|
||||
$scope.sections = model.sections;
|
||||
$scope.previousItems = [];
|
||||
|
||||
@@ -38,6 +38,7 @@ var ATEditor = (function(ATEditor, model, importExport) {
|
||||
$scope.editObj(section, item);
|
||||
};
|
||||
|
||||
exampleData.init($http);
|
||||
};
|
||||
|
||||
controllers.ActorConditionController = function($scope, $routeParams) {
|
||||
@@ -233,8 +234,6 @@ var ATEditor = (function(ATEditor, model, importExport) {
|
||||
$scope.obj = $scope.datasource.findById($routeParams.id);
|
||||
};
|
||||
|
||||
String.prototype.trim = String.prototype.trim || (function(){return this.replace(/^\s+|\s+$/g, '');});
|
||||
|
||||
controllers.ImportController = function($scope) {
|
||||
$scope.sections = model.sections;
|
||||
$scope.content = "";
|
||||
@@ -253,7 +252,7 @@ var ATEditor = (function(ATEditor, model, importExport) {
|
||||
function error(msg) {
|
||||
$scope.errorMsg = "Error importing data: " + msg;
|
||||
}
|
||||
importExport.importData(section, $scope.content, success, error);
|
||||
importExport.importText(section, $scope.content, success, error);
|
||||
};
|
||||
};
|
||||
controllers.ExportController = function($scope) {
|
||||
@@ -267,4 +266,4 @@ var ATEditor = (function(ATEditor, model, importExport) {
|
||||
|
||||
ATEditor.controllers = controllers;
|
||||
return ATEditor;
|
||||
})(ATEditor, ATEditor.model, ATEditor.importExport);
|
||||
})(ATEditor, ATEditor.model, ATEditor.importExport, ATEditor.exampleData);
|
||||
|
||||
@@ -243,6 +243,7 @@
|
||||
<script src="defaults.js"></script>
|
||||
<script src="importexport.js"></script>
|
||||
<script src="model.js"></script>
|
||||
<script src="exampledata.js"></script>
|
||||
<script src="controllers.js"></script>
|
||||
<script src="app.js"></script>
|
||||
<script src="directives.js"></script>
|
||||
|
||||
90
AndorsTrailEdit/exampledata.js
Normal file
90
AndorsTrailEdit/exampledata.js
Normal file
@@ -0,0 +1,90 @@
|
||||
var ATEditor = (function(ATEditor, model, _, $) {
|
||||
|
||||
var http;
|
||||
var resources = {};
|
||||
|
||||
function loadUrlFromGit(relativeUrl, successCallback, errorCallback) {
|
||||
var url = document.location.href;
|
||||
var idx = url.lastIndexOf('#');
|
||||
if (idx > 0) {
|
||||
url = url.substring(0, idx);
|
||||
}
|
||||
url = url.substring(0, url.lastIndexOf('/'));
|
||||
url = url.substring(0, url.lastIndexOf('/'));
|
||||
url = url + "/" + relativeUrl;
|
||||
http.get(url)
|
||||
.success(function(data, status, headers, config) {
|
||||
successCallback(data);
|
||||
}).error(function(data, status, headers, config) {
|
||||
if(errorCallback) { errorCallback(status); }
|
||||
});
|
||||
}
|
||||
|
||||
function addExampleModelItems() {
|
||||
var _import = function(section, data) {
|
||||
ATEditor.importExport.importDataObjects(section, data);
|
||||
};
|
||||
|
||||
_import(model.quests, [
|
||||
{id: "testQuest", name: "Test quest", showInLog: 1, stages: [ { progress: 10, logText: "Stage 10"} , { progress: 20, logText: "Stage 20", finishesQuest: 1 } ] }
|
||||
]);
|
||||
}
|
||||
|
||||
function init($http) {
|
||||
http = $http;
|
||||
|
||||
// http://andors-trail.googlecode.com/git/AndorsTrail/res/values/loadresources.xml
|
||||
loadUrlFromGit("AndorsTrail/res/values/loadresources.xml", function(data) {
|
||||
var parseListOfResourceFiles = function(xmlname, section) {
|
||||
var items = [];
|
||||
resources[section.id] = items;
|
||||
$(data).find("array[name='" + xmlname + "'] item").each(function(idx, f) {
|
||||
var match = (/^@.*\/(.+)$/g).exec($(f).text());
|
||||
if (match) {
|
||||
items.push(match[1] + ".json");
|
||||
}
|
||||
});
|
||||
};
|
||||
parseListOfResourceFiles("loadresource_itemcategories", model.itemCategories);
|
||||
parseListOfResourceFiles("loadresource_actorconditions", model.actorConditions);
|
||||
parseListOfResourceFiles("loadresource_items", model.items);
|
||||
parseListOfResourceFiles("loadresource_droplists", model.droplists);
|
||||
parseListOfResourceFiles("loadresource_quests", model.quests);
|
||||
parseListOfResourceFiles("loadresource_conversationlists", model.dialogue);
|
||||
|
||||
_.each(resources['itemcategory'], function(file) {
|
||||
loadUrlFromGit("AndorsTrail/res/raw/" + file, function(data) {
|
||||
ATEditor.importExport.importDataObjects(model.itemCategories, data);
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
loadUrlFromGit("AndorsTrail/res/raw/actorconditions_v069.json", function(data) {
|
||||
ATEditor.importExport.importDataObjects(model.actorConditions, data);
|
||||
});
|
||||
loadUrlFromGit("AndorsTrail/res/raw/conversationlist_mikhail.json", function(data) {
|
||||
ATEditor.importExport.importDataObjects(model.dialogue, data);
|
||||
});
|
||||
loadUrlFromGit("AndorsTrail/res/raw/droplists_crossglen.json", function(data) {
|
||||
ATEditor.importExport.importDataObjects(model.droplists, data);
|
||||
});
|
||||
loadUrlFromGit("AndorsTrail/res/raw/monsterlist_crossglen_animals.json", function(data) {
|
||||
ATEditor.importExport.importDataObjects(model.monsters, data);
|
||||
});
|
||||
loadUrlFromGit("AndorsTrail/res/raw/monsterlist_crossglen_animals.json", function(data) {
|
||||
ATEditor.importExport.importDataObjects(model.monsters, data);
|
||||
});
|
||||
loadUrlFromGit("AndorsTrail/res/raw/itemlist_v069_2.json", function(data) {
|
||||
ATEditor.importExport.importDataObjects(model.items, data);
|
||||
});
|
||||
|
||||
addExampleModelItems(model);
|
||||
}
|
||||
|
||||
ATEditor.exampleData = {
|
||||
init: init
|
||||
,resources: resources
|
||||
};
|
||||
|
||||
return ATEditor;
|
||||
})(ATEditor, ATEditor.model, _, jQuery);
|
||||
@@ -4,14 +4,14 @@ var ATEditor = (function(ATEditor, _) {
|
||||
prep.actorcondition = function(o) {
|
||||
o.hasRoundEffect = ATEditor.utils.hasValues(_.omit(o.roundEffect, 'visualEffectID'));
|
||||
o.hasFullRoundEffect = ATEditor.utils.hasValues(_.omit(o.fullRoundEffect, 'visualEffectID'));
|
||||
o.abilityEffect.hasCritical = o.abilityEffect.increaseCriticalSkill || o.abilityEffect.setCriticalMultiplier;
|
||||
o.abilityEffect.hasCritical = _.toBool(o.abilityEffect.increaseCriticalSkill || o.abilityEffect.setCriticalMultiplier);
|
||||
o.hasAbilityEffect = ATEditor.utils.hasValues(o.abilityEffect);
|
||||
};
|
||||
prep.quest = function(o) {
|
||||
};
|
||||
prep.item = function(o) {
|
||||
o.hasEquipEffect = ATEditor.utils.hasValues(o.equipEffect);
|
||||
o.equipEffect.hasCritical = o.equipEffect.increaseCriticalSkill || o.equipEffect.setCriticalMultiplier;
|
||||
o.equipEffect.hasCritical = _.toBool(o.equipEffect.increaseCriticalSkill || o.equipEffect.setCriticalMultiplier);
|
||||
o.hasUseEffect = ATEditor.utils.hasValues(o.useEffect);
|
||||
o.hasHitEffect = ATEditor.utils.hasValues(o.hitEffect);
|
||||
o.hasKillEffect = ATEditor.utils.hasValues(o.killEffect);
|
||||
@@ -21,9 +21,10 @@ var ATEditor = (function(ATEditor, _) {
|
||||
prep.dialogue = function(o) {
|
||||
};
|
||||
prep.monster = function(o) {
|
||||
o.hasConversation = o.phraseID;
|
||||
o.hasHitEffect = o.hitEffect.increaseCurrentHP.min || o.hitEffect.increaseCurrentAP.min || _.some(o.hitEffect.conditionsSource) || _.some(o.hitEffect.conditionsTarget);
|
||||
o.hasCombatTraits = o.attackChance || o.attackDamage.min || o.criticalSkill || o.criticalMultiplier || o.blockChance || o.damageResistance || o.hasHitEffect;
|
||||
o.hasConversation = _.toBool(o.phraseID);
|
||||
o.hasHitEffect = _.toBool(o.hitEffect.increaseCurrentHP.min || o.hitEffect.increaseCurrentAP.min || _.some(o.hitEffect.conditionsSource) || _.some(o.hitEffect.conditionsTarget));
|
||||
o.hasCritical = _.toBool(o.criticalSkill || o.criticalMultiplier);
|
||||
o.hasCombatTraits = _.toBool(o.attackChance || o.attackDamage.min || o.hasCritical || o.blockChance || o.damageResistance || o.hasHitEffect);
|
||||
};
|
||||
prep.itemcategory = function(o) {
|
||||
};
|
||||
@@ -105,7 +106,7 @@ var ATEditor = (function(ATEditor, _) {
|
||||
|
||||
function importDataObjects(section, data, success, error) {
|
||||
if (!data || _.isEmpty(data)) {
|
||||
error("No data?");
|
||||
if (error) { error("No data?"); }
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -115,22 +116,22 @@ var ATEditor = (function(ATEditor, _) {
|
||||
} else if (_.isObject(data)) {
|
||||
data = [ data ];
|
||||
} else {
|
||||
error("Malformed data? Expected array or object.");
|
||||
if (error) { error("Malformed data? Expected array or object."); }
|
||||
return;
|
||||
}
|
||||
|
||||
if (!section.getId(first)) {
|
||||
error("Malformed data? Expected to find at least an id field, but no such field was found.");
|
||||
if (error) { error("Malformed data? Expected to find at least an id field, but no such field was found."); }
|
||||
return;
|
||||
}
|
||||
|
||||
prepareObjectsForEditor(section, data);
|
||||
|
||||
_.each(data, section.add);
|
||||
success();
|
||||
if (success) { success(); }
|
||||
};
|
||||
|
||||
function importData(section, content, success, error) {
|
||||
function importText(section, content, success, error) {
|
||||
var data = ATEditor.legacy.deserialize(content);
|
||||
if (data) {
|
||||
data = data.items;
|
||||
@@ -142,7 +143,7 @@ var ATEditor = (function(ATEditor, _) {
|
||||
try {
|
||||
data = JSON.parse(content);
|
||||
} catch(e) {
|
||||
error("Unable to parse data as JSON.");
|
||||
if (error) { error("Unable to parse data as JSON."); }
|
||||
return;
|
||||
}
|
||||
}
|
||||
@@ -156,7 +157,7 @@ var ATEditor = (function(ATEditor, _) {
|
||||
};
|
||||
|
||||
ATEditor.importExport = {
|
||||
importData: importData
|
||||
importText: importText
|
||||
,importDataObjects: importDataObjects
|
||||
,exportData: exportData
|
||||
};
|
||||
|
||||
@@ -53,44 +53,6 @@ var ATEditor = (function(ATEditor, DataStore, FieldList, _) {
|
||||
model.sections = sections;
|
||||
model.getSectionFromID = function(id) { return sectionIds[id]; };
|
||||
|
||||
function addExampleModelItems(model) {
|
||||
var _import = function(section, data) {
|
||||
var _void = function() {};
|
||||
ATEditor.importExport.importDataObjects(section, data, _void, _void);
|
||||
};
|
||||
|
||||
_import(model.actorConditions, [
|
||||
{id: "bless", name: "Bless", isPositive: 1, iconID: "actorconditions_1:38", category: 0, abilityEffect: { increaseAttackChance: 15, increaseBlockChance: 5} }
|
||||
,{id: "poison_weak", name: "Weak Poison", iconID: "actorconditions_1:60", category: 3, roundEffect: { visualEffectID: 2, increaseCurrentHP: { min: -1, max: -1} } }
|
||||
]);
|
||||
|
||||
_import(model.quests, [
|
||||
{id: "testQuest", name: "Test quest", showInLog: 1, stages: [ { progress: 10, logText: "Stage 10"} , { progress: 20, logText: "Stage 20", finishesQuest: 1 } ] }
|
||||
]);
|
||||
|
||||
_import(model.items, [
|
||||
{id: "item0", iconID: "items_weapons:0", name: "Longsword", category: 'lsword', baseMarketCost: 51, equipEffect: { increaseAttackChance: 10, increaseAttackDamage: { min: 2, max: 4 }, increaseAttackCost: 4 } }
|
||||
,{id: "dmg_ring1", iconID: "items_jewelry:0", name: "Ring of damage +1", category: 'ring', baseMarketCost: 62, equipEffect: { increaseAttackDamage: { min: 1, max: 1 } } }
|
||||
]);
|
||||
|
||||
_import(model.droplists, [
|
||||
{id: "merchant1", items: [ { itemID: 'dmg_ring1', quantity: { min: 4, max: 5 }, chance: 100 } , { itemID: 'item0', quantity: { min: 1, max: 1 }, chance: 100 } ] }
|
||||
]);
|
||||
|
||||
_import(model.dialogue, [
|
||||
{id: "mikhail_default", message: 'Anything else I can help you with?', replies: [ { text: 'Do you have any tasks for me?', nextPhraseID: 'mikhail_tasks' }, { text: 'Is there anything else you can tell me about Andor?', nextPhraseID: 'mikhail_andor1' } ]}
|
||||
,{id: 'mikhail_andor1', message: 'As I said, Andor went out yesterday and hasn\'t been back since. I\'m starting to worry about him. Please go look for your brother, he said he would only be out a short while.'}
|
||||
,{id: 'mikhail_tasks', message: 'Oh yes, there were some things I need help with, bread and rats. Which one would you like to talk about?'}
|
||||
]);
|
||||
|
||||
_import(model.monsters, [
|
||||
{id: "small_ant", name: "Small ant", iconID: "monsters_insects:2", maxHP: 30 }
|
||||
,{id: "red_ant", name: "Red ant", iconID: "monsters_insects:3", maxHP: 20 }
|
||||
,{id: "wasp", name: "Wasp", iconID: "monsters_insects:1", maxHP: 10 }
|
||||
]);
|
||||
}
|
||||
addExampleModelItems(model);
|
||||
|
||||
ATEditor.model = ATEditor.model || model;
|
||||
return ATEditor;
|
||||
})(ATEditor, ATEditor.DataStore, ATEditor.FieldList, _);
|
||||
|
||||
@@ -17,7 +17,7 @@ var ATEditor = (function(ATEditor, _) {
|
||||
var key;
|
||||
for (key in defaults) {
|
||||
var v = defaults[key];
|
||||
if (!o[key]) {
|
||||
if ((!o[key]) && (o[key] !== 0)) {
|
||||
o[key] = v;
|
||||
} else if (_.isObject(v)) {
|
||||
copyDefaults(o[key], v);
|
||||
@@ -102,6 +102,10 @@ var ATEditor = (function(ATEditor, _) {
|
||||
}
|
||||
}
|
||||
|
||||
_.toBool = function(b) {
|
||||
return b ? true : false;
|
||||
};
|
||||
|
||||
ATEditor.utils = {
|
||||
deepClone: deepClone
|
||||
,removeDefaults: removeDefaults
|
||||
|
||||
Reference in New Issue
Block a user