Implement standard debuggers.
These debug actions are added to all players by default.
This commit is contained in:
@ -101,6 +101,54 @@ func (b *BasicCard[C]) Drawn(_ *Player[C]) bool {
|
||||
return true
|
||||
}
|
||||
|
||||
// A PanelCard is a Card that takes its title and text from an InfoPanel,
|
||||
// while options, urgency, and the post-option callback are specified
|
||||
// (like a BasicCard). It never does anything in particular when drawn.
|
||||
//
|
||||
// Omitting all options yields an inactionable card, which can be displayed
|
||||
// but not played. This can be useful for adding an info panel as a debug action.
|
||||
type PanelCard[C StatsCollection] struct {
|
||||
Panel InfoPanel[C]
|
||||
IsUrgent bool
|
||||
CardOptions []CardOption[C]
|
||||
// AfterOption is given the card itself as its first argument.
|
||||
AfterOption func(c Card[C], p *Player[C], option CardOption[C]) error
|
||||
}
|
||||
|
||||
// Title implements Card.
|
||||
func (c *PanelCard[C]) Title(p *Player[C]) Message {
|
||||
return c.Panel.Title(p)
|
||||
}
|
||||
|
||||
// Urgent implements Card.
|
||||
func (c *PanelCard[C]) Urgent(_ *Player[C]) bool {
|
||||
return c.IsUrgent
|
||||
}
|
||||
|
||||
// EventText implements Card.
|
||||
func (c *PanelCard[C]) EventText(p *Player[C]) (Message, error) {
|
||||
msgs, err := c.Panel.Info(p)
|
||||
return MultiMessage(msgs), err
|
||||
}
|
||||
|
||||
// Options implements Card.
|
||||
func (c *PanelCard[C]) Options(_ *Player[C]) ([]CardOption[C], error) {
|
||||
return c.CardOptions, nil
|
||||
}
|
||||
|
||||
// Then implements Card.
|
||||
func (c *PanelCard[C]) Then(p *Player[C], option CardOption[C]) error {
|
||||
if c.AfterOption == nil {
|
||||
return nil
|
||||
}
|
||||
return c.AfterOption(c, p, option)
|
||||
}
|
||||
|
||||
// Drawn implements Card.
|
||||
func (c *PanelCard[C]) Drawn(_ *Player[C]) bool {
|
||||
return true
|
||||
}
|
||||
|
||||
// A BasicOption is a CardOption with fixed text, effects, and output.
|
||||
// It's always enabled.
|
||||
type BasicOption[C StatsCollection] struct {
|
||||
@ -151,3 +199,17 @@ func (o *optionFunc[C]) Enact(p *Player[C]) (Message, error) {
|
||||
func (o *optionFunc[C]) Enabled(p *Player[C]) bool {
|
||||
return true
|
||||
}
|
||||
|
||||
// OnlyDiscardFree returns a []CardOption[C] providing a single option, which
|
||||
// returns the action point. It does not shuffle the card back into the deck
|
||||
// or draw a replacement (consider the AfterFunc for that if needed). This
|
||||
// can be used for cards that are displayable but not actionable, but show up
|
||||
// as cards rather than permanent or debug actions for some reason.
|
||||
func OnlyDiscardFree[C StatsCollection](msg Message) []CardOption[C] {
|
||||
return []CardOption[C]{
|
||||
OptionFunc(msg, func(p *Player[C]) (Message, error) {
|
||||
p.ActionsRemaining++
|
||||
return MsgStr("Okay."), nil
|
||||
}),
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user