// Typewriter.js
(function () {
/* global adventurejs A */
/**
* @ajspath adventurejs.Atom.Asset.Matter.Tangible.Thing.Typewriter
* @augments adventurejs.Thing
* @class adventurejs.Typewriter
* @ajsconstruct MyGame.createAsset({ "class":"Typewriter", "name":"foo", [...] })
* @ajsconstructedby adventurejs.Game#createAsset
* @ajsnavheading WritingClasses
* @param {String} game_name The name of the top level game object.
* @param {String} name A name for the object, to be serialized and used as ID.
* @summary A typewriter that players can type on.
* @tutorial Tangibles_AboutTangibles
* @ajsdemo WritingDemo, Office, Playroom, Classroom, Library, Scorecard
* @ajscss Styles
* @ajstangiblecontainer in
* @classdesc
* <strong>Typewriter</strong> is a subclass of
* {@link adventurejs.Thing|Thing} with a
* subscription to the
* {@link adventurejs.Verb|Verb} {@link type}.
* (For more information about verb subscriptions, see
* <a href="/doc/Scripting_VerbPhases.html">Verb Subscriptions</a>.)
* It accepts input in the form of
* <code class="property">type "foo" on typewriter</code> where "foo" is a
* string with quotes around it. If keyboard's
* <code class="property">typing_targets</code> property
* contains any asset IDs, the input string will display on
* those assets. See the following
* transcript to get an idea how this plays out.
* </p>
* <pre class="display border outline">
* <span class="ajs-player-input">> x typewriter</span>
* It's a typewriter.
*
* <span class="ajs-player-input">> type "foo" on typewriter</span>
* There's no paper in the typewriter. You bang out "foo"
* on the keys but nothing comes of it.
*
* <span class="ajs-player-input">> open middle drawer</span>
* You open the middle drawer. In the middle drawer you see a blue sheet.
*
* <span class="ajs-player-input">> take blue sheet</span>
* You take the blue sheet from the middle drawer.
*
* <span class="ajs-player-input">> put blue sheet in typewriter</span>
* You put the blue sheet in the typewriter.
*
* <span class="ajs-player-input">> type "cordon bleu" on typewriter</span>
* You type "cordon bleu" on the blue sheet.
*
* <span class="ajs-player-input">> x blue sheet</span>
* It's a blue sheet of paper. Printed on the blue sheet is a phrase: "cordon bleu".
* </pre>
* <h3 class="examples">Example:</h3>
* <pre class="display"><code class="language-javascript">MyGame.createAsset({
* class: "Typewriter",
* name: "typewriter",
* place: { on: "desk" },
* descriptions: { look: "It's an old fashioned Corona typewriter. ", },
* dov: { take: false, },
* });
* MyGame.createAsset({
* class: "Paper",
* name: "blue sheet",
* descriptions: { look: "It's a blue sheet of paper. ", },
* place: { in: "middle drawer" },
* });
* </code></pre>
**/
class Typewriter extends adventurejs.Thing {
constructor(name, game_name) {
super(name, game_name);
this.class = "Typewriter";
this.setDOVs(["put", "get", "take", "give"]);
this.setIOVs(["put", "take"]);
this.setIOV({ type: { with_params: { tool: true } } });
// this.setDOV({ type: { with_params: { tool: true } } });
this.aspects.in = new adventurejs.Aspect(
"in",
this.game_name,
this.id
).set({
classes_allowed: ["Paper"],
list_contents_in_examine: true,
know_contents_with_parent: true,
see_contents_with_parent: true,
contents_limits: { count: 1 },
});
/**
* Typewriter needs a sheet of paper in it.
*
* doAfterTry lets the verb's standard checks run
* before checking specifics for this object
*
* doBeforeSuccess preempts doSuccess because
* we want to override the standard success
*
* for purposes of parsing,
* typewriter is always iov
* paper is always dov
*/
// this.iov.type.doAfterTry = function (params) {
// var input = this.game.getInput();
// var tool_asset = input.verb_params.tool_asset;
// if (tool_asset.aspects.in.contents.length == 0) {
// this.game.debug(
// `D1490 | Typewriter.js iov.type.doAfterTry | ${tool_asset.id}.aspects.in.contents is empty`
// );
// var msg = `There's no paper in ${tool_asset.articlename}. {We} peck `;
// if (0 < input.strings.length) {
// msg += `out "${input.strings[0]}" `;
// }
// msg += `on the keyboard but nothing comes of it. `;
// this.game.dictionary.verbs[params.verb].handleFailure(
// msg,
// tool_asset
// );
// return null;
// }
// return true;
// };
// this.iov.type.doBeforeSuccess = function (params) {
// var input = this.game.getInput();
// var tool_asset = input.verb_params.tool_asset;
// var target_asset = input.verb_params.target_asset;
// var msg = "";
// this.game.debug(
// `D1494 | Typewriter.js iov.type.doBeforeSuccess | ${tool_asset.id}`
// );
// if (!target_asset) {
// target_asset = this.game.getAsset(tool_asset.aspects.in.contents[0]);
// }
// // state change?
// if (target_asset && input.strings.length) {
// target_asset.typed_strings.push(input.strings[0]);
// }
// // compose output
// msg += `TYPEWRITER {We} type `;
// msg += input.strings.length ? `"${input.strings[0]}" ` : ``;
// msg += `on ${
// target_asset ? target_asset.articlename : tool_asset.articlename
// }. `;
// // --------------------------------------------------
// // print output
// // --------------------------------------------------
// this.game.dictionary.verbs[params.verb].handleSuccess(msg, tool_asset);
// return null;
// };
}
}
adventurejs.Typewriter = Typewriter;
})();