// findSubstanceContainers.js
(function () {
/* global adventurejs A */
var p = adventurejs.Game.prototype;
/**
* Find assets containing the specified substance.
* @method adventurejs.Game#findSubstanceContainers
* @memberOf adventurejs.Game
* @param {String} substance_id
* @param {Array} selects
* @returns {Array}
*/
p.findSubstanceContainers = function Game_getSubstanceContainers(
substance_id,
parent,
selects = []
) {
this.game.log(
"L1076",
"log",
"high",
"game.findSubstanceContainers > receive: " + substance_id,
"Game"
);
if (typeof substance_id !== "string") {
console.warn("findSubstanceContainers received non-string", substance_id);
return [];
}
var containers = [];
var contents = parent.getAllNestedContents(); // returns [ids]
for (let i in contents) {
let asset = this.game.getAsset(contents[i]);
if (!asset) continue;
if (asset.containsSubstance(substance_id)) {
containers.push(asset);
}
}
if ("string" === typeof selects) selects = selects.split(" ");
for (let i in selects) {
containers = this.parser["select" + selects[i]](containers);
}
this.game.log(
"L1077",
"log",
"high",
`[findSubstanceContainers.js] return:\n${containers.map((container) => container.id).join(", ")}`,
"Game"
);
return containers;
};
})();