Pre-release
AdventureJS Docs Downloads Bundler Devlog Score: 0 Moves: 0
Tutorial explaining how to work with furniture in AdventureJS. tutorial, furniture WorkingWithFurniture styles

Working With...Furniture

Furniture includes tables and chairs, desks, thrones, beds, all the things you'd expect. They're fairly simple as assets go. The primary characteristic of furniture is that players can sit on them, stand on them, lie on them, and perhaps go under them. Typically they're not movable, though they can be made movable. A chief consideration of furniture is what players can reach while they're on one. Authors can control whether players on furniture can reach things elsewhere in the room, and whether plays can use exits directly from furniture without being prompted to get off it first.

 

Demo Game

// WorkingWithFurniture.js
/* global AdventureJS A Game */

var WorkingWithFurniture = new AdventureJS.Game(
  "WorkingWithFurniture",
  "WorkingWithFurnitureContainer"
);

// --------------------------------------------------
// Settings
// --------------------------------------------------

WorkingWithFurniture.settings.set({
  display: "inline",
  layout: "classic",
  title: "Working With Furniture",
  author: "Ivan Cockrum",
  description: "Today we are Working With Furniture ",
  version: "0.0.1",

  // There are only two rooms each with one exit and
  // we're going to include exits in room description,
  // so we don't want the usual exits list.
  print_exits_in_room_descriptions: false,

  // The automatic statusbar compass isn't helpful
  // in our two room situation.
  show_statusbar_compass: false,

  // By default, if player is nested and tries
  // to use an exit, they're denied unless
  // the exit is explicitly defined as reachable
  // from that nest. This setting allows player
  // to go to the closet from the crash crouch
  // without being told they have to get up first.
  auto_unnest_on_travel: true,

  debug: {
    general: true,
    //   verbaction: true,
    //   verbreaction: true,
    //   verbphase: true,
    //   travel: true,
  },
  log: {
    verbaction: true,
    verbreaction: true,
    verbphase: true,
    travel: true,
    game: true,
    verb: true,
    parser: true,
    // entity: true,
    all: true,
  },
});

// --------------------------------------------------
// Player
// --------------------------------------------------

WorkingWithFurniture.createAsset({
  class: "Player",
  name: "Explorer",
  place: { on: "crash couch" },
});

// --------------------------------------------------
// Rooms
// --------------------------------------------------

WorkingWithFurniture.createAsset({
  class: "Room",
  name: "Control Room",

  // definite_article: "the",
  the: "the", // shorthand to definite_article

  // we're using a player conditional placeholder
  // to dynamically adjust this output
  description: `
    {We're} in the control room of the launch pod, 
    though using the word "room" is being generous. 
    The space is dominated by a crash couch, 
    {[if player is on crash couch] into which you are strapped,} 
    faced on one side by the launch control panel  
    and on the other{[if player is on crash couch], though it's hard to see behind you,} 
    by the science station. A small closet is tucked 
    between the two stations.
  `,
  exits: {
    closet: "Closet",
  },
});

WorkingWithFurniture.createAsset({
  class: "Room",
  name: "Closet",
  the: "the",
  description: `
    This tiny cramped closet is used as a storage locker. 
  `,
  exits: {
    "Control Room": "Control Room",
  },
});

// --------------------------------------------------
// Objects
// --------------------------------------------------

WorkingWithFurniture.createAsset({
  class: "Desk",
  name: "science station",
  place: { in: "Control Room" },
  description: `The science station fills a wall of the capsule behind the crash couch. `,

  // We don't want this desk listed in the room's inventory
  // because it's included in the room description.
  is: { listed: false },
  // But we do want things on the desk to be listed.
  aspects: { on: { list_contents_in_room: true } },
});

WorkingWithFurniture.createAsset({
  class: "Desk",
  name: "launch control panel",
  place: { in: "Control Room" },
  description: `The launch control panel fills the wall in front of the crash couch. `,

  // We don't want this desk listed in the room's inventory
  // because it's included in the room description.
  is: { listed: false },
  // But we do want things on the desk to be listed.
  aspects: { on: { list_contents_in_room: true } },
});

WorkingWithFurniture.createAsset({
  class: "Chair",
  name: "crash couch",
  place: { in: "Control Room" },
  is: { listed: false },
  aspects: { on: { list_contents_in_room: true } },

  // we're using a player conditional placeholder
  // to dynamically adjust this output
  description: `
    The heavy crash couch 
    {[if player is on crash couch] that you are strapped to} 
    dominates the center of the cramped Control Room. 
  `,

  nests: { on_can_reach: ["launch control panel"] },

  // doPlayerEnter is a function that can be called
  // from anything the player can get in/on/etc
  doPlayerEnter: function () {
    let msg = `{We} lay down on the crash couch and strap {ourselves} in. `;
    WorkingWithFurniture.overrideOutput(msg);
  },

  // doPlayerExit is a function that can be called
  // from anything the player can get in/on/etc
  doPlayerExit: function () {
    let msg = `{We} unstrap {ourselves} from the couch and climb down off it. `;
    WorkingWithFurniture.overrideOutput(msg);
  },
});

WorkingWithFurniture.createAsset({
  class: "Pencil",
  name: "carbon pencil",
  place: { on: "launch control panel" },
});

WorkingWithFurniture.createAsset({
  class: "Pen",
  name: "antigravity pen",
  // indefinite_article: "an",
  a: "an", // shorthand for indefinite_article
  place: { on: "science station" },
});

WorkingWithFurniture.createAsset({
  class: "Paper",
  name: "laminated sheet of paper",
  synonyms: ["launch instructions"],
  description: `It's a laminated sheet of paper with launch instructions printed on it. `,
  place: { in: "Control Room" },
});

Demo Source files

Right-click and choose "Save as..." to download source files.

Notes:

  • Demo games are set to a small size to fit doc pages. They can easily be enlarged via display settings.
  • Demo games all use the same theme. Colors and fonts can be changed via custom CSS.
  • Demo games don't include the core AdventureJS code. To run downloaded games locally, you'll need to also download copies of the core JS and CSS and set up this local folder structure.
AdventureJS
└── js
|   └── adventure.min.js
└── css
|   └── adventurejs.min.css
└── games
    ├── demogame01
    ├── demogame02
    └── demogame03

 

Reachability

Reachability is an important characteristic of furniture. When players go in/on/under/behind an asset, they do so via nesting, which is a special method for player characters so that they can be be nested in an asset while still being in a room. Any asset can have multiple nests. For instance, a player might be able to go on or under a desk. A player that is nested in/on/under/behind a piece of furniture can't necessarily reach things beyond that nest. Imagine being strapped in to a rocket's crash couch, where items on the rocket's science station desk can't be reached from the crash couch... unless it's explicitly specified that the science station desk is reachable from the crash couch.

MyGame.createAsset({
  class: "Desk",
  name: "science station",
  place: { in: "Control Room" },
  description: `The science station fills a wall of the capsule behind the crash couch. `,
});

MyGame.createAsset({
  class: "Desk",
  name: "launch control station",
  place: { in: "Control Room" },
  description: `The launch control station rests in front of the crash couch. `,
});

MyGame.createAsset({
  class: "Chair",
  name: "crash couch",
  place: { in: "Control Room" },
  description: `
    The heavy crash couch 
    {[if player is on crash couch] that you are strapped to} 
    dominates the center of the cramped Control Room. 
  `,
  // we're using a shorthand method of nest to set reachability
  nests: { on_can_reach: ["science station"] },
});

Further Reference