From 9152c3e0ee2b37dfa94ccf8c781eae1a9ab8ee19 Mon Sep 17 00:00:00 2001 From: Florian Fischer Date: Tue, 29 Apr 2025 14:57:09 -0500 Subject: improve the sealed activity Do not export the sealed client type. Validate the entered set list. Show the default set list. --- go/client/sealed.go | 52 +++++++++++++++++++++++++++++++--------------------- 1 file changed, 31 insertions(+), 21 deletions(-) (limited to 'go/client') 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() -- cgit v1.2.3