Skip to content

The Character class

Ondolin edited this page Mar 10, 2021 · 4 revisions

Each torchly character should be an instance of the Character class.

This ensures each character has all the necessary properties and functions a character should have.

In the following, all variables and functions will be explained.

Property name  type description
name string the in-game character name
token  string  URL of an image of the character meant to be displayed on the bord
pos  object contains the point, rot and size attribute
pos.point object contains the x nad y attribute
pos.point.x number  horizontal position of the token (top left corner in fields not pixel)
pos.point.y number vertical position of the token (top left corner in fields not pixel)
pos.rot number rotation where 0 means no rotation and 0.5 means 180° rotation
pos.size number size of the token (size = number of fields on the board occupied by the token)
players string[] an array of all player ids controlling this character
details  object contains the hp, ac and notes attribute
details.hp  number hitpoints of the token
details.ac number armour class of the token
details.notes string users can save notes to a character
_id  string unique identifier for the character (do not change the id unless you are sure what you do)
conditions string[] an array of the names of conditions (like blinded)

All of these attributes are necessary to create a character. Sometimes _id is not usefully defined (because ids are managed by the backend). In the current state of the project, it is still necessary to provide a value for _id. It will be ignored.

The Character class also provides some functions.

function name return value parameters  description
delete void - deletes the character and updates the backend
setAttrs this* rot: number, size: number set rotation and size of the token (see above what these values mean)
setPosition this* {x: number, y: number} set token position to given x and y values
moveRelative this* {x: number, y: number} move character relative to previous position
setPlayers** this*  string[] set controlling players to given array
setPlayers** this* Player[] unpacks the player ids and set them as controlling players
setDetails this* { hp: number, ac: number, notes: string } set these attributes
setConditions this* string[] set conditions
setName  this* string set name
setInitiative this* number add or edit initiative for this character
setRotation this* number sets rotation
setSize this* number sets size
setHP this* number sets hp value
setAC this* number sets ac value
setNotes this* string sets notes value

* this is the character on which you execute the function. IMPORTANT: the character will be returned before the changes take place!

** the called function depends on the parameters given

Super Class

The Character class derived from the Subscribable class. Therefore it shares all of those methods too.

Clone this wiki locally