Skip to content

Commit 14c30fb

Browse files
committed
feat: add suit order gamma
1 parent 9c0699e commit 14c30fb

File tree

6 files changed

+42
-18
lines changed

6 files changed

+42
-18
lines changed

src/components/CreateLobby.tsx

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import {
2+
Badge,
23
Button,
34
Modal,
45
ModalBody,
@@ -52,7 +53,10 @@ export default function CreateLobby({ closeToast }: Props) {
5253
me={2}
5354
onClick={onClick}
5455
>
55-
Create lobby
56+
Create lobby{' '}
57+
<Badge variant="solid" bgColor="blue.300" ms={1} py={1} rounded="md">
58+
🎉 New 🎉
59+
</Badge>
5660
</Button>
5761

5862
<Modal isOpen={isOpen} onClose={onClose} isCentered size="lg">

src/components/LobbyForm.tsx

Lines changed: 26 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
import Rules, { ALL_RULES, describe, rulesToArray } from '@big-two/Rules';
2+
import { SUIT_RANKING_ORDERS } from '@big-two/Util';
23
import {
4+
Badge,
35
Box,
46
Checkbox,
57
CheckboxGroup,
@@ -69,11 +71,23 @@ export default function LobbyForm({ game, submitForm }: Props) {
6971
colorScheme="purple"
7072
>
7173
<VStack alignItems="start">
72-
{ALL_RULES.slice(0, 2).map((suit_order) => (
73-
<Radio key={suit_order} value={`${suit_order}`}>
74-
{describe(suit_order)}
75-
</Radio>
76-
))}
74+
{ALL_RULES.slice(0, Object.keys(SUIT_RANKING_ORDERS).length).map(
75+
(suit_order) => (
76+
<Radio key={suit_order} value={`${suit_order}`}>
77+
{describe(suit_order)}
78+
{suit_order === Rules.SUIT_ORDER_GAMMA && (
79+
<Badge
80+
variant="solid"
81+
bgColor="blue.300"
82+
ms={2}
83+
rounded="md"
84+
>
85+
🎉 New 🎉
86+
</Badge>
87+
)}
88+
</Radio>
89+
),
90+
)}
7791
</VStack>
7892
</RadioGroup>
7993

@@ -85,11 +99,13 @@ export default function LobbyForm({ game, submitForm }: Props) {
8599
colorScheme="green"
86100
>
87101
<VStack alignItems="start">
88-
{ALL_RULES.slice(2).map((rule) => (
89-
<Checkbox key={rule} value={rule}>
90-
{describe(rule)}
91-
</Checkbox>
92-
))}
102+
{ALL_RULES.slice(Object.keys(SUIT_RANKING_ORDERS).length).map(
103+
(rule) => (
104+
<Checkbox key={rule} value={rule}>
105+
{describe(rule)}
106+
</Checkbox>
107+
),
108+
)}
93109
</VStack>
94110
</CheckboxGroup>
95111
</FormControl>

src/components/Version.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ export default function Version(props: TextProps) {
1616
href="https://github.com/AdoryVo/big-two/blob/main/CHANGELOG.md"
1717
isExternal
1818
>
19-
v1.2.1
19+
v1.2.2
2020
</Link>
2121
</Text>
2222
</Tooltip>

src/lib/big-two/Rules.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ enum Rules {
22
// Suit ordering
33
SUIT_ORDER_ALPHA = 1,
44
SUIT_ORDER_BETA = 0,
5+
SUIT_ORDER_GAMMA = 1 << 6,
56

67
// Straights
78
STRAIGHTS_WRAP_AROUND = 1 << 1,
@@ -25,6 +26,7 @@ enum Rules {
2526
export const ALL_RULES = [
2627
Rules.SUIT_ORDER_ALPHA,
2728
Rules.SUIT_ORDER_BETA,
29+
Rules.SUIT_ORDER_GAMMA,
2830
Rules.STRAIGHTS_WRAP_AROUND,
2931
Rules.STRAIGHTS_ALLOW_RUNS,
3032
Rules.CAN_PLAY_AFTER_PASS,
@@ -37,7 +39,9 @@ export function describe(rule: Rules) {
3739
case Rules.SUIT_ORDER_ALPHA:
3840
return 'Suit order alpha (clubs < diamonds < hearts < spades)';
3941
case Rules.SUIT_ORDER_BETA:
40-
return 'Suit order Tiến (spades < clubs < diamonds < hearts)';
42+
return 'Suit order beta [Tiến] (spades < clubs < diamonds < hearts)';
43+
case Rules.SUIT_ORDER_GAMMA:
44+
return 'Suit order gamma [Hong Kong] (diamonds < clubs < hearts < spades)';
4145
case Rules.STRAIGHTS_WRAP_AROUND:
4246
return 'Straights wrap around';
4347
case Rules.STRAIGHTS_ALLOW_RUNS:

src/lib/big-two/Util.ts

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,10 @@ import Rules from './Rules';
88

99
export const CARD_STRING_SEPARATOR = ';'; // "2;clubs"
1010

11-
const SUIT_RANKING_ORDERS = {
11+
export const SUIT_RANKING_ORDERS = {
1212
[Rules.SUIT_ORDER_ALPHA]: ['clubs', 'diamonds', 'hearts', 'spades'],
1313
[Rules.SUIT_ORDER_BETA]: ['spades', 'clubs', 'diamonds', 'hearts'],
14+
[Rules.SUIT_ORDER_GAMMA]: ['diamonds', 'clubs', 'hearts', 'spades'],
1415
};
1516

1617
const RANK_ABBR_TO_NAME: { [key: string]: string } = {
@@ -55,7 +56,9 @@ class Util {
5556
const suit = card.suit.name;
5657
if (this.rules & Rules.SUIT_ORDER_ALPHA)
5758
return SUIT_RANKING_ORDERS[Rules.SUIT_ORDER_ALPHA].indexOf(suit);
58-
else return SUIT_RANKING_ORDERS[Rules.SUIT_ORDER_BETA].indexOf(suit);
59+
else if (this.rules & Rules.SUIT_ORDER_BETA)
60+
return SUIT_RANKING_ORDERS[Rules.SUIT_ORDER_BETA].indexOf(suit);
61+
else return SUIT_RANKING_ORDERS[Rules.SUIT_ORDER_GAMMA].indexOf(suit);
5962
}
6063

6164
compare_cards(c1: Card, c2: Card) {

src/pages/index.tsx

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -122,9 +122,6 @@ export default function Home() {
122122
<Box>
123123
<NextLink href={'/game/singleplayer'} passHref>
124124
<Button colorScheme="blue" onClick={() => toast.closeAll()}>
125-
<Text fontSize="sm" fontFamily="cursive" color="pink.100">
126-
🎉NEW🎉
127-
</Text>{' '}
128125
Singleplayer mode 🤖
129126
</Button>
130127
</NextLink>

0 commit comments

Comments
 (0)