From 369e97048a56bda56e47d419f71320a4ce535e1b Mon Sep 17 00:00:00 2001 From: Stefano Pigozzi Date: Tue, 18 Oct 2022 09:31:29 +0000 Subject: [PATCH 1/7] Add support for `CardSet::TheDarkinSaga.to_code` --- src/data/setbundle/set.rs | 1 + 1 file changed, 1 insertion(+) diff --git a/src/data/setbundle/set.rs b/src/data/setbundle/set.rs index 637cfdb..0d8c102 100644 --- a/src/data/setbundle/set.rs +++ b/src/data/setbundle/set.rs @@ -84,6 +84,7 @@ impl CardSet { Self::EmpiresOfTheAscended => Some("04".to_string()), Self::BeyondTheBandlewood => Some("05".to_string()), Self::Worldwalker => Some("06".to_string()), + Self::TheDarkinSaga => Some("06".to_string()), _ => None, } From 11bd4204ddd3e56b76adb4c61c98e5556506c50f Mon Sep 17 00:00:00 2001 From: Stefano Pigozzi Date: Tue, 18 Oct 2022 09:33:26 +0000 Subject: [PATCH 2/7] Remove support for `CardSet::Worldwalker.from_code` 06 is now ambiguous --- src/data/setbundle/set.rs | 1 - 1 file changed, 1 deletion(-) diff --git a/src/data/setbundle/set.rs b/src/data/setbundle/set.rs index 0d8c102..b8ada99 100644 --- a/src/data/setbundle/set.rs +++ b/src/data/setbundle/set.rs @@ -65,7 +65,6 @@ impl CardSet { "03" => Self::CallOfTheMountain, "04" => Self::EmpiresOfTheAscended, "05" => Self::BeyondTheBandlewood, - "06" => Self::Worldwalker, _ => Self::Unsupported, } From e5aa83af96efb0b28adc6407f81f8cc42782062f Mon Sep 17 00:00:00 2001 From: Stefano Pigozzi Date: Tue, 18 Oct 2022 09:35:33 +0000 Subject: [PATCH 3/7] Document the `CardSet::from_code` change --- src/data/setbundle/set.rs | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/data/setbundle/set.rs b/src/data/setbundle/set.rs index b8ada99..b75f3af 100644 --- a/src/data/setbundle/set.rs +++ b/src/data/setbundle/set.rs @@ -55,8 +55,10 @@ impl CardSet { hm.get(self) } - /// Get the [`CardSet`] from its short code, **assuming it is not an [`CardSet::Events`] card**. + /// Get the [`CardSet`] from its short code. /// + /// [`CardSet::Worldwalker`] and [`CardSet::TheDarkinSaga`] share the same code `06`, so a variant cannot be determined. + /// /// [`CardSet::Events`] cards have the short code of the set they were released in, so it is impossible to determine if a card belongs to that set from its short code. pub fn from_code(value: &str) -> Self { match value { From 75279c8ba7714980e97de4b403e586bb38914261 Mon Sep 17 00:00:00 2001 From: Stefano Pigozzi Date: Tue, 18 Oct 2022 09:38:55 +0000 Subject: [PATCH 4/7] Remove support for `CardSet::Worldwalker::from::` 06 is now ambiguous --- src/data/setbundle/set.rs | 1 - 1 file changed, 1 deletion(-) diff --git a/src/data/setbundle/set.rs b/src/data/setbundle/set.rs index b75f3af..6a3ff27 100644 --- a/src/data/setbundle/set.rs +++ b/src/data/setbundle/set.rs @@ -103,7 +103,6 @@ impl From for CardSet { 3 => CardSet::CallOfTheMountain, 4 => CardSet::EmpiresOfTheAscended, 5 => CardSet::BeyondTheBandlewood, - 6 => CardSet::Worldwalker, _ => CardSet::Unsupported, } } From 8978ccd82ed976655e53122a1ea6e64b78846499 Mon Sep 17 00:00:00 2001 From: Stefano Pigozzi Date: Tue, 18 Oct 2022 09:41:14 +0000 Subject: [PATCH 5/7] Allow `u32::try_from::` to work on `CardSet::TheDarkinSaga` --- src/data/setbundle/set.rs | 1 + 1 file changed, 1 insertion(+) diff --git a/src/data/setbundle/set.rs b/src/data/setbundle/set.rs index 6a3ff27..da9d7d3 100644 --- a/src/data/setbundle/set.rs +++ b/src/data/setbundle/set.rs @@ -122,6 +122,7 @@ impl TryFrom for u32 { CardSet::EmpiresOfTheAscended => Ok(4), CardSet::BeyondTheBandlewood => Ok(5), CardSet::Worldwalker => Ok(6), + CardSet::TheDarkinSaga => Ok(6), _ => Err(()), } } From 6c63d36ca3cf4e7080fe4e4c2368c2091357c960 Mon Sep 17 00:00:00 2001 From: Stefano Pigozzi Date: Tue, 18 Oct 2022 09:44:14 +0000 Subject: [PATCH 6/7] Document the `CardSet::from::` changes --- src/data/setbundle/set.rs | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/data/setbundle/set.rs b/src/data/setbundle/set.rs index da9d7d3..5962e88 100644 --- a/src/data/setbundle/set.rs +++ b/src/data/setbundle/set.rs @@ -94,6 +94,8 @@ impl CardSet { /// Get the [`CardSet`] from its internal id. /// +/// [`CardSet::Worldwalker`] and [`CardSet::TheDarkinSaga`] share the same id, so a variant cannot be determined. +/// /// [`CardSet::Events`] cards have the id of the set they were released in, so it is impossible to determine if a card belongs to that set from its id. impl From for CardSet { fn from(value: u32) -> Self { From 1f6e05d419dde77453e257fc015482549de7e0bf Mon Sep 17 00:00:00 2001 From: Stefano Pigozzi Date: Tue, 18 Oct 2022 22:11:41 +0200 Subject: [PATCH 7/7] Do not try to convert "set" deck code portions to `CardSet` variants --- src/data/deckcode/deck.rs | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-) diff --git a/src/data/deckcode/deck.rs b/src/data/deckcode/deck.rs index 34f56aa..e092d28 100644 --- a/src/data/deckcode/deck.rs +++ b/src/data/deckcode/deck.rs @@ -198,9 +198,7 @@ impl Deck { let card_count = reader.read_u32_varint().map_err(DeckDecodingError::Read)?; let set = reader.read_u32_varint().map_err(DeckDecodingError::Read)?; - let set = CardSet::from(set) - .to_code() - .ok_or(DeckDecodingError::UnknownSet)?; + let set = format!("{:02}", &set); let region = reader.read_u32_varint().map_err(DeckDecodingError::Read)?; let region = CardRegion::from(region) @@ -229,8 +227,7 @@ impl Deck { .write_u32_varint(len) .map_err(DeckEncodingError::Write)?; - let set: u32 = CardSet::from_code(set) - .try_into() + let set: u32 = set.parse() .map_err(|_| DeckEncodingError::UnknownSet)?; writer .write_u32_varint(set)