use serde::{Deserialize, Serialize};
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash, Serialize, Deserialize)]
pub enum ApiType {
Abandon,
ActivateAbility,
AddOrRemoveCounter,
AddPhase,
AddTurn,
AdvanceCrank,
Airbend,
AlterAttribute,
Amass,
Animate,
AnimateAll,
Attach,
Ascend,
AssembleContraption,
AssignGroup,
Balance,
BecomeMonarch,
BecomesBlocked,
BidLife,
Blight,
Block,
Bond,
Branch,
Camouflage,
ChangeCombatants,
ChangeSpeed,
ChangeTargets,
ChangeText,
ChangeX,
ChangeZone,
ChangeZoneAll,
ChaosEnsues,
Charm,
ChooseCard,
ChooseCardName,
ChooseColor,
ChooseDirection,
ChooseEvenOdd,
ChooseGeneric,
ChooseNumber,
ChoosePlayer,
ChooseSector,
ChooseSource,
ChooseType,
ClaimThePrize,
Clash,
ClassLevelUp,
Cleanup,
Cloak,
Clone,
Connive,
CopyPermanent,
CopySpellAbility,
ControlSpell,
ControlPlayer,
Counter,
CountersMove,
CountersNote,
DamageAll,
DamagePrevent,
DealDamage,
Detain,
DayTime,
Debuff,
DelayedTrigger,
Destroy,
DestroyAll,
Dig,
DigMultiple,
DigUntil,
Discard,
Discover,
DrainMana,
Draft,
Draw,
EachDamage,
Earthbend,
Effect,
Encode,
EndCombatPhase,
EndTurn,
Endure,
ExchangeLife,
ExchangeLifeVariant,
ExchangeControl,
ExchangeControlVariant,
ExchangePower,
ExchangeZone,
ExchangeTextBox,
Explore,
Fight,
FlipACoin,
FlipOntoBattlefield,
Fog,
GainControl,
GainControlVariant,
GainLife,
GainOwnership,
GameDrawn,
GenericChoice,
Goad,
Haunt,
Heist,
Investigate,
Intensify,
ImmediateTrigger,
Incubate,
Learn,
LookAt,
LoseLife,
LosePerpetual,
LosesGame,
MakeCard,
Mana,
ManaReflected,
Manifest,
ManifestDread,
Meld,
Mill,
MoveCounter,
MultiplePiles,
MultiplyCounter,
MustBlock,
Mutate,
NameCard,
OpenAttraction,
PeekAndReveal,
PermanentCreature,
PermanentNoncreature,
Phases,
Planeswalk,
Play,
PlayLandVariant,
Poison,
PreventDamage,
Proliferate,
Protection,
ProtectionAll,
Pump,
PumpAll,
PutCounter,
PutCounterAll,
Radiation,
RearrangeTopOfLibrary,
Regenerate,
Regeneration,
RemoveCounter,
RemoveCounterAll,
RemoveFromCombat,
RemoveFromGame,
RemoveFromMatch,
ReorderZone,
Repeat,
RepeatEach,
ReplaceCounter,
ReplaceEffect,
ReplaceMana,
ReplaceDamage,
ReplaceToken,
ReplaceSplitDamage,
RestartGame,
Reveal,
RevealHand,
ReverseTurnOrder,
RingTemptsYou,
RollDice,
RollPlanarDice,
RunChaos,
Sacrifice,
SacrificeAll,
Scry,
Seek,
SetInMotion,
SetLife,
SetState,
Shuffle,
SkipPhase,
SkipTurn,
StoreSVar,
Subgame,
Surveil,
SwitchBlock,
TakeInitiative,
Tap,
TapAll,
TapOrUntap,
TapOrUntapAll,
TimeTravel,
Token,
TwoPiles,
Unattach,
UnlockDoor,
Untap,
UntapAll,
Venture,
VillainousChoice,
Vote,
WinsGame,
ZoneExchange,
BlankLine,
DamageResolve,
ChangeZoneResolve,
CompanionChoose,
InternalLegendaryRule,
InternalIgnoreEffect,
InternalRadiation,
Plot,
}
impl ApiType {
pub fn smart_value_of(value: &str) -> Option<ApiType> {
let lower = value.to_ascii_lowercase();
ALL_API_TYPES
.iter()
.find(|(name, _)| name.to_ascii_lowercase() == lower)
.map(|(_, api)| *api)
}
pub fn name(&self) -> &'static str {
ALL_API_TYPES
.iter()
.find(|(_, api)| api == self)
.map(|(name, _)| *name)
.unwrap_or("Unknown")
}
}
impl std::fmt::Display for ApiType {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
f.write_str(self.name())
}
}
const ALL_API_TYPES: &[(&str, ApiType)] = &[
("Abandon", ApiType::Abandon),
("ActivateAbility", ApiType::ActivateAbility),
("AddOrRemoveCounter", ApiType::AddOrRemoveCounter),
("AddPhase", ApiType::AddPhase),
("AddTurn", ApiType::AddTurn),
("AdvanceCrank", ApiType::AdvanceCrank),
("Airbend", ApiType::Airbend),
("AlterAttribute", ApiType::AlterAttribute),
("Amass", ApiType::Amass),
("Animate", ApiType::Animate),
("AnimateAll", ApiType::AnimateAll),
("Attach", ApiType::Attach),
("Ascend", ApiType::Ascend),
("AssembleContraption", ApiType::AssembleContraption),
("AssignGroup", ApiType::AssignGroup),
("Balance", ApiType::Balance),
("BecomeMonarch", ApiType::BecomeMonarch),
("BecomesBlocked", ApiType::BecomesBlocked),
("BidLife", ApiType::BidLife),
("Blight", ApiType::Blight),
("Block", ApiType::Block),
("Bond", ApiType::Bond),
("Branch", ApiType::Branch),
("Camouflage", ApiType::Camouflage),
("ChangeCombatants", ApiType::ChangeCombatants),
("ChangeSpeed", ApiType::ChangeSpeed),
("ChangeTargets", ApiType::ChangeTargets),
("ChangeText", ApiType::ChangeText),
("ChangeX", ApiType::ChangeX),
("ChangeZone", ApiType::ChangeZone),
("ChangeZoneAll", ApiType::ChangeZoneAll),
("ChaosEnsues", ApiType::ChaosEnsues),
("Charm", ApiType::Charm),
("ChooseCard", ApiType::ChooseCard),
("ChooseCardName", ApiType::ChooseCardName),
("ChooseColor", ApiType::ChooseColor),
("ChooseDirection", ApiType::ChooseDirection),
("ChooseEvenOdd", ApiType::ChooseEvenOdd),
("ChooseGeneric", ApiType::ChooseGeneric),
("ChooseNumber", ApiType::ChooseNumber),
("ChoosePlayer", ApiType::ChoosePlayer),
("ChooseSector", ApiType::ChooseSector),
("ChooseSource", ApiType::ChooseSource),
("ChooseType", ApiType::ChooseType),
("ClaimThePrize", ApiType::ClaimThePrize),
("Clash", ApiType::Clash),
("ClassLevelUp", ApiType::ClassLevelUp),
("Cleanup", ApiType::Cleanup),
("Cloak", ApiType::Cloak),
("Clone", ApiType::Clone),
("Connive", ApiType::Connive),
("CopyPermanent", ApiType::CopyPermanent),
("CopySpellAbility", ApiType::CopySpellAbility),
("ControlSpell", ApiType::ControlSpell),
("ControlPlayer", ApiType::ControlPlayer),
("Counter", ApiType::Counter),
("CountersMove", ApiType::CountersMove),
("CountersNote", ApiType::CountersNote),
("DamageAll", ApiType::DamageAll),
("DamagePrevent", ApiType::DamagePrevent),
("DealDamage", ApiType::DealDamage),
("Detain", ApiType::Detain),
("DayTime", ApiType::DayTime),
("Debuff", ApiType::Debuff),
("DelayedTrigger", ApiType::DelayedTrigger),
("Destroy", ApiType::Destroy),
("DestroyAll", ApiType::DestroyAll),
("Dig", ApiType::Dig),
("DigMultiple", ApiType::DigMultiple),
("DigUntil", ApiType::DigUntil),
("Discard", ApiType::Discard),
("Discover", ApiType::Discover),
("DrainMana", ApiType::DrainMana),
("Draft", ApiType::Draft),
("Draw", ApiType::Draw),
("EachDamage", ApiType::EachDamage),
("Earthbend", ApiType::Earthbend),
("Effect", ApiType::Effect),
("Encode", ApiType::Encode),
("EndCombatPhase", ApiType::EndCombatPhase),
("EndTurn", ApiType::EndTurn),
("Endure", ApiType::Endure),
("ExchangeLife", ApiType::ExchangeLife),
("ExchangeLifeVariant", ApiType::ExchangeLifeVariant),
("ExchangeControl", ApiType::ExchangeControl),
("ExchangeControlVariant", ApiType::ExchangeControlVariant),
("ExchangePower", ApiType::ExchangePower),
("ExchangeZone", ApiType::ExchangeZone),
("ExchangeTextBox", ApiType::ExchangeTextBox),
("Explore", ApiType::Explore),
("Fight", ApiType::Fight),
("FlipACoin", ApiType::FlipACoin),
("FlipOntoBattlefield", ApiType::FlipOntoBattlefield),
("Fog", ApiType::Fog),
("GainControl", ApiType::GainControl),
("GainControlVariant", ApiType::GainControlVariant),
("GainLife", ApiType::GainLife),
("GainOwnership", ApiType::GainOwnership),
("GameDrawn", ApiType::GameDrawn),
("GenericChoice", ApiType::GenericChoice),
("Goad", ApiType::Goad),
("Haunt", ApiType::Haunt),
("Heist", ApiType::Heist),
("Investigate", ApiType::Investigate),
("Intensify", ApiType::Intensify),
("ImmediateTrigger", ApiType::ImmediateTrigger),
("Incubate", ApiType::Incubate),
("Learn", ApiType::Learn),
("LookAt", ApiType::LookAt),
("LoseLife", ApiType::LoseLife),
("LosePerpetual", ApiType::LosePerpetual),
("LosesGame", ApiType::LosesGame),
("MakeCard", ApiType::MakeCard),
("Mana", ApiType::Mana),
("ManaReflected", ApiType::ManaReflected),
("Manifest", ApiType::Manifest),
("ManifestDread", ApiType::ManifestDread),
("Meld", ApiType::Meld),
("Mill", ApiType::Mill),
("MoveCounter", ApiType::MoveCounter),
("MultiplePiles", ApiType::MultiplePiles),
("MultiplyCounter", ApiType::MultiplyCounter),
("MustBlock", ApiType::MustBlock),
("Mutate", ApiType::Mutate),
("NameCard", ApiType::NameCard),
("OpenAttraction", ApiType::OpenAttraction),
("PeekAndReveal", ApiType::PeekAndReveal),
("PermanentCreature", ApiType::PermanentCreature),
("PermanentNoncreature", ApiType::PermanentNoncreature),
("Phases", ApiType::Phases),
("Planeswalk", ApiType::Planeswalk),
("Play", ApiType::Play),
("PlayLandVariant", ApiType::PlayLandVariant),
("Plot", ApiType::Plot),
("Poison", ApiType::Poison),
("PreventDamage", ApiType::PreventDamage),
("Proliferate", ApiType::Proliferate),
("Protection", ApiType::Protection),
("ProtectionAll", ApiType::ProtectionAll),
("Pump", ApiType::Pump),
("PumpAll", ApiType::PumpAll),
("PutCounter", ApiType::PutCounter),
("PutCounterAll", ApiType::PutCounterAll),
("Radiation", ApiType::Radiation),
("RearrangeTopOfLibrary", ApiType::RearrangeTopOfLibrary),
("Regenerate", ApiType::Regenerate),
("Regeneration", ApiType::Regeneration),
("RemoveCounter", ApiType::RemoveCounter),
("RemoveCounterAll", ApiType::RemoveCounterAll),
("RemoveFromCombat", ApiType::RemoveFromCombat),
("RemoveFromGame", ApiType::RemoveFromGame),
("RemoveFromMatch", ApiType::RemoveFromMatch),
("ReorderZone", ApiType::ReorderZone),
("Repeat", ApiType::Repeat),
("RepeatEach", ApiType::RepeatEach),
("ReplaceCounter", ApiType::ReplaceCounter),
("ReplaceEffect", ApiType::ReplaceEffect),
("ReplaceMana", ApiType::ReplaceMana),
("ReplaceDamage", ApiType::ReplaceDamage),
("ReplaceToken", ApiType::ReplaceToken),
("ReplaceSplitDamage", ApiType::ReplaceSplitDamage),
("RestartGame", ApiType::RestartGame),
("Reveal", ApiType::Reveal),
("RevealHand", ApiType::RevealHand),
("ReverseTurnOrder", ApiType::ReverseTurnOrder),
("RingTemptsYou", ApiType::RingTemptsYou),
("RollDice", ApiType::RollDice),
("RollPlanarDice", ApiType::RollPlanarDice),
("RunChaos", ApiType::RunChaos),
("Sacrifice", ApiType::Sacrifice),
("SacrificeAll", ApiType::SacrificeAll),
("Scry", ApiType::Scry),
("Seek", ApiType::Seek),
("SetInMotion", ApiType::SetInMotion),
("SetLife", ApiType::SetLife),
("SetState", ApiType::SetState),
("Shuffle", ApiType::Shuffle),
("SkipPhase", ApiType::SkipPhase),
("SkipTurn", ApiType::SkipTurn),
("StoreSVar", ApiType::StoreSVar),
("Subgame", ApiType::Subgame),
("Surveil", ApiType::Surveil),
("SwitchBlock", ApiType::SwitchBlock),
("TakeInitiative", ApiType::TakeInitiative),
("Tap", ApiType::Tap),
("TapAll", ApiType::TapAll),
("TapOrUntap", ApiType::TapOrUntap),
("TapOrUntapAll", ApiType::TapOrUntapAll),
("TimeTravel", ApiType::TimeTravel),
("Token", ApiType::Token),
("TwoPiles", ApiType::TwoPiles),
("Unattach", ApiType::Unattach),
("UnlockDoor", ApiType::UnlockDoor),
("Untap", ApiType::Untap),
("UntapAll", ApiType::UntapAll),
("Venture", ApiType::Venture),
("VillainousChoice", ApiType::VillainousChoice),
("Vote", ApiType::Vote),
("WinsGame", ApiType::WinsGame),
("ZoneExchange", ApiType::ZoneExchange),
("BlankLine", ApiType::BlankLine),
("DamageResolve", ApiType::DamageResolve),
("ChangeZoneResolve", ApiType::ChangeZoneResolve),
("CompanionChoose", ApiType::CompanionChoose),
("InternalLegendaryRule", ApiType::InternalLegendaryRule),
("InternalIgnoreEffect", ApiType::InternalIgnoreEffect),
("InternalRadiation", ApiType::InternalRadiation),
("ControlExchange", ApiType::ExchangeControl),
("ControlGain", ApiType::GainControl),
("ControlGainVariant", ApiType::GainControlVariant),
("LifeSet", ApiType::SetLife),
("LifeExchange", ApiType::ExchangeLife),
("LifeExchangeVariant", ApiType::ExchangeLifeVariant),
("GameWin", ApiType::WinsGame),
("GameLoss", ApiType::LosesGame),
("GameDraw", ApiType::GameDrawn),
("RingTempts", ApiType::RingTemptsYou),
("TaporUntapAll", ApiType::TapOrUntapAll),
("CountersMultiply", ApiType::MultiplyCounter),
("CountersRemoveAll", ApiType::RemoveCounterAll),
("CountersPutOrRemove", ApiType::AddOrRemoveCounter),
("PowerExchange", ApiType::ExchangePower),
("TextBoxExchange", ApiType::ExchangeTextBox),
("Replace", ApiType::ReplaceEffect),
];
#[cfg(test)]
mod tests {
use super::*;
#[test]
fn smart_value_of_basic() {
assert_eq!(
ApiType::smart_value_of("DealDamage"),
Some(ApiType::DealDamage)
);
assert_eq!(
ApiType::smart_value_of("dealdamage"),
Some(ApiType::DealDamage)
);
assert_eq!(
ApiType::smart_value_of("DEALDAMAGE"),
Some(ApiType::DealDamage)
);
}
#[test]
fn smart_value_of_unknown() {
assert_eq!(ApiType::smart_value_of("NotAnApi"), None);
}
#[test]
fn name_roundtrip() {
let api = ApiType::GainLife;
assert_eq!(ApiType::smart_value_of(api.name()), Some(api));
}
#[test]
fn alias_resolution() {
assert_eq!(
ApiType::smart_value_of("ControlGain"),
Some(ApiType::GainControl)
);
assert_eq!(ApiType::smart_value_of("LifeSet"), Some(ApiType::SetLife));
assert_eq!(ApiType::smart_value_of("GameWin"), Some(ApiType::WinsGame));
assert_eq!(
ApiType::smart_value_of("RingTempts"),
Some(ApiType::RingTemptsYou)
);
assert_eq!(
ApiType::smart_value_of("TaporUntapAll"),
Some(ApiType::TapOrUntapAll)
);
assert_eq!(
ApiType::smart_value_of("Replace"),
Some(ApiType::ReplaceEffect)
);
}
}