Refactoring of Character class to add effect appliers and removers

This commit is contained in:
Thaum
2014-11-03 11:30:14 +00:00
parent e7f7f75436
commit 25b2a95f14
9 changed files with 139 additions and 93 deletions

View File

@@ -0,0 +1,49 @@
// turns dot notation strings into keys of root
// argument formats:
// 157, anything -> 157
// "some.number", object -> object.some.number
// "some.function", object -> object.some.function()
// "some.function arg1 arg2", object -> object.some.function(arg1, arg2)
pop = function(input, root){
if(typeof(input) === "string"){
//we need root for this part
if(root === undefined) return;
//this is a likely to fail if the string is malformed
try{
//split over spaces
var parts = input.split(" ");
//for each word
for (var i = 0; i < parts.length; i++){
//split over dots
var str = parts[i].split(".");
//start at root
parts[i] = root;
//for each word between dots
for (var j = 0; j < str.length; j++){
parts[i] = parts[i][str[j]];
}
}
//pull the first word out, might be a function
var func = parts.splice(0, 1)[0];
//if it's a function, apply the arguments to it
if(_.isFunction(func)) return +func.apply(root, parts);
//if it's a number, return it
if(!isNaN(func)) return +func;
} catch (err) {
//TODO pokemon catch statement is bad
//"gotta catch em all"
console.log(err);
return;
}
}
return +input;
}