Skip to content

Commit f84c964

Browse files
committed
fix promotion ui
1 parent c169ac3 commit f84c964

3 files changed

Lines changed: 13 additions & 3 deletions

File tree

src/components/BoardPanel.vue

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@
4242
</template>
4343
<div v-if="promotionPending" class="promotion-overlay" @click="$emit('cancel-promotion')"></div>
4444
<Promotion v-if="promotionPending" :color="promotionPending.color" :style="promotionStyle ?? undefined"
45+
:is-flipped="isFlipped"
4546
@select="(piece: string) => $emit('apply-promotion', piece)" />
4647
</div>
4748

src/components/Promotion.vue

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,17 +18,19 @@ import { promotionImg } from '../assets/resourcePaths'
1818
1919
const props = defineProps<{
2020
color: 'white' | 'black';
21-
style?: CSSProperties
21+
style?: CSSProperties;
22+
isFlipped?: boolean;
2223
}>()
2324
2425
defineEmits<{
2526
(e: 'select', piece: string): void
2627
}>()
2728
2829
const pieces = computed(() => {
29-
return props.color === 'white'
30+
const basePieces = props.color === 'white'
3031
? ['queen', 'knight', 'rook', 'bishop']
3132
: ['bishop', 'rook', 'knight', 'queen']
33+
return props.isFlipped ? [...basePieces].reverse() : basePieces
3234
})
3335
3436
// 如果父级传入的 style 包含位置,这里做一个简单的容错和整合

src/composables/useGameState.ts

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { ref, computed, onUnmounted, type CSSProperties, nextTick } from 'vue'
1+
import { ref, computed, onUnmounted, watch, type CSSProperties, nextTick } from 'vue'
22
import type { Board, Color, Piece, Move } from '../models/chess'
33
import {
44
createInitialBoard,
@@ -733,6 +733,13 @@ export function useGameState(
733733
}
734734
}
735735

736+
// 棋盘翻转时,重新计算升变 UI 位置
737+
watch(isFlipped, () => {
738+
if (promotionPending.value) {
739+
computePromotionStyle(promotionPending.value.to.row, promotionPending.value.to.col)
740+
}
741+
})
742+
736743
const applyPromotion = (newType: string) => {
737744
if (!promotionPending.value) return
738745
const { from, to } = promotionPending.value

0 commit comments

Comments
 (0)