aboutsummaryrefslogtreecommitdiff
path: root/go/client/main.go
blob: c696ccf7654be73ddb2dbc4dd01840340f04bc4e (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
package main

import (
	"flag"
	"image/color"
	"io"
	"log"
	"os"

	"github.com/hajimehoshi/ebiten/v2"

	"muhq.space/muhqs-game/go/font"
)

const (
	WINDOW_WIDTH  = 800
	WINDOW_HEIGHT = 1024
)

var playerColors = []color.RGBA{
	{1, 0xff, 1, 0xff},
	{1, 1, 0xff, 0xff},
}

var startDeckPath string

type app struct {
	windowWidth  int
	windowHeight int

	activities []ebiten.Game
}

func (a *app) pushActivity(activity ebiten.Game) {
	a.activities = append(a.activities, activity)
}

func (a *app) popActivity() {
	a.activities = a.activities[:len(a.activities)-1]
}

func (a *app) Update() error {
	return a.activities[len(a.activities)-1].Update()
}

func (a *app) Draw(screen *ebiten.Image) {
	a.activities[len(a.activities)-1].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")
	flag.Parse()

	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`
	}

	app.pushActivity(startMenu)
	if err := ebiten.RunGame(app); err != nil {
		if err != ebiten.Termination {
			log.Fatal(err)
		}
	}
}