Commit | Line | Data |
---|---|---|
cf2343ce | 1 | <script> |
a3ab5fdb | 2 | // Component for moves list on the right |
cf2343ce BA |
3 | export default { |
4 | name: 'my-move-list', | |
7d9e99bc | 5 | props: ["moves","cursor"], //TODO: other props for e.g. players names + connected indicator |
7ee085c2 BA |
6 | // --> we could also add turn indicator here |
7 | data: function() { | |
8 | return { | |
a3ab5fdb | 9 | something: "", //TODO? |
7ee085c2 BA |
10 | }; |
11 | }, | |
12 | // TODO: extend rendering for more than 2 colors: would be a parameter | |
a3ab5fdb | 13 | // in that case some moves for some colors could be just skipped (if a player lost) |
7ee085c2 BA |
14 | render(h) { |
15 | if (this.moves.length == 0) | |
16 | return; | |
17 | const nbColors = 2; | |
7d9e99bc BA |
18 | // TODO: name colors "white", "black", "red", "yellow" ? |
19 | if (this.moves[0].color == "b") | |
20 | this.moves.unshift({color: "w", notation: "..."}); | |
7ee085c2 BA |
21 | let tableContent = []; |
22 | let moveCounter = 0; | |
23 | let tableRow = undefined; | |
24 | let moveCells = undefined; | |
25 | let curCellContent = ""; | |
26 | for (let i=0; i<this.moves.length; i++) | |
27 | { | |
7d9e99bc | 28 | if (this.moves[i].color == "w") |
7ee085c2 | 29 | { |
7d9e99bc | 30 | if (i == 0 || i>0 && this.moves[i-1].color=="b") |
7ee085c2 BA |
31 | { |
32 | if (!!tableRow) | |
7d9e99bc BA |
33 | { |
34 | tableRow.children = moveCells; | |
7ee085c2 | 35 | tableContent.push(tableRow); |
7d9e99bc | 36 | } |
7ee085c2 BA |
37 | moveCells = [ |
38 | h( | |
39 | "td", | |
7d9e99bc | 40 | { domProps: { innerHTML: (++moveCounter) + "." } } |
7ee085c2 BA |
41 | ) |
42 | ]; | |
43 | tableRow = h( | |
44 | "tr", | |
7d9e99bc | 45 | { } |
7ee085c2 BA |
46 | ); |
47 | curCellContent = ""; | |
48 | } | |
7d9e99bc BA |
49 | } |
50 | curCellContent += this.moves[i].notation; | |
51 | if (i < this.moves.length-1 && this.moves[i+1].color == this.moves[i].color) | |
52 | curCellContent += ","; | |
53 | else //color change | |
54 | { | |
7ee085c2 BA |
55 | moveCells.push( |
56 | h( | |
57 | "td", | |
7d9e99bc BA |
58 | { |
59 | domProps: { innerHTML: curCellContent }, | |
60 | on: { click: () => this.gotoMove(i) }, | |
d337a94c | 61 | "class": { "highlight-lm": this.cursor == i }, |
7d9e99bc BA |
62 | } |
63 | ) | |
64 | ); | |
65 | curCellContent = ""; | |
7ee085c2 BA |
66 | } |
67 | } | |
68 | // Complete last row, which might not be full: | |
7d9e99bc | 69 | if (moveCells.length-1 < nbColors) |
7ee085c2 BA |
70 | { |
71 | const delta = nbColors - (moveCells.length-1); | |
72 | for (let i=0; i<delta; i++) | |
73 | { | |
74 | moveCells.push( | |
7d9e99bc BA |
75 | h( |
76 | "td", | |
77 | { domProps: { innerHTML: "" } } | |
78 | ) | |
7ee085c2 BA |
79 | ); |
80 | } | |
7ee085c2 | 81 | } |
7d9e99bc BA |
82 | tableRow.children = moveCells; |
83 | tableContent.push(tableRow); | |
7ee085c2 BA |
84 | const movesTable = h( |
85 | "table", | |
86 | { }, | |
87 | tableContent | |
88 | ); | |
89 | return movesTable; | |
90 | }, | |
7d9e99bc BA |
91 | methods: { |
92 | gotoMove: function(index) { | |
93 | this.$emit("goto-move", index); | |
94 | }, | |
95 | }, | |
cf2343ce BA |
96 | }; |
97 | </script> |