// selectSubstance.js
(function () {
/* global AdventureJS A */
var p = AdventureJS.Parser.prototype;
/**
* Exclude from a list of assets all assets that are not substances.
* @method AdventureJS.Parser#selectSubstance
* @memberOf AdventureJS.Parser
* @param {Array} list
* @returns {Array}
*/
p.selectSubstance = function Parser_selectSubstance(list) {
if ("string" === typeof list) list = [list];
if (!Array.isArray(list)) {
this.game.log(
"L1254",
"error",
"critical",
["[selectSubstance.js] selectSubstance() received non-array", list],
"Parser"
);
return [];
}
this.game.log(
"L1141",
"log",
"high",
`[selectSubstance.js] selectSubstance() receive:\n${list}`,
"Parser"
);
var foundObjects = [];
for (var i = 0; i < list.length; i++) {
var object = this.game.getAsset(list[i], { prefer_substance: true });
if (object instanceof AdventureJS.Assets.Substance) {
foundObjects.push(list[i]);
}
}
this.game.log(
"L1679",
"log",
"high",
`[selectSubstance.js] selectSubstance() return:\n${foundObjects}`,
"Parser"
);
return foundObjects;
};
})();