Hide unavailable options on SwitchingCard.
This commit is contained in:
parent
e0dad09045
commit
301d8ae161
@ -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
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user