diff options
| author | Florian Fischer <florian.fischer@muhq.space> | 2025-04-29 14:57:09 -0500 |
|---|---|---|
| committer | Florian Fischer <florian.fischer@muhq.space> | 2025-08-20 15:57:16 +0200 |
| commit | 9152c3e0ee2b37dfa94ccf8c781eae1a9ab8ee19 (patch) | |
| tree | ebea488f7c1b4faaf827e325d20ca850941d4387 | |
| parent | be2aad1142bde494229d9d27d4123923aa578c1a (diff) | |
| download | muhqs-game-9152c3e0ee2b37dfa94ccf8c781eae1a9ab8ee19.tar.gz muhqs-game-9152c3e0ee2b37dfa94ccf8c781eae1a9ab8ee19.zip | |
improve the sealed activity
Do not export the sealed client type.
Validate the entered set list.
Show the default set list.
| -rw-r--r-- | go/client/sealed.go | 52 | ||||
| -rw-r--r-- | go/game/set.go | 18 | ||||
| -rw-r--r-- | go/ui/colors.go | 1 |
3 files changed, 50 insertions, 21 deletions
diff --git a/go/client/sealed.go b/go/client/sealed.go index c219dbf6..efe1006e 100644 --- a/go/client/sealed.go +++ b/go/client/sealed.go @@ -1,8 +1,6 @@ package main import ( - "strings" - "github.com/hajimehoshi/ebiten/v2" "github.com/hajimehoshi/ebiten/v2/inpututil" @@ -11,19 +9,21 @@ import ( ) const ( - SIDEBARD_WIDTH = 200 + SEALED_DECK_STRIP_WIDTH = 200 ) -type Sealed struct { +type sealed struct { ui.Collection app *app + setInput *ui.TextInput + pool game.PileOfCards deck game.PileOfCards } -func NewSealed(width, height int, app *app) *Sealed { - s := &Sealed{ +func NewSealed(width, height int, app *app) *sealed { + s := &sealed{ app: app, Collection: ui.Collection{Width: width, Height: height}, } @@ -36,14 +36,14 @@ func NewSealed(width, height int, app *app) *Sealed { "sets:", ).Centering(true)) - setInput := ui.NewTextInput( + s.setInput = ui.NewTextInput( (s.Width-START_BUTTON_WIDTH)/2, (s.Height-START_BUTTON_HEIGHT)/2-START_BUTTON_HEIGHT, START_BUTTON_WIDTH, START_BUTTON_HEIGHT, - "set list", + "base,equipments,magic", ) - s.AddWidget(setInput) + s.AddWidget(s.setInput) s.AddWidget(ui.NewSimpleButton( (s.Width-START_BUTTON_WIDTH)/2, @@ -52,13 +52,17 @@ func NewSealed(width, height int, app *app) *Sealed { START_BUTTON_HEIGHT, "Start", func(*ui.SimpleButton) { - s.startSealed(setInput.Text()) + s.startSealed(s.setInput.TextOrLabel()) })) return s } -func (s *Sealed) Update() error { +func (s *sealed) Update() error { + if err := ui.TouchManager.Update(); err != nil { + return err + } + if err := s.Collection.Update(); err != nil { return err } @@ -70,19 +74,24 @@ func (s *Sealed) Update() error { return nil } -func (s *Sealed) Layout(width, height int) (int, int) { +func (s *sealed) Layout(width, height int) (int, int) { return s.Width, s.Height } -func (s *Sealed) startSealed(_sets string) { +func (s *sealed) startSealed(setList string) { + sets, err := game.SetListToSets(setList) + if err != nil { + s.setInput.Bg(ui.WarningBg) + s.setInput.SetInput("") + return + } + s.pool = game.NewPileOfCards() s.deck = game.NewPileOfCards() s.Clear() - sets := strings.Split(_sets, ",") - for _, setName := range sets { - set := game.SetNames[setName] + for _, set := range sets { setDeck := game.NewDeck() for _, c := range game.NewDeckFromCardPaths(set.CardPaths()).Cards() { if c.IsBuyable() { @@ -92,11 +101,11 @@ func (s *Sealed) startSealed(_sets string) { setDeck.MoveInto(s.pool) } - deckList := ui.NewPocList(s.Width-SIDEBARD_WIDTH/2, s.Height-START_BUTTON_HEIGHT-20, s.deck) + deckList := ui.NewPocList(s.Width-SEALED_DECK_STRIP_WIDTH/2, s.Height-START_BUTTON_HEIGHT-20, s.deck) deckList.Bg(ui.Gray) s.AddWidget(deckList) - grid := ui.NewCardGrid(0, 0, s.Width-SIDEBARD_WIDTH, s.Height, 0.5, s.pool).Columns(3) + grid := ui.NewCardGrid(0, 0, s.Width-SEALED_DECK_STRIP_WIDTH, s.Height, 0.5, s.pool).Columns(3) selectCard := func(x, y int) { _card := grid.FindObjectAt(x, y) if _card == nil { @@ -108,10 +117,11 @@ func (s *Sealed) startSealed(_sets string) { grid.ForceRedraw() deckList.ForceRedraw() } - s.AddWidget(ui.NewClickWrapper(grid, selectCard)) + grid.RegisterHandler("click", selectCard) + s.AddWidget(grid) s.AddWidget(ui.NewSimpleButton( - s.Width-SIDEBARD_WIDTH/2-START_BUTTON_WIDTH/2, + s.Width-SEALED_DECK_STRIP_WIDTH/2-START_BUTTON_WIDTH/2, s.Height-START_BUTTON_HEIGHT, START_BUTTON_WIDTH, START_BUTTON_HEIGHT, @@ -121,7 +131,7 @@ func (s *Sealed) startSealed(_sets string) { })) } -func (s *Sealed) done() { +func (s *sealed) done() { startMenu := s.app.activities[len(s.app.activities)-2].(*StartMenu) startMenu.deckInput.SetInput(s.deck.ToList()) s.app.popActivity() diff --git a/go/game/set.go b/go/game/set.go index 23cc7084..fe25e3a1 100644 --- a/go/game/set.go +++ b/go/game/set.go @@ -1,6 +1,8 @@ package game import ( + "errors" + "fmt" "log" "net/http" "path" @@ -115,3 +117,19 @@ func (set SetIdentifier) CardPaths() []string { walk(doc) return paths } + +func SetListToSets(setList string) ([]SetIdentifier, error) { + var err error + sets := []SetIdentifier{} + setList = strings.Replace(setList, " ", "", 0) + setsRaw := strings.Split(setList, ",") + for _, s := range setsRaw { + set, found := SetNames[s] + if found { + sets = append(sets, set) + } else { + err = errors.New(fmt.Sprintf("Unknown set: %s", set)) + } + } + return sets, err +} diff --git a/go/ui/colors.go b/go/ui/colors.go index 49085f1b..fd1b8d06 100644 --- a/go/ui/colors.go +++ b/go/ui/colors.go @@ -10,6 +10,7 @@ var ( HighlightSelectionColor = color.RGBA{0xc7, 0x89, 0x33, 0xff} HighlightOptionColor = color.RGBA{0xc7, 0x52, 0x33, 0xff} + WarningBg = color.RGBA{0xff, 0, 0, 0x80} ) var PlayerColors = []color.RGBA{ |
