// Drainable_Is.js
(function () {
/* global adventurejs A */
/**
* @ajspath adventurejs.Atom.StateManager.Asset_Is.Tangible_Is.Drainable_Is
* @augments adventurejs.Tangible_Is
* @class adventurejs.Drainable_Is
* @ajsnavheading StateClasses
* @param {String} game_name Name of top level game instance that is scoped to window.
* @param {String} name Instance name.
* @summary A container for state variables.
* @classdesc
* <p>
* <strong>Drainable_Is.js</strong> handles is.state management for
* {@link adventurejs.Drainable|Drainable Assets}.
**/
class Drainable_Is extends adventurejs.Tangible_Is {
constructor(name = "is", game_name, context_id) {
// Call the constructor of the super class
super(name, game_name, context_id);
this.class = "Drainable_Is";
this._plugged = false;
return this;
}
/**
* <code>plugged</code> indicates whether the object is plugged
* via the verb plug. The Drainable class handles plugged
* distinctly from other classes, because a Drainable instance
* may be set so that substances drain out of it, or it may be
* linked to a separate asset that acts as its drain. This
* sounds confusing, so here's an example: imagine an author
* wants to make a sink that users can plug and unplug with a
* stopper. Fair enough, and we can set that sink.is.plugged.
* Now, imagine an author wants players to be able to interact
* with the sink and the drain as distinct objects; in this
* case the author would link a Drain asset to the Sink asset.
* In the latter scenario, checking plugged on the sink
* would actually return the plugged value of the drain.
* @var {Boolean} adventurejs.Drainable#is!plugged
* @default false
*/
get plugged() {
let context = this.context;
if (context.linked_components?.Drain) {
let drain = this.game.getAsset(context.linked_components.Drain);
return drain.is.plugged;
} else return this._plugged;
}
set plugged(value) {
let context = this.context;
if (context.linked_components?.Drain) {
let drain = this.game.getAsset(context.linked_components.Drain);
drain.is.plugged = value;
} else this._plugged = value;
}
get on() {
if (this.context.linked_components?.Faucet) {
const faucet = this.game.getAsset(
this.context.linked_components.Faucet
);
return faucet.is.on;
} else {
return this._on;
}
}
set on(value) {
if (this.context.linked_components?.Faucet) {
// @NOTE in theory we could turn the faucet off from here
// but we don't, as the verb action should handle it.
} else {
this._on = value;
}
}
get emitting() {
if (this.context.linked_components?.Faucet) {
// this doesn't emit, but we accept a linked faucet
// emitting as meaning that this is emitting
const faucet = this.game.getAsset(
this.context.linked_components.Faucet
);
return faucet.is.emitting;
} else return this._emitting;
}
set emitting(value) {
if (this.context.linked_components?.Faucet) {
// not settable from here - too many complications
// this.context.linked_components.Faucet.setEmitter(value);
} else this._emitting = value;
}
}
adventurejs.Drainable_Is = Drainable_Is;
})();