Skip to content

Commit

Permalink
v3.4.14
Browse files Browse the repository at this point in the history
  • Loading branch information
gruppler committed May 13, 2024
2 parents 61a7664 + 2d1951a commit 8fc98c2
Show file tree
Hide file tree
Showing 10 changed files with 76 additions and 48 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "ptn-ninja",
"version": "3.4.13",
"version": "3.4.14",
"description": "An editor and viewer for Portable Tak Notation",
"productName": "PTN Ninja",
"author": "Craig Laparo <gruppler+github@gmail.com>",
Expand Down
7 changes: 7 additions & 0 deletions src/Game/base.js
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,7 @@ export default class GameBase {
editingTPS,
onInit,
onError,
onInsertPly,
}) {
// Set up init handler
if (isFunction(onInit)) {
Expand All @@ -102,6 +103,12 @@ export default class GameBase {
if (isFunction(onError)) {
this.onError = onError;
}

// Set up other handlers
if (isFunction(onInsertPly)) {
this.onInsertPly = onInsertPly;
}

const handleError = (error) => {
if (this.onError) {
this.onError(error, this.plies.length - 1);
Expand Down
26 changes: 20 additions & 6 deletions src/Game/mutations.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import Nop from "./PTN/Nop";
import Ply from "./PTN/Ply";
import Tag from "./PTN/Tag";

import { escapeRegExp, flatten, isArray } from "lodash";
import { escapeRegExp, flatten, isArray, isFunction, uniqBy } from "lodash";

export default class GameMutations {
replacePTN(ptn, state = this.minState) {
Expand Down Expand Up @@ -78,7 +78,7 @@ export default class GameMutations {
ply = this.plies[ply.id + 1];
includeSiblings = true;
}
return descendents;
return uniqBy(descendents, "id");
};

const oldID = ply.id;
Expand All @@ -90,10 +90,10 @@ export default class GameMutations {
let oldMain = getDescendents(this.plies[newID], branch);

// Rename new main branches
let oldBranchRegExp = new RegExp(
const oldBranchRegExp = new RegExp(
"^" + (branch ? escapeRegExp(branch) + "(\\/|$)" : "")
);
let newBranchFull = branch && mainBranch ? mainBranch + "$1" : mainBranch;
const newBranchFull = branch && mainBranch ? mainBranch + "$1" : mainBranch;
let length = 0;
newMain.forEach((ply) => {
if (ply.branch === branch) {
Expand All @@ -107,9 +107,17 @@ export default class GameMutations {
});

// Rename old main branches
const newBranchRegExp = new RegExp(
"^" + (branch ? escapeRegExp(mainBranch) + "(\\/|$)" : "")
);
let oldBranchFull = branch && mainBranch ? branch + "$1" : branch;
oldMain.forEach((ply) => {
ply.branch =
ply.branch === mainBranch ? branch : branch + "/" + ply.branch;
if (branch && mainBranch) {
ply.branch = ply.branch.replace(newBranchRegExp, oldBranchFull);
} else {
ply.branch =
ply.branch === mainBranch ? branch : branch + "/" + ply.branch;
}
ply.linenum.branch = ply.branch;
if (this.board.plyID === ply.id) {
this.board.targetBranch = ply.branch;
Expand Down Expand Up @@ -735,6 +743,12 @@ export default class GameMutations {
this.board.updatePTNOutput();
this.board.updatePositionOutput();
this.board.updateBoardOutput();
if (isFunction(this.onInsertPly)) {
if (ply.constructor === Ply) {
ply = ply.text;
}
this.onInsertPly(this, ply);
}
return true;
}
});
Expand Down
10 changes: 5 additions & 5 deletions src/components/controls/Highlighter.vue
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<template>
<div
class="highlighter row no-wrap justify-around items-center full-height absolute-fit"
v-shortkey="hotkeys"
v-shortkey="isDialogOpen ? null : hotkeys"
@shortkey="hotkey($event.srcKey)"
>
<ColorPicker v-model="selectedColor" :palette="palette" icon="edit" stretch>
Expand Down Expand Up @@ -79,6 +79,9 @@ export default {
isEmpty() {
return isEmpty(this.$store.state.ui.highlighterSquares);
},
isDialogOpen() {
return !["local", "game"].includes(this.$route.name);
},
},
methods: {
clear() {
Expand All @@ -94,10 +97,7 @@ export default {
if (color) {
this.selectedColor = color;
}
} else if (
key === "clear" &&
["local", "game"].includes(this.$route.name)
) {
} else if (key === "clear") {
this.clear();
}
},
Expand Down
40 changes: 14 additions & 26 deletions src/components/database/DatabaseGame.vue
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,6 @@
</template>

<script>
import Game from "../../Game";
import Result from "../PTN/Result";
export default {
Expand Down Expand Up @@ -60,31 +59,20 @@ export default {
},
},
methods: {
async loadGame() {
try {
this.loading = true;
let response = await fetch(
`https://openings.exegames.de/api/v1/game/${this.playtakId}`
);
if (response.ok) {
let data = await response.json();
let game = new Game({
ptn: data.ptn,
state: {
plyIndex: this.$store.state.game.position.plyIndex,
plyIsDone: this.$store.state.game.position.plyIsDone,
},
});
this.$store.dispatch("game/ADD_GAME", game);
} else {
this.notifyError("HTTP-Error: " + response.status);
}
} catch (error) {
this.notifyError(error);
} finally {
this.loading = false;
}
loadGame() {
this.loading = true;
this.$store
.dispatch("game/ADD_PLAYTAK_GAME", {
id: this.playtakId,
state: {
plyIndex: this.$store.state.game.position.plyIndex,
plyIsDone: this.$store.state.game.position.plyIsDone,
},
})
.catch()
.finally(() => {
this.loading = false;
});
},
},
};
Expand Down
2 changes: 1 addition & 1 deletion src/dialogs/PlayTakGameID.vue
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ export default {
load() {
this.loading = true;
this.$store
.dispatch("game/ADD_PLAYTAK_GAME", this.gameID)
.dispatch("game/ADD_PLAYTAK_GAME", { id: this.gameID })
.then(() => {
this.$emit("submit");
this.close();
Expand Down
2 changes: 1 addition & 1 deletion src/i18n/en-us/about.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# PTN Ninja

**Version [3.4.13](https://github.com/gruppler/PTN-Ninja/releases)**
**Version [3.4.14](https://github.com/gruppler/PTN-Ninja/releases)**

This is an editor and viewer for [Portable Tak Notation (PTN)](https://ustak.org/portable-tak-notation/). It aims to be...

Expand Down
1 change: 1 addition & 0 deletions src/i18n/en-us/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -385,6 +385,7 @@ export default {
"Player exists": "That name is already taken",
"Unable to download": "Unable to download files",
"Unable to read clipboard": "Unable to read clipboard",
unknown: "An unknown error occurred",
"Unrecognized tag": "Unrecognized tag",
UnvalidatedEmail: "Please validate your email address.",
"auth/invalid-email": "Invalid email address",
Expand Down
27 changes: 20 additions & 7 deletions src/store/game/actions.js
Original file line number Diff line number Diff line change
Expand Up @@ -460,18 +460,31 @@ export const OPEN_FILES = async function ({ dispatch, state }, files) {
});
};

export const ADD_PLAYTAK_GAME = async function ({ dispatch }, id) {
export const ADD_PLAYTAK_GAME = async function ({ dispatch }, { id, state }) {
try {
const response = await fetch(
`https://api.playtak.com/v1/games-history/ptn/${id}`
// `https://api.beta.playtak.com/v1/games-history/ptn/${id}`
);
console.log(response);
const ptn = await response.text();
console.log(ptn);
let game = new Game({ ptn });
game.warnings.forEach((warning) => notifyWarning(warning));
return dispatch("ADD_GAME", game);
if (response && response.ok) {
const ptn = await response.text();
console.log(ptn);
let game = new Game({ ptn, state });
game.warnings.forEach((warning) => notifyWarning(warning));
return dispatch("ADD_GAME", game);
} else {
if (response) {
if (response.status === 404) {
throw "Game does not exist";
} else {
response = await response.json();
console.log(response);
throw response && response.message ? response.message : "unknown";
}
} else {
throw "unknown";
}
}
} catch (error) {
notifyError(error);
throw error;
Expand Down
7 changes: 6 additions & 1 deletion src/store/game/mutations.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,9 @@ export const SET_GAME = (state, game) => {
onInit: (game) => {
SET_GAME(state, game);
},
onInsertPly: (game, ply) => {
postMessage("INSERT_PLY", ply);
},
onError: (error, plyID) => {
handleError(error, plyID);
},
Expand All @@ -33,6 +36,9 @@ export const SET_GAME = (state, game) => {
game.onInit = (game) => {
SET_GAME(state, game);
};
game.onInsertPly = (game, ply) => {
postMessage("INSERT_PLY", ply);
};
game.onError = (error, plyID) => {
handleError(error, plyID);
};
Expand Down Expand Up @@ -228,7 +234,6 @@ export const INSERT_PLY = (state, ply) => {
const game = Vue.prototype.$game;
if (game) {
game.insertPly(ply, false, false);
postMessage("INSERT_PLY", ply);
}
};

Expand Down

0 comments on commit 8fc98c2

Please sign in to comment.