// selectParentOrRoom.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#selectParentOrRoom
* @memberOf adventurejs.Parser
* @param {Array} list
* @returns {Array}
*/
p.selectParentOrRoom = function Parser_selectParentOrRoom(list) {
if ("string" === typeof list) list = [list];
if (!Array.isArray(list)) {
this.game.log(
"L1517",
"error",
"critical",
[
"[selectParentOrRoom.js] selectParentOrRoom() received non-array",
list,
],
"Parser"
);
return [];
}
this.game.log(
"L1518",
"log",
"high",
`[selectParentOrRoom.js] selectParentOrRoom() 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();
const nested = subject.isNested();
for (var i = 0; i < list.length; i++) {
var object = this.game.getAsset(list[i]);
if (object.id === room.id) {
foundObjects.push(list[i]);
} else if (nested && object.id === subject.getNestId()) {
foundObjects.push(list[i]);
} /* else if (false === nested && object.id === room.id) {
foundObjects.push(list[i]);
} else if (
nested &&
object.id === room.id &&
subject.getNestAsset() instanceof adventurejs.Floor
) {
foundObjects.push(room.id);
} */
if (0 < foundObjects.length) break;
}
return foundObjects;
};
})();