Skip to content

Commit

Permalink
Merge pull request #19 from edumudu/feature/#18
Browse files Browse the repository at this point in the history
#18 put loading svg
  • Loading branch information
edumudu authored Jul 13, 2020
2 parents 04788d9 + 567a366 commit ed26da3
Show file tree
Hide file tree
Showing 6 changed files with 32 additions and 8 deletions.
1 change: 1 addition & 0 deletions client/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
"html-webpack-plugin": "^3.2.0",
"socket.io-client": "^2.3.0",
"style-loader": "^0.23.1",
"svg-inline-loader": "^0.8.2",
"webpack": "^4.29.3",
"webpack-cli": "^3.2.3",
"webpack-dev-server": "^3.1.14"
Expand Down
14 changes: 14 additions & 0 deletions client/src/assets/svgs/loader.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
3 changes: 2 additions & 1 deletion client/src/js/Modal.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,9 +30,10 @@ class Modal {
this.hide();
}

show() {
show(bg = 'rgba(0,0,0,0.7)') {
this.#visible = true;
this.#overlay.style.display = 'flex';
this.#overlay.style.backgroundColor = bg
}

hide() {
Expand Down
14 changes: 9 additions & 5 deletions client/src/js/main.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import '../scss/app.scss';
import loaderSvg from '../assets/svgs/loader.svg';
import '@fortawesome/fontawesome-free/js/all';
import Board from './Game/Board';
import Modal from './Modal';
Expand All @@ -13,23 +14,25 @@ let room;

menu.setAction('<i class="fas fa-play"></i>', () => {
socket.emit('room');
menu.setTitle('Waiting for other player')
menu.setTitle('Waiting for other player');
menu.setContent(loaderSvg);
menu.disableAction(0);
});
menu.show();

menu.show('black');

modal.setAction('<i class="fas fa-undo-alt"></i>', () => {
socket.emit('room', room);
modal.hide();
menu.show();
menu.show('black');
game.destroy();
}, 'success', 'Rematch');

modal.setAction('<i class="fas fa-play"></i>', () => {
socket.emit('player-left');
socket.emit('room');
modal.hide();
menu.show();
menu.show('black');
game.destroy();
}, '', 'New game');

Expand All @@ -38,13 +41,14 @@ socket.on('start-game', (board, playerRoom) => {
game = new Board(el, board, socket.id);
game.setPlayerTurn(board.playerOfTheTime);
menu.hide();
menu.setContent('');

socket.on('enemy-left', () => {
game.destroy();
modal.hide();
menu.setTitle('Enemy left the room');
menu.enableAction(0);
menu.show();
menu.show('black');
})

socket.on('check', ids => {
Expand Down
3 changes: 1 addition & 2 deletions client/src/scss/modal.scss
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
align-items: center;
width: 100%;
height: 100%;
background-color: rgba(0,0,0,0.7);

.modal {
padding: 20px 30px;
Expand All @@ -18,7 +17,7 @@

.title {
color: #fff;
font-size: 4rem;
font-size: clamp(2rem, 10vw, 4rem);
text-align: center;
}

Expand Down
5 changes: 5 additions & 0 deletions client/webpack.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,11 @@ module.exports = {
test: /\.(wav|mp3)$/,
use: ['file-loader']
},
{
exclude: /node_modules/,
test: /\.svg$/,
loader: 'svg-inline-loader'
}
]
},
output: {
Expand Down

0 comments on commit ed26da3

Please sign in to comment.