-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathapp.go
175 lines (152 loc) · 4.62 KB
/
app.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
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
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
package main
import (
"context"
"os"
"path/filepath"
"strings"
"github.com/ncruces/zenity"
rlbot "github.com/swz-git/go-interface"
"github.com/swz-git/go-interface/flat"
)
// App struct
type App struct {
ctx context.Context
}
func (a *App) IgnoreMe(
_ BotInfo,
_ PsyonixBotInfo,
_ HumanInfo,
) {
}
// NewApp creates a new App application struct
func NewApp() *App {
return &App{}
}
// startup is called when the app starts. The context is saved
// so we can call the runtime methods
func (a *App) startup(ctx context.Context) {
a.ctx = ctx
}
// // Greet returns a greeting for the given name
// func (a *App) Greet(name string) string {
// return fmt.Sprintf("Hello %s, It's show time!", name)
// }
func recursiveFileSearch(root, targetName string) ([]string, error) {
var matches []string
err := filepath.Walk(root, func(path string, info os.FileInfo, err error) error {
if err != nil {
return err
}
if strings.HasSuffix(info.Name(), targetName) {
matches = append(matches, path)
}
return nil
})
return matches, err
}
type Result struct {
Success bool `json:"success"`
Message string `json:"message"`
}
type ExtraOptions struct {
EnableRendering bool `json:"enableRendering"`
EnableStateSetting bool `json:"enableStateSetting"`
InstantStart bool `json:"instantStart"`
SkipReplays bool `json:"skipReplays"`
AutoSaveReplay bool `json:"autoSaveReplay"`
ExistingMatchBehavior byte `json:"existingMatchBehavior"`
}
type StartMatchOptions struct {
Map string `json:"map"`
GameMode string `json:"gameMode"`
BluePlayers []PlayerJs `json:"bluePlayers"`
OrangePlayers []PlayerJs `json:"orangePlayers"`
MutatorSettings flat.MutatorSettingsT `json:"mutatorSettings"`
ExtraOptions ExtraOptions `json:"extraOptions"`
Launcher string `json:"launcher"`
GamePath string `json:"gamePath"`
}
func (a *App) StartMatch(options StartMatchOptions) Result {
// TODO: Save this in App struct
// TODO: Make dynamic, pull from env var?
conn, err := rlbot.Connect("127.0.0.1:23234")
if err != nil {
return Result{false, "Failed to connect to rlbot"}
}
var gameMode flat.GameMode
switch options.GameMode {
case "Soccer":
gameMode = flat.GameModeSoccer
case "Hoops":
gameMode = flat.GameModeHoops
case "Dropshot":
gameMode = flat.GameModeDropshot
case "Hockey":
gameMode = flat.GameModeHockey
case "Rumble":
gameMode = flat.GameModeRumble
case "Heatseeker":
gameMode = flat.GameModeHeatseeker
case "Gridiron":
gameMode = flat.GameModeGridiron
default:
println("No mode chosen, defaulting to soccer")
gameMode = flat.GameModeSoccer
}
var launcher flat.Launcher
switch options.Launcher {
case "steam":
launcher = flat.LauncherSteam
case "epic":
launcher = flat.LauncherEpic
case "custom":
launcher = flat.LauncherCustom
default:
println("No launcher chosen, defaulting to steam")
launcher = flat.LauncherSteam
}
var playerConfigs []*flat.PlayerConfigurationT
for _, playerInfo := range options.BluePlayers {
println(playerInfo.ToPlayer().ToPlayerConfig(0))
playerConfigs = append(playerConfigs, playerInfo.ToPlayer().ToPlayerConfig(0))
}
for _, playerInfo := range options.OrangePlayers {
playerConfigs = append(playerConfigs, playerInfo.ToPlayer().ToPlayerConfig(1))
}
println(playerConfigs)
conn.SendPacket(&flat.MatchSettingsT{
AutoStartBots: true,
GameMapUpk: options.Map,
PlayerConfigurations: playerConfigs,
GameMode: gameMode,
MutatorSettings: &options.MutatorSettings,
EnableRendering: options.ExtraOptions.EnableRendering,
EnableStateSetting: options.ExtraOptions.EnableStateSetting,
InstantStart: options.ExtraOptions.InstantStart,
SkipReplays: options.ExtraOptions.SkipReplays,
AutoSaveReplay: options.ExtraOptions.AutoSaveReplay,
Launcher: launcher,
GamePath: options.GamePath,
ExistingMatchBehavior: flat.ExistingMatchBehavior(options.ExtraOptions.ExistingMatchBehavior),
})
return Result{true, ""}
}
func (a *App) StopMatch(shutdownServer bool) Result {
// TODO: Save this in App struct
// TODO: Make dynamic, pull from env var?
conn, err := rlbot.Connect("127.0.0.1:23234")
if err != nil {
return Result{false, "Failed to connect to rlbot"}
}
conn.SendPacket(&flat.StopCommandT{
ShutdownServer: shutdownServer,
})
return Result{true, ""}
}
func (a *App) PickFolder() string {
path, err := zenity.SelectFile(zenity.Directory())
if err != nil {
println("ERR: File picker failed")
}
return path
}