diff --git a/cardsim/card.go b/cardsim/card.go index 9e8f1ed..df5cc07 100644 --- a/cardsim/card.go +++ b/cardsim/card.go @@ -16,6 +16,11 @@ type Card[C StatsCollection] interface { // Options returns the possible actions the player can take for this card. // There must be at least one option. Options(p *Player[C]) ([]CardOption[C], error) + + // Then is invoked after an option is selected and executed. The selected + // option is provided as an argument. This allows cards to do certain + // cleanup for every action -- for example, returning to the deck. + Then(p *Player[C], option CardOption[C]) error } // A CardOption represents a choice a player could make for some card. @@ -35,11 +40,12 @@ type CardOption[C StatsCollection] interface { Enact(p *Player[C]) (Message, error) } -// A BasicCard is a Card with fixed title, text, and options. +// A BasicCard is a Card with fixed title, text, options, and optional post-option callback. type BasicCard[C StatsCollection] struct { CardTitle Message CardText Message CardOptions []CardOption[C] + AfterOption func(p *Player[C], option CardOption[C]) error } func (b *BasicCard[C]) Title(p *Player[C]) (Message, error) { @@ -54,6 +60,13 @@ func (b *BasicCard[C]) Options(_ *Player[C]) ([]CardOption[C], error) { return b.CardOptions, nil } +func (b *BasicCard[C]) Then(p *Player[C], option CardOption[C]) error { + if b.AfterOption == nil { + return nil + } + return b.AfterOption(p, option) +} + // A BasicOption is a CardOption with fixed text, effects, and output. type BasicOption[C StatsCollection] struct { Text Message