Adventure.js Docs Downloads
Score: 0 Moves: 0

Class: Atom

Defined in: adventure/Atom.js, line 5

Framework class

Public Constructor:

MyGame.createAsset({ "class":"Atom", "name":"foo" })
Atom is the base class for all Assets in the game world. It defines several important base properties including name, class, id, and the set method. Authors should not need to instantiate or subclass Atom. Start with the Tangible class to create new physical Assets, or the Intangible class to create new abstract Assets.

Private Constructor:

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

Parameters:

  • game_name String
    A reference back to the top level game object, by way of window[game_name]. Done this way rather than using an object reference in order to avoid circular references, because they're difficult to parse into JSON, the method that's used for saving/restoring game data.
  • name String
    The name of the object in the game world, ie "brass lantern". The name is also used to create the object's id.
Inherited Overrides
IndexMethodsProperties

Methods Collapse all  |  Expand all

getInheritance() → {Array}

Defined in: adventure/Atom.js, line 238

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

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

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

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

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

class :String

Defined in: adventure/Atom.js, line 74

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

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

Defined in: adventure/Atom.js, line 100

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

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

Defined in: adventure/Atom.js, line 54

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.
UID :String

Defined in: adventure/Atom.js, line 93

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:08 GMT-0800 (Pacific Standard Time)
Found a problem or error in the docs? Report it to docs@adventurejs.com.