Class: Avatar

Defined in: src/avatar.coffee

Overview

A simple model class providing convenience methods for working with avatars.

Instance Method Summary

Constructor Details

- (void) constructor(client, attributes)

Create a new Avatar.

Avatars should normally be created by Totem, using Totem#avatar or by retrieval using Totem#avatars.

Parameters:

  • client (Object) A hapilib restClient
  • attributes (Object) A hash of avatar attributes Id:, Label:, Metadata:

Instance Method Details

- (void) representation(representation)

Sets and gets the avatar's representation.

@param [String] representation The representation to set @param [Boolean] notify Whether to notify observers to the "representationChange" event. Defaults to true @return [String] The representation currently set

@overload representation() Gets the representation currently set.

@return [String] The representation currently set

Overloads:

- (void) representation(representation)

Sets the representation property in the avatar's {#metadata metadata}, and, optionally, notifies observers of the "changeRepresentation" event. Data sent with the event is avatar:<Avatar>.

- (void) clear()

Clear and initialise the avatar's current ensemble.

- (void) build(ensemble)

Equip some or all of an avatar's categories with assets. Notifies observers to the "build" event. Data sent with the event is avatar:<Avatar>.

Parameters:

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

- (Object) equip(category, asset, colours = null)

Equip an asset to a category. Notifies observers to the "equip" event. Data sent with the event is avatar:<Avatar>, category:<String>.

Parameters:

  • category (String) A valid category
  • asset (Object) A valid asset
  • colours (Object) Optional: a pair of colours (in hex format) to set on the asset, in form colour1:<String>, colour2:<String>

Returns:

  • (Object) — The asset equipped to the given category

- (Object) equipped(category)

Get the asset equipped to the given category.

Parameters:

  • category (String) The category from which to get the equipped asset

Returns:

  • (Object) — The asset equipped to the given category

- (Object) ensemble()

Get the complete ensemble equipped to the avatar.

Returns:

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

- (void) colour1(colour)
- (void) colour1(colour, category)

Get and set colour1 globally or by category.

Parameters:

  • colour (String) A colour in hex format
  • category (String) The category on which to set the colour.

Overloads:

- (void) colour1(colour)

Set colour1 globally on the avatar. Notifies observers of the "colour1" event. Data sent with the event is avatar:<Avatar>.

- (void) colour1(colour, category)

Set colour1 on the given category. Notifies observers of the "colour1" event. Data sent with the event is avatar:<Avatar>, category:<String>.

- (void) colour2(colour)
- (void) colour2(colour, category)

Get and set colour2 globally or by category.

Parameters:

  • colour (String) A colour in hex format
  • category (String) The category on which to set the colour.

Overloads:

- (void) colour2(colour)

Set colour2 globally on the avatar. Notifies observers of the "colour2" event. Data sent with the event is avatar:<Avatar>.

- (void) colour2(colour, category)

Set colour2 on the given category. Notifies observers of the "colour2" event. Data sent with the event is avatar:<Avatar>, category:<String>.

- (void) colourEnsemble(palette)

Set colours on the given categories. Notifies observers of the "colourEnsemble" event. Data sent with the event is avatar:<Avatar>.

Parameters:

  • palette (Object) A palette in form <category>: colour1:<String>, colour2<String>.

- (String) imageUrl(options = {})

Get the url for a rendered image of the avatar.

Parameters:

  • representation (String) The representation to render
  • options (Object) Options to apply to the returned url

Options Hash: (option):

  • download (Boolean) Return a url which will force download of the image
  • representation (String) Get the image url for a specific representation

Throws:

  • (Error) — If a representation is not given
  • (Error) — If the avatar has no Id attribute (i.e. has not been saved)

Returns:

  • (String) — The url of the rendered image

- (Object) save()

Save the avatar to remote storage.

Returns:

  • (Object) — A promise, resolving when the action is complete

- (Object) delete()

Delete the avatar from remote storage.

Throws:

  • (Error) — If the avatar has no Id attribute (i.e. has not been saved)

Returns:

  • (Object) — A promise, resolving when the action is complete

- (Array<Object>) assetList()

Get a list of assets equipped to the avatar.

Returns:

  • (Array<Object>) — A list of assets, each in the form AssetId:, Colour1:, Colour2:

- (Object) metadata()
- (Object) metadata(key)
- (Object) metadata(metadata)
- (Object) metadata(key, value)

Get and set metadata on the avatar.

Overloads:

- (Object) metadata()

Get the avatar's metadata as a JavaScript object.

Returns:

  • (Object) — The avatar's metadata

- (Object) metadata(key)

Get the value for a key in the avatar's metadata.

Parameters:

  • key (String) The key for the value you want to get

Returns:

  • (Object) — The value of the given key

- (Object) metadata(metadata)

Set the complete metadata for the avatar.

Parameters:

  • metadata (Object) The metadata value to set

Returns:

  • (Object) — The avatar's metadata

- (Object) metadata(key, value)

Set the value for a key in the avatar's metadata.

Parameters:

  • key (String) The key for which to set the value
  • value (Object) The value to set

Returns:

  • (Object) — The avatar's metadata