39 lines
1.0 KiB
JavaScript
39 lines
1.0 KiB
JavaScript
class PuzzleState {
|
|
constructor({ imageKey, imagePath, pieceCount, roomCode, cols, rows, pieces, groups, completed }) {
|
|
this.imageKey = imageKey;
|
|
this.imagePath = imagePath;
|
|
this.pieceCount = pieceCount;
|
|
this.roomCode = roomCode;
|
|
this.cols = cols;
|
|
this.rows = rows;
|
|
this.pieces = pieces; // PieceData[]
|
|
this.groups = groups; // number[][] — each inner array is one group's piece IDs
|
|
this.completed = completed || false;
|
|
}
|
|
|
|
serialize() {
|
|
return {
|
|
imageKey: this.imageKey,
|
|
imagePath: this.imagePath,
|
|
pieceCount: this.pieceCount,
|
|
roomCode: this.roomCode,
|
|
cols: this.cols,
|
|
rows: this.rows,
|
|
pieces: this.pieces.map(p => ({
|
|
id: p.id,
|
|
gridRow: p.gridRow,
|
|
gridCol: p.gridCol,
|
|
edges: p.edges,
|
|
x: p.x,
|
|
y: p.y
|
|
})),
|
|
groups: this.groups,
|
|
completed: this.completed
|
|
};
|
|
}
|
|
|
|
static deserialize(obj) {
|
|
return new PuzzleState(obj);
|
|
}
|
|
}
|