1 import ChessRules
from "/base_rules.js";
3 export default class AbstractClickFillRules
extends ChessRules
{
6 return Object
.assign({'A': AbstractClickFillRules
}, ChessRules
.Aliases
);
14 for (let i
=0; i
<this.size
.x
; i
++) {
15 for (let j
=0; j
<this.size
.y
; j
++) {
17 !!this.marks
&& this.marks
.some(m
=> m
[0] == i
&& m
[1] == j
);
18 if (this.board
[i
][j
] != "" || markHere
) {
19 let elt
= document
.getElementById(this.coordsToId({x: i
, y: j
}));
20 elt
.classList
.remove("neutral-square");
22 elt
.classList
.add("bg-mark");
24 const sqColor
= (this.getColor(i
, j
) == 'w' ? "white" : "black");
25 elt
.classList
.add("bg-" + sqColor
);
33 move.vanish
.forEach(v
=> {
34 let elt
= document
.getElementById(this.coordsToId({x: v
.x
, y: v
.y
}));
35 elt
.classList
.remove("bg-" + (v
.c
== 'w' ? "white" : "black"));
37 move.appear
.forEach(a
=> {
38 let elt
= document
.getElementById(this.coordsToId({x: a
.x
, y: a
.y
}));
39 elt
.classList
.add("bg-" + (a
.c
== 'w' ? "white" : "black"));
43 animateFading(arr
, cb
) {
44 const animLength
= 350; //TODO: 350ms? More? Less?
47 document
.getElementById(this.coordsToId({x: e
.x
, y: e
.y
}));
48 fadingSquare
.style
.transitionDuration
= (animLength
/ 1000) + "s";
49 //fadingSquare.style.backgroundColor = "0"; //TODO: type in or out
50 if (this.board
[e
.x
][e
.y
] != "") {
51 // TODO: fade out curCol --> neutral
54 // TODO: fade in neutral --> this.getColor(e.x, e.y)
57 setTimeout(cb
, animLength
);
60 animate(move, callback
) {
61 // No movement, but use fading effects: TODO
62 // https://stackoverflow.com/questions/14350126/transition-color-fade-on-hover
63 // https://stackoverflow.com/questions/22581789/fade-in-fade-out-background-color-of-an-html-element-with-javascript-or-jquer
64 if (true || this.noAnimate
|| move.noAnimate
) {
68 let targetObj
= new TargetObj(callback
);
69 const allChanges
= move.appear
.concat(move.vanish
);
70 if (allChanges
.length
> 0) {
72 this.animateFading(allChanges
, () => targetObj
.increment());
75 this.customAnimate(move, segments
, () => targetObj
.increment());
76 if (targetObj
.target
== 0)