Class: Doll

Doll()

Encapsulates one paperdoll that might be drawn or animated to a canvas in the Game. A Doll has a width and height and either an image or background color. It also has a number of DollSlot subrectangles, on which other images or solid colors may be drawn. DollSlots can be animated if they responds to update events, can collide if respond to collision events, or can be clicked on if they respond to click events. A Doll can be navigable if it has a player dollslot and scrollable if it is vaigable and its dimension are large than its viewable area.

Constructor

new Doll()

Source:

Members

has_click_listeners :boolean

Whether the current Doll or any of its DollSlot objects respond to click events
Type:
  • boolean
Source:

has_collision_listeners :boolean

Whether the current Doll or any of its DollSlot objects respond to collision between DollSlot events
Type:
  • boolean
Source:

has_update_listeners :boolean

Whether the current Doll or any of its DollSlot objects have an update listener specified to be called according to the update time function
Type:
  • boolean
Source:

num_loading :int

Number of images in DollSlot object on this Doll that have yet to load
Type:
  • int
Source:

player_index :int|boolean

If the Doll is navigable, then this holds the index of the PlayerSlot in the array this.slots.items of DollSlot objects
Type:
  • int | boolean
Source:

render_requests :Array.<Canvas>

An array of canvas objects on which this Doll has been requested to render, but can't yet (say because relies on images which are still loading)
Type:
  • Array.<Canvas>
Source:

rendering :boolean

Is true if the Doll is currently being drawn in some other thread
Type:
  • boolean
Source:

Methods

checkCollisions(dollhouse)

Checks for any collisions between DollSlot objects on the current Doll that have collision listeners specified. If there are then the listeners are called with an event containing info about the two DollSlots involved and the Dollhouse on which the Doll will be rendered.
Parameters:
Name Type Description
dollhouse Dollhouse on which the current Doll is to be rendered
Source:

getPlayerSlot(dollhousenullable) → {DollSlot}

Returns the DollSlot used to manage the player's coordinates and icon image within the current Doll (provided the Doll is navigable). If the player DollSlot doesn't exist an attempt is made to create it. If a Dollhouse is provided this is used in the attempt to create the player slot.
Parameters:
Name Type Attributes Default Description
dollhouse DollHouse <nullable>
null that may be used to help create the player DollSlot
Source:
Returns:
the player DollSlot
Type
DollSlot

init()

Used to set up the Doll. This involves loading all images related to doll, and initializing the has_click_listeners, has_collision_listeners, has_update_listeners booleant
Source:

loadImage(URL) → {HTMLImageElement}

Initiates loading of the image at URL into an Image object and returns this object. Adds one to num_loading property of this Doll, so know Doll is tracking one more image to be loaded. Sets up a callback such that if all the images that have been requested for this Doll have loaded, and there have been requests to render this doll, then the Doll is rendered to each canvas requested.
Parameters:
Name Type Description
URL string of image to load
Source:
Returns:
image to be loaded
Type
HTMLImageElement

push(slot) → {boolean}

If the passed slot is a DollSlot adds it to slots and returns true; otherwise, does nothing and returns false
Parameters:
Name Type Description
slot DollSlot to insert
Source:
Returns:
whether the item was added or not
Type
boolean

render(canvas)

Draws the current Doll to the provided canvas view. Note given the Doll's coordinate system only some portion of the Doll may be visible. If not all of the images for this Doll have been downloaded a render request is made instead.
Parameters:
Name Type Description
canvas HTMLCanvasElement to draw Doll onto
Source:

setPlayerSlot(player_slot)

Sets the DollSlot object that corresponds to the person playing the game to player_slot. This object holds player info when a Doll is navigable
Parameters:
Name Type Description
player_slot DollSlot a doll slot with player's rectangle info on the doll, and icon or color to draw for player
Source: