mumuki-puzzle-runner
bundle install
RACK_ENV=development rackup -p 4567
You will need instaling jsdoc-to-markdown first
npm install --global jsdoc-to-markdown
jsdoc2md lib/public/js/muzzle.js 2>&1
Muzzle.basic(3, 2, 'https://flbulgarelli.github.io/headbreaker/static/berni.jpg');
const baseUrl = 'https://raw.githubusercontent.com/MumukiProject/mumuki-guia-gobstones-alternativa-kids/master/assets/attires/';
// with left and right pieces
Muzzle.match([
`${baseUrl}/va_vacio.png`,
`${baseUrl}/cu_vacio.png`,
`${baseUrl}/chips_poco.png`
], [
`${baseUrl}/va_fru.png`,
`${baseUrl}/cu_vai.png`,
`${baseUrl}/chips_mucho.png`,
]);
// with left and right pieces, and left odd pieces
Muzzle.match([
`${baseUrl}/va_vacio.png`,
`${baseUrl}/cu_vacio.png`,
`${baseUrl}/chips_poco.png`
], [
`${baseUrl}/va_fru.png`,
`${baseUrl}/cu_vai.png`,
`${baseUrl}/chips_mucho.png`,
], [
`${baseUrl}/choc_mitad_vacio2.png`
]);
// with left and right pieces, and right odd pieces
Muzzle.match([
`${baseUrl}/va_vacio.png`,
`${baseUrl}/cu_vacio.png`,
`${baseUrl}/chips_poco.png`
], [
`${baseUrl}/va_fru.png`,
`${baseUrl}/cu_vai.png`,
`${baseUrl}/chips_mucho.png`,
],
[], [
`${baseUrl}/choc_mitad_vacio2.png`
]);
The solution accepted by this runner is a JSON string with the following format:
{
"positions": [
[10, 20],
[15, 20],
[20, 20],
[10, 25],
[15, 25],
[20, 25]
]
}:
- MuzzleCanvas
Facade for referencing and creating a global puzzle canvas, handling solutions persistence and submitting them
- another(id) ⇒
MuzzleCanvas
Creates a suplementary canvas at the element of the given id
- PieceConfig :
object
- Point :
Array.<number>
- Solution :
object
Facade for referencing and creating a global puzzle canvas, handling solutions persistence and submitting them
Kind: global class
- MuzzleCanvas
- .canvasId :
string
- .expectedRefsAreOnlyDescriptive :
boolean
- .canvasWidth :
number
- .canvasHeight :
number
- .borderFill :
number
- .strokeWidth :
number
- .pieceSize :
number
- .scaleImageWidthToFit :
boolean
- .previousSolutionContent :
string
- .baseConfig
- .canvas ⇒
Canvas
- .solution ⇒
Solution
- .solutionContent
- .clientResultStatus ⇒
"passed"
|"failed"
- .onReady()
- .onSubmit(submission)
- .onValid()
- .draw()
- .expect(refs)
- .basic(x, y, imagePath) ⇒
Promise.<Canvas>
- .multi(x, y, [imagePaths]) ⇒
Promise.<Canvas>
- .match(leftUrls, rightUrls, leftOddUrls, rightOddUrls) ⇒
Promise.<Canvas>
- .custom(canvas) ⇒
Promise.<Canvas>
- .ready()
- .loadSolution(solution)
- .loadPreviousSolution()
- .submit()
- .canvasId :
The id of the HTML element that will contain the canvas Override it you are going to place in a non-standard way
Kind: instance property of MuzzleCanvas
Wether expected refs shall be ignored by Muzzle.
They will still be evaluated server-side.
Kind: instance property of MuzzleCanvas
Width of canvas
Kind: instance property of MuzzleCanvas
Height of canvas
Kind: instance property of MuzzleCanvas
Size of fill. Set null for perfect-match
Kind: instance property of MuzzleCanvas
Canvas line width
Kind: instance property of MuzzleCanvas
Piece size
Kind: instance property of MuzzleCanvas
- Whether image's width should be scaled to piece
Kind: instance property of MuzzleCanvas
The previous solution to the current puzzle in a past session, if any
Kind: instance property of MuzzleCanvas
Kind: instance property of MuzzleCanvas
The currently active canvas, or null if it has not yet initialized
Kind: instance property of MuzzleCanvas
muzzleCanvas.solution ⇒ Solution
The state of the current puzzle expressed as a Solution object
Kind: instance property of MuzzleCanvas
The current solution, expressed as a JSON string
Kind: instance property of MuzzleCanvas
The solution validation status
Kind: instance property of MuzzleCanvas
Callback that will be executed when muzzle has fully loaded and rendered its first canvas.
It does nothing by default but you can override this property with any code you need the be called here
Kind: instance method of MuzzleCanvas
Callback to be executed when submitting puzzle.
Does nothing by default but you can override it to perform additional actions
Kind: instance method of MuzzleCanvas
Param | Type |
---|---|
submission | Object |
Callback that will be executed when muzzle's puzzle becomes valid
It does nothing by default but you can override this property with any code you need the be called here
Kind: instance method of MuzzleCanvas
Draws the - previusly built - current canvas.
Prefer {@code this.currentCanvas.redraw()} when performing small updates to the pieces.
Kind: instance method of MuzzleCanvas
Kind: instance method of MuzzleCanvas
Param | Type |
---|---|
refs | Array.<Point> |
Creates a basic puzzle canvas with a rectangular shape and a background image, that is automatically submitted when solved
Kind: instance method of MuzzleCanvas
Returns: Promise.<Canvas>
- the promise of the built canvas
Param | Type | Description |
---|---|---|
x | number |
the number of horizontal pieces |
y | number |
the number of vertical pieces |
imagePath | string |
Kind: instance method of MuzzleCanvas
Returns: Promise.<Canvas>
- the promise of the built canvas
Param | Type |
---|---|
x | number |
y | number |
[imagePaths] | Array.<string> |
Craates a match puzzle, where left pieces are matched against right pieces, with optional odd left and right pieces that don't match
Kind: instance method of MuzzleCanvas
Returns: Promise.<Canvas>
- the promise of the built canvas
Param | Type | Description |
---|---|---|
leftUrls | Array.<string> |
|
rightUrls | Array.<string> |
must be of the same size of lefts |
leftOddUrls | Array.<string> |
|
rightOddUrls | Array.<string> |
Kind: instance method of MuzzleCanvas
Returns: Promise.<Canvas>
- the promise of the built canvas
Param | Type |
---|---|
canvas | Canvas |
Mark Muzzle as ready, loading previous solution and drawing the canvas
Kind: instance method of MuzzleCanvas
Loads - but does not draw - a solution into the canvas.
Kind: instance method of MuzzleCanvas
Param | Type |
---|---|
solution | Solution |
Loads - but does not draw - the current canvas with the previous solution, if available.
Kind: instance method of MuzzleCanvas
Submits the puzzle to the bridge, validating it if necessary
Kind: instance method of MuzzleCanvas
another(id) ⇒ MuzzleCanvas
Creates a suplementary canvas at the element of the given id
Kind: global function
Param | Type |
---|---|
id | string |
Kind: global typedef Properties
Name | Type |
---|---|
imagePath | string |
structure | string |
Kind: global typedef Properties
Name | Type | Description |
---|---|---|
positions | Array.<Point> |
list of points |