(function () {
class GraduatedController extends adventurejs.Thing {
constructor(name, game_name) {
super(name, game_name);
this.class = "GraduatedController";
this.singlePluralPairs = [["controller", "controllers"]];
this.descriptions.look = "It's a controller.";
this.is.listed_in_parent = false;
this.can.turn = true;
this.dimensions.width = 1;
this.dimensions.height = 1;
this.unsetDOV("take");
this.setDOVs([{ turn: { with_nothing: true } }]);
this.control_positions = 2;
this.current_position = 0;
this.control_target_id = "";
this.set_substance_id = "";
this.set_substance_temperature = 25;
this.turnOn_doAfterTry = function (params) {
var input = this.game.getInput();
var verb_phrase = input.verb_phrase;
var direct_object = input.getAsset(1);
var msg = "";
if (2 > direct_object.control_positions) {
msg += `${direct_object.Articlename} can't be turned on. `;
if (msg) this.game.print(msg, input.output_class);
return null;
}
if (
direct_object.current_position + 1 ===
direct_object.control_positions
) {
msg = `${direct_object.Articlename_is} already turned on. `;
if (msg) this.game.print(msg, input.output_class);
return null;
}
return true;
};
this.turnOn_doBeforeSuccess = function (params) {
var game = window[game_name];
var input = game.getInput();
var direct_object = input.getAsset(1);
var msg = "";
var results;
direct_object.current_position = direct_object.current_position + 1;
if (2 < direct_object.control_positions) {
if (
direct_object.current_position + 1 ===
direct_object.control_positions
) {
msg += `$(We) turn ${direct_object.articlename} all the way on. `;
} else {
msg += `$(We) turn ${direct_object.articlename} further on. `;
}
} else {
msg += `$(We) turn ${direct_object.articlename} to on. `;
}
var indirect_object = game.getAsset(direct_object.control_target_id);
if (
Object(indirect_object) === indirect_object &&
"function" === typeof indirect_object.onChangeGraduatedController
) {
results = indirect_object.onChangeGraduatedController(direct_object);
if (A.isFalseOrNull(results)) return results;
if ("string" === typeof results) msg += results;
}
if (msg) game.print(msg, input.output_class);
return null;
};
this.turnOff_doAfterTry = function (params) {
var game = window[game_name];
var input = game.getInput();
var direct_object = input.getAsset(1);
var msg = "";
if (2 > direct_object.control_positions) {
msg = `${direct_object.Articlename} can't be turned off. `;
if (msg) game.print(msg, input.output_class);
return null;
}
if (direct_object.current_position === 0) {
msg = `${direct_object.Articlename_is} already turned off. `;
if (msg) game.print(msg, input.output_class);
return null;
}
return true;
};
this.turnOff_doBeforeSuccess = function (params) {
var game = window[game_name];
var input = game.getInput();
var direct_object = input.getAsset(1);
var msg = "";
var results;
direct_object.current_position = direct_object.current_position - 1;
if (2 < direct_object.control_positions) {
if (direct_object.current_position === 0) {
msg += `$(We) turn ${direct_object.articlename} all the way off. `;
} else {
msg += `$(We) turn ${direct_object.articlename} further off. `;
}
} else {
msg += `$(We) turn ${direct_object.articlename} to off. `;
}
var indirect_object = game.getAsset(direct_object.control_target_id);
if (
Object(indirect_object) === indirect_object &&
"function" === typeof indirect_object.onChangeGraduatedController
) {
results = indirect_object.onChangeGraduatedController(direct_object);
if (A.isFalseOrNull(results)) return results;
if ("string" === typeof results) msg += results;
}
if (msg) game.print(msg, input.output_class);
return null;
};
this.dov.turn.doAfterTry = function (params) {
var input = this.game.getInput();
var verb_phrase = input.verb_phrase;
var direct_object = input.getAsset(1);
var direct_preposition = input.getPreposition(1);
if (input.hasStructure("verb preposition noun")) {
if (direct_preposition === "on") return this.turnOn_doAfterTry();
if (direct_preposition === "off") return this.turnOff_doAfterTry();
}
if (input.hasStructure("verb noun")) {
if (direct_object.control_positions < 2) {
var msg = direct_object.Articlename + " doesn't turn. ";
if (msg) this.game.print(msg, input.output_class);
return null;
}
}
return true;
};
this.dov.turn.doBeforeSuccess = function (params) {
var input = this.game.getInput();
var verb_phrase = input.verb_phrase;
var direct_object = input.getAsset(1);
var direct_preposition = input.getPreposition(1);
var msg = "";
var results;
if (input.hasStructure("verb preposition noun")) {
if (direct_preposition === "on") return this.turnOn_doBeforeSuccess();
if (direct_preposition === "off")
return this.turnOff_doBeforeSuccess();
}
if (input.hasStructure("verb noun")) {
if (direct_object.control_positions === 2) {
direct_object.current_position = Math.abs(
direct_object.current_position - 1
);
msg += `$(We) turn ${direct_object.articlename} to ${
direct_object.current_position == 1 ? "open" : "closed"
}. `;
} else if (2 < direct_object.control_positions) {
if (
direct_object.current_position <
direct_object.control_positions - 1
) {
direct_object.current_position++;
} else {
direct_object.current_position--;
}
}
var indirect_object = this.game.getAsset(
direct_object.control_target_id
);
if (
Object(indirect_object) === indirect_object &&
"function" === typeof indirect_object.onChangeGraduatedController
) {
results =
indirect_object.onChangeGraduatedController(direct_object);
if (A.isFalseOrNull(results)) return results;
if ("string" === typeof results) msg += results;
}
if (msg) this.game.print(msg, input.output_class);
return null;
}
return true;
};
}
get set_substance_id() {
return this._set_substance_id;
}
set set_substance_id(substance_id) {
if ("string" !== typeof substance_id) {
var msg = this.id + ".set_substance_id must be a string. ";
this.game.log("L1438", "warn", "critical", msg);
return;
}
this._set_substance_id = A.serialize(substance_id);
}
get set_substance_temperature() {
return this._set_substance_temperature;
}
set set_substance_temperature(substance_temperature) {
if ("number" !== typeof substance_temperature) {
var msg = this.id + ".set_substance_temperature must be a number. ";
this.game.log("L1439", "warn", "critical", msg, "warning");
return;
}
this._set_substance_temperature = substance_temperature;
}
}
adventurejs.GraduatedController = GraduatedController;
})();