Pre-release
AdventureJS Docs Downloads
Score: 0 Moves: 0

Extends: adventurejs.Atom

Defined in: adventure/assets/Aspect.js, line 5

More info: Aspects

Description

Aspect is a special class that creates spaces within any Tangible Asset, which can contain other Tangibles and/or Substances, with the addition of a Vessel. The five most commonly used aspects are behind, in, on, under, and attached, and a lot of default logic is predicated on using one of these. However it is possible to create aspects at any preposition. Just note that it might lead to unexpected results and require custom code.

this.aspects.behind = {};

Here is an example of how to set the properties of a Aspect of an existing class using createAsset. If you use a preposition that hasn't been defined for the class you're using, a new Aspect will be constructed automatically during construction.

MyGame.createAsset({
  class: "Desk",
  name: "desk",
  place: { in: "Office" },
  behind: {
    list_contents_in_room: false,
    list_contents_in_examine: true,
    contents_limits: {
      height: 1,
      width: 6,
      depth: 4,
    },
  }
});

To define a new class with an Aspect, use the Aspect constructor within the class constructor. Here is a very simple example of a new class with a behind Aspect.

class NewClass {
  constructor( name, game_name ) {
    super( name, game_name );
    this.aspects.newaspect = new adventurejs.Aspect( "behind", this.game_name, this.id )
    .set({
      // optional params
    });
   }
  }
  adventurejs.NewClass = NewClass;
};

Private Constructor:

var foo = new adventurejs.Aspect(game_name, name)

Parameters:

  • game_name String
    Name of top level game instance that is scoped to window.
  • name String
    Instance name.
Inherited Overrides

Methods Collapse all  |  Expand all

getClassInheritance
getClassInheritance() → {Array}

Defined in: adventure/Atom.js, line 168

Inherited from: adventurejs.Atom#getClassInheritance

getClassInheritance is a utility method to get an asset's class inheritance chain. Returns a list of class names from high to low.

Returns:

Array
hasClass
hasClass(prop) → {Boolean}

Defined in: adventure/Atom.js, line 148

Inherited from: adventurejs.Atom#hasClass

Parameters:

  • prop String
    Name of the class to test for.
A method to test whether the Atom is an instance of a given class.

Returns:

Boolean
set
set(props) → {Object}

Defined in: adventure/Atom.js, line 136

Overrides from: adventurejs.Atom#set

Parameters:

  • props Object
    A generic object containing properties to copy to the Object instance.
Provides a chainable shortcut method for setting a number of properties on the instance.

Returns:

Object Returns the instance the method is called on (useful for chaining calls.)

Properties  | 

contents
contents :Array

Defined in: adventure/assets/Aspect.js, line 150

Default value: []

A list of asset ids that are contained in this aspect.
contents_limits
contents_limits :Array

Defined in: adventure/assets/Aspect.js, line 157

Default value: { height: -1, width: -1, depth: -1, count: -1, weight: -1, }

Set maximums for contents of dimensions, count, and volume. -1 means infinite.
game
game :Getter

Defined in: adventure/Atom.js, line 115

Inherited from: adventurejs.Atom#game

Returns the top level game object. Use this.game.
know_contents_with_parent
know_contents_with_parent :boolean

Defined in: adventure/assets/Aspect.js, line 116

Default value: true

This property allows authors some control over when asset contents become known. Generally speaking, assets are unknown until they have been "seen", which usually occurs when the player enters a room containing the asset. When an asset becomes known, it may or may not be desirable for its contents to become known. For example, items on a desk should probably be known, whereas items under a bed might better remain unknown until the player tries "look under bed". Or consider a knapsack: if it's closed, the player might see the knapsack, but shouldn't know what's inside of it until they open it.
list_contents_in_examine
list_contents_in_examine :boolean

Defined in: adventure/assets/Aspect.js, line 104

Default value: true

When an asset is examined, authors may control whether aspect contents are listed in the description. Consider a pocket protector: examining it might list the pens and pencils in it. On the other hand, consider a desk with drawers: if the drawers are part of the desk's general description, the author might not want them listed.
list_contents_in_room
list_contents_in_room :boolean

Defined in: adventure/assets/Aspect.js, line 89

Default value: true

When the player enters a room, items in the room are listed in the room's description, and the contents of those items may or may not be listed as well, depending on this setting. For example, consider a bed with pillows on it: "There is a bed here. On the bed you see some pillows." Now consider the monster under the bed: "There is a bed here. Under the bed you see a monster." To prevent the monster from being revealed in the room description, simply set bed.aspects.under.list_contents_in_room to false.
Name
Name :String

Defined in: adventure/Atom.js, line 102

Inherited from: adventurejs.Atom#Name

Name returns the name of the class instance with the first character uppercased.
nest
nest :Object

Defined in: adventure/assets/Aspect.js, line 232

Default value: {}

Nests allow aspects to contain characters. Vessel is a distinct class with its own methods and properties for managing substances. A collection of properties that defines whether a player may enter this aspect, what actions they are allowed to perform in it, and the default posture they will take upon entering. Aspects and Rooms both share these properties. To initialize a nest:
this.nest = new adventurejs.Nest(
  "nest",
  this.game_name,
  this.context_id
).set({
  preposition: this.name,
});
orientation
orientation :String

Defined in: adventure/assets/Aspect.js, line 253

Default value: "horizontal"

orientation determines whether an Aspect is horizontal or vertical. Chiefly meant to distinguish between player being on a flat surface such as a table, vs player being on a vertical face such as a tree.
player_can_add_assets_to_contents
player_can_add_assets_to_contents :boolean

Defined in: adventure/assets/Aspect.js, line 205

Default value: true

Determine whether the player can add assets to this aspect's contents.
player_can_remove_assets_from_contents
player_can_remove_assets_from_contents :boolean

Defined in: adventure/assets/Aspect.js, line 212

Default value: true

Determine whether the player can remove assets from this aspect's contents.
scale_increment
scale_increment :Array

Defined in: adventure/assets/Aspect.js, line 171

Default value: -1

Objects that are taller than player height may be scaled (ie climbed, though the action is not exclusive to climb verb). This var determines how far the player climbs per turn. For example, a tree with height of 5 and scale_increment of 1 will take the player 5 turns of climbing to reach the top, whereas a scale_increment of 5 will let players climb the tree in 1 turn. The default scale_increment of -1 will let players climb an object in 1 turn regardless of height.
see_contents_with_parent
see_contents_with_parent :boolean

Defined in: adventure/assets/Aspect.js, line 132

Default value: true

This property allows authors some control over when asset contents become seen. Generally speaking, assets are unseen until they have been "seen", which usually occurs when the player enters a room containing the asset. When an asset becomes seen, it may or may not be desirable for its contents to become seen. For example, items on a desk should probably be seen, whereas items under a bed might better remain unseen until the player tried "look under bed". Or consider a knapsack: if it's closed, the player might see the knapsack, but shouldn't see what's inside of it until they open it. Known and seen are distinct properties because it's possible to know about an asset without seeing it.
vessel
vessel :Object

Defined in: adventure/assets/Aspect.js, line 219

Default value: {}

Vessels allow aspects to contain substances. Vessel is a distinct class with its own methods and properties for managing substances. In theory, any aspect can contain substances: but in practice, only in aspects are used. For example, consider a pile of dust under a bed: rather than adding the dust to bed.aspects.under.vessel, you would create a dustpile asset and add dust to dustpile.aspects.in.vessel.
with_assets
with_assets :Array

Defined in: adventure/assets/Aspect.js, line 185

Default value: []

A list of asset ids that are allowed to be contained in this aspect. Use this to limit what things can be put in other things. For example, consider a scabbard which only allows one particular sword to be put in it.
with_classes
with_classes :Array

Defined in: adventure/assets/Aspect.js, line 195

Default value: []

A list of classes that are allowed to be contained in this aspect. Use this to limit what things can be put in other things. For example, consider a pocket protector, which only allows pens and pencils to be put in it.