-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.go
More file actions
93 lines (82 loc) · 2.7 KB
/
Copy pathmain.go
File metadata and controls
93 lines (82 loc) · 2.7 KB
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
package main
import (
"context"
"fmt"
"os"
"runtime/debug"
tea "charm.land/bubbletea/v2"
"github.com/aviorstudio/termcade/internal/engine"
"github.com/aviorstudio/termcade/internal/plugin"
"github.com/aviorstudio/termcade/internal/scores"
"github.com/aviorstudio/termcade/internal/settings"
"github.com/aviorstudio/termcade/internal/shell"
"github.com/aviorstudio/termcade/internal/starter"
"github.com/aviorstudio/termcade/sdk"
)
// discoverGames seeds the starter pack on first run, then loads every
// installed game. The arcade compiles no games in — everything on the menu is
// a .tcade running in the sandbox, bundled or added — so a fresh install has
// something to play before it has an account or a network.
//
// A failed seed is reported and survived: the arcade with no games still
// beats no arcade.
func discoverGames(rt *plugin.Runtime) []engine.Registration {
dir, err := plugin.GamesDir()
if err != nil {
fmt.Fprintln(os.Stderr, "termcade: games directory unavailable:", err)
return nil
}
if err := starter.Seed(dir); err != nil {
fmt.Fprintln(os.Stderr, "termcade: starter pack:", err)
}
return plugin.Games(rt, dir, nil)
}
// version is stamped by the release build (-X main.version=…). When it
// isn't — `go run …@v0.0.2` compiles without our ldflags — the module
// version Go embeds in the binary is the same truth.
var version = "dev"
func resolveVersion() string {
if version != "dev" {
return version
}
if info, ok := debug.ReadBuildInfo(); ok && info.Main.Version != "(devel)" && info.Main.Version != "" {
return info.Main.Version
}
return version
}
func main() {
if runCommand(os.Args[1:]) {
return
}
st, err := scores.Load()
if err != nil {
fmt.Fprintln(os.Stderr, "termcade: score file unavailable:", err)
}
shape := pixelShape()
rt := plugin.NewRuntime(context.Background())
defer rt.Close()
games := discoverGames(rt)
p := tea.NewProgram(shell.New(games, st, shape, newMarketplace(rt, st)))
if _, err := p.Run(); err != nil {
fmt.Fprintln(os.Stderr, "termcade:", err)
os.Exit(1)
}
}
// pixelShape picks the cell subdivision. Quadrants are the default because they
// render in any font; sextants are sharper but need Unicode 13 coverage, so
// opting in is left to whoever knows their terminal.
func pixelShape() sdk.CellShape {
if name, ok := os.LookupEnv("TERMCADE_PIXELS"); ok {
if shape, ok := sdk.LookupShape(name); ok {
return shape
}
fmt.Fprintf(os.Stderr, "termcade: unknown TERMCADE_PIXELS %q; ignoring\n", name)
}
// The env is a per-run override; the arcade's p toggle persists here.
if st, err := settings.Load(); err == nil {
if shape, ok := sdk.LookupShape(st.Pixels); ok {
return shape
}
}
return sdk.Quadrant
}