diff options
| author | Florian Fischer <florian.fischer@muhq.space> | 2025-06-06 16:42:46 -0500 |
|---|---|---|
| committer | Florian Fischer <florian.fischer@muhq.space> | 2025-08-20 15:57:18 +0200 |
| commit | bcffeac4c5086eba59448d4fe5d79bb786b05de2 (patch) | |
| tree | cc0b3648f2b070c731225e88b42fb3f4adcb65da /go/client/sealed.go | |
| parent | c15142c3bcae4316c8580adb7a9f0b223e586ae9 (diff) | |
| download | muhqs-game-bcffeac4c5086eba59448d4fe5d79bb786b05de2.tar.gz muhqs-game-bcffeac4c5086eba59448d4fe5d79bb786b05de2.zip | |
refactor client activities
Make the activity stack explicit and move reusable activities to the
activity package.
Diffstat (limited to 'go/client/sealed.go')
| -rw-r--r-- | go/client/sealed.go | 138 |
1 files changed, 0 insertions, 138 deletions
diff --git a/go/client/sealed.go b/go/client/sealed.go deleted file mode 100644 index efe1006e..00000000 --- a/go/client/sealed.go +++ /dev/null @@ -1,138 +0,0 @@ -package main - -import ( - "github.com/hajimehoshi/ebiten/v2" - "github.com/hajimehoshi/ebiten/v2/inpututil" - - "muhq.space/muhqs-game/go/game" - "muhq.space/muhqs-game/go/ui" -) - -const ( - SEALED_DECK_STRIP_WIDTH = 200 -) - -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{ - app: app, - Collection: ui.Collection{Width: width, Height: height}, - } - - s.AddWidget(ui.NewFixedTextBox( - (s.Width-START_BUTTON_WIDTH)/2-START_BUTTON_WIDTH, - (s.Height-START_BUTTON_HEIGHT)/2-START_BUTTON_HEIGHT, - START_BUTTON_WIDTH, - START_BUTTON_HEIGHT, - "sets:", - ).Centering(true)) - - 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, - "base,equipments,magic", - ) - s.AddWidget(s.setInput) - - s.AddWidget(ui.NewSimpleButton( - (s.Width-START_BUTTON_WIDTH)/2, - (s.Height-START_BUTTON_HEIGHT)/2, - START_BUTTON_WIDTH, - START_BUTTON_HEIGHT, - "Start", - func(*ui.SimpleButton) { - s.startSealed(s.setInput.TextOrLabel()) - })) - - return s -} - -func (s *sealed) Update() error { - if err := ui.TouchManager.Update(); err != nil { - return err - } - - if err := s.Collection.Update(); err != nil { - return err - } - - if inpututil.IsKeyJustPressed(ebiten.KeyEscape) { - s.app.popActivity() - } - - return nil -} - -func (s *sealed) Layout(width, height int) (int, int) { - return s.Width, s.Height -} - -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() - - for _, set := range sets { - setDeck := game.NewDeck() - for _, c := range game.NewDeckFromCardPaths(set.CardPaths()).Cards() { - if c.IsBuyable() { - setDeck.AddCard(c) - } - } - setDeck.MoveInto(s.pool) - } - - 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-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 { - return - } - - card := _card.(*game.Card) - s.pool.MoveCard(card, s.deck) - grid.ForceRedraw() - deckList.ForceRedraw() - } - grid.RegisterHandler("click", selectCard) - s.AddWidget(grid) - - s.AddWidget(ui.NewSimpleButton( - s.Width-SEALED_DECK_STRIP_WIDTH/2-START_BUTTON_WIDTH/2, - s.Height-START_BUTTON_HEIGHT, - START_BUTTON_WIDTH, - START_BUTTON_HEIGHT, - "Done", - func(*ui.SimpleButton) { - s.done() - })) -} - -func (s *sealed) done() { - startMenu := s.app.activities[len(s.app.activities)-2].(*StartMenu) - startMenu.deckInput.SetInput(s.deck.ToList()) - s.app.popActivity() -} |
