Puzzle object is declared as class pzpr.Puzzle
.
You can generate it by new pzpr.Puzzle()
constructor.
pzpr.Puzzle([canvas][,option])
Create puzzle object.canvas:Node
The canvas of the puzzle.option:object
See below.option.type:string
Select puzzle object type.option.type==='editor'
Default value. The puzzle can be inputted question data and answer data.option.type==='player'
The puzzle can be only taken answer data.option.type==='viewer'
The puzzle can display the puzzle but reject any input.
option.config:object
Input initial config data as a object. See pzpr.Puzzle.Config section.option.mode
Select initial mode:editmode
orplaymode
. Value is the same aspuzzle.setMain()
.option.graphic:string
Specify graphic type. It can be'svg'
or'canvas'
.option.width:number
andoption.height:number
Specify the size of the canvas.option.cellsize:number
Specify the size of the canvas by the cellsize of the board.
If neither width, height nor cellsize is given, the size of given canvas element is used for the size of puzzle.
puzzle.open(data[, variety][, callback])
Open the specific URL/file data.- This API can be also used for opening new empty board as
'(pid)/cols/rows'
format, likepuzzle.open('nurikabe/5/5')
. - Return value:
puzzle object itself
data:string
Data to be opened.data:URLData or FileData
Data can be aURLData
orFileData
object generated bypzpr.parser
functions.pid:string
Predefined puzzle veriety name.callback:function
It will be called after opening operation finishs andready
event fired.
- This API can be also used for opening new empty board as
puzzle.getURL([urltype])
Return URL of the board.- Return value: Generated URL string.
urltype:URLType
Specify URL type.
puzzle.getFileData([filetype[, option]])
Return File Data of the board.- Return value: Generated File data.
filetype:FileType
Specify URL type. Default ispzpr.parser.FILE_PZPR
.option.history:boolean
If filetype is FILE_PZPR and it is true, operation history will be outputted.option.time:boolean
If filetype is FILE_PZPR, option.history and it is true, operation history and operation time (millisecond) will be outputted.option.trial:boolean
If filetype is FILE_PZPR, option.history is false and it is true in trial mode, trial mode data will be outputted.
puzzle.clone([option])
Return cloned puzzle object from the puzzle.- Return value: cloned puzzle object.
option.type:string
It means the same as option.type in constructor. If not specified, the type of the puzzle will be used.option.width:number
andoption.height:number
Set the size of the canvas of cloned puzzle object. If not specified, the size of current canvas will be used.
puzzle.on(eventtype, listener)
Register event listener to pzpr object.puzzle.once(eventtype, listener)
Register once event listener to pzpr object.eventtype:string
Event type. See event section below.listener:function
Function to be called.
puzzle.setMode(type)
It changes the puzzle into playmode or editmode when the puzzle type is 'editor'.type
Ifpuzzle.MODE_PLAYER
or'play'
, it will change the puzzle mode toplaymode
.
Ifpuzzle.MODE_EDITOR
or'edit'
, puzzle mode will change intoeditmode
.
puzzle.getConfig(configname)
Get the value of the config data. See below to get the list of the config.- Return value: the value of the specified config.
configname:string
the id name of the config. Seepzpr.Puzzle.Config class
secrion.
puzzle.setConfig(configname, value)
Set the config data to the given value.configname:string
the id name of the config. Seepzpr.Puzzle.Config class
secrion.value
value to be set. Type is eitherstring
,number
orboolean
.
puzzle.resetConfig(configname)
Reset the config data to the initial value. See below to get the list of the config.configname:string
the id name of the config. Seepzpr.Puzzle.Config class
secrion.
puzzle.getCurrentConfig()
Return the list of the config values for current puzzle variety.- Return value:
object
.
- Return value:
puzzle.saveConfig()
Return current changed config list from default value as object.- Return value:
object
.
- Return value:
puzzle.restoreConfig(object)
Set config list by given object.object:object
the list of the config to be restored. Usually this is the object whichpuzzle.saveConfig()
returned.
puzzle.setCanvas(canvas[, graphictype])
Set the canvas element after the puzzle object created.canvas:Node
The canvas of the puzzle.graphictype:string
Graphic type used for the canvas.'svg'
or'canvas'
.
puzzle.setCanvasSize(width, height)
Set the canvas of the canvas.puzzle.setCanvasSizeByCellSize(cellsize)
Set the canvas of the canvas by the cellsize of the board.puzzle.redraw([flush])
Redraw the whole canvas.flush:boolean
Iftrue
, it will destroy all cached data and redraw, otherwise cached data will be kept.
puzzle.irowake()
Regenerate the color of the line if config.irowake (set individual color to line) is set.
These methods have arguments below.
-
graphictype:string
supports'svg'
,'png'
,'jpeg'
,'gif'
and'webp'
if the environment supports. By default,'svg'
is used. -
quality:number
Compression quality forjpeg
orwebp
. -
option.cellsize:number
orcellsize:number
Identify output size by the size of cells. -
option.bgcolor:string
Specify background color. If this is empty, background will be transparent. -
puzzle.toDataURL([graphictype][, quality][, cellsize][, option])
Return the canvas graphic data as Data URL.- Return value: Generated Data URL.
-
puzzle.toBuffer([graphictype][, quality][, cellsize][, option])
Return raw image data of the canvas.- Return value: Generated data as string.
-
puzzle.toBlob(callback[, graphictype][, quality][, cellsize][, option])
Generate the canvas graphic data as Blob.- Return value: No return value. Please use
callback(blob)
.
- Return value: No return value. Please use
puzzle.check([activemode])
Check if the board is modified or not.- Return value:
CheckInfo
which contains if the check succeed or not and failure information.info.complete
true
if the answer is correct.info.text
contains error description unlessactivemode===false
.info.gettext(['en' or 'ja'])
method gets error description in English or Japanese.
activemode:boolean
- If
true
, checking answer routine will set error information and display what has error. - If
false
, it will only check errors, ignore'multierr'
config andinfo.text
remains empty. - Otherwise, it will only check errors but respect
'multierr'
config and setinfo.text
.
- If
- Return value:
puzzle.ansclear()
Clear answer data on the board but it preserves operation history data.puzzle.subclear()
Clear auxiliary marks on the board.puzzle.errclear()
Wipe out the error information given after check() is called.puzzle.clear()
For'editor'
type puzzle, clean all board data. As for'player'
type puzzle, it clears answer data. In addition, it clears operation history data for both'editor'
and'player'
.
puzzle.undo()
Undo an operation.- Return value:
true
if it is the first operation.
- Return value:
puzzle.redo()
Redo an operation.- Return value:
true
if it is the last operation.
- Return value:
puzzle.undoall()
Undo all recorded operations. No return value.puzzle.redoall()
Redo all recorded operations. No return value.puzzle.ismodified()
Check if the board is modified or not.- Return value:
true
when the puzzle is modified and the puzzle type is 'editor'.
- Return value:
puzzle.saved()
Letpuzzle.ismodified()
returnfalse
.
puzzle.enterTrial()
Enter trial mode.puzzle.acceptTrial()
Finalize all trial mode changes and exit trial mode.puzzle.rejectTrial()
Erase all trial mode changes and exit trial mode.puzzle.rejectCurrentTrial()
Erase current trial mode stage changes and back to previous trial stage.
puzzle.getTime()
Return consumed time from the puzzle data is created or URL/filedata is opened.- Return value: consumed time in millisecond scale.
'ready'
Emitted afterpuzzle.open
finished successfully.- Callback:
function(puzzle)
- Callback:
'fail-open'
Emitted ifpuzzle.open
failed.- Callback:
function(puzzle)
- Callback:
'canvasReady'
Emitted after both canvas is initialized and puzzle become ready. It is fired after'ready'
and'resize'
events finished.- Callback:
function(puzzle)
- Callback:
'resize'
Emitted if the size of the canvas is changed.- Callback:
function(puzzle)
- Callback:
'adjust'
Emitted after rows and cols on the board is expanded, reduced or the board is flipped or turned.- Callback:
function(puzzle)
- Callback:
'config'
Emitted after a config has changed.- Callback:
function(puzzle, configname, value)
- Callback:
'key'
Emitted when keyboard event is called, before common routine is called.- Callback:
function(puzzle, keycode)
- Callback:
'mouse'
Emitted when mouse/touch event is called, before common routine is called.- Callback:
function(puzzle)
- Callback:
'history'
Emitted after operation history is added or undo/redo is executed.- Callback:
function(puzzle)
- Callback:
'trial'
Emitted after trial mode stage is changed.- Callback:
function(puzzle, trialstage)
- Callback:
'mode'
Emitted afterready
and mode (playmode or editmode) is changed.- Callback:
function(puzzle)
- Callback:
puzzle.pzpr
Reference to pzpr object.puzzle.ready:boolean
true
after the URL/FileData is opened and board, painter and other related objects are set.puzzle.pid:string
specifies the variety/genre of the current puzzle.puzzle.info:object
Reference to VarietyInfo of the current puzzle.puzzle.canvas:Node
The node currently the puzzle has been using.puzzle.editmode:boolean
true
if the puzzle is inputting question data at the moment.puzzle.playmode:boolean
true
if the puzzle is inputting answer data at the moment.
For editmode
or playmode
property, one is true
and the other is false
.
Puzzle object has puzzle.board
, puzzle.metadata
, puzzle.moouse
, puzzle.key
and so on.
For detail, see sub-objects of puzzle object document
There are some puzzle configurations. For details, see list of puzzle config document.
Name | Type | Default value | Description |
---|---|---|---|
irowake |
boolean |
false |
Set individual color to lines |
autocmp |
boolean |
false |
Show complete numbers apart from incompleted one automatically. |
autocmp_area |
boolean |
false |
Paint background of completed blocks/areas automatically. |
autoerr |
boolean |
false |
Show incomplete/wrong numbers automatically. |
multierr |
boolean |
false |
Check prural errors in puzzle.check() API. |