// selectParent.js
(function () {
/* global adventurejs A */
var p = adventurejs.Parser.prototype;
/**
* Exclude from a list of assets all assets but subject's parent.
* Should only ever return one object.
* @method adventurejs.Parser#selectParent
* @memberOf adventurejs.Parser
* @param {Array} list
* @returns {Array}
*/
p.selectParent = function Parser_selectParent(list) {
if ("string" === typeof list) list = [list];
if (!Array.isArray(list)) {
this.game.log(
"L1239",
"error",
"critical",
["[selectParent.js] selectParent() received non-array", list],
"Parser"
);
return [];
}
this.game.log(
"L1151",
"log",
"high",
`[selectParent.js] selectParent() receive:\n${list}`,
"Parser"
);
var foundObjects = [];
var input = this.game.getInput();
var player = this.game.getPlayer();
var subject = input.getSubject();
var room = this.game.getRoom();
for (var i = 0; i < list.length; i++) {
var object = this.game.getAsset(list[i]);
if (subject.isNested() && object.id === subject.getNestId()) {
foundObjects.push(list[i]);
} else if (false === subject.isNested() && object.id === room.id) {
foundObjects.push(list[i]);
} else if (
subject.isNested() &&
object.id === room.id &&
subject.getNestAsset() instanceof adventurejs.Floor
) {
foundObjects.push(room.id);
}
if (0 < foundObjects.length) break;
}
return foundObjects;
};
})();