mirror of
https://github.com/OMGeeky/andors-trail.git
synced 2026-02-23 15:38:29 +01:00
Refactor content editor - Added views for updating, exporting and importing quests and actor conditions.
This commit is contained in:
@@ -12,43 +12,91 @@ var ATEditor = (function(ATEditor, _) {
|
||||
}
|
||||
}
|
||||
}
|
||||
function cleanCopy(o, defaults) {
|
||||
if (!o) { return null; }
|
||||
o = _.clone(o);
|
||||
if (defaults) {
|
||||
removeDefaults(o, defaults);
|
||||
}
|
||||
for (var key in o) {
|
||||
function removeAngularFields(o) {
|
||||
var key;
|
||||
for (key in o) {
|
||||
var v = o[key];
|
||||
if (key.charAt(0) === '$') {
|
||||
delete o[key];
|
||||
} else if (_.isArray(v) || _.isObject(v)) {
|
||||
removeAngularFields(v);
|
||||
}
|
||||
}
|
||||
for (var key in o) {
|
||||
}
|
||||
function compact(o) {
|
||||
if (!o) { return null; }
|
||||
var key;
|
||||
for (key in o) {
|
||||
var v = o[key];
|
||||
if (!v) {
|
||||
delete o[key];
|
||||
} else if (_.isArray(v)) {
|
||||
if (!_.some(v)) {
|
||||
delete o[key];
|
||||
} else {
|
||||
o[key] = _.map(v, function(o) { cleanCopy(o); });
|
||||
}
|
||||
if (_.isArray(v)) {
|
||||
v = _.map(v, compact);
|
||||
} else if (_.isObject(v)) {
|
||||
v = cleanCopy(v);
|
||||
if (v) {
|
||||
o[key] = v;
|
||||
} else {
|
||||
delete o[key];
|
||||
}
|
||||
v = compact(v);
|
||||
}
|
||||
if (!hasValues(v)) {
|
||||
delete o[key];
|
||||
} else {
|
||||
o[key] = v;
|
||||
}
|
||||
}
|
||||
if (!_.some(_.keys(o))) { return null; }
|
||||
if (!hasValues(o)) { return null; }
|
||||
return o;
|
||||
}
|
||||
|
||||
function hasValues(o) {
|
||||
if (_.isArray(o)) {
|
||||
return _.some(o, hasValues);
|
||||
} else if (_.isObject(o)) {
|
||||
var key;
|
||||
for (key in o) {
|
||||
if (hasValues(o[key])) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
return o;
|
||||
}
|
||||
|
||||
function convertStringsToIntegers(o) {
|
||||
var key;
|
||||
for (key in o) {
|
||||
var v = o[key];
|
||||
if (_.isString(v)) {
|
||||
v = parseInt(v);
|
||||
if (!_.isNaN(v)) {
|
||||
o[key] = v;
|
||||
}
|
||||
} else if (_.isArray(v)) {
|
||||
convertStringsToIntegers(v);
|
||||
} else if (_.isObject(v)) {
|
||||
convertStringsToIntegers(v);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
function convertIntegersToStrings(o) {
|
||||
var key;
|
||||
for (key in o) {
|
||||
var v = o[key];
|
||||
if (_.isNumber(v)) {
|
||||
o[key] = String(v);
|
||||
} else if (_.isArray(v)) {
|
||||
convertIntegersToStrings(v);
|
||||
} else if (_.isObject(v)) {
|
||||
convertIntegersToStrings(v);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
ATEditor.utils = {
|
||||
deepClone: deepClone
|
||||
,cleanCopy: cleanCopy
|
||||
,removeDefaults: removeDefaults
|
||||
,removeAngularFields: removeAngularFields
|
||||
,compact: compact
|
||||
,hasValues: hasValues
|
||||
,convertStringsToIntegers: convertStringsToIntegers
|
||||
,convertIntegersToStrings: convertIntegersToStrings
|
||||
};
|
||||
|
||||
return ATEditor;
|
||||
|
||||
Reference in New Issue
Block a user