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

Defined in: Adventure.js, line 6

Constructor:

this.AdventureJS = this.AdventureJS||{}

Description

AdventureJS is a self-invoking anonymous function that creates a container to hold the engine for adventure.js. AdventureJS is singular and scoped to window (meaning, the browser window object), and can support simultaneous multiple Game instances. See Game for more information on constructing a Game instance.

Engine Classes

  • Atom Experimental class made with Javascript ES6 class keyword.
  • Dictionary Engine class that manages verb instances and lookup tables for verbs and nouns.
  • Display Manages the main game display including all related HTML elements.
  • Game Constructs a new game object.
  • Goalcard Manages goals for a Game instance.
  • GoalManager Manages the display of the goal system.
  • Hintcard Manages hints for a Game instance.
  • HintManager Manages the display of the hint system.
  • Introcard Manages the introcard for a Game instance.
  • LoginManager Manage user login to adventurejs.com.
  • Outrocard Manages the outrocard for a Game instance.
  • Parser Interprets player input.
  • Reactor Modern custom event system using EventTarget.
  • RestoreManager Manages the process of restoring saved games.
  • SaveManager Manages the process of saving games.
  • Scorecard Manages score for a Game instance.
  • Settings Manages settings for a Game instance.
  • UserManager Interface for a user account logged in to adventurejs.com.

Asset Classes

  • Branch Carve it, burn it, whack with it.
  • Player_Can A container for state variables.
  • Schmack A place to hang your coat. And hat, of course.
Inherited Overrides

Methods Collapse all  |  Expand all

addWorldToHistory
addWorldToHistory(world)

Defined in: adventure/utils/addWorldToHistory.js, line 4

Parameters:

  • world Object
Save the current world state for UNDO.
arrayToLowerCase
arrayToLowerCase(array) → {Array}

Defined in: adventure/utils/arrayToLowerCase.js, line 4

Parameters:

  • array Array
Takes an array of strings, converts them to lowercase, and returns the array.

Returns:

Array
camelToSnake
camelToSnake(string) → {String}

Defined in: adventure/utils/camelToSnake.js, line 4

Parameters:

  • string String
Converts a string from camelCase to snake_case.

Returns:

String
clone
clone(source) → {Object}

Defined in: adventure/utils/clone.js, line 4

Parameters:

  • source Object
A deep clone function for simple object types.

Returns:

Object output
cloneWorld
cloneWorld(source) → {Object}

Defined in: adventure/utils/cloneWorld.js, line 5

Parameters:

  • source Object
Clone the game world for save / restore functions.

Returns:

Object Returns a copy of the source world.
convertVolume
convertVolume(volume, context_id) → {Number}

Defined in: adventure/utils/convertVolume.js, line 4

Todos: Handle measurements other than milliliters.

Parameters:

  • volume Number | String
    In milliliters.
  • context_id String
    The ID of the Vessel containing the substance.
Converts a string or number into milliliters. Accepts a number representing volume in milliliters, or a string to be converted to milliliters (ex: "100ml"), in nL, μL, mL, cL, dL, L, daL, hL, kL, ML.

Returns:

Number
countCommonElements
countCommonElements(world) → {Number}

Defined in: adventure/utils/countCommonElements.js, line 4

Parameters:

  • world Object
Count the number of common items between two comma delimited strings.

Returns:

Number
deepSet
deepSet(props, object) → {Object}

Defined in: adventure/utils/deepSet.js, line 4

Parameters:

  • props Object
    A generic object containing properties to copy to the classed object.
  • object Object
    A class instance to copy properties to.
This is a deep copy method used for assets and verbs. Returns the object being set for chaining.

Returns:

Object Returns the instance the method is called on (useful for chaining calls.)
denormalize
denormalize(name) → {String}

Defined in: adventure/utils/denormalize.js, line 4

Parameters:

  • name String
Reverses serialize function. Convert '_' to ' '.

Returns:

String
diff
diff(baseline_object, updated_object) → {Object}

Defined in: adventure/utils/diff.js, line 4

Parameters:

  • baseline_object Object
    Old object
  • updated_object Object
    New object
diff function for comparing objects. Specifically intended to support UNDO and SAVE / RESTORE. It recurses objects, stringifies arrays, copies others.

Returns:

Object
dijkstra
dijkstra(graph, s) → {Object}

Defined in: adventure/utils/dijkstra.js, line 4

Parameters:

  • graph Array
  • s String
A pathfinding function used to determine whether travel between two given locations is possible. Based on Dijkstra's algorithm, specifically adapted from jpillora's dijkstra.js.

Returns:

Object
encrypt
encrypt(text) → {String}

Defined in: adventure/utils/encrypt.js, line 5

Parameters:

  • text String
Encrypt a string. Used to make point and hint data non human readable via encryption.

Returns:

String
generateCombinations
generateCombinations(world)

Defined in: adventure/utils/generateCombinations.js, line 4

Parameters:

  • world Object
Generate string combinations from an array of substrings.
getBaselineDiff
getBaselineDiff(source_world) → {String}

Defined in: adventure/utils/getBaselineDiff.js, line 5

Parameters:

  • source_world Object
Get the diff between the baseline world state and the current world state to create a minimum data set for writing saved games.

Returns:

String Returns a stringified diff.
getHorizontalDistance
getHorizontalDistance(point1, point2) → {Float}

Defined in: adventure/utils/getHorizontalDistance.js, line 4

Parameters:

  • point1 Object
  • point2 Object
Calculate the distance between the x/z of two points.

Returns:

Float
getRecentAssets
getRecentAssets() → {Object}

Defined in: adventure/utils/getRecentAssets.js, line 5

Get a list of recently referred assets. Not currently used but intended as a utility method to help with disambiguation. To use call A.FX.getRecentAssets.call(this.game)

Returns:

Object
getStringArrayFunction
getStringArrayFunction(obj, scope, params) → {String}

Defined in: adventure/utils/getStringArrayFunction.js, line 5

Parameters:

  • obj *
    Can be string or array or function.
  • scope Object
    Optional reference to set scope to an object.
  • params Object
    Optional params to pass to a function.
This is an important and flexible tool in the author's quiver. Because Javascript is untyped, we can pass any kind of value in a variable. We take advantage of that to set properties that print a string back to the player using a string or an array or a function. For more information and examples, see How to Use String Array Function.

Returns:

String
getVerticalDistance
getVerticalDistance(point1, point2) → {Float}

Defined in: adventure/utils/getVerticalDistance.js, line 4

Parameters:

  • point1 Object
  • point2 Object
Calculate the distance between the y of two points.

Returns:

Float
handlePlaceholders
handlePlaceholders(msg) → {String}

Defined in: adventure/utils/handlePlaceholders.js, line 4

Todos: placeholders for "any key to continue" and wipe screen

Parameters:

  • msg String
    A string on which to perform placeholder substitutions.
handlePlaceholders acts on strings prior to printing them to Display. Placeholder substitution is the last step of Game.print(). It replaces placeholders, aka substrings inside {squiggly brackets}, like {door [is] open [or] closed}.

For example:
descriptions: { look: "The drawer is { drawer [is] open [or] closed }." }


This method is similar to Javascript ES6 template literals but with important distinctions.
  • The AdventureJS version uses no $dollar sign: {foo}.
  • Substrings with {no dollar signs} are evaluated by AdventureJS, rather than native Javascript, so they have limited scope.


  • There are several types of valid placeholders:
  • { author_variables } refers to author-created game variables that are stored within the game scope so that they can be written out to saved game files. (See Basic Scripting: Game Variables for more info.)
  • { asset [is] state [or] unstate } allows authors to refer to a game asset by name or id and print certain verb states. Names are serialized during the substitution process, meaning that, for example: { brown jar [is] open [or] closed } will be interpreted to check for MyGame.world.brown_jar.is.closed.
  • {[myclass]text} is a shortcut to <span class="myclass">text</span>, to make it easier to add custom CSS styles to text.

    AdventureJS placeholders can be mixed & matched with template literals. Placeholders can be used in any string that outputs to the game display. However, because template literals in strings are evaluated when the properties containing them are created, they will cause errors on game startup. In order to use native Javascript template literals, they must be returned by functions. MyGame.createAsset({ class: "Room", name: "Standing Room", descriptions: { brief: "The north door is {north [is] open [or] closed}. ", through: "Through the door you see a {northcolor} light. ", verbose: return function(){ `The north door ${MyGame.world.aurora_door.is.closed ? "is closed, hiding the aurora. " : "is open, revealing the {northcolor} aurora light" }` } } })
  • Returns:

    String
    hasDuplicates
    hasDuplicates(array, string) → {Boolean}

    Defined in: adventure/utils/hasDuplicates.js, line 4

    Parameters:

    • array Array
    • string String
    Takes an array and returns whether it contains any duplicate items.

    Returns:

    Boolean
    indexOfSubarray
    indexOfSubarray(sub, arr) → {int}

    Defined in: adventure/utils/indexOfSubarray.js, line 4

    Parameters:

    • sub Array
      0=log, 1=warn, 2=error
    • arr Array
      0=critical, 1=high, 2=medium, 3=low
    Determine if one array is nested in another.

    Returns:

    int
    isFalseOrNull
    isFalseOrNull(value) → {Boolean}

    Defined in: adventure/utils/isFalseOrNull.js, line 4

    Parameters:

    • value *
    A simple function to check whether a value is === false or null.

    Returns:

    Boolean
    isIdInMixedArray
    isIdInMixedArray(array) → {Array}

    Defined in: adventure/utils/isIdInMixedArray.js, line 4

    Parameters:

    • array Array
    Convert an array of arbitrary strings to an array of IDs useable by game objects.
    • convert ' ' to '_'
    • convert ' and ' to '&'
    • convert '.' to '$'

    Returns:

    Array
    isIndexInRanges
    isIndexInRanges(index, ranges) → {Boolean}

    Defined in: adventure/utils/isIndexInRanges.js, line 6

    Parameters:

    • index Int
    • ranges Array
      A nested array of ranges: [[start,end]]
    Check if the specified index is within the provided ranges.

    Returns:

    Boolean
    isObfuscated
    isObfuscated(text) → {Boolean}

    Defined in: adventure/utils/isObfuscated.js, line 5

    Parameters:

    • text String
    Test if string is obfuscated. Our current scheme uses a character shift that converts a JSON file's leading { char to a ~ char.

    Returns:

    Boolean
    mergeWorld
    mergeWorld(source, dest) → {Object}

    Defined in: adventure/utils/mergeWorld.js, line 4

    Parameters:

    • source Object
    • dest Object
    Deep mergeWorld function for simple object types, used to merge restored save game files into baseline game state.

    Returns:

    Object dest
    normalize
    normalize(name) → {String}

    Defined in: adventure/utils/normalize.js, line 4

    Parameters:

    • name String
    Convert an arbitrary string to an id useable by game objects. Converts to lowercase and converts ' ' to '_'.

    Returns:

    String
    normalizeArray
    normalizeArray(array) → {Array}

    Defined in: adventure/utils/normalizeArray.js, line 4

    Parameters:

    • array Array
    Convert an array of arbitrary strings to an array of IDs useable by game objects. Convert to lowercase and convert ' ' to '_'.

    Returns:

    Array
    obfuscate
    obfuscate(text) → {String}

    Defined in: adventure/utils/obfuscate.js, line 5

    Parameters:

    • text String
    Obfuscate a string. Used to make saved game files non human readable via a simple character shift.

    Returns:

    String
    pickRandom
    pickRandom(string) → {String}

    Defined in: adventure/utils/pickRandom.js, line 4

    Parameters:

    • string String
    Return a random item from an array of strings.

    Returns:

    String
    propercase
    propercase(string) → {String}

    Defined in: adventure/utils/propercase.js, line 4

    Parameters:

    • string String
    Converts a string to Propercase (lower case with leading cap).

    Returns:

    String
    replaceStringsWithObjects
    replaceStringsWithObjects(source, destination)

    Defined in: adventure/utils/replaceStringsWithObjects.js, line 4

    Parameters:

    • source Object
    • destination Object
    Replace strings in destination object with objects from source object as needed.
    restoreWorld
    restoreWorld(source)

    Defined in: adventure/utils/restoreWorld.js, line 5

    Parameters:

    • source Object
    For UNDO and RESTORE. Revert the world to the baseline snapshot and then merge in updates from a partial copy.
    sentencecase
    sentencecase(string) → {String}

    Defined in: adventure/utils/sentencecase.js, line 4

    Parameters:

    • string String
    Capitalizes the first char of a string.

    Returns:

    String
    stringToArray
    stringToArray(string) → {Array}

    Defined in: adventure/utils/stringToArray.js, line 4

    Parameters:

    • string String
    Convert a string into an array containing the string.

    Returns:

    Array
    validateAssetList
    validateAssetList(property) → {Array}

    Defined in: adventure/utils/validateAssetList.js, line 4

    Parameters:

    • property String | Array
    Serialize asset names in an array. Asset names may be nested inside objects in the array. A secondary effect of this function is that it converts object properties from strings to arrays, which corrects for cases of authors providing strings for properties that want arrays. For example: "skeleton key" would be converted to ["skeleton_key"].

    Returns:

    Array
    validateClassList
    validateClassList(property) → {Array}

    Defined in: adventure/utils/validateClassList.js, line 4

    Todos: Is this unused?

    Parameters:

    • property String | Array
    Validate a list of classes. Unused?

    Returns:

    Array

    Properties  |