From 4f08874c9a24052edef2ebd3c11e456e3e187ea3 Mon Sep 17 00:00:00 2001 From: Alberto Xamin Date: Wed, 25 Jan 2023 18:33:57 +0000 Subject: [PATCH] add animations for cards against someone --- backend/bang/cards.py | 1 + frontend/src/components/AnimatedCard.vue | 19 +++++++++++--- frontend/src/components/Lobby.vue | 32 +++++++++++++++++++----- 3 files changed, 42 insertions(+), 10 deletions(-) diff --git a/backend/bang/cards.py b/backend/bang/cards.py index e776404..4fdf07e 100644 --- a/backend/bang/cards.py +++ b/backend/bang/cards.py @@ -85,6 +85,7 @@ class Card(ABC): player.equipment.append(self) self.can_be_used_now = False if against: + G.sio.emit('card_against', room=player.game.name, data={'player': player.name, 'target': against, 'card': self.__dict__}) G.sio.emit('chat_message', room=player.game.name, data=f'_play_card_against|{player.name}|{self.name}|{against}') else: diff --git a/frontend/src/components/AnimatedCard.vue b/frontend/src/components/AnimatedCard.vue index 9838935..fba04c1 100644 --- a/frontend/src/components/AnimatedCard.vue +++ b/frontend/src/components/AnimatedCard.vue @@ -13,6 +13,7 @@ export default { props: { card: Object, startPosition: Object, + midPosition: Object, endPosition: Object, }, data: () => ({ @@ -24,12 +25,22 @@ export default { }, mounted() { this.style = `position: absolute;top:${this.startPosition.top}px;left: ${this.startPosition.left}px` - setTimeout(() => { - this.style = `position: absolute;top:${this.endPosition.top}px;left: ${this.endPosition.left}px;transform: scale(0.5);` - }, 200) + if (this.midPosition) { + setTimeout(() => { + this.style = `position: absolute;top:${this.midPosition.top}px;left: ${this.midPosition.left}px;transform: scale(0.5);` + }, 200) + setTimeout(() => { + this.style = `position: absolute;top:${this.endPosition.top}px;left: ${this.endPosition.left}px;transform: scale(0.5);` + }, 800) + } + else { + setTimeout(() => { + this.style = `position: absolute;top:${this.endPosition.top}px;left: ${this.endPosition.left}px;transform: scale(0.5);` + }, 200) + } setTimeout(() => { this.style = `display:none;` - }, 800) + }, this.midPosition ? 1600 : 800) } } diff --git a/frontend/src/components/Lobby.vue b/frontend/src/components/Lobby.vue index d205834..2c29f19 100644 --- a/frontend/src/components/Lobby.vue +++ b/frontend/src/components/Lobby.vue @@ -74,7 +74,7 @@ - +
@@ -233,8 +233,9 @@ export default { let playerOffset = cumulativeOffset(phand) playerOffset.top -= 30 playerOffset.left += 10 + let key = Math.random() this.cardsToAnimate.push({ - key: Math.random(), + key: key, card: { name: 'PewPew!', icon: '💥', @@ -242,9 +243,27 @@ export default { }, startPosition: decelOffset, endPosition: playerOffset }) setTimeout(() => { - this.cardsToAnimate.shift() + this.cardsToAnimate = this.cardsToAnimate.filter(x => x.key !== key) }, 900); }, + card_against(data) { + let target = document.getElementById(`${data.target}-hand`) + let targetOffset = cumulativeOffset(target.parentElement) + let decel = document.getElementById('actual-scrap') + let decelOffset = cumulativeOffset(decel) + let phand = document.getElementById(`${data.player}-hand`) + let playerOffset = cumulativeOffset(phand) + playerOffset.top -= 30 + playerOffset.left += 10 + let key = data.card.name+data.card.number+data.player + this.cardsToAnimate.push({ + key: key, + card: data.card, startPosition: playerOffset, midPosition: targetOffset, endPosition: decelOffset + }) + setTimeout(() => { + this.cardsToAnimate = this.cardsToAnimate.filter(x => x.key !== key) + }, 1800); + }, card_scrapped(data) { let decel = document.getElementById('actual-scrap') if (!decel) { @@ -260,13 +279,14 @@ export default { let playerOffset = cumulativeOffset(phand) playerOffset.top -= 30 playerOffset.left += 10 - console.log('card_scrapped'+decelOffset + ' '+ playerOffset) + console.log('card_scrapped' + decelOffset + ' ' + playerOffset) + let key = data.card.name+data.card.number+data.player this.cardsToAnimate.push({ - key: data.card.name+data.card.number+data.player, + key: key, card: data.card, startPosition: playerOffset, endPosition: decelOffset }) setTimeout(() => { - this.cardsToAnimate.shift() + this.cardsToAnimate = this.cardsToAnimate.filter(x => x.key !== key) }, 900); }, mount_status() {