https://github.com/arranf/deck-codes
A Rust library for parsing Hearthstone deck codes
https://github.com/arranf/deck-codes
deck-codes hearthstone
Last synced: 9 months ago
JSON representation
A Rust library for parsing Hearthstone deck codes
- Host: GitHub
- URL: https://github.com/arranf/deck-codes
- Owner: arranf
- Created: 2019-04-07T21:33:59.000Z (about 7 years ago)
- Default Branch: master
- Last Pushed: 2024-11-10T23:50:02.000Z (over 1 year ago)
- Last Synced: 2025-08-22T06:53:46.245Z (10 months ago)
- Topics: deck-codes, hearthstone
- Language: Rust
- Size: 31.3 KB
- Stars: 1
- Watchers: 0
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# deck_codes
[](https://circleci.com/gh/arranf/deck_codes/tree/master)
[](https://crates.io/crates/deck_codes)
A Rust library for encoding and decoding Hearthstone deck codes or deckstrings.
Examples of deck codes can be found [here](https://hearthsim.info/docs/deckstrings/).
Any deckstring or deck definition returned by this library will be canonical.
This means that the cards and heroes are sorted in ascending order by dbf id.
A mapping between dbf ids and cards can be found at [HearthstoneJSON](https://hearthstonejson.com/).
## Usage
```rust
extern deck_codes;
use deck_codes::{decode_deck_code, encode_deck_code, format::Format};
fn main() {
let code = "AAECAf0EBMABobcC3s0Cps4CDXHDAbsClQOrBJYF7AWjtgLXtgLpugKHvQLBwQKYxAIA";
let deck = decode_deck_code(code).expect("Decoded safely");
assert_eq!(deck.format, Format::Standard);
assert_eq!(deck.heroes, vec![637]); // dbfid for Jaina
assert_eq!(deck.total_cards(), 30);
let expected_cards = vec![
// Singles
(1, 192), (1, 39841), (1, 42718), (1, 42790),
// Doubles
(2, 113), (2, 195), (2, 315), (2, 405), (2, 555), (2, 662), (2, 748),
(2, 39715), (2, 39767), (2, 40297), (2, 40583), (2, 41153), (2, 41496)
];
assert_eq!(deck.cards(), expected_cards);
let reverse_code = encode_deck_code(deck);
assert_eq!(code, reverse_code);
}
```