-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.go
80 lines (71 loc) · 2.19 KB
/
main.go
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
// Package main is a game of simon-says. It provides a server and client application
// as well as a static-resource generator for the game.
package main
import (
"flag"
"log"
"net/http"
"time"
"github.com/jan-xyz/simon-says/game"
"github.com/jan-xyz/simon-says/ui"
"github.com/maxence-charriere/go-app/v9/pkg/app"
)
func main() {
serve := flag.Bool("serve", false, "set to serve instead of generating resources")
flag.Parse()
l := game.New()
// TODO: improved statistics
// TODO: for endless mode add histogram of how far you got.
// TODO: add tests
// TODO: add dependabot
// TODO: light/dark mode
app.Handle(ui.EventClick, l.HandleClick)
app.Handle(ui.EventNewGame, l.HandleNewGame)
g := ui.NewUI()
app.Route("/", g)
// When executed on the client-side, the RunWhenOnBrowser() function
// launches the app, starting a loop that listens for app events and
// executes client instructions. Since it is a blocking call, the code below
// it will never be executed.
//
// When executed on the server-side, RunWhenOnBrowser() does nothing, which
// lets room for server implementation without the need for precompiling
// instructions.
app.RunWhenOnBrowser()
h := &app.Handler{
Name: "Simon Says",
Description: "A game of simon says",
Scripts: []string{
"https://go-echarts.github.io/go-echarts-assets/assets/echarts.min.js",
},
Styles: []string{
"/web/styles.css",
},
Icon: app.Icon{
Default: "/web/icon.png",
Large: "/web/icon.png",
SVG: "/web/icon.svg",
AppleTouch: "/web/icon.png",
},
LoadingLabel: "Loading...",
AutoUpdateInterval: 15 * time.Minute,
}
if !*serve {
h.Resources = app.GitHubPages("simon-says")
err := app.GenerateStaticWebsite("_site", h)
if err != nil {
log.Fatal(err)
}
return
}
// Finally, launching the server that serves the app is done by using the Go
// standard HTTP package.
//
// The Handler is an HTTP handler that serves the client and all its
// required resources to make it work into a web browser. Here it is
// configured to handle requests with a path that starts with "/".
http.Handle("/", h)
if err := http.ListenAndServe(":8000", nil); err != nil {
log.Fatal(err)
}
}