-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathmain.go
More file actions
147 lines (126 loc) · 4.63 KB
/
main.go
File metadata and controls
147 lines (126 loc) · 4.63 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
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
package main
import (
"context"
"embed"
"flag"
"fmt"
"image/color"
"path/filepath"
"time"
"github.com/disintegration/gift"
"github.com/oakmound/game-template/internal/scenes"
"github.com/oakmound/game-template/internal/scenes/debug"
"github.com/oakmound/game-template/internal/scenes/loading"
"github.com/oakmound/game-template/internal/scenes/sample"
"github.com/oakmound/oak/v4"
"github.com/oakmound/oak/v4/dlog"
"github.com/oakmound/oak/v4/event"
"github.com/oakmound/oak/v4/render"
"github.com/oakmound/oak/v4/render/mod"
"golang.org/x/sync/errgroup"
)
//go:embed assets
var assets embed.FS
var debugFlag = flag.Bool("debug", false, "turn on debug")
func main() {
// Load flags
flag.Parse()
// This is not a great method but shows how one can pass flags into the initial oak call for operational updates.
debugEnabled := *debugFlag
oak.SetFS(assets)
// A common set of draw stacks, Composite as background, dynamic as foreground and then the static layer as a UI type thing.
// See internal/layering/layers.go for the names.
render.SetDrawStack(
render.NewCompositeR(),
render.NewDynamicHeap(),
render.NewStaticHeap(),
)
errG, ctx := errgroup.WithContext(context.Background())
// Add scenes from local internal packages
mainWindow := oak.NewWindow()
mainWindow.ParentContext = context.WithValue(ctx, "name", "Sample App")
mainWindow.AddScene(scenes.Batchloading, loading.Scene)
mainWindow.AddScene(scenes.Sample, sample.Scene)
if debugEnabled {
dlog.Info("Enabled Debug mode and console")
debugger := oak.NewWindow()
debugger.ParentContext = context.WithValue(mainWindow.ParentContext, "name", "debugger")
debugger.ParentContext = context.WithValue(debugger.ParentContext, debug.ExtraBus, mainWindow.EventHandler())
fmt.Println(debugger.AddScene(scenes.Debug, debug.Scene))
secondaryCaller := event.NewCallerMap()
debugger.SetLogicHandler(event.NewBus(secondaryCaller))
debugger.CallerMap = secondaryCaller
debugger.DrawStack = render.NewDrawStack(render.NewStaticHeap())
errG.Go(func() error {
err := debugger.Init(scenes.Debug, func(c oak.Config) (oak.Config, error) {
c.Debug.Level = "VERBOSE"
c.Title = "Debugging Console"
c.Screen = oak.Screen{
Width: 960,
Height: 360,
Scale: 1,
}
c.TopMost = true
c.FrameRate = 30
c.DrawFrameRate = 120
c.EnableDebugConsole = true
return c, nil
})
return fmt.Errorf("finished debug window with output of: %v", err)
})
}
mainWindow.ParentContext = context.WithValue(mainWindow.ParentContext, loading.PreLoadTimeStr, time.Now())
screenR := render.NewColorBox(mainWindow.Bounds().X(), mainWindow.Bounds().Y(), color.RGBA{255, 255, 22, 0})
mid := mainWindow.Bounds().DivConst(2)
// CONSIDER: Providing some image that reassures users that yes the sytstem is doing work.
// loadSheet, err := render.LoadSheet(filepath.Join("assets", "images", "32x32", "loading.png"), intgeom.Point2{32, 32})
// if err == nil {
// loadingSeq, err := render.NewSheetSequence(loadSheet, 32, 0, 0, 1, 0, 2, 0, 3, 0, 4, 0, 5, 0, 6, 0, 7, 0)
// // loadingSeq.SetPos(float64(ctx.Window.Bounds().X()/2)-16, float64(ctx.Window.Bounds().Y())-64)
// dlog.ErrorCheck(err)
// // go ctx.DoAfter(2*time.Second, func() {
// // // after some time, we start displaying the loading circle to reassure
// // // the player things are still happening
// // ctx.DrawStack.Draw(loadingSeq, layers.StackBackground, layers.Back)
// // })
// } else {
// fmt.Prindt have loading.png", err.Error())
// }
// CONSIDER: Provide an ident to show an image that represents you as a creator
ident, err := render.LoadSprite(filepath.Join("assets", "images", "raw", "ident.png"))
if err == nil {
ident.Modify(mod.ResizeToFit(400, 400, gift.CubicResampling))
// identw, identh := ident.GetDims()
// ident.SetPos(
// float64().Bounds().X())/2-float64(identw)/2,
// float64(ctx.Window.Bounds().Y())/2-float64(identh)/2,
// )
// ctx.DrawStack.Draw(ident, layers.StackBackground, layers.Back)
ident.Draw(screenR, float64(mid.X()), float64(mid.Y()))
}
mainWindow.LoadingR = screenR
errG.Go(func() error {
err := mainWindow.Init(scenes.Batchloading, func(c oak.Config) (oak.Config, error) {
// Setup oak config
c.FrameRate = 60
c.DrawFrameRate = 60
c.Screen = oak.Screen{
Width: 1280,
Height: 720,
Scale: 1,
}
c.Debug = oak.Debug{
Level: "Info",
}
c.Title = "Sample App"
c.TrackInputChanges = true
c.LoadBuiltinCommands = true
c.TopMost = true
c.EnableDebugConsole = debugEnabled
c.BatchLoad = false
return c, nil
})
return fmt.Errorf("finished main window with output of: %v", err)
})
errG.Wait()
}