|
|
|
@ -185,6 +185,7 @@ export class PuzzleMenuState extends TextualGameState {
|
|
|
|
|
for (const puzzle of puzzles) {
|
|
|
|
|
const elem = document.createElement("div");
|
|
|
|
|
elem.classList.add("puzzle");
|
|
|
|
|
elem.setAttribute("data-puzzle-id", String(puzzle.id));
|
|
|
|
|
|
|
|
|
|
if (this.activeCategory !== "mine") {
|
|
|
|
|
elem.classList.toggle("completed", puzzle.completed);
|
|
|
|
@ -255,6 +256,23 @@ export class PuzzleMenuState extends TextualGameState {
|
|
|
|
|
icon.appendChild(canvas);
|
|
|
|
|
elem.appendChild(icon);
|
|
|
|
|
|
|
|
|
|
if (this.activeCategory === "mine") {
|
|
|
|
|
const deleteButton = document.createElement("button");
|
|
|
|
|
deleteButton.classList.add("styledButton", "delete");
|
|
|
|
|
this.trackClicks(
|
|
|
|
|
deleteButton,
|
|
|
|
|
() => {
|
|
|
|
|
this.tryDeletePuzzle(puzzle);
|
|
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
consumeEvents: true,
|
|
|
|
|
preventClick: true,
|
|
|
|
|
preventDefault: true,
|
|
|
|
|
}
|
|
|
|
|
);
|
|
|
|
|
elem.appendChild(deleteButton);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
container.appendChild(elem);
|
|
|
|
|
|
|
|
|
|
this.trackClicks(elem, () => this.playPuzzle(puzzle));
|
|
|
|
@ -268,6 +286,33 @@ export class PuzzleMenuState extends TextualGameState {
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* @param {import("../savegame/savegame_typedefs").PuzzleMetadata} puzzle
|
|
|
|
|
*/
|
|
|
|
|
tryDeletePuzzle(puzzle) {
|
|
|
|
|
const signals = this.dialogs.showWarning(
|
|
|
|
|
T.dialogs.puzzleDelete.title,
|
|
|
|
|
T.dialogs.puzzleDelete.desc.replace("<title>", puzzle.title),
|
|
|
|
|
["delete:bad", "cancel:good"]
|
|
|
|
|
);
|
|
|
|
|
signals.delete.add(() => {
|
|
|
|
|
const closeLoading = this.dialogs.showLoadingDialog();
|
|
|
|
|
|
|
|
|
|
this.asyncChannel
|
|
|
|
|
.watch(this.app.clientApi.apiDeletePuzzle(puzzle.id))
|
|
|
|
|
.then(() => {
|
|
|
|
|
const element = this.htmlElement.querySelector("[data-puzzle-id='" + puzzle.id + "']");
|
|
|
|
|
if (element) {
|
|
|
|
|
element.remove();
|
|
|
|
|
}
|
|
|
|
|
})
|
|
|
|
|
.catch(err => {
|
|
|
|
|
this.dialogs.showWarning(T.global.error, String(err));
|
|
|
|
|
})
|
|
|
|
|
.then(closeLoading);
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
*
|
|
|
|
|
* @param {*} category
|
|
|
|
|