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

View File

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