2021-08-19 06:57:40 +00:00
|
|
|
package main
|
|
|
|
|
|
|
|
import (
|
2021-08-26 03:30:04 +00:00
|
|
|
"bufio"
|
|
|
|
"flag"
|
2021-08-19 06:57:40 +00:00
|
|
|
"log"
|
2021-08-26 03:30:04 +00:00
|
|
|
"os"
|
2021-08-31 04:26:49 +00:00
|
|
|
"os/signal"
|
|
|
|
"syscall"
|
2021-08-26 03:30:04 +00:00
|
|
|
"time"
|
2021-08-19 06:57:40 +00:00
|
|
|
|
|
|
|
"code.rocketnine.space/tslocum/boxcars/game"
|
|
|
|
"github.com/hajimehoshi/ebiten/v2"
|
|
|
|
)
|
|
|
|
|
|
|
|
const (
|
|
|
|
screenWidth = 1024
|
|
|
|
screenHeight = 768
|
|
|
|
)
|
|
|
|
|
|
|
|
func main() {
|
|
|
|
ebiten.SetWindowTitle("Boxcars")
|
|
|
|
ebiten.SetWindowSize(screenWidth, screenHeight)
|
|
|
|
ebiten.SetWindowResizable(true)
|
2021-08-31 04:26:49 +00:00
|
|
|
ebiten.SetFPSMode(ebiten.FPSModeVsyncOffMinimum)
|
2021-08-20 03:18:28 +00:00
|
|
|
ebiten.SetMaxTPS(60) // TODO allow users to set custom value
|
2021-08-19 06:57:40 +00:00
|
|
|
ebiten.SetRunnableOnUnfocused(true) // Note - this currently does nothing in ebiten
|
2021-08-31 04:26:49 +00:00
|
|
|
ebiten.SetWindowClosingHandled(true)
|
2021-08-19 06:57:40 +00:00
|
|
|
|
|
|
|
fullscreenWidth, fullscreenHeight := ebiten.ScreenSizeInFullscreen()
|
|
|
|
if fullscreenWidth <= screenWidth || fullscreenHeight <= screenHeight {
|
|
|
|
ebiten.SetFullscreen(true)
|
|
|
|
}
|
|
|
|
|
2021-08-26 03:30:04 +00:00
|
|
|
g := game.NewGame()
|
|
|
|
|
|
|
|
flag.StringVar(&g.Username, "username", "", "Username")
|
|
|
|
flag.StringVar(&g.Password, "password", "", "Password")
|
|
|
|
flag.StringVar(&g.ServerAddress, "address", "fibs.com:4321", "Server address")
|
|
|
|
flag.BoolVar(&g.Watch, "watch", false, "Watch random game")
|
|
|
|
flag.Parse()
|
|
|
|
|
|
|
|
// Auto-connect
|
|
|
|
if g.Username != "" && g.Password != "" {
|
|
|
|
g.Connect()
|
|
|
|
}
|
|
|
|
|
|
|
|
go func() {
|
|
|
|
scanner := bufio.NewScanner(os.Stdin)
|
|
|
|
for scanner.Scan() {
|
|
|
|
// TODO temporary
|
|
|
|
if string(scanner.Bytes()) == "/board" {
|
|
|
|
g.Client.Out <- []byte("set boardstyle 2")
|
|
|
|
time.Sleep(time.Second / 2)
|
|
|
|
g.Client.Out <- []byte("board")
|
|
|
|
time.Sleep(time.Second / 2)
|
|
|
|
g.Client.Out <- []byte("set boardstyle 3")
|
|
|
|
continue
|
|
|
|
}
|
|
|
|
|
|
|
|
g.Client.Out <- append(scanner.Bytes())
|
|
|
|
}
|
|
|
|
|
|
|
|
if scanner.Err() != nil {
|
|
|
|
// TODO
|
|
|
|
}
|
|
|
|
}()
|
|
|
|
|
2021-08-31 04:26:49 +00:00
|
|
|
sigc := make(chan os.Signal, 1)
|
|
|
|
signal.Notify(sigc,
|
|
|
|
syscall.SIGINT,
|
|
|
|
syscall.SIGTERM)
|
|
|
|
go func() {
|
|
|
|
<-sigc
|
|
|
|
|
|
|
|
g.Exit()
|
|
|
|
}()
|
|
|
|
|
2021-08-26 03:30:04 +00:00
|
|
|
if err := ebiten.RunGame(g); err != nil {
|
2021-08-19 06:57:40 +00:00
|
|
|
log.Fatal(err)
|
|
|
|
}
|
|
|
|
}
|