forked from johreh/gloomycompanion
-
Notifications
You must be signed in to change notification settings - Fork 1
/
ModifierDeck.jsx
101 lines (92 loc) · 3.49 KB
/
ModifierDeck.jsx
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
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
import classNames from 'classnames';
import PropTypes from 'prop-types';
import React from 'react';
import ButtonDiv from './ButtonDiv';
import Card from './Card';
import ModifierCardCounter from './ModifierCardCounter';
import ModifierCardFront from './ModifierCardFront';
import ModifierDeckState from './ModifierDeckState';
import * as CardCss from './style/Card.scss';
import * as css from './style/ModifierDeck.scss';
function ShuffleIndicator(props) {
const classes = classNames(css.counterIcon, css.shuffle, {
[css.notRequired]: !props.needsShuffled,
});
return <ButtonDiv className={classes} onClick={props.onClick} />;
}
ShuffleIndicator.propTypes = {
needsShuffled: PropTypes.bool.isRequired,
onClick: PropTypes.func.isRequired,
};
export default function ModifierDeck(props) {
const renderCard = (card, zIndex, cardClasses, faceUp) => (
<Card
key={card.id}
classes={cardClasses}
deckType="modifier"
faceUp={faceUp}
zIndex={zIndex}
renderBack={() => null}
renderFront={() => (
<ModifierCardFront image={card.card_image} />
)}
/>
);
let deckElement;
const [topDraw] = props.deckState.draw_pile;
const [topDiscard, sndDiscard, thdDiscard] = props.deckState.discard;
if (props.deckState.advantage_card == null) {
deckElement = (
<ButtonDiv className={classNames(CardCss.cardContainer, CardCss.modifier)} onClick={props.onDrawClick}>
{topDraw ? renderCard(topDraw, -7, [CardCss.draw], false) : null}
{topDiscard ? renderCard(topDiscard, -3, [CardCss.discard, CardCss.pull], true) : null}
{sndDiscard ? renderCard(sndDiscard, -4, [CardCss.discard, CardCss.lift], true) : null}
</ButtonDiv>
);
} else {
deckElement = (
<ButtonDiv className={classNames(CardCss.cardContainer, CardCss.modifier)} onClick={props.onDrawClick}>
{topDraw ? renderCard(topDraw, -7, [CardCss.draw], false) : null}
{renderCard(topDiscard, -3, [CardCss.discard, CardCss.pull, CardCss.right], true)}
{renderCard(sndDiscard, -3, [CardCss.discard, CardCss.pull, CardCss.left], true)}
{thdDiscard ? renderCard(thdDiscard, -4, [CardCss.discard, CardCss.lift], true) : null}
</ButtonDiv>
);
}
const style = { display: props.hidden ? 'none' : 'block' };
return (
<div className={CardCss.cardContainer} style={style}>
<div className={css.modifierDeckColumn2}>
{deckElement}
<ButtonDiv className={`${css.button} ${css.drawTwo}`} onClick={props.onDoubleDrawClick} />
</div>
<div className={css.modifierDeckColumn1}>
<ModifierCardCounter
deckState={props.deckState}
modifierType="bless"
addSpecial={props.onAddSpecialClick}
removeSpecial={props.onRemoveSpecialClick}
/>
<ModifierCardCounter
deckState={props.deckState}
modifierType="curse"
addSpecial={props.onAddSpecialClick}
removeSpecial={props.onRemoveSpecialClick}
/>
<ShuffleIndicator
needsShuffled={props.deckState.needs_shuffled}
onClick={props.onEndRoundClick}
/>
</div>
</div>
);
}
ModifierDeck.propTypes = {
deckState: PropTypes.instanceOf(ModifierDeckState).isRequired,
hidden: PropTypes.bool.isRequired,
onDrawClick: PropTypes.func.isRequired,
onDoubleDrawClick: PropTypes.func.isRequired,
onEndRoundClick: PropTypes.func.isRequired,
onAddSpecialClick: PropTypes.func.isRequired,
onRemoveSpecialClick: PropTypes.func.isRequired,
};