Class: Grid
Grid class Represents a grid has many helper functions to manipulate the grid
Constructors
constructor
• new Grid(rows
, cols
, id?
)
Grid constructor
Parameters
Name | Type | Description |
---|---|---|
rows | number | Number of rows |
cols | number | Number of columns |
id? | string | id of the grid |
Defined in
Properties
cells
• cells: Cell
[][]
Cells of the grid
Defined in
cols
• cols: number
number of columns within the grid
Defined in
comment
• comment: string
Comment of the grid
Defined in
created
• created: number
Date of creation(db)
Defined in
id
• id: string
Id of the grid(db)
Defined in
optionsId
• optionsId: string
Id of the options(db)
See
GridOptions Might be removed soon with books
Defined in
rows
• rows: number
nuber of rows within the grid
Defined in
title
• title: string
Title of the grid
Defined in
Methods
decrement
▸ decrement(v
, direction
): Cell
Decrement a position by a direction, and return the cell at the new position
Parameters
Name | Type | Description |
---|---|---|
v | Vec | starting position |
direction | Direction | direction to decrement |
Returns
the cell at the new position, or nullCell if the new position is out of bounds
Defined in
getBounds
▸ getBounds(coordinates
, direction
): Bounds
Given a cell and a direction, returns the bounds of the word
Parameters
Name | Type | Description |
---|---|---|
coordinates | Vec | coordinates of the cell |
direction | Direction | The direction of the word |
Returns
All the cells of the word, and the start and end positions
Defined in
getCell
▸ getCell(coordinates
): Cell
Get the cell at the given coordinates
Parameters
Name | Type | Description |
---|---|---|
coordinates | Vec | coordinates of the cell |
Returns
the cell at the given coordinates
Defined in
highlight
▸ highlight(cells
): void
Highlight the given cells (unhighlight all other cells)
Parameters
Name | Type | Description |
---|---|---|
cells | Cell [] | cells to highlight |
Returns
void
Defined in
increment
▸ increment(v
, direction
): Cell
Increment a position by a direction, and return the cell at the new position
Parameters
Name | Type | Description |
---|---|---|
v | Vec | starting position |
direction | Direction | direction to increment |
Returns
the cell at the new position, or nullCell if the new position is out of bounds
Defined in
isDefinition
▸ isDefinition(point
): boolean
Checks if the cell at the given coordinates is a definition cell
Parameters
Name | Type | Description |
---|---|---|
point | Vec | coordinates |
Returns
boolean
true if the cell is a definition cell
Defined in
isValid
▸ isValid(point
): boolean
Checks wether coordinates are within the bounds of the grid
Parameters
Name | Type | Description |
---|---|---|
point | Vec | coordinates |
Returns
boolean
false if x or y is out of bounds
Defined in
resize
▸ resize(rows
, cols
): void
Resizes the grid to the given dimensions
Parameters
Name | Type | Description |
---|---|---|
rows | number | height of the grid |
cols | number | width of the grid |
Returns
void
Defined in
serialize
▸ serialize(): string
Converts the grid to a sreialized string
Returns
string
GridState JSON string
Defined in
setArrow
▸ setArrow(v
, index
, direction
): void
Set the arrow of a definition cell
See
Grid.setArrow
Parameters
Name | Type | Description |
---|---|---|
v | Vec | - |
index | number | The index of the arrow to set |
direction | ArrowDir | arrow direction |
Returns
void
Defined in
setDefinition
▸ setDefinition(coordinates
, value
): void
Set the cell at the given coordinates as a definition cell (or not)
Parameters
Name | Type | Description |
---|---|---|
coordinates | Vec | |
value | boolean | true to make it a definition cell, false to make it a normal cell |
Returns
void
Defined in
setSpaceH
▸ setSpaceH(coordinates
, value
): void
Set horizontal space of a cell
Parameters
Name | Type | Description |
---|---|---|
coordinates | Vec | coordinates of the cell |
value | boolean | true to set the space, false to remove it |
Returns
void
Defined in
setSpaceV
▸ setSpaceV(coordinates
, value
): void
Set vertical space of a cell
Parameters
Name | Type | Description |
---|---|---|
coordinates | Vec | coordinates of the cell |
value | boolean | true to set the space, false to remove it |
Returns
void
Defined in
setText
▸ setText(coordinates
, value
): void
Set the text to the cell at the given coordinates
Parameters
Name | Type | Description |
---|---|---|
coordinates | Vec | |
value | string | text to set |
Returns
void
Defined in
setWord
▸ setWord(word
, point
, direction
): void
Write a word within the grid, one letter per cell
Parameters
Name | Type | Description |
---|---|---|
word | string | word to write |
point | Vec | start coordinates of the word |
direction | Direction | writing direction |
Returns
void
Defined in
suggest
▸ suggest(words
, start
, directions
): void
Set the suggestion of the given cells
Parameters
Name | Type | Description |
---|---|---|
words | string [] | Words to suggest |
start | Vec [] | start position of each word |
directions | Direction [] | direction of each word |
Returns
void
Defined in
equal
▸ Static
equal(a
, b
): boolean
Checks if two cells have the same coordinates
Parameters
Name | Type | Description |
---|---|---|
a | Vec | First cell |
b | Vec | Second cell |
Returns
boolean
Weather the two cells have the same coordinates
Defined in
getDirVec
▸ Static
getDirVec(direction
): Vector
Converts a direction to a vector
Parameters
Name | Type | Description |
---|---|---|
direction | Direction | Direction to convert |
Returns
Vector
Vector corresponding to the direction
Defined in
newCell
▸ Static
newCell(x
, y
): Cell
Creates a new cell
Parameters
Name | Type | Description |
---|---|---|
x | number | x coordinate |
y | number | y coordinate |
Returns
new cell
Defined in
perpendicular
▸ Static
perpendicular(direction
): Direction
Converts a direction to its perpendicular vector
Parameters
Name | Type | Description |
---|---|---|
direction | Direction | Direction to convert |
Returns
Vector perpendicular to the direction
Defined in
setArrow
▸ Static
setArrow(cell
, index
, direction
): void
Set one of the arrows of a definition cell
Parameters
Name | Type | Description |
---|---|---|
cell | Cell | cell to set the arrow |
index | number | The index of the arrow to set |
direction | ArrowDir | arrow direction |
Returns
void
Defined in
unserialize
▸ Static
unserialize(s
): Grid
Creates a grid from a serialized string
Parameters
Name | Type | Description |
---|---|---|
s | string | GridState JSON string |
Returns
A new grid