Skip to content

LocalAttributes.js

kyleady edited this page Jan 24, 2018 · 1 revision

Purpose

Effectively stores attributes' current values as a JSON string in a token's gm notes, allowing tokens that represent the same character to have different attributes.

Usage

new LocalAttributes(graphic)

Parses the JSON within the graphic's gmnotes into this.Attributes.

If there is no JSON, this.Attributes will be set to an empty object.

this.gmnotes will store the graphic's gmnotes.

LocalAttributes.prototype.get(attribute)

Returns the parsed value of the named local attribute.

LocalAttributes.prototype.set(attribute, value)

Sets the named local attribute to the given value, and saves the change.

LocalAttributes.prototype.remove(attribute)

Deletes the named local attribute from the local attributes and saves the change.

LocalAttributes.prototype.save()

Converts this.Attributes to a JSON string and replaces the old JSON string in the graphic's gmnotes. If there is no JSON string to replace, it will attend the JSON string on a new line in the gmnotes.

Note that when parsing and saving the gmnotes it will use decodeURIcomponent() and encodeURIcomponent() respectively.

Requirements

Clone this wiki locally