Class: Inventory

Defined in: src/inventory.coffee

Overview

The Inventory abstracts away communication with HAPI, providing a convenient API to access goods and assets belonging to a User.

Instance Method Summary

Constructor Details

- (void) constructor(categories, assets)

Create a new Inventory.

Parameters:

  • categories (Array<Object) The categories used by the avatar
  • assets (Object) A hash of good: [assets]

Instance Method Details

- (void) setAssets(assets)

Set the assets to be used by the inventory.

Parameters:

  • assets (Object) A hash of good: [assets]

- (void) representation(_representation)

Set the default representation to be used. Setting a default representation allows you to call other methods that may require a representation without supplying one.

Parameters:

  • _representation (String) A valid representation

- (void) good(_good)

Set the default good to be used. Setting a default good allows you to call other methods that may require a good without supplying one.

Parameters:

  • _good (String) A valid good

- (void) category(_category)

Set the default category to be used. Setting a default category allows you to call other methods that may require a category without supplying one.

Parameters:

  • _category (String) A valid category

- (Object/Array) get(options = {})

Get data from the inventory. The data must be scoped by representation; other scopings are optional. If only a representation is supplied, the returned data is in the form category: [assets]. If a category is given, an array of assets belonging to the given category is returned. If a good is given, assets are restricted to the given good.

Parameters:

  • options (Object) Options to narrow the scope of the data returned

Options Hash: (option):

  • representation (String) A valid representation (required)
  • category (String) A valid category. Will use the default if not given
  • good (String) A valid good. Will use the default if not given

Throws:

  • (Error) — If no representation option is given

Returns:

  • (Object/Array) — Data scoped as per the options

- (Object) getAsset(assetLabel, representation = @_representation)

Get an asset by label and representation.

Parameters:

  • assetLabel (String) Label of the asset to get
  • representation (String) Representation of the asset to get. Will use the default if set

Returns:

  • (Object) — An asset collapsed to the given representation, or null if none can be found

- (Object) assetById(assetId, representation = null)

Find an asset by its Id.

Parameters:

  • assetId (Integer) The id of the asset to search for
  • representation (String) Optional. Collapse the asset to the given representation

Returns:

  • (Object) — An asset, or null if none could be found

- (Object) assetByLabel(assetLabel, representation = null)

Find an asset by its Label.

Parameters:

  • assetLabel (String) The Label of the asset to search for
  • representation (String) Optional. Collapse the asset to the given representation

Returns:

  • (Object) — An asset, or null if none could be found

- (Object) randomEnsemble(options)

Get a random ensemble. This can be used to build an Avatar.

Parameters:

  • options (Object) Options to be used in creating the ensemble

Options Hash: (option):

  • representation (String) A valid representation (required)
  • palette (Array<Array<String>>) A colour palette in the form [[colours], [colours]]
  • globalPalette (Boolean) Whether the given palette should be used globally
  • good (String) If given, restrict randomised assets to a particular good

Returns:

  • (Object) — An ensemble of category: asset pairs

- (Object) avatarEnsemble(assets, representation)

Get an ensemble based on a list of assets. This can be used to build an Avatar. The list of assets will typically have been obtained by a call to HAPI, and each element will be of the form AssetId:, Colour1:, Colour2:.

Parameters:

  • assets (Array<Object>) A list of assets to be used in the ensemble
  • representation (String) The representation used to build the ensemble

Returns:

  • (Object) — An ensemble in the form category: asset