From 301d8ae161634259edfe212aa2c8c7e8f1344e9f Mon Sep 17 00:00:00 2001 From: Kistaro Windrider Date: Tue, 4 Apr 2023 20:20:43 -0700 Subject: [PATCH] Hide unavailable options on SwitchingCard. --- koboldsim/cardtypes.go | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) diff --git a/koboldsim/cardtypes.go b/koboldsim/cardtypes.go index e20d151..d2b04d0 100644 --- a/koboldsim/cardtypes.go +++ b/koboldsim/cardtypes.go @@ -48,6 +48,11 @@ type SwitchingCard struct { After func(Card, *Player, CardOption) error Policies []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. @@ -71,7 +76,7 @@ func (s *SwitchingCard) EventText(*Player) (cardsim.Message, error) { } // Options implements Card. -func (s *SwitchingCard) Options(*Player) ([]CardOption, error) { +func (s *SwitchingCard) Options(player *Player) ([]CardOption, error) { lastIdx := -1 for i, p := range s.Policies { if p.Is(s.lastPolicy) { @@ -79,10 +84,12 @@ func (s *SwitchingCard) Options(*Player) ([]CardOption, error) { break } } - ret := make([]CardOption, len(s.Policies)) - for i, p := range s.Policies { + ret := make([]CardOption, 0, len(s.Policies)) + for _, p := range s.Policies { p.LastEnacted(lastIdx, s.lastPolicy) - ret[i] = p + if s.ShowUnavailable || p.Enabled(player) { + ret = append(ret, p) + } } return ret, nil }