|
17 | 17 | :aria-label="getSquareLabel(getActualRow(displayRow - 1), getActualCol(displayCol - 1))"> |
18 | 18 |
|
19 | 19 | <img class="square-background base" draggable="false" |
20 | | - :src="isWhiteSquare(getActualRow(displayRow - 1), getActualCol(displayCol - 1)) ? './texture/board/board_white.png' : './texture/board/board_black.png'" |
| 20 | + :src="isWhiteSquare(getActualRow(displayRow - 1), getActualCol(displayCol - 1)) ? getAssetUrl('texture/board/board_white.png') : getAssetUrl('texture/board/board_black.png')" |
21 | 21 | alt="" /> |
22 | 22 |
|
23 | 23 | <img v-if="getOverlayTexture(getActualRow(displayRow - 1), getActualCol(displayCol - 1))" |
@@ -99,6 +99,11 @@ import Promotion from './components/Promotion.vue' |
99 | 99 | import Sidebar from './components/Sidebar.vue' |
100 | 100 | import GameSetup from './components/GameSetup.vue' |
101 | 101 |
|
| 102 | +// --- 动态导入 src/assets 资源的辅助函数 --- |
| 103 | +const getAssetUrl = (path: string): string => { |
| 104 | + return new URL(`../assets/${path}`, import.meta.url).href |
| 105 | +} |
| 106 | +
|
102 | 107 | // --- 存储 Key 常量 --- |
103 | 108 | const STORAGE_KEYS = { |
104 | 109 | SOUND_ENABLED: 'chess_sound_enabled', |
@@ -146,12 +151,12 @@ const getDisplayedRank = (displayRow: number): string => { |
146 | 151 | } |
147 | 152 |
|
148 | 153 | const sounds = { |
149 | | - move: new Audio('./sound/Move.ogg'), |
150 | | - capture: new Audio('./sound/Capture.ogg'), |
151 | | - check: new Audio('./sound/Check.ogg'), |
152 | | - victory: new Audio('./sound/Victory.ogg'), |
153 | | - defeat: new Audio('./sound/Defeat.ogg'), |
154 | | - draw: new Audio('./sound/Draw.ogg'), |
| 154 | + move: new Audio(getAssetUrl('sound/Move.ogg')), |
| 155 | + capture: new Audio(getAssetUrl('sound/Capture.ogg')), |
| 156 | + check: new Audio(getAssetUrl('sound/Check.ogg')), |
| 157 | + victory: new Audio(getAssetUrl('sound/Victory.ogg')), |
| 158 | + defeat: new Audio(getAssetUrl('sound/Defeat.ogg')), |
| 159 | + draw: new Audio(getAssetUrl('sound/Draw.ogg')), |
155 | 160 | } |
156 | 161 |
|
157 | 162 | interface GameSetupConfig { |
@@ -394,22 +399,22 @@ const isSelectedSquare = (row: number, col: number): boolean => { |
394 | 399 | const getPieceImage = (piece: Piece): string => { |
395 | 400 | if (piece.type === 'king') { |
396 | 401 | if (isDraw.value) { |
397 | | - return `./texture/pieces/king_draw_${piece.color}.png` |
| 402 | + return getAssetUrl(`texture/pieces/king_draw_${piece.color}.png`) |
398 | 403 | } |
399 | 404 | if (hasResigned.value && piece.color === hasResigned.value) { |
400 | | - return `./texture/pieces/king_checkmate_${piece.color}.png` |
| 405 | + return getAssetUrl(`texture/pieces/king_checkmate_${piece.color}.png`) |
401 | 406 | } |
402 | 407 | if (timeoutWinner.value && piece.color !== timeoutWinner.value) { |
403 | | - return `./texture/pieces/king_checkmate_${piece.color}.png` |
| 408 | + return getAssetUrl(`texture/pieces/king_checkmate_${piece.color}.png`) |
404 | 409 | } |
405 | 410 | if (isCheckmate(board.value, piece.color)) { |
406 | | - return `./texture/pieces/king_checkmate_${piece.color}.png` |
| 411 | + return getAssetUrl(`texture/pieces/king_checkmate_${piece.color}.png`) |
407 | 412 | } |
408 | 413 | if (isKingInCheck(board.value, piece.color)) { |
409 | | - return `./texture/pieces/king_check_${piece.color}.png` |
| 414 | + return getAssetUrl(`texture/pieces/king_check_${piece.color}.png`) |
410 | 415 | } |
411 | 416 | } |
412 | | - return `./texture/pieces/${piece.type}_${piece.color}.png` |
| 417 | + return getAssetUrl(`texture/pieces/${piece.type}_${piece.color}.png`) |
413 | 418 | } |
414 | 419 |
|
415 | 420 | const isGameOver = computed(() => { |
@@ -595,21 +600,21 @@ const applyClockAfterMove = (moverColor: Color, nextTurn: Color, nextBoard: Boar |
595 | 600 |
|
596 | 601 | const getOverlayTexture = (row: number, col: number): string | null => { |
597 | 602 | if (isSelectedSquare(row, col)) { |
598 | | - return './texture/board/board_hover.png' |
| 603 | + return getAssetUrl('texture/board/board_hover.png') |
599 | 604 | } |
600 | 605 |
|
601 | 606 | const move = possibleMoves.value.find((candidate) => candidate.row === row && candidate.col === col) |
602 | 607 |
|
603 | 608 | if (move) { |
604 | 609 | if (isDragging.value && hoverSquare.value?.row === row && hoverSquare.value?.col === col) { |
605 | | - return './texture/board/board_hover.png' |
| 610 | + return getAssetUrl('texture/board/board_hover.png') |
606 | 611 | } |
607 | 612 |
|
608 | 613 | const targetPiece = board.value[row]?.[col] ?? null |
609 | 614 | if (targetPiece !== null) { |
610 | | - return './texture/board/board_capture.png' |
| 615 | + return getAssetUrl('texture/board/board_capture.png') |
611 | 616 | } |
612 | | - return './texture/board/board_placeable.png' |
| 617 | + return getAssetUrl('texture/board/board_placeable.png') |
613 | 618 | } |
614 | 619 |
|
615 | 620 | return null |
|
0 commit comments