Hide unavailable options on SwitchingCard.

This commit is contained in:
Kistaro Windrider 2023-04-04 20:20:43 -07:00
parent e0dad09045
commit 301d8ae161
Signed by: kistaro
SSH Key Fingerprint: SHA256:TBE2ynfmJqsAf0CP6gsflA0q5X5wD5fVKWPsZ7eVUg8

View File

@ -48,6 +48,11 @@ type SwitchingCard struct {
After func(Card, *Player, CardOption) error After func(Card, *Player, CardOption) error
Policies []Policy Policies []Policy
lastPolicy Policy lastPolicy Policy
// ShowUnavailable controls whether options for which Enabled() = false
// should be presented to the player at all. Indexes for "last enacted"
// still refer to the original list, not the shortened one.
ShowUnavailable bool
} }
// Title implements Card. // Title implements Card.
@ -71,7 +76,7 @@ func (s *SwitchingCard) EventText(*Player) (cardsim.Message, error) {
} }
// Options implements Card. // Options implements Card.
func (s *SwitchingCard) Options(*Player) ([]CardOption, error) { func (s *SwitchingCard) Options(player *Player) ([]CardOption, error) {
lastIdx := -1 lastIdx := -1
for i, p := range s.Policies { for i, p := range s.Policies {
if p.Is(s.lastPolicy) { if p.Is(s.lastPolicy) {
@ -79,10 +84,12 @@ func (s *SwitchingCard) Options(*Player) ([]CardOption, error) {
break break
} }
} }
ret := make([]CardOption, len(s.Policies)) ret := make([]CardOption, 0, len(s.Policies))
for i, p := range s.Policies { for _, p := range s.Policies {
p.LastEnacted(lastIdx, s.lastPolicy) p.LastEnacted(lastIdx, s.lastPolicy)
ret[i] = p if s.ShowUnavailable || p.Enabled(player) {
ret = append(ret, p)
}
} }
return ret, nil return ret, nil
} }