package main

import (
	"flag"
	"log"
	"os"

	"code.ur.gs/lupine/ordoor/internal/assetstore"
	"code.ur.gs/lupine/ordoor/internal/ui"
)

var (
	gamePath = flag.String("game-path", "./orig", "Path to a WH40K: Chaos Gate installation")
	menuName = flag.String("menu", "", "Name of a menu, e.g. Main")

	winX = flag.Int("win-x", 1280, "Pre-scaled window X dimension")
	winY = flag.Int("win-y", 1024, "Pre-scaled window Y dimension")
)

func main() {
	flag.Parse()

	if *gamePath == "" || *menuName == "" {
		flag.Usage()
		os.Exit(1)
	}

	assets, err := assetstore.New(*gamePath)
	if err != nil {
		log.Fatal(err)
	}

	menu, err := assets.Menu(*menuName)
	if err != nil {
		log.Fatalf("Couldn't load menu %s: %v", *menuName, err)
	}

	driver, err := ui.NewDriver(menu)
	if err != nil {
		log.Fatalf("Couldn't initialize interface: %v", err)
	}

	win, err := ui.NewWindow(driver, "View Menu: "+*menuName, *winX, *winY)
	if err != nil {
		log.Fatal("Couldn't create window: %v", err)
	}

	if err := win.Run(); err != nil {
		log.Fatal(err)
	}
}
