1
0
mirror of https://github.com/danbee/chess synced 2025-03-04 08:39:06 +00:00

Render the pieces with background images

This commit is contained in:
Daniel Barber 2016-11-14 21:45:47 +00:00
parent 5976901d18
commit 04a91e994c
Signed by: danbarber
GPG Key ID: 931D8112E0103DD8
2 changed files with 21 additions and 15 deletions

View File

@ -1,20 +1,17 @@
<template> <template>
<div class="board-square"> <div class="board-square" :class="classes(piece)">
<img v-if="piece != null" :src="pieceImage(piece)">
</div> </div>
</template> </template>
<script> <script>
export default { export default {
methods: { methods: {
pieceImage: (piece) => { classes: (piece) => {
return "/images/" if (piece != null) {
+ piece.type return [piece.type, piece.colour];
+ "_"
+ piece.colour
+ ".svg";
} }
}, },
},
props: ["piece"] props: ["piece"]
}; };

View File

@ -10,6 +10,9 @@ $white-square-color: #d0bfa1;
$square-outline-color: darken($black-square-color, 20%); $square-outline-color: darken($black-square-color, 20%);
$colours: black white;
$pieces: king queen bishop knight rook pawn;
.board { .board {
display: inline-block; display: inline-block;
font-size: 0; font-size: 0;
@ -24,19 +27,25 @@ $square-outline-color: darken($black-square-color, 20%);
width: $board-square-size; width: $board-square-size;
height: $board-square-size; height: $board-square-size;
img { background-size: 100%;
position: absolute; background-repeat: no-repeat;
margin: 0; background-position: center;
width: $board-square-size;
@each $colour in $colours {
@each $piece in $pieces {
&.#{$colour}.#{$piece} {
background-image: url(/images/#{$piece}_#{$colour}.svg);
}
}
} }
} }
%black-square { %black-square {
background: $black-square-color; background-color: $black-square-color;
} }
%white-square { %white-square {
background: $white-square-color; background-color: $white-square-color;
} }
.board-row:nth-child(odd) { .board-row:nth-child(odd) {