Class: Piece

Piece(structureopt, configopt)

A jigsaw piece

Constructor

new Piece(structureopt, configopt)

Parameters:
Name Type Attributes Description
structure Structure <optional>
config PieceConfig <optional>
Source:

Members

_size :Size

Type:
Source:

centralAnchor :Anchor

Type:
Source:

connections :Array.<Piece>

Type:
Source:

connectListeners :Array.<ConnectionListener>

Type:
Source:

diameter :Vector

The double of the radius
Type:
Source:

disconnectListeners :Array.<ConnectionListener>

Type:
Source:

downAnchor :Anchor

Type:
Source:

horizontalConnector

Source:

id :string

This piece id. It is extracted from metadata
Type:
  • string
Source:

inserts :Array.<Insert>

Type:
Source:

leftAnchor :Anchor

Type:
Source:

leftConnection :Piece

Type:
Source:

metadata :any

Type:
  • any
Source:

presentConnections :Array.<Piece>

Type:
Source:

proximity :number

Type:
  • number
Source:

radius :Vector

Type:
Source:

rightAnchor :Anchor

Type:
Source:

translateListeners :Array.<TranslationListener>

Type:
Source:

upAnchor :Anchor

Type:
Source:

upConnection :Piece

Type:
Source:

verticalConnector

Source:

Methods

(static) import(dump) → {Piece}

Converts this piece back from a dump. Connections are not restored. Puzzle#autoconnect method should be used after importing all them
Parameters:
Name Type Description
dump PieceDump
Source:
Returns:
Type
Piece

annotate(metadata)

Adds unestructured user-defined metadata on this piece.
Parameters:
Name Type Description
metadata object
Source:

attractHorizontally(other)

Parameters:
Name Type Description
other Piece
Source:

attractVertically(other)

Parameters:
Name Type Description
other Piece
Source:

belongTo(puzzle)

Parameters:
Name Type Description
puzzle
Source:

canConnectHorizontallyWith(other) → {boolean}

Parameters:
Name Type Description
other Piece
Source:
Returns:
Type
boolean

canConnectVerticallyWith(other) → {boolean}

Parameters:
Name Type Description
other Piece
Source:
Returns:
Type
boolean

centerAround(anchor)

Sets the centralAnchor for this piece.
Parameters:
Name Type Description
anchor Anchor
Source:

configure(config)

Runs positining, sizing and metadata configurations in a single step
Parameters:
Name Type Description
config PieceConfig
Source:

connectHorizontallyWith(other, backopt)

Parameters:
Name Type Attributes Default Description
other Piece
back boolean <optional>
false
Source:

connectVerticallyWith(other, backopt)

Parameters:
Name Type Attributes Default Description
other Piece
back boolean <optional>
false
Source:

drag(dx, dy)

Parameters:
Name Type Description
dx number
dy number
Source:

dragShouldDisconnect(dx, dy)

Whether this piece should get disconnected while dragging on the given direction, according to its puzzle's drag mode.
Parameters:
Name Type Description
dx number
dy number
Source:
See:

export(options) → {PieceDump}

Converts this piece into a plain, stringify-ready object. Connections should have ids
Parameters:
Name Type Description
options object
Properties
Name Type Attributes Description
compact boolean <optional>
Source:
Returns:
Type
PieceDump

fireConnect(other)

Parameters:
Name Type Description
other Piece
Source:

fireDisconnect(others)

Parameters:
Name Type Description
others Array.<Piece>
Source:

fireTranslate(dx, dy)

Parameters:
Name Type Description
dx number
dy number
Source:

getConnector(kind) → {Connector}

Retrieves the requested connector, initializing it if necessary.
Parameters:
Name Type Description
kind "vertical" | "horizontal"
Source:
Returns:
Type
Connector

horizontallyCloseTo(other) → {boolean}

Parameters:
Name Type Description
other Piece
Source:
Returns:
Type
boolean

horizontallyMatch(other) → {boolean}

Parameters:
Name Type Description
other Piece
Source:
Returns:
Type
boolean

isAt(x, y) → {boolean}

Tells whether this piece central anchor is at given point
Parameters:
Name Type Description
x number
y number
Source:
Returns:
Type
boolean

locateAt(x, y)

Sets the initial position of this piece. This method is similar to Piece#centerAround, but takes a pair instead of an anchor.
Parameters:
Name Type Description
x number
y number
Source:

onConnect(f)

Parameters:
Name Type Description
f ConnectionListener the callback
Source:

onDisconnect(f)

Parameters:
Name Type Description
f ConnectionListener the callback
Source:

onTranslate(f)

Parameters:
Name Type Description
f TranslationListener the callback
Source:

push(dx, dy, quietopt, pushedPiecesopt)

Parameters:
Name Type Attributes Default Description
dx number
dy number
quiet boolean <optional>
false
pushedPieces Array.<Piece> <optional>
Source:

reannotate(metadata)

Sets unestructured user-defined metadata on this piece. This object has no strong requirement, but it is recommended to have an id property.
Parameters:
Name Type Description
metadata object
Source:

recenterAround(anchor, quietopt)

Moves this piece to the given position, firing translation events. Piece must be already centered.
Parameters:
Name Type Attributes Default Description
anchor Anchor the new central anchor
quiet boolean <optional>
false indicates whether events should be suppressed
Source:

relocateTo(x, y, quietopt)

Moves this piece to the given position, firing translation events. Piece must be already centered. This method is similar to Piece#recenterAround, but takes a pair instead of an anchor.
Parameters:
Name Type Attributes Default Description
x number the final x position
y number the final y position
quiet boolean <optional>
false indicates whether events should be suppressed
Source:

resize(size)

Defines this piece's own dimension, overriding puzzle's default dimension
Parameters:
Name Type Description
size Size
Source:

translate(dx, dy, quietopt)

Move this piece a given distance, firing translation events
Parameters:
Name Type Attributes Default Description
dx number the x distance
dy number the y distance
quiet boolean <optional>
false indicates whether events should be suppressed
Source:

tryConnectHorizontallyWith(other, backopt)

Parameters:
Name Type Attributes Default Description
other Piece
back boolean <optional>
false
Source:

tryConnectVerticallyWith(other, backopt)

Parameters:
Name Type Attributes Default Description
other Piece
back boolean <optional>
false
Source:

tryConnectWith(other, backopt)

Parameters:
Name Type Attributes Default Description
other Piece
back boolean <optional>
false
Source:

verticallyCloseTo(other) → {boolean}

Parameters:
Name Type Description
other Piece
Source:
Returns:
Type
boolean

verticallyMatch(other) → {boolean}

Parameters:
Name Type Description
other Piece
Source:
Returns:
Type
boolean