46 lines
880 B
Go
46 lines
880 B
Go
package play
|
|
|
|
import (
|
|
"gitea.konchin.com/ytshih/inp2025/game/plays"
|
|
"gitea.konchin.com/ytshih/inp2025/game/tracing"
|
|
tea "github.com/charmbracelet/bubbletea"
|
|
"github.com/go-resty/resty/v2"
|
|
"github.com/spf13/cobra"
|
|
)
|
|
|
|
var RootCmd = &cobra.Command{
|
|
Use: "play",
|
|
Short: "Play game",
|
|
Args: cobra.ExactArgs(1),
|
|
Run: func(cmd *cobra.Command, args []string) {
|
|
appname := "game-tui"
|
|
tracing.InitTracer(appname)
|
|
|
|
client := resty.New().
|
|
SetBaseURL(args[0]).
|
|
SetDisableWarn(true)
|
|
|
|
queue := []*tea.Program{}
|
|
queue = append(queue, tea.NewProgram(
|
|
plays.NewLanding(plays.NewBase(client))))
|
|
|
|
for len(queue) > 0 {
|
|
program := queue[0]
|
|
queue = queue[1:]
|
|
|
|
res, err := program.Run()
|
|
if err != nil {
|
|
panic(err)
|
|
}
|
|
err = res.(plays.Next).Next(&queue)
|
|
if err != nil {
|
|
panic(err)
|
|
}
|
|
}
|
|
},
|
|
}
|
|
|
|
func init() {
|
|
RootCmd.AddCommand(clientCmd)
|
|
}
|