// registerComponents.js
(function () {
/* global adventurejs A */
var p = adventurejs.Tangible.prototype;
/**
* registerComponents is a method that links integrated assets.
* For example, a sink of class Drainable can have a Faucet,
* a Drain, and multiple Handle(s), each of which
* may interact with the base asset or each other
* in different ways.
* @memberOf adventurejs.Tangible
* @method adventurejs.Tangible#registerComponents
*/
p.registerComponents = function Tangible_registerComponents() {
if (this.components.length > 0) {
//var msg = this.class + " " + this.id + " registerComponents found components";
var msg = this.id + ".registerComponents)() found components:";
this.game.log("L1452", "log", "high", msg, "Tangible");
}
for (var i = this.components.length - 1; i > -1; i--) {
var part_id = this.components[i];
var part = this.game.getAsset(this.components[i]);
this.components.splice(i, 1);
if (!part) {
//var msg = this.class + " " + this.name + " components contains an invalid id: " + id;
var msg = this.name + " components contains an invalid id: " + part_id;
this.game.log("L1453", "error", "critical", msg, "Tangible");
continue;
}
part.linked_parent = this.id;
var linkableClassKeys = Object.keys(this.linkableClasses);
for (var r = 0; r < linkableClassKeys.length; r++) {
var linkedClass = linkableClassKeys[r];
if (true === part instanceof adventurejs[linkedClass]) {
// pass in a reference to 'this' as well as the part to be registered
// because we're going into anonymous functions that don't have scope
this.linkableClasses[linkedClass].call(this, part);
var msg = "-- " + this.id + " register " + part.id;
this.game.log("L1454", "log", "high", msg, "Tangible");
continue;
}
}
}
};
})();