summaryrefslogtreecommitdiff
path: root/frontend/src/components/game/Hand.jsx
blob: 2b8ca19631022e73977c1a47b721520daeea8c03 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
import { Button, ButtonGroup, Classes, Intent } from '@blueprintjs/core';
import React from 'react';
import type { ApiHandCard, ApiPlayerMove } from '../../api/model';
import './Hand.css'

type HandProps = {
  cards: ApiHandCard[],
  wonderUpgradable: boolean,
  prepareMove: (move: ApiPlayerMove) => void
}

export const Hand = ({cards, wonderUpgradable, prepareMove}: HandProps) => {
  return <div className='hand'>{cards.map((c, i) => <HandCard key={i} card={c}
                                                              wonderUpgradable={wonderUpgradable}
                                                              prepareMove={prepareMove}/>)}</div>;
};

type HandCardProps = {
  card: ApiHandCard,
  wonderUpgradable: boolean,
  prepareMove: (move: ApiPlayerMove) => void
}

const HandCard = ({card, wonderUpgradable, prepareMove}: HandCardProps) => {
  let playableClass = card.playability.playable ? '' : 'unplayable';
  return <div className={`hand-card ${playableClass}`}>
    <img src={`/images/cards/${card.image}`}
         title={card.name}
         alt={'Card ' + card.name}
         className="hand-card-img"/>
    <ActionButtons card={card} wonderUpgradable={wonderUpgradable} prepareMove={prepareMove} />
  </div>
};

const ActionButtons = ({card, wonderUpgradable, prepareMove}) => <ButtonGroup className="action-buttons">
  <Button title="PLAY" className={Classes.LARGE} intent={Intent.SUCCESS} icon='play'
          disabled={!card.playability.playable}
          onClick={() => prepareMove({type: 'PLAY', cardName: card.name, boughtResources: []})}/>
  <Button title="BUILD WONDER" className={Classes.LARGE} intent={Intent.PRIMARY} icon='key-shift'
          disabled={!wonderUpgradable}
          onClick={() => prepareMove({type: 'UPGRADE_WONDER', cardName: card.name, boughtResources: []})}/>
  <Button title="DISCARD" className={Classes.LARGE} intent={Intent.DANGER} icon='cross'
          onClick={() => prepareMove({type: 'DISCARD', cardName: card.name, boughtResources: []})}/>
</ButtonGroup>;
bgstack15