Class: SvgBoard

SvgBoard

a whole board to play with

Constructor

new SvgBoard()

Author:
  • mark.veltzer@gmail.com (Mark Veltzer)
Source:

Members

(static) ObjRotateLeft

Which sides go to which when rotating left.
Author:
  • mark.veltzer@gmail.com (Mark Veltzer)
Source:

(static) ObjRotateRight

Which sides go to which when rotating right.
Author:
  • mark.veltzer@gmail.com (Mark Veltzer)
Source:

Methods

drawBoard()

Draw the board (white and black squares)
This:
Author:
  • mark.veltzer@gmail.com (Mark Veltzer)
Source:

drawBorder()

Draw the border
This:
Author:
  • mark.veltzer@gmail.com (Mark Veltzer)
Source:

eventGlobal(eventtype, x, y, type)

Events for position. Positions are logical and do not depend on the flipping of the board. Types of events: mouseover, mouseout, click and more.
This:
Parameters:
Name Type Description
eventtype string which event happened.
x int x position of event.
y int y position of event.
type string which event happened.
Author:
  • mark.veltzer@gmail.com (Mark Veltzer)
Source:

eventPiece(boardPiece, type)

Event handler for events happening on the pieces. Types of events: click, mouseover and more...
This:
Parameters:
Name Type Description
boardPiece BoardPiece instance the event happened on.
type string the type of event that happened.
Author:
  • mark.veltzer@gmail.com (Mark Veltzer)
Source:

eventPosition(piecePosition, rec, type)

Events for position. Positions are logical and do not depend on the flipping of the board. Types of events: mouseover, mouseout, click and more.
This:
Parameters:
Name Type Description
piecePosition PiecePosition the position of the event.
rec rect the Raphael.js rectangle where the event happened.
type string which is the name of the event that happened.
Author:
  • mark.veltzer@gmail.com (Mark Veltzer)
Source:

flip()

Flips the board (see it from the other side) If the board is 90 deg left it be will 90 deg right. Black view will turn to white and white to black.
This:
Author:
  • mark.veltzer@gmail.com (Mark Veltzer)
Source:

getBoard() → {Board}

get the logical board [Board] associated with this SvgBoard
This:
Author:
  • mark.veltzer@gmail.com (Mark Veltzer)
Source:
Returns:
the logical board associated with this SvgBoard.
Type
Board

getRec(piecePosition) → {rec}

Return the square at a position. This method must take into consideraton board rotation
This:
Parameters:
Name Type Description
piecePosition PiecePosition the logical position for which to return the square.
Author:
  • mark.veltzer@gmail.com (Mark Veltzer)
Source:
Returns:
the Raphael.js rec in question.
Type
rec

getValue(key) → {anything}

get the config value for a key
This:
Parameters:
Name Type Description
key string the key to get the config for.
Author:
  • mark.veltzer@gmail.com (Mark Veltzer)
Source:
Returns:
the value of the configuration option.
Type
anything

glow(boardPiece, glow)

Make a piece glow
This:
Parameters:
Name Type Description
boardPiece BoardPiece the piece to make glow.
glow object properties to pass to the glow function as per Raphael.js.
Author:
  • mark.veltzer@gmail.com (Mark Veltzer)
Source:

hidePiece(boardPiece)

Quick method to hide a piece
This:
Parameters:
Name Type Description
boardPiece BoardPiece the piece to hide.
Author:
  • mark.veltzer@gmail.com (Mark Veltzer)
Source:

initialize(board, dict) → {SvgBoard}

creates a new instance
This:
Parameters:
Name Type Description
board Board instance to use as the abstract board.
dict object overridables to the configuration for this object.
Author:
  • mark.veltzer@gmail.com (Mark Veltzer)
Source:
Returns:
the new instance.
Type
SvgBoard

newPosition()

Internal method. This method is called whenever the cursor changes position over the board and ONLY when it changes position. No parameters are passed because This method uses: this.selectedPiece, this.selectedRec, this.lastPos, this.currentPos to do it's work.
This:
Author:
  • mark.veltzer@gmail.com (Mark Veltzer)
Source:

overlay()

Create an overlay rectange for the entire board
This:
Author:
  • mark.veltzer@gmail.com (Mark Veltzer)
Source:

pixelsToPos(svgPixelPosition) → {PiecePosition}

Translates pixel position (x,y) to board position (0..7,0..7) This method must take board rotation into consideration
This:
Parameters:
Name Type Description
svgPixelPosition SvgPixelPosition object to translate.
Author:
  • mark.veltzer@gmail.com (Mark Veltzer)
Source:
Returns:
logical position.
Type
PiecePosition

pixelsToPosForgiving(svgPixelPosition) → {PiecePosition}

Forgiving version of the previous function.
This:
Parameters:
Name Type Description
svgPixelPosition SvgPixelPosition object to translate.
Author:
  • mark.veltzer@gmail.com (Mark Veltzer)
Source:
Returns:
logical position.
Type
PiecePosition

postAddPiece(boardPiece, piecePosition)

Callback method that is called after the logical board adds a piece. This is where we add the SVG representation of the piece in real graphics.
This:
Parameters:
Name Type Description
boardPiece BoardPiece the piece that was added.
piecePosition PiecePosition the position where the piece was added.
Author:
  • mark.veltzer@gmail.com (Mark Veltzer)
Source:

postGraphics()

Callback method that is called whenever a piece is added to the board This method is to be used to do something after a piece is added, removed etc.
This:
Author:
  • mark.veltzer@gmail.com (Mark Veltzer)
Source:

postMovePiece(boardPiece, fromPiecePosition, toPiecePosition)

Callback called when the logical board moves a piece
This:
Parameters:
Name Type Description
boardPiece BoardPiece the piece to move.
fromPiecePosition PiecePosition position from which to move.
toPiecePosition PiecePosition position to which to move.
Author:
  • mark.veltzer@gmail.com (Mark Veltzer)
Source:

posToPixels(piecePosition) → {SvgPixelPosition}

Translates position (0..7,0..7) to pixels This method must take board rotation into consideration
This:
Parameters:
Name Type Description
piecePosition PiecePosition logical (0..7,0..7) to translate.
Author:
  • mark.veltzer@gmail.com (Mark Veltzer)
Source:
Returns:
position in pixels.
Type
SvgPixelPosition

postRemovePiece(boardPiece, piecePosition)

Callback method that is called after the logical board removes a piece.
Parameters:
Name Type Description
boardPiece BoardPiece the piece to add.
piecePosition PiecePosition the position where the piece was removed.
Author:
  • mark.veltzer@gmail.com (Mark Veltzer)
Source:

raphaelPrep()

Prepare the raphael paper so we could do graphics
This:
Author:
  • mark.veltzer@gmail.com (Mark Veltzer)
Source:

rectFill(rec, anim)

Fill a rectangle using the default color This method must take board rotation into consideration It currently doesn't because the board looks the same in terms of white/black square when you totally flip it. If we ever support 90% flips then this method must be modified.
This:
Parameters:
Name Type Description
rec rect Raphael.js rectangle object to fill.
anim boolean do you want animation (slow transition).
Author:
  • mark.veltzer@gmail.com (Mark Veltzer)
Source:

redraw(oldview)

Redraw the entire board
This:
Parameters:
Name Type Description
oldview viewType the old view of the board.
Author:
  • mark.veltzer@gmail.com (Mark Veltzer)
Source:

resize(set)

Resize the board
This:
Parameters:
Name Type Description
set set Raphael set to resize.
Author:
  • mark.veltzer@gmail.com (Mark Veltzer)
Source:

rotateleft()

Rotate the board to the left 90 degrees
This:
Author:
  • mark.veltzer@gmail.com (Mark Veltzer)
Source:

rotateright()

Rotate the board to the right 90 degrees
This:
Author:
  • mark.veltzer@gmail.com (Mark Veltzer)
Source:

showHidePiece(boardPiece, hide)

Shows or hides a given piece according to parameter
This:
Parameters:
Name Type Description
boardPiece BoardPiece piece to show or hide.
hide boolean show or hide the piece.
Author:
  • mark.veltzer@gmail.com (Mark Veltzer)
Source:

showPiece(boardPiece)

Quick method to show a piece
This:
Parameters:
Name Type Description
boardPiece BoardPiece the piece to show.
Author:
  • mark.veltzer@gmail.com (Mark Veltzer)
Source:

timeMovePiece(boardPiece, fromPiecePosition, toPiecePosition)

Move a piece on the board (including animation if so configured)
This:
Parameters:
Name Type Description
boardPiece BoardPiece the piece to move.
fromPiecePosition PiecePosition position from which to move.
toPiecePosition PiecePosition position to which to move.
Author:
  • mark.veltzer@gmail.com (Mark Veltzer)
Source:

toString() → {string}

toString function This method is not yet implemented and will throw an exception.
This:
Author:
  • mark.veltzer@gmail.com (Mark Veltzer)
Source:
Returns:
a string representation of this object.
Type
string

translatePos(pos) → {PiecePosition}

Translate a position from a rectangle position to a logical position according to board rotation.
This:
Parameters:
Name Type Description
pos PiecePosition the position to translate.
Author:
  • mark.veltzer@gmail.com (Mark Veltzer)
Source:
Returns:
the logical position.
Type
PiecePosition