Skip to content

Commit 1e951f3

Browse files
committed
fix(v1.3.1): prevent multiple suit order rules from being enabled
1 parent 98c32fe commit 1e951f3

File tree

6 files changed

+28
-15
lines changed

6 files changed

+28
-15
lines changed

CHANGELOG.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,12 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
1414
- Improved bot skill
1515
- More to come soon!
1616

17+
## [1.3.1] - 2025-10-05
18+
19+
### Changed
20+
21+
- Bugfix: Refactored suit order editing logic to prevent having multiple suit order rules enabled
22+
1723
## [1.3.0] - 2025-10-02
1824

1925
### Added
@@ -98,6 +104,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
98104
- All existing functionality as of 10-22-2023
99105

100106
[unreleased]: https://github.com/AdoryVo/big-two/compare/v1.1.0...HEAD
107+
[1.3.1]: https://github.com/AdoryVo/big-two/releases/tag/v1.3.1
101108
[1.3.0]: https://github.com/AdoryVo/big-two/releases/tag/v1.3.0
102109
[1.2.1]: https://github.com/AdoryVo/big-two/releases/tag/v1.2.1
103110
[1.2.0]: https://github.com/AdoryVo/big-two/releases/tag/v1.2.0

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "big-two",
3-
"version": "1.3.0",
3+
"version": "1.3.1",
44
"private": true,
55
"scripts": {
66
"dev": "next dev",

src/components/LobbyForm.tsx

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -28,20 +28,29 @@ interface Props {
2828
submitForm: (body: object) => void;
2929
}
3030

31+
const SUIT_ORDER_BITS = sum(
32+
// Note: Don't directly pass in parseInt as the map() function
33+
// to prevent passing in `index` to the `radix` argument.
34+
Object.keys(SUIT_RANKING_ORDERS).map((bitAsStr) => Number.parseInt(bitAsStr)),
35+
);
36+
3137
export default function LobbyForm({ game, submitForm }: Props) {
3238
const defaults = game?.settings ?? {
33-
rules: Rules.DEFAULT,
39+
// In this form, suit order is tracked separately than other rules.
40+
rules: Rules.DEFAULT & ~SUIT_ORDER_BITS,
3441
public: false,
3542
spectating: true,
3643
playerMax: 4,
3744
deckCount: 1,
3845
};
3946

47+
// Capture existing suit order or default to alpha.
4048
const [suitOrder, setSuitOrder] = useState(
41-
`${defaults.rules & Rules.SUIT_ORDER_ALPHA}`,
49+
`${defaults.rules & SUIT_ORDER_BITS || Rules.SUIT_ORDER_ALPHA}`,
4250
);
51+
// In this form, suit order is tracked separately than other rules.
4352
const [rules, setRules] = useState<number[]>(
44-
rulesToArray(defaults.rules & ~Rules.SUIT_ORDER_ALPHA),
53+
rulesToArray(defaults.rules & ~SUIT_ORDER_BITS),
4554
);
4655

4756
const formik = useFormik({

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.3.0
19+
v1.3.1
2020
</Link>
2121
</Text>
2222
</Tooltip>

src/lib/big-two/Rules.ts

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
enum Rules {
22
// Suit ordering
33
SUIT_ORDER_ALPHA = 1,
4-
SUIT_ORDER_BETA = 0,
4+
SUIT_ORDER_BETA = 1 << 7,
55
SUIT_ORDER_GAMMA = 1 << 6,
66

77
// Straights
@@ -58,11 +58,7 @@ export function describe(rule: Rules) {
5858
}
5959

6060
export function rulesToArray(rules: number) {
61-
const array = ALL_RULES.filter((rule) => rules & rule);
62-
if (!(rules & Rules.SUIT_ORDER_ALPHA)) {
63-
array.unshift(0);
64-
}
65-
return array;
61+
return ALL_RULES.filter((rule) => rules & rule);
6662
}
6763

6864
export default Rules;

src/lib/big-two/Util.ts

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -54,11 +54,12 @@ class Util {
5454

5555
_suit_val(card: Card) {
5656
const suit = card.suit.name;
57-
if (this.rules & Rules.SUIT_ORDER_ALPHA)
58-
return SUIT_RANKING_ORDERS[Rules.SUIT_ORDER_ALPHA].indexOf(suit);
59-
else if (this.rules & Rules.SUIT_ORDER_BETA)
57+
if (this.rules & Rules.SUIT_ORDER_BETA)
6058
return SUIT_RANKING_ORDERS[Rules.SUIT_ORDER_BETA].indexOf(suit);
61-
else return SUIT_RANKING_ORDERS[Rules.SUIT_ORDER_GAMMA].indexOf(suit);
59+
else if (this.rules & Rules.SUIT_ORDER_GAMMA)
60+
return SUIT_RANKING_ORDERS[Rules.SUIT_ORDER_GAMMA].indexOf(suit);
61+
// Default to suit order alpha.
62+
else return SUIT_RANKING_ORDERS[Rules.SUIT_ORDER_ALPHA].indexOf(suit);
6263
}
6364

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

0 commit comments

Comments
 (0)