Skip to content

Commit 0a012ae

Browse files
authored
Merge pull request #39 from Mind-Sports-Games/442-backgammon
fix active dice values now that dice can be in any order
2 parents c6e10d8 + f449825 commit 0a012ae

File tree

3 files changed

+5
-3
lines changed

3 files changed

+5
-3
lines changed

package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "chessground",
3-
"version": "7.11.1-pstrat2.39",
3+
"version": "7.11.1-pstrat2.40",
44
"description": "playstrategy.org chess ui, forked from lichess.org",
55
"type": "commonjs",
66
"main": "chessground.js",

src/drop.ts

+2-1
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,8 @@ export function drop(s: State, e: cg.MouchEvent): void {
4848
}
4949

5050
function dropFromPocket(s: State, role: cg.Role): void {
51-
const activeDiceValue = s.dice.length > 0 && s.dice[0].isAvailable ? s.dice[0].value : undefined;
51+
const activeDiceValue =
52+
s.dice.filter(d => d.isAvailable).length > 0 ? s.dice.filter(d => d.isAvailable)[0].value : undefined;
5253
const activeDiceKey = activeDiceValue
5354
? util.pos2key([s.dimensions.width + 1 - activeDiceValue, s.myPlayerIndex === 'p1' ? 2 : 1])
5455
: undefined;

src/events.ts

+2-1
Original file line numberDiff line numberDiff line change
@@ -118,7 +118,8 @@ function startDragOrDraw(s: State): MouchBind {
118118
const isLiftDest =
119119
s.liftable.liftDests && s.liftable.liftDests.length > 0 && s.liftable.liftDests.includes(orig);
120120
const hasMovableDest = s.movable.dests && s.movable.dests.has(orig);
121-
const activeDiceValue = s.dice.length > 0 && s.dice[0].isAvailable ? s.dice[0].value : undefined;
121+
const activeDiceValue =
122+
s.dice.filter(d => d.isAvailable).length > 0 ? s.dice.filter(d => d.isAvailable)[0].value : undefined;
122123
//if a piece can both lift and move then use dice to decide what todo on a single click?
123124
if (piece && piece.playerIndex === s.turnPlayerIndex && hasMovableDest) {
124125
const dest = s.movable.dests!.get(orig)![0];

0 commit comments

Comments
 (0)