|
64 | 64 | :size="setFenSize()" |
65 | 65 | @change="checkValidFEN" |
66 | 66 | > |
| 67 | + <div |
| 68 | + v-if="opening" |
| 69 | + class="opening-label" |
| 70 | + > |
| 71 | + {{ opening.eco }} – {{ opening.name }} |
| 72 | + </div> |
67 | 73 | </div> |
68 | 74 | <div |
69 | 75 | v-else |
|
78 | 84 | :size="setFenSize()" |
79 | 85 | @change="checkValidFEN" |
80 | 86 | > |
| 87 | + <div |
| 88 | + v-if="opening" |
| 89 | + class="opening-label" |
| 90 | + > |
| 91 | + {{ opening.eco }} – {{ opening.name }} |
| 92 | + </div> |
81 | 93 | </div> |
82 | 94 | <div |
83 | 95 | v-if="QuickTourIndex !== 5" |
@@ -139,6 +151,7 @@ import PgnBrowser from './PgnBrowser.vue' |
139 | 151 | import SettingsTab from './SettingsTab' |
140 | 152 | import EvalPlotButton from './EvalPlotButton' |
141 | 153 | import GameInfo from './GameInfo.vue' |
| 154 | +import { findBestOpeningForFen } from '../../shared/openingLookup' |
142 | 155 | import { mapGetters } from 'vuex' |
143 | 156 |
|
144 | 157 | export default { |
@@ -178,6 +191,12 @@ export default { |
178 | 191 | fen () { |
179 | 192 | return this.$store.getters.fen |
180 | 193 | }, |
| 194 | + opening () { |
| 195 | + if (!this.fen) return null |
| 196 | + // only makes sense for standard chess |
| 197 | + if (this.variant && this.variant !== 'chess') return null |
| 198 | + return this.findOpeningProgressive() |
| 199 | + }, |
181 | 200 | mainFirstMove () { |
182 | 201 | return this.$store.getters.mainFirstMove |
183 | 202 | }, |
@@ -347,6 +366,21 @@ export default { |
347 | 366 | deselectPocketPieces () { |
348 | 367 | this.$store.commit('selectPocketPiece', ['boardA', '']) |
349 | 368 | }, |
| 369 | + findOpeningProgressive () { |
| 370 | + let mov = this.currentMove |
| 371 | + // check current position |
| 372 | + const opening = findBestOpeningForFen(this.fen) |
| 373 | + if (opening) return opening |
| 374 | +
|
| 375 | + // if no exact match, backtrack |
| 376 | + while (mov && mov.prev) { |
| 377 | + mov = mov.prev |
| 378 | + const opening = findBestOpeningForFen(mov.fen) |
| 379 | + if (opening) return opening |
| 380 | + } |
| 381 | +
|
| 382 | + return null |
| 383 | + }, |
350 | 384 | getBoardPos (event) { |
351 | 385 | if (event.explicitOriginalTarget.className === 'cg-board' && this.selectedPockedPiece.boardA !== '') { |
352 | 386 | // get click field |
@@ -618,4 +652,21 @@ input { |
618 | 652 | border-radius: 8px; |
619 | 653 | } |
620 | 654 |
|
| 655 | +.opening-label { |
| 656 | + margin-top: 4px; |
| 657 | + font-size: 11pt; |
| 658 | + color: var(--main-text-color); |
| 659 | + opacity: 0.9; |
| 660 | +} |
| 661 | +
|
| 662 | +.opening-label-qt { |
| 663 | + margin-top: 4px; |
| 664 | + font-size: 11pt; |
| 665 | + color: var(--main-text-color); |
| 666 | + opacity: 0.9; |
| 667 | + border: 5px solid var(--quicktour-highlight); |
| 668 | + padding: 2px 4px; |
| 669 | + border-radius: 4px; |
| 670 | +} |
| 671 | +
|
621 | 672 | </style> |
0 commit comments