// createCustomParser.js
(function () {
/*global adventurejs A*/
"use strict";
var p = adventurejs.Parser.prototype;
/**
* Install custom parser(s) defined by author.
* @memberOf adventurejs.Parser
* @method adventurejs.Parser#createCustomParser
* @param {Object} parsers An object containing one or more parser functions.
*/
p.createCustomParser = function Parser_createCustomParser(parsers) {
var keys = Object.keys(parsers);
for (var i = 0; i < keys.length; i++) {
var parser_name = keys[i];
var msg = "";
if ("undefined" !== typeof this.custom_parsers[parser_name]) {
msg =
"createCustomParser received more than one parser named " +
parser_name +
". ";
console.warn(msg);
return false;
}
//console.warn( parsers[ parser_name ], typeof parsers[ parser_name ]);
if ("function" !== typeof parsers[parser_name]) {
msg =
"createCustomParser received something that is not a function for parser " +
parser_name +
". ";
console.warn(msg);
return false;
}
this.custom_parsers[parser_name] = parsers[parser_name];
this.custom_parsers_enabled[parser_name] = false;
msg = "createCustomParser.js > registered " + parser_name + ". ";
//console.log( msg );
this.game.log("log", "high", msg, "Parser");
}
return;
};
})();