show cards in frontend

This commit is contained in:
Alberto Xamin 2021-06-15 18:10:48 +02:00
parent 8b9f095e4b
commit 46456ed433
No known key found for this signature in database
GPG Key ID: 4F026F48309500A2
6 changed files with 57 additions and 3 deletions

View File

@ -100,6 +100,7 @@ def get_me(sid, room):
de_games[0].notify_event_card(sid)
de_games[0].notify_scrap_pile(sid)
de_games[0].notify_all()
de_games[0].notify_gold_rush_shop()
de_games[0].notify_event_card()
else:
create_room(sid, room['name'])

View File

@ -36,10 +36,12 @@ class Deck:
self.event_cards.append(random.choice(endgame_cards))
random.shuffle(self.cards)
self.shop_deck = []
self.shop_cards = []
if 'gold_rush' in game.expansions:
import bang.expansions.gold_rush.shop_cards as gr
self.shop_cards = [None, None, None]
self.shop_deck = gr.get_cards()
random.shuffle(self.shop_deck)
self.fill_gold_rush_shop()
self.scrap_pile: List[cs.Card] = []
print(f'Deck initialized with {len(self.cards)} cards')
@ -48,6 +50,14 @@ class Deck:
self.event_cards.append(self.event_cards.pop(0))
self.game.notify_event_card()
def fill_gold_rush_shop(self):
if not any([c == None for c in self.shop_cards]):
return
for i in range(3):
if self.shop_cards[i] == None:
self.shop_cards[i] = self.shop_deck.pop(0)
self.game.notify_gold_rush_shop()
def peek(self, n_cards: int) -> list:
return self.cards[:n_cards]

View File

@ -6,7 +6,7 @@ class ShopCardKind(IntEnum):
class ShopCard(Card):
def __init__(self, name:str, cost:int, kind:ShopCardKind):
super().__init__('💵', cost, name=name)
super().__init__(suit='💵', number=cost, name=name)
self.kind = kind
def play_card(self, player, against, _with=None):

View File

@ -27,7 +27,7 @@ class Game:
self.initial_players = 0
self.password = ''
self.expansions = []
self.available_expansions = ['dodge_city', 'fistful_of_cards', 'high_noon']
self.available_expansions = ['dodge_city', 'fistful_of_cards', 'high_noon', 'gold_rush']
self.shutting_down = False
self.is_competitive = False
self.disconnect_bot = True
@ -159,6 +159,8 @@ class Game:
self.initial_players = len(self.players)
self.distribute_roles()
self.choose_characters()
if 'gold_rush' in self.expansions:
self.notify_gold_rush_shop()
def distribute_roles(self):
available_roles: List[roles.Role] = []
@ -430,6 +432,12 @@ class Game:
else:
self.sio.emit('event_card', room=room, data=None)
def notify_gold_rush_shop(self, sid=None):
if 'gold_rush' in self.expansions and self.deck and self.deck.shop_cards and len(self.deck.shop_cards) > 0:
room = self.name if sid == None else sid
print(f'gold_rush_shop room={room}, data={self.deck.shop_cards}')
self.sio.emit('gold_rush_shop', room=room, data=json.dumps(self.deck.shop_cards, default=lambda o: o.__dict__))
def notify_scrap_pile(self, sid=None):
print('scrap')
room = self.name if sid == None else sid

View File

@ -27,6 +27,8 @@ export default {
if (this.card && !isNaN(this.card.suit)) {
let x = ['♦️','♣️','♥️','♠️']
return x[this.card.suit];
} else if (this.card.suit) {
return this.card.suit;
}
return '';
},
@ -107,6 +109,17 @@ export default {
);
border: 2pt solid rgb(50 122 172);
}
.card.brown.gold-rush {
box-shadow: 0 0 0pt 4pt var(--bg-color), 0 0 5pt 4pt #aaa;
border: 2pt dotted #9C7340;
}
.card.black.gold-rush {
box-shadow: 0 0 0pt 4pt var(--bg-color), 0 0 5pt 4pt #aaa;
border: 2pt dotted #000;
}
.card.back.gold-rush {
background: repeating-linear-gradient(347deg, #ffb32f, #987e51 );
}
.card h4 {
position: absolute;
text-align: center;

View File

@ -2,6 +2,14 @@
<div>
<div class="deck">
<card v-if="endTurnAction && isPlaying" :donotlocalize="true" v-show="pending_action == 2" :card="endTurnCard" class="end-turn" @click.native="endTurnAction"/>
<card v-if="goldRushShopOpen && goldRushCards.length > 0" :key="goldRushCards[0].name" :card="goldRushCards[0]" :class="{'gold-rush':true, 'brown':goldRushCards[0].kind === 0, 'black':goldRushCards[0].kind === 1}"/>
<card v-if="goldRushShopOpen && goldRushCards.length > 1" :key="goldRushCards[1].name" :card="goldRushCards[1]" :class="{'gold-rush':true, 'brown':goldRushCards[1].kind === 0, 'black':goldRushCards[1].kind === 1}"/>
<card v-if="goldRushShopOpen && goldRushCards.length > 2" :key="goldRushCards[2].name" :card="goldRushCards[2]" :class="{'gold-rush':true, 'brown':goldRushCards[2].kind === 0, 'black':goldRushCards[2].kind === 1}"/>
<div style="position:relative">
<div class="card gold-rush back" style="position:relative; bottom:-3pt;right:-3pt;"/>
<div class="card gold-rush back" style="position:absolute; bottom:-1.5pt;right:-1.5pt;"/>
<card :card="goldRushCardBack" :donotlocalize="true" class="gold-rush back last-event" @click.native="goldRushShopOpen = !goldRushShopOpen"/>
</div>
<div v-if="eventCard" style="position:relative">
<div class="card fistful-of-cards" style="position:relative; bottom:-3pt;right:-3pt;"/>
<div class="card fistful-of-cards" style="position:absolute; bottom:-1.5pt;right:-1.5pt;"/>
@ -44,12 +52,18 @@ export default {
name: 'PewPew!',
icon: '💥',
},
goldRushCardBack: {
name: 'GoldRush!',
icon: '🤑️',
},
lastScrap: null,
eventCard: null,
previousScrap: null,
pending_action: false,
isPlaying: true,
desc: '',
goldRushShopOpen: true,
goldRushCards: [],
}),
sockets: {
self(self){
@ -68,6 +82,10 @@ export default {
expansion: 'fistful-of-cards',
} : card
},
gold_rush_shop(cards) {
console.log('GOLD RUSH:'+ cards)
this.goldRushCards = JSON.parse(cards)
},
},
computed: {
endTurnCard() {
@ -140,6 +158,10 @@ export default {
opacity: 0.8;
transform: translateY(-10px);
}
.gold-rush:not(.back) {
animation-duration: 0.8s;
animation-name: slidein;
}
@keyframes slidein {
from {
transform: translate(-100px, 10px) scale(1.3) rotate(-10deg);