package main import ( "flag" "io" "log/slog" "os" "strings" "github.com/hajimehoshi/ebiten/v2" "muhq.space/muhqs-game/go/activities" "muhq.space/muhqs-game/go/font" "muhq.space/muhqs-game/go/log" ) const ( WINDOW_WIDTH = 800 WINDOW_HEIGHT = 1024 ) var startDeckPath string type app struct { windowWidth int windowHeight int } func (a *app) Update() error { return activities.CurActivity().Update() } func (a *app) Draw(screen *ebiten.Image) { activities.CurActivity().Draw(screen) } func (a *app) Layout(outsideWidth, outsideHeight int) (int, int) { return a.windowWidth, a.windowHeight } func main() { font.InitFont() app := &app{} startMenu := NewStartMenu(app) flag.IntVar(&app.windowWidth, "windowWidth", WINDOW_WIDTH, "the window width") flag.IntVar(&app.windowHeight, "windowHeight", WINDOW_HEIGHT, "the window height") flag.StringVar(&startMenu.playerName, "player", "muhq", "player name") flag.StringVar(&startDeckPath, "deck", "", "deck list to load") flag.StringVar(&startMenu.mapPath, "map", "the-kraken", "the map to load") flag.StringVar(&startMenu.remote, "remote", "", "address of remote game to connect to") logLevel := flag.Int("logLevel", int(slog.LevelInfo.Level()), "active log level") loggedFilesVar := flag.String("loggedFiles", "", "files to log") flag.Parse() if *logLevel != int(slog.LevelInfo.Level()) || *loggedFilesVar != "" { loggedFiles := strings.Split(*loggedFilesVar, " ") log.Configure(loggedFiles, &slog.HandlerOptions{ AddSource: true, Level: slog.Level(*logLevel), }) } ebiten.SetWindowSize(app.windowWidth, app.windowHeight) ebiten.SetWindowTitle("Muhq's Game") startMenu.Width, startMenu.Height = app.windowWidth, app.windowHeight if startDeckPath != "" { file, err := os.Open(startDeckPath) if err != nil { log.Fatal(err) } defer file.Close() deckList, err := io.ReadAll(file) if err != nil { log.Fatal(err) } startMenu.startDeck = string(deckList) } else { startMenu.startDeck = `1 nautics/barge 1 nautics/captain 1 nautics/fisher 1 nautics/galley` } activities.PushActivity(startMenu) if err := ebiten.RunGame(app); err != nil { if err != ebiten.Termination { log.Fatal(err) } } }