Adventure.js Docs Downloads
Score: 0 Moves: 0

Class: Aspect

Extends: adventurejs.Atom

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

How to: UseAspects

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.can_put.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_in_room: false,
    list_in_examine: true,
    maxheight: 1,
    maxwidth: 6,
    maxdepth: 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.

function NewClass( name, game_name ) 
{
  this.Tangible_constructor( name, game_name );
  this.can_put.newaspect = new adventurejs.Aspect( "newaspect", this.game_name )
  .set({ 
    "parent_id": this.id,
  });
 }
 var p = adventurejs.extend(NewClass, adventurejs.Tangible);
 adventurejs.Bowl = adventurejs.promote(NewClass, "Tangible");
}());

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
IndexMethodsProperties

Methods Collapse all  |  Expand all

getInheritance() → {Array}

Defined in: adventure/Atom.js, line 238

Inherited from: adventurejs.Atom#getInheritance

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

Returns:

Array
getProperty(prop) → {Boolean}

Defined in: adventure/Atom.js, line 184

Inherited from: adventurejs.Atom#getProperty

Parameters:

  • prop String
    Name of the property to test for. Can include dot notation.
A method to get a deep property without throwing an error. Allows for getting deep properties, ie "foo.bar.baz". Returns false if property doesn't exist, so beware of if(false === foo.bar.baz) comparisons.

Returns:

Boolean
hasClass(prop) → {Boolean}

Defined in: adventure/Atom.js, line 216

Inherited from: adventurejs.Atom#hasClass

Parameters:

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

Returns:

Boolean
hasProperty(prop) → {Boolean}

Defined in: adventure/Atom.js, line 148

Inherited from: adventurejs.Atom#hasProperty

Parameters:

  • prop String
    Name of the property to test for. Can include dot notation.
A method to test whether the Atom has a given property. Allows for testing deep properties, ie "foo.bar.baz". For stupid and unaccountable reasons Ivan has decided to code adventurejs entirely in Javascript ES5, so we don't have the nicety of optional chaining introduced in ES6. This method fills in for optional chaining until we someday upgrade to ES6.

Returns:

Boolean
set(props) → {Object}

Defined in: adventure/Atom.js, line 134

Inherited 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 Collapse all  |  Expand all

can_hold_player :boolean

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

Default value: false

class :String

Defined in: adventure/Atom.js, line 74

Inherited from: adventurejs.Atom#class

Class identifier to be provided in the asset definition. All game objects start as generic objects that get passed to createAsset, which uses an object's class field to specify a class constructor.
game :Getter

Defined in: adventure/Atom.js, line 123

Inherited from: adventurejs.Atom#game

Getter function that returns the top level game object. Use this.game.
game_name :Getter/Setter

Defined in: adventure/Atom.js, line 100

Inherited from: adventurejs.Atom#game_name

game_name holds a copy of the variable name used to store the current game instance, to which every asset in the game world holds a reference. (By default, we use "MyGame", but you can use any name.) The variable is scoped to window, and in order to get the game object, we call window[this.game_name]. Though it would be easier to use a direct object reference, doing so creates a circular reference, which complicates JSON encoding, which is how we save/restore the game state.
id :String

Defined in: adventure/Atom.js, line 86

Inherited from: adventurejs.Atom#id

A unique ID for the game asset, based on the object name provided in the asset definition.
is_false_nest :boolean

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

Default value: false

name :String

Defined in: adventure/Atom.js, line 54

Inherited from: adventurejs.Atom#name

String provided by author in game file. The name gets serialized - which here means removing periods and spaces and converting to lowercase - and saved as a unique id for the asset.
orientation :String

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

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_climb :boolean

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

Default value: false

player_can_crawl :boolean

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

Default value: false

player_can_float :boolean

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

Default value: false

player_can_fly :boolean

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

Default value: false

player_can_hide :boolean

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

Default value: false

player_can_hover :boolean

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

Default value: false

player_can_jump :boolean

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

Default value: false

player_can_kneel :boolean

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

Default value: false

player_can_lie :boolean

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

Default value: false

player_can_nest :boolean

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

Default value: false

player_can_reach :boolean

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

Default value: true

player_can_reach :boolean

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

Default value: true

player_can_run :boolean

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

Default value: false

player_can_sit :boolean

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

Default value: false

player_can_slither :boolean

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

Default value: false

player_can_stand :boolean

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

Default value: false

player_can_step :boolean

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

Default value: false

player_can_swim :boolean

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

Default value: false

player_can_walk :boolean

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

Default value: false

player_posture :String

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

Default value: "stand"

player_preposition :String

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

things_player_can_reach_from_positions_of_this_aspect :Object|Array

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

Todos: for this to work properly each aspect needs its own local coordinates

UID :String

Defined in: adventure/Atom.js, line 93

Inherited from: adventurejs.Atom#UID

A unique numerical ID for the game asset. Currently unused but included as a potential alternative to id.
Documentation generated by JSDoc 3.6.11 on Mon Nov 20 2023 18:01:07 GMT-0800 (Pacific Standard Time)
Found a problem or error in the docs? Report it to docs@adventurejs.com.