mumuki-puzzle-runner 0.0.1 → 0.4.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/lib/metadata_hook.rb +4 -3
- data/lib/public/css/muzzle-editor.css +10 -1
- data/lib/public/js/muzzle-editor.js +36 -21
- data/lib/public/js/muzzle.js +323 -64
- data/lib/public/vendor/headbreaker.d.ts +313 -99
- data/lib/public/vendor/headbreaker.js +1 -1
- data/lib/public/vendor/headbreaker.js.map +1 -1
- data/lib/test_hook.rb +12 -6
- data/lib/version_hook.rb +1 -1
- metadata +3 -3
@@ -28,14 +28,14 @@ declare class Anchor {
|
|
28
28
|
/**
|
29
29
|
* Converts this anchor into a point
|
30
30
|
*/
|
31
|
-
|
31
|
+
asPair(): Pair;
|
32
32
|
/**
|
33
|
-
* Converts this anchor into a
|
33
|
+
* Converts this anchor into a vector
|
34
34
|
*/
|
35
|
-
|
36
|
-
export():
|
35
|
+
asVector(): Vector;
|
36
|
+
export(): Vector;
|
37
37
|
static atRandom(maxX: number, maxY: number): Anchor;
|
38
|
-
static import(
|
38
|
+
static import(vector: Vector): Anchor;
|
39
39
|
}
|
40
40
|
|
41
41
|
/**
|
@@ -43,6 +43,8 @@ declare class Anchor {
|
|
43
43
|
*/
|
44
44
|
declare function anchor(x: number, y: number): Anchor;
|
45
45
|
|
46
|
+
declare type Axis = Vertical | Horizontal;
|
47
|
+
|
46
48
|
declare type Label = any;
|
47
49
|
|
48
50
|
declare type Figure = {
|
@@ -76,9 +78,10 @@ declare type LabelMetadata = {
|
|
76
78
|
|
77
79
|
declare type CanvasMetadata = {
|
78
80
|
id?: string;
|
79
|
-
targetPosition?:
|
80
|
-
currentPosition?:
|
81
|
+
targetPosition?: Vector;
|
82
|
+
currentPosition?: Vector;
|
81
83
|
color?: string;
|
84
|
+
fixed?: boolean;
|
82
85
|
strokeColor?: string;
|
83
86
|
image?: ImageLike;
|
84
87
|
label?: LabelMetadata;
|
@@ -86,6 +89,7 @@ declare type CanvasMetadata = {
|
|
86
89
|
|
87
90
|
declare type Template = {
|
88
91
|
structure: StructureLike;
|
92
|
+
size?: Size;
|
89
93
|
metadata: CanvasMetadata;
|
90
94
|
};
|
91
95
|
|
@@ -93,25 +97,37 @@ declare type Template = {
|
|
93
97
|
* An HTML graphical area where puzzles and pieces can be rendered. No assumption of the rendering backend is done - it may be
|
94
98
|
* and be a plain HTML SVG or canvas element, or a higher-level library - and this task is fully delegated to {@link Painter}
|
95
99
|
* @param id - the html id of the element where to place the canvas
|
100
|
+
* @param [options.pieceSize] - the piece size expresed as it edge-to-edge diameter
|
96
101
|
* @param [options.borderFill] - the broder fill of the pieces, expresed in pixels. 0 means no border fill, 0.5 * pieceSize means full fill
|
97
102
|
* @param [options.lineSoftness] - how soft the line will be
|
98
103
|
* @param [options.image] - an optional background image for the puzzle that will be split across all pieces.
|
104
|
+
* @param [options.fixed] - whether the canvas can is fixed or can be dragged
|
99
105
|
* @param [options.painter] - the Painter object used to actually draw figures in canvas
|
106
|
+
* @param [options.puzzleDiameter] - the puzzle diameter used to calculate the maximal width and height
|
107
|
+
* You only need to specify this option when pieces are manually sketched and images must be adjusted
|
108
|
+
* @param [options.maxPiecesCount] - the maximal amount of pieces used to calculate the maximal width and height.
|
109
|
+
* You only need to specify this option when pieces are manually sketched and images must be adjusted
|
100
110
|
*/
|
101
111
|
declare class Canvas {
|
102
112
|
constructor(id: string, options: {
|
103
113
|
width: number;
|
104
114
|
height: number;
|
105
|
-
pieceSize?: number;
|
115
|
+
pieceSize?: Vector | number;
|
106
116
|
proximity?: number;
|
107
|
-
borderFill?: number;
|
117
|
+
borderFill?: Vector | number;
|
108
118
|
strokeWidth?: number;
|
109
119
|
strokeColor?: string;
|
110
120
|
lineSoftness?: number;
|
111
121
|
image?: ImageLike;
|
122
|
+
fixed?: boolean;
|
112
123
|
painter?: Painter;
|
124
|
+
puzzleDiameter?: Vector | number;
|
125
|
+
maxPiecesCount?: Vector | number;
|
113
126
|
});
|
114
127
|
_painter: Painter;
|
128
|
+
_maxPiecesCount: Vector;
|
129
|
+
_puzzleDiameter: Vector;
|
130
|
+
_imageAdjuster: any;
|
115
131
|
_puzzle: Puzzle;
|
116
132
|
figures: {
|
117
133
|
[key: string]: Figure;
|
@@ -133,7 +149,7 @@ declare class Canvas {
|
|
133
149
|
renderPieces(pieces: Piece[]): void;
|
134
150
|
/**
|
135
151
|
* Renders a previously created puzzle object. This method
|
136
|
-
* overrides this canvas' {@link Canvas#
|
152
|
+
* overrides this canvas' {@link Canvas#pieceDiameter} and {@link Canvas#proximity}
|
137
153
|
*/
|
138
154
|
renderPuzzle(puzzle: Puzzle): void;
|
139
155
|
/**
|
@@ -157,9 +173,17 @@ declare class Canvas {
|
|
157
173
|
*/
|
158
174
|
sketchPieceUsingTemplate(id: string, templateName: string): void;
|
159
175
|
/**
|
160
|
-
* @param farness - from 0 to 1, how far pieces will be placed from x =
|
176
|
+
* @param farness - from 0 to 1, how far pieces will be placed from x = pieceDiameter.x, y = pieceDiameter.y
|
161
177
|
*/
|
162
178
|
shuffle(farness?: number): void;
|
179
|
+
/**
|
180
|
+
* **Warning**: this method requires {@code maxPiecesCount} to be set.
|
181
|
+
*/
|
182
|
+
shuffleColumns(farness?: number): void;
|
183
|
+
/**
|
184
|
+
* **Warning**: this method requires {@code maxPiecesCount} to be set.
|
185
|
+
*/
|
186
|
+
shuffleGrid(farness?: number): void;
|
163
187
|
/**
|
164
188
|
* Draws this canvas for the first time
|
165
189
|
*/
|
@@ -189,6 +213,11 @@ declare class Canvas {
|
|
189
213
|
* positions, overriding any previously configured validator
|
190
214
|
*/
|
191
215
|
attachRelativePositionValidator(): void;
|
216
|
+
/**
|
217
|
+
* Sets a validator that will report when puzzle are at the expected given
|
218
|
+
* relative refs
|
219
|
+
*/
|
220
|
+
attachRelativeRefsValidator(expected: any): void;
|
192
221
|
/**
|
193
222
|
* Sets a validator that will report when puzzle pieces are in their expected absolute
|
194
223
|
* positions, overriding any previously configured validator
|
@@ -204,6 +233,10 @@ declare class Canvas {
|
|
204
233
|
onDisconnect(f: CanvasConnectionListener): void;
|
205
234
|
onTranslate(f: CanvasTranslationListener): void;
|
206
235
|
onValid(f: ValidationListener): void;
|
236
|
+
/**
|
237
|
+
* Returns the current validation status
|
238
|
+
*/
|
239
|
+
valid: boolean;
|
207
240
|
/**
|
208
241
|
* Answers the visual representation for the given piece.
|
209
242
|
* This method uses piece's id.
|
@@ -213,6 +246,14 @@ declare class Canvas {
|
|
213
246
|
* Answers the visual representation for the given piece id.
|
214
247
|
*/
|
215
248
|
getFigureById(id: string): Figure;
|
249
|
+
/**
|
250
|
+
* Sets the new width and height of the canvas
|
251
|
+
*/
|
252
|
+
resize(width: number, height: number): void;
|
253
|
+
/**
|
254
|
+
* Scales the canvas contents to the given factor
|
255
|
+
*/
|
256
|
+
scale(factor: Vector | number): void;
|
216
257
|
_annotatePiecePosition(piece: Piece): void;
|
217
258
|
/**
|
218
259
|
* Configures updates from piece into group
|
@@ -222,13 +263,64 @@ declare class Canvas {
|
|
222
263
|
* * Configures updates from group into piece
|
223
264
|
*/
|
224
265
|
_bindPieceToGroup(piece: Piece, group: Group): void;
|
225
|
-
|
226
|
-
|
266
|
+
_baseImageMetadataFor(piece: Piece): ImageMetadata;
|
267
|
+
imageMetadataFor(piece: Piece): ImageMetadata;
|
268
|
+
/**
|
269
|
+
* Configures canvas to adjust images axis to puzzle's axis.
|
270
|
+
*
|
271
|
+
* **Warning**: this method requires {@code maxPiecesCount} or {@code puzzleDiameter} to be set.
|
272
|
+
*/
|
273
|
+
adjustImagesToPuzzle(axis: Axis): void;
|
274
|
+
/**
|
275
|
+
* Configures canvas to adjust images width to puzzle's width
|
276
|
+
*
|
277
|
+
* **Warning**: this method requires {@code maxPiecesCount} or {@code puzzleDiameter} to be set.
|
278
|
+
*/
|
279
|
+
adjustImagesToPuzzleWidth(): void;
|
280
|
+
/**
|
281
|
+
* Configures canvas to adjust images height to puzzle's height
|
282
|
+
*
|
283
|
+
* **Warning**: this method requires {@code maxPiecesCount} or {@code puzzleDiameter} to be set.
|
284
|
+
*/
|
285
|
+
adjustImagesToPuzzleHeight(): void;
|
286
|
+
/**
|
287
|
+
* Configures canvas to adjust images axis to pieces's axis
|
288
|
+
*
|
289
|
+
* **Warning**: this method requires {@code maxPiecesCount} or {@code puzzleDiameter} to be set.
|
290
|
+
*/
|
291
|
+
adjustImagesToPiece(axis: Axis): void;
|
292
|
+
/**
|
293
|
+
* Configures canvas to adjust images width to pieces's width
|
294
|
+
*
|
295
|
+
* **Warning**: this method requires {@code maxPiecesCount} or {@code puzzleDiameter} to be set.
|
296
|
+
*/
|
297
|
+
adjustImagesToPieceWidth(): void;
|
298
|
+
/**
|
299
|
+
* Configures canvas to adjust images height to pieces's height
|
300
|
+
*
|
301
|
+
* **Warning**: this method requires {@code maxPiecesCount} or {@code puzzleDiameter} to be set.
|
302
|
+
*/
|
303
|
+
adjustImagesToPieceHeight(): void;
|
304
|
+
/**
|
305
|
+
* @param structureLike - the piece structure
|
306
|
+
*/
|
307
|
+
_newPiece(structureLike: StructureLike, size: Size, metadata: CanvasMetadata): void;
|
308
|
+
/**
|
309
|
+
* The puzzle diameter, using the
|
310
|
+
* configured puzzle diameter or the estimated one, if the first is not available.
|
311
|
+
*/
|
312
|
+
puzzleDiameter: Vector;
|
313
|
+
/**
|
314
|
+
* The estimated puzzle diameter calculated using the the max pieces count.
|
315
|
+
*/
|
316
|
+
estimatedPuzzleDiameter: Vector;
|
317
|
+
pieceRadio: Vector;
|
318
|
+
pieceDiameter: Vector;
|
227
319
|
/**
|
228
320
|
* The puzzle rendered by this canvas
|
229
321
|
*/
|
230
|
-
puzzle:
|
231
|
-
settings:
|
322
|
+
puzzle: Puzzle;
|
323
|
+
settings: Settings;
|
232
324
|
}
|
233
325
|
|
234
326
|
declare interface DummyPainter extends Painter {
|
@@ -245,7 +337,7 @@ declare class DummyPainter implements Painter {
|
|
245
337
|
|
246
338
|
declare type ImageMetadata = {
|
247
339
|
content: HTMLImageElement;
|
248
|
-
offset?:
|
340
|
+
offset?: Vector;
|
249
341
|
scale?: number;
|
250
342
|
};
|
251
343
|
|
@@ -258,30 +350,7 @@ declare module "ImageMetadata" {
|
|
258
350
|
function asImageMetadata(imageLike: ImageLike): ImageMetadata;
|
259
351
|
}
|
260
352
|
|
261
|
-
declare module "headbreaker" {
|
262
|
-
var anchor: any;
|
263
|
-
var position: any;
|
264
|
-
var Anchor: any;
|
265
|
-
var Puzzle: any;
|
266
|
-
var Piece: any;
|
267
|
-
var Canvas: any;
|
268
|
-
var Manufacturer: any;
|
269
|
-
var InsertSequence: any;
|
270
|
-
var PieceValidator: any;
|
271
|
-
var PuzzleValidator: any;
|
272
|
-
var NullValidator: any;
|
273
|
-
var Tab: any;
|
274
|
-
var Slot: any;
|
275
|
-
var None: any;
|
276
|
-
var Pair: any;
|
277
|
-
var Metadata: any;
|
278
|
-
var SpatialMetadata: any;
|
279
|
-
var Outline: any;
|
280
|
-
var Structure: any;
|
281
|
-
var Position: any;
|
282
|
-
var generators: any;
|
283
|
-
var painters: any;
|
284
|
-
}
|
353
|
+
declare module "headbreaker" { }
|
285
354
|
|
286
355
|
/**
|
287
356
|
* A connection element of a piece
|
@@ -298,6 +367,8 @@ declare class KonvaPainter implements Painter {
|
|
298
367
|
initialize(canvas: Canvas, id: string): void;
|
299
368
|
draw(canvas: Canvas): void;
|
300
369
|
reinitialize(canvas: Canvas): void;
|
370
|
+
resize(canvas: Canvas, width: number, height: number): void;
|
371
|
+
scale(canvas: Canvas, factor: Vector): void;
|
301
372
|
sketch(canvas: Canvas, piece: Piece, figure: Figure): void;
|
302
373
|
label(_canvas: Canvas, piece: Piece, figure: Figure): void;
|
303
374
|
physicalTranslate(_canvas: Canvas, group: Group, piece: Piece): void;
|
@@ -340,6 +411,8 @@ declare class Manufacturer {
|
|
340
411
|
|
341
412
|
declare class Positioner {
|
342
413
|
constructor(puzzle: Puzzle, headAnchor: Anchor);
|
414
|
+
initializeOffset(headAnchor: Anchor): void;
|
415
|
+
offset: Vector;
|
343
416
|
naturalAnchor(x: number, y: number): void;
|
344
417
|
}
|
345
418
|
|
@@ -358,7 +431,7 @@ declare module "Metadata" {
|
|
358
431
|
*/
|
359
432
|
declare module "Outline" {
|
360
433
|
function select(insert: Insert, t: number, s: number, n: number): void;
|
361
|
-
function draw(piece: Piece, size?: number): number[];
|
434
|
+
function draw(piece: Piece, size?: Vector | number, borderFill?: Vector | number): number[];
|
362
435
|
}
|
363
436
|
|
364
437
|
declare type VectorAction = (dx: number, dy: number) => void;
|
@@ -370,6 +443,7 @@ declare type Action = () => void;
|
|
370
443
|
* order to create UI representations of a puzzle.
|
371
444
|
*/
|
372
445
|
declare interface Painter {
|
446
|
+
resize(canvas: Canvas, width: number, height: number): void;
|
373
447
|
/**
|
374
448
|
* Creates the rendering backend, initializig all its contents.
|
375
449
|
* After this call, painter is ready to receive any other messages
|
@@ -385,6 +459,10 @@ declare interface Painter {
|
|
385
459
|
* Draws the canvas figures in the rendering backend
|
386
460
|
*/
|
387
461
|
draw(canvas: Canvas): void;
|
462
|
+
/**
|
463
|
+
* Scales the canvas contents
|
464
|
+
*/
|
465
|
+
scale(canvas: Canvas, factor: Vector): void;
|
388
466
|
/**
|
389
467
|
* Adds a piece to the rendering backend, so that it is ready to be drawn
|
390
468
|
* @param figure - the rendering backend information for this piece. This method may mutate it if necessary
|
@@ -418,7 +496,10 @@ declare module "Pair" {
|
|
418
496
|
* Tells whether this pair is (0, 0)
|
419
497
|
*/
|
420
498
|
function isNull(x: number, y: number): boolean;
|
421
|
-
|
499
|
+
/**
|
500
|
+
* @param [delta = 0] - tolerance in comparison
|
501
|
+
*/
|
502
|
+
function equal(x1: number, y1: number, x2: number, y2: number, delta?: number): boolean;
|
422
503
|
/**
|
423
504
|
* Calculates the difference of two vectors
|
424
505
|
*/
|
@@ -429,25 +510,39 @@ declare type TranslationListener = (piece: Piece, dx: number, dy: number) => voi
|
|
429
510
|
|
430
511
|
declare type ConnectionListener = (piece: Piece, target: Piece) => void;
|
431
512
|
|
513
|
+
declare type PieceConfig = {
|
514
|
+
centralAnchor?: Vector;
|
515
|
+
size?: Size;
|
516
|
+
metadata?: any;
|
517
|
+
};
|
518
|
+
|
432
519
|
/**
|
433
520
|
* A piece primitive representation that can be easily stringified, exchanged and persisted
|
434
521
|
*/
|
435
522
|
declare type PieceDump = {
|
436
|
-
centralAnchor:
|
437
|
-
|
438
|
-
connections?: Orthogonal<object>;
|
523
|
+
centralAnchor: Vector;
|
524
|
+
size?: Size;
|
439
525
|
metadata: any;
|
526
|
+
connections?: Orthogonal<object>;
|
527
|
+
structure: string;
|
440
528
|
};
|
441
529
|
|
442
530
|
/**
|
443
531
|
* A jigsaw piece
|
444
532
|
*/
|
445
533
|
declare class Piece {
|
446
|
-
constructor(
|
534
|
+
constructor(structure?: Structure, config?: PieceConfig);
|
535
|
+
metadata: any;
|
447
536
|
centralAnchor: Anchor;
|
537
|
+
_size: Size;
|
448
538
|
translateListeners: TranslationListener[];
|
449
539
|
connectListeners: ConnectionListener[];
|
450
540
|
disconnectListeners: ConnectionListener[];
|
541
|
+
/**
|
542
|
+
* Runs positining, sizing and metadata configurations
|
543
|
+
* in a single step
|
544
|
+
*/
|
545
|
+
configure(config: PieceConfig): void;
|
451
546
|
/**
|
452
547
|
* Adds unestructured user-defined metadata on this piece.
|
453
548
|
*/
|
@@ -460,7 +555,9 @@ declare class Piece {
|
|
460
555
|
*/
|
461
556
|
reannotate(metadata: any): void;
|
462
557
|
belongTo(puzzle: any): void;
|
463
|
-
presentConnections:
|
558
|
+
presentConnections: Piece[];
|
559
|
+
connections: Piece[];
|
560
|
+
inserts: Insert[];
|
464
561
|
/**
|
465
562
|
* @param f - the callback
|
466
563
|
*/
|
@@ -531,16 +628,25 @@ declare class Piece {
|
|
531
628
|
horizontallyCloseTo(other: Piece): boolean;
|
532
629
|
verticallyMatch(other: Piece): boolean;
|
533
630
|
horizontallyMatch(other: Piece): boolean;
|
534
|
-
downAnchor:
|
535
|
-
rightAnchor:
|
536
|
-
upAnchor:
|
537
|
-
leftAnchor:
|
538
|
-
|
539
|
-
|
631
|
+
downAnchor: Anchor;
|
632
|
+
rightAnchor: Anchor;
|
633
|
+
upAnchor: Anchor;
|
634
|
+
leftAnchor: Anchor;
|
635
|
+
/**
|
636
|
+
* Defines this piece's own dimmension, overriding puzzle's
|
637
|
+
* default dimmension
|
638
|
+
*/
|
639
|
+
resize(size: Size): void;
|
640
|
+
radio: Vector;
|
641
|
+
/**
|
642
|
+
* The double of the radio
|
643
|
+
*/
|
644
|
+
diameter: Vector;
|
645
|
+
proximity: number;
|
540
646
|
/**
|
541
647
|
* This piece id. It is extracted from metadata
|
542
648
|
*/
|
543
|
-
id:
|
649
|
+
id: string;
|
544
650
|
/**
|
545
651
|
* Converts this piece into a plain, stringify-ready object.
|
546
652
|
* Connections should have ids
|
@@ -555,37 +661,6 @@ declare class Piece {
|
|
555
661
|
static import(dump: PieceDump): Piece;
|
556
662
|
}
|
557
663
|
|
558
|
-
declare type Position = {
|
559
|
-
x: number;
|
560
|
-
y: number;
|
561
|
-
};
|
562
|
-
|
563
|
-
declare function position(x: number, y: number): Position;
|
564
|
-
|
565
|
-
/**
|
566
|
-
* This module contains functions for dealing with objects with x and y
|
567
|
-
* coordinates that represent or include point data
|
568
|
-
*/
|
569
|
-
declare module "Position" {
|
570
|
-
/**
|
571
|
-
* Returns a new (0, 0) position
|
572
|
-
*/
|
573
|
-
function origin(): Position;
|
574
|
-
/**
|
575
|
-
* Compares two points
|
576
|
-
*/
|
577
|
-
function equal(one: Position, other: Position): boolean;
|
578
|
-
/**
|
579
|
-
* Creates a copy of the given point
|
580
|
-
*/
|
581
|
-
function copy(one: Position): Position;
|
582
|
-
function update(position: Position, x: any, y: any): void;
|
583
|
-
/**
|
584
|
-
* @returns ;
|
585
|
-
*/
|
586
|
-
function diff(one: Position, other: Position): Pair;
|
587
|
-
}
|
588
|
-
|
589
664
|
declare type Orthogonal = {
|
590
665
|
up: A;
|
591
666
|
down: A;
|
@@ -609,13 +684,13 @@ declare module "Prelude" {
|
|
609
684
|
* A puzzle primitive representation that can be easily stringified, exchanged and persisted
|
610
685
|
*/
|
611
686
|
declare type PuzzleDump = {
|
612
|
-
|
687
|
+
pieceRadio: Vector;
|
613
688
|
proximity: number;
|
614
689
|
pieces: PieceDump[];
|
615
690
|
};
|
616
691
|
|
617
692
|
declare type Settings = {
|
618
|
-
|
693
|
+
pieceRadio?: Vector | number;
|
619
694
|
proximity?: number;
|
620
695
|
};
|
621
696
|
|
@@ -629,10 +704,11 @@ declare class Puzzle {
|
|
629
704
|
validator: Validator;
|
630
705
|
/**
|
631
706
|
* Creates and adds to this puzzle a new piece
|
632
|
-
* @param [
|
707
|
+
* @param [structure] - the piece structure
|
708
|
+
* @param [config] - the piece config
|
633
709
|
* @returns the new piece
|
634
710
|
*/
|
635
|
-
newPiece(
|
711
|
+
newPiece(structure?: Structure, config?: PieceConfig): Piece;
|
636
712
|
addPiece(piece: Piece): void;
|
637
713
|
addPieces(pieces: Piece[]): void;
|
638
714
|
/**
|
@@ -658,6 +734,7 @@ declare class Puzzle {
|
|
658
734
|
*/
|
659
735
|
autoconnectWith(piece: Piece): void;
|
660
736
|
shuffle(maxX: number, maxY: number): void;
|
737
|
+
shuffleWith(shuffler: Shuffler): void;
|
661
738
|
translate(dx: number, dy: number): void;
|
662
739
|
onTranslate(f: TranslationListener): void;
|
663
740
|
onConnect(f: ConnectionListener): void;
|
@@ -667,29 +744,59 @@ declare class Puzzle {
|
|
667
744
|
* Answers the list of points where
|
668
745
|
* central anchors of pieces are located
|
669
746
|
*/
|
670
|
-
points:
|
747
|
+
points: Pair[];
|
671
748
|
/**
|
672
749
|
* Answers a list of points whose coordinates are scaled
|
673
750
|
* to the {@link Puzzle#pieceWidth}
|
674
751
|
*/
|
675
|
-
refs:
|
752
|
+
refs: Pair[];
|
753
|
+
metadata: any[];
|
676
754
|
/**
|
677
755
|
* Returns the first piece
|
678
756
|
*/
|
679
|
-
head:
|
757
|
+
head: Piece;
|
680
758
|
/**
|
681
759
|
* Returns the central anchor of the first piece
|
682
760
|
*/
|
683
|
-
headAnchor:
|
761
|
+
headAnchor: Anchor;
|
684
762
|
attachValidator(validator: Validator): void;
|
763
|
+
/**
|
764
|
+
* Checks whether this puzzle is valid.
|
765
|
+
*
|
766
|
+
* Calling this method will not fire any validation listeners nor update the
|
767
|
+
* valid property.
|
768
|
+
*/
|
769
|
+
isValid(): boolean;
|
770
|
+
/**
|
771
|
+
* Returns the current validation status
|
772
|
+
*
|
773
|
+
* Calling this property will not fire any validation listeners.
|
774
|
+
*/
|
775
|
+
valid: boolean;
|
776
|
+
/**
|
777
|
+
* Checks whether this puzzle is valid, updating valid property
|
778
|
+
* and firing validation listeners if becomes valid
|
779
|
+
*/
|
780
|
+
validate(): void;
|
781
|
+
/**
|
782
|
+
* Checks whether this puzzle is valid, updating valid property.
|
783
|
+
*
|
784
|
+
* Validations listeners are NOT fired.
|
785
|
+
*/
|
786
|
+
updateValidity(): void;
|
685
787
|
/**
|
686
788
|
* Wether all the pieces in this puzzle are connected
|
687
789
|
*/
|
688
|
-
connected:
|
790
|
+
connected: boolean;
|
689
791
|
/**
|
690
|
-
* The piece width, from edge to edge
|
792
|
+
* The piece width, from edge to edge.
|
793
|
+
* This is the double of the {@link Puzzle#pieceRadio}
|
691
794
|
*/
|
692
|
-
|
795
|
+
pieceDiameter: Vector;
|
796
|
+
/**
|
797
|
+
* The piece width, from center to edge
|
798
|
+
*/
|
799
|
+
pieceRadio: Vector;
|
693
800
|
/**
|
694
801
|
* Converts this piece into a plain, stringify-ready object.
|
695
802
|
* Pieces should have ids
|
@@ -744,9 +851,30 @@ declare module "sequence" {
|
|
744
851
|
}
|
745
852
|
}
|
746
853
|
|
854
|
+
declare function random(maxX: number, maxY: number): Shuffler;
|
855
|
+
|
856
|
+
declare function grid(): void;
|
857
|
+
|
858
|
+
declare function columns(): void;
|
859
|
+
|
860
|
+
declare function padder(padding: number, width: number, height: number): Shuffler;
|
861
|
+
|
862
|
+
declare function noise(maxDistance: Vector): Shuffler;
|
863
|
+
|
864
|
+
declare function noop(): void;
|
865
|
+
|
866
|
+
declare type Size = {
|
867
|
+
radio: Vector;
|
868
|
+
diameter: Vector;
|
869
|
+
};
|
870
|
+
|
871
|
+
declare function radio(value: Vector | number): Size;
|
872
|
+
|
873
|
+
declare function diameter(value: Vector | number): Size;
|
874
|
+
|
747
875
|
declare type SpatialMetadata = {
|
748
|
-
targetPosition?:
|
749
|
-
currentPosition?:
|
876
|
+
targetPosition?: Vector;
|
877
|
+
currentPosition?: Vector;
|
750
878
|
};
|
751
879
|
|
752
880
|
/**
|
@@ -754,10 +882,11 @@ declare type SpatialMetadata = {
|
|
754
882
|
* and pieces and puzzles that are annotated with it
|
755
883
|
*/
|
756
884
|
declare module "SpatialMetadata" {
|
885
|
+
function diffToTarget(piece: Piece): void;
|
757
886
|
function solved(): void;
|
758
887
|
function relativePosition(): void;
|
759
888
|
function absolutePosition(): void;
|
760
|
-
function initialize(metadata: SpatialMetadata, target:
|
889
|
+
function initialize(metadata: SpatialMetadata, target: Vector, current?: Vector): void;
|
761
890
|
}
|
762
891
|
|
763
892
|
declare type Structure = {
|
@@ -778,6 +907,33 @@ declare type Validator = PieceValidator | PuzzleValidator | NullValidator;
|
|
778
907
|
|
779
908
|
declare type ValidationListener = (puzzle: Puzzle) => void;
|
780
909
|
|
910
|
+
declare class AbstractValidator {
|
911
|
+
validListeners: ValidationListener[];
|
912
|
+
/**
|
913
|
+
* Validates the puzzle, updating the validity state and
|
914
|
+
* firing validation events
|
915
|
+
*/
|
916
|
+
validate(puzzle: Puzzle): void;
|
917
|
+
/**
|
918
|
+
* Updates the valid state.
|
919
|
+
*/
|
920
|
+
updateValidity(puzzle: Puzzle): void;
|
921
|
+
fireValid(puzzle: Puzzle): void;
|
922
|
+
/**
|
923
|
+
* Registers a validation listener
|
924
|
+
*/
|
925
|
+
onValid(f: ValidationListener): void;
|
926
|
+
/**
|
927
|
+
* Answers the current validity status of this validator. This
|
928
|
+
* property neither alters the current status nor triggers new validity checks
|
929
|
+
*/
|
930
|
+
valid: boolean;
|
931
|
+
/**
|
932
|
+
* Answers wether this is the {@link NullValidator}
|
933
|
+
*/
|
934
|
+
isNull: boolean;
|
935
|
+
}
|
936
|
+
|
781
937
|
declare type PieceCondition = (puzzle: Piece) => boolean;
|
782
938
|
|
783
939
|
declare type PuzzleCondition = (puzzle: Puzzle) => boolean;
|
@@ -790,9 +946,20 @@ declare class PieceValidator {
|
|
790
946
|
isValid(puzzle: Puzzle): boolean;
|
791
947
|
}
|
792
948
|
|
949
|
+
/**
|
950
|
+
* A validator that evaluates the whole puzzle
|
951
|
+
*/
|
793
952
|
declare class PuzzleValidator {
|
794
953
|
constructor(f: PuzzleCondition);
|
795
954
|
isValid(puzzle: Puzzle): void;
|
955
|
+
/**
|
956
|
+
* Compares two pairs
|
957
|
+
*/
|
958
|
+
static equalDiffs(param0: Pair, param1: Pair): boolean;
|
959
|
+
/**
|
960
|
+
* The delta used to compare distances
|
961
|
+
*/
|
962
|
+
static DIFF_DELTA: number;
|
796
963
|
static connected(): void;
|
797
964
|
/**
|
798
965
|
* @param expected - the expected relative refs
|
@@ -800,3 +967,50 @@ declare class PuzzleValidator {
|
|
800
967
|
static relativeRefs(expected: Pair[]): PuzzleCondition;
|
801
968
|
}
|
802
969
|
|
970
|
+
/**
|
971
|
+
* A validator that always is invalid
|
972
|
+
*/
|
973
|
+
declare class NullValidator {
|
974
|
+
isValid(puzzle: Puzzle): void;
|
975
|
+
isNull: boolean;
|
976
|
+
}
|
977
|
+
|
978
|
+
declare type Vector = {
|
979
|
+
x: number;
|
980
|
+
y: number;
|
981
|
+
};
|
982
|
+
|
983
|
+
declare function vector(x: number, y: number): Vector;
|
984
|
+
|
985
|
+
declare function cast(value: Vector | number): Vector;
|
986
|
+
|
987
|
+
/**
|
988
|
+
* This module contains functions for dealing with objects with x and y
|
989
|
+
* coordinates that represent or include point data
|
990
|
+
*/
|
991
|
+
declare module "Vector" {
|
992
|
+
/**
|
993
|
+
* Returns a new (0, 0) vector
|
994
|
+
*/
|
995
|
+
function zero(): Vector;
|
996
|
+
/**
|
997
|
+
* Compares two points
|
998
|
+
* @param [delta = 0] - the tolance in comparison
|
999
|
+
*/
|
1000
|
+
function equal(one: Vector, other: Vector, delta?: number): boolean;
|
1001
|
+
/**
|
1002
|
+
* Creates a copy of the given point
|
1003
|
+
*/
|
1004
|
+
function copy(one: Vector): Vector;
|
1005
|
+
function update(vector: Vector, x: any, y: any): void;
|
1006
|
+
/**
|
1007
|
+
* @returns ;
|
1008
|
+
*/
|
1009
|
+
function diff(one: Vector, other: Vector): Pair;
|
1010
|
+
function multiply(one: Vector | number, other: Vector | number): Vector;
|
1011
|
+
function divide(one: Vector | number, other: Vector | number): Vector;
|
1012
|
+
function plus(one: Vector | number, other: Vector | number): Vector;
|
1013
|
+
function minus(one: Vector | number, other: Vector | number): Vector;
|
1014
|
+
function apply(one: Vector | number, other: Vector | number, f: any): Vector;
|
1015
|
+
}
|
1016
|
+
|