GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — gui/players.go at master · RLBot/gui

Expand file tree

/

players.go

Copy path
More file actions
More file actions

Latest commit

 

History

History
History
568 lines (503 loc) · 16.9 KB
/

players.go

Copy path

File metadata and controls

568 lines (503 loc) · 16.9 KB
Raw
Copy raw file
Download raw file
Open symbols panel
Edit and raw actions
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
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
package main
import (
"encoding/base64"
"encoding/json"
"fmt"
"log"
"os"
"path/filepath"
"regexp"
"runtime"
"sort"
"strings"
"github.com/BurntSushi/toml"
"github.com/RLBot/go-interface/flat"
"github.com/wailsapp/mimetype"
)
type PlayerJs struct {
Sort string `json:"sort"`
Player json.RawMessage `json:"player"`
}
func (playerJs PlayerJs) ToPlayer() Player {
switch playerJs.Sort {
case "rlbot":
var correct BotInfo
if err := json.Unmarshal([]byte(playerJs.Player), &correct); err != nil {
log.Fatal("unable to unmarshal PlayerJs")
}
return correct
case "psyonix":
var correct PsyonixBotInfo
if err := json.Unmarshal([]byte(playerJs.Player), &correct); err != nil {
log.Fatal("unable to unmarshal PlayerJs")
}
return correct
case "human":
var correct HumanInfo
if err := json.Unmarshal([]byte(playerJs.Player), &correct); err != nil {
log.Fatal("unable to unmarshal PlayerJs")
}
return correct
}
log.Println("ERROR: invalid sort field in PlayerJs")
return PsyonixBotInfo{}
}
type Player interface {
ToPlayerConfig(team uint32) *flat.PlayerConfigurationT
}
type PsyonixBotInfo struct {
Name string `json:"name"`
Loadout *LoadoutConfig `json:"loadout,omitempty"`
// Beginner: 0, Rookie: 1, Pro: 2, AllStar: 3
Skill byte `json:"skill"`
}
func (info PsyonixBotInfo) ToPlayerConfig(team uint32) *flat.PlayerConfigurationT {
var loadout *flat.PlayerLoadoutT = nil
if info.Loadout != nil {
var teamLoadout *TeamLoadoutConfig
if team == 0 {
teamLoadout = &info.Loadout.Blue
} else {
teamLoadout = &info.Loadout.Orange
}
loadout = teamLoadout.ToPlayerLoadout()
}
return &flat.PlayerConfigurationT{
Variety: &flat.PlayerClassT{
Type: flat.PlayerClassPsyonixBot,
Value: &flat.PsyonixBotT{
Name: info.Name,
Loadout: loadout,
BotSkill: flat.PsyonixSkill(info.Skill),
},
},
Team: team,
PlayerId: 0,
}
}
type HumanInfo struct{}
func (info HumanInfo) ToPlayerConfig(team uint32) *flat.PlayerConfigurationT {
return &flat.PlayerConfigurationT{
Variety: &flat.PlayerClassT{
Type: flat.PlayerClassHuman,
Value: &flat.HumanT{},
},
Team: team,
PlayerId: 0,
}
}
type TeamPaintConfig struct {
CarPaintId uint32 `toml:"car_paint_id" json:"carPaintId"`
DecalPaintId uint32 `toml:"decal_paint_id" json:"decalPaintId"`
WheelsPaintId uint32 `toml:"wheels_paint_id" json:"wheelsPaintId"`
BoostPaintId uint32 `toml:"boost_paint_id" json:"boostPaintId"`
AntennaPaintId uint32 `toml:"antenna_paint_id" json:"antennaPaintId"`
HatPaintId uint32 `toml:"hat_paint_id" json:"hatPaintId"`
TrailsPaintId uint32 `toml:"trails_paint_id" json:"trailsPaintId"`
GoalExplosionPaintId uint32 `toml:"goal_explosion_paint_id" json:"goalExplosionPaintId"`
}
type TeamLoadoutConfig struct {
TeamColorId uint32 `toml:"team_color_id" json:"teamColorId"`
CustomColorId uint32 `toml:"custom_color_id" json:"customColorId"`
CarId uint32 `toml:"car_id" json:"carId"`
DecalId uint32 `toml:"decal_id" json:"decalId"`
WheelsId uint32 `toml:"wheels_id" json:"wheelsId"`
BoostId uint32 `toml:"boost_id" json:"boostId"`
AntennaId uint32 `toml:"antenna_id" json:"antennaId"`
HatId uint32 `toml:"hat_id" json:"hatId"`
PaintFinishId uint32 `toml:"paint_finish_id" json:"paintFinishId"`
CustomFinishId uint32 `toml:"custom_finish_id" json:"customFinishId"`
EngineAudioId uint32 `toml:"engine_audio_id" json:"engineAudioId"`
TrailsId uint32 `toml:"trails_id" json:"trailsId"`
GoalExplosionId uint32 `toml:"goal_explosion_id" json:"goalExplosionId"`
Paint TeamPaintConfig `toml:"paint" json:"paint"`
}
func (teamLoadout TeamLoadoutConfig) ToPlayerLoadout() *flat.PlayerLoadoutT {
return &flat.PlayerLoadoutT{
TeamColorId: teamLoadout.TeamColorId,
CustomColorId: teamLoadout.CustomColorId,
CarId: teamLoadout.CarId,
DecalId: teamLoadout.DecalId,
WheelsId: teamLoadout.WheelsId,
BoostId: teamLoadout.BoostId,
AntennaId: teamLoadout.AntennaId,
HatId: teamLoadout.HatId,
PaintFinishId: teamLoadout.PaintFinishId,
CustomFinishId: teamLoadout.CustomFinishId,
EngineAudioId: teamLoadout.EngineAudioId,
TrailsId: teamLoadout.TrailsId,
GoalExplosionId: teamLoadout.GoalExplosionId,
LoadoutPaint: &flat.LoadoutPaintT{
CarPaintId: teamLoadout.Paint.CarPaintId,
DecalPaintId: teamLoadout.Paint.DecalPaintId,
WheelsPaintId: teamLoadout.Paint.WheelsPaintId,
BoostPaintId: teamLoadout.Paint.BoostPaintId,
AntennaPaintId: teamLoadout.Paint.AntennaPaintId,
HatPaintId: teamLoadout.Paint.HatPaintId,
TrailsPaintId: teamLoadout.Paint.TrailsPaintId,
GoalExplosionPaintId: teamLoadout.Paint.GoalExplosionPaintId,
},
PrimaryColorLookup: &flat.ColorT{},
SecondaryColorLookup: &flat.ColorT{},
}
}
type LoadoutConfig struct {
Blue TeamLoadoutConfig `toml:"blue_loadout" json:"blueLoadout"`
Orange TeamLoadoutConfig `toml:"orange_loadout" json:"orangeLoadout"`
}
type BotInfo struct {
Config BotConfig `json:"config"`
Loadout *LoadoutConfig `json:"loadout,omitempty"`
TomlPath string `json:"tomlPath"`
Icon string `json:"icon"`
}
type BotEnvironment struct {
Common map[string]string
Windows map[string]string
Linux map[string]string
}
func decodeEnvironmentTable(data any) (map[string]string, error) {
table, ok := data.(map[string]any)
if !ok {
return nil, fmt.Errorf("environment platform must be a table")
}
values := make(map[string]string, len(table))
for name, rawValue := range table {
value, ok := rawValue.(string)
if !ok {
return nil, fmt.Errorf("environment variable %q must have a string value", name)
}
values[name] = value
}
return values, nil
}
func (environment *BotEnvironment) UnmarshalTOML(data any) error {
table, ok := data.(map[string]any)
if !ok {
return fmt.Errorf("environment must be a table")
}
environment.Common = make(map[string]string)
for name, rawValue := range table {
switch name {
case "windows":
values, err := decodeEnvironmentTable(rawValue)
if err != nil {
return fmt.Errorf("environment.windows: %w", err)
}
environment.Windows = values
case "linux":
values, err := decodeEnvironmentTable(rawValue)
if err != nil {
return fmt.Errorf("environment.linux: %w", err)
}
environment.Linux = values
default:
value, ok := rawValue.(string)
if !ok {
return fmt.Errorf("environment variable %q must have a string value", name)
}
environment.Common[name] = value
}
}
return nil
}
func (environment BotEnvironment) Values() map[string]string {
values := make(map[string]string, len(environment.Common))
for name, value := range environment.Common {
values[name] = value
}
var overrides map[string]string
switch runtime.GOOS {
case "windows":
overrides = environment.Windows
case "linux":
overrides = environment.Linux
}
for name, value := range overrides {
values[name] = expandEnvironmentValue(value)
}
return values
}
func (environment BotEnvironment) MarshalJSON() ([]byte, error) {
return json.Marshal(environment.Values())
}
func (environment *BotEnvironment) UnmarshalJSON(data []byte) error {
var values map[string]string
if err := json.Unmarshal(data, &values); err != nil {
return err
}
environment.Common = values
environment.Windows = nil
environment.Linux = nil
return nil
}
// findTorchLibDir walks up the directory tree from the given path,
// checking each ancestor for a torch-archive/torch/lib directory.
// Returns the full path to the lib directory if found, or "" if not.
func findTorchLibDir(fromPath string) string {
dir := fromPath
if info, err := os.Stat(dir); err != nil || !info.IsDir() {
dir = filepath.Dir(dir)
}
for i := 0; i < 5; i++ {
candidate := filepath.Join(dir, "torch-archive", "torch", "lib")
if info, err := os.Stat(candidate); err == nil && info.IsDir() {
return candidate
}
parent := filepath.Dir(dir)
if parent == dir {
break
}
dir = parent
}
return ""
}
// pathSeparator returns the platform-specific path list separator as a string.
func pathSeparator() string {
if runtime.GOOS == "windows" {
return ";"
}
return ":"
}
var environmentVariablePattern = regexp.MustCompile(`%([^%]+)%|\$(?:\{([A-Za-z_][A-Za-z0-9_]*)\}|([A-Za-z_][A-Za-z0-9_]*))`)
func expandEnvironmentValue(value string) string {
// Scan the input once. Replacement values can contain literal variable references.
return environmentVariablePattern.ReplaceAllStringFunc(value, func(match string) string {
var name string
switch {
case match[0] == '%':
name = match[1 : len(match)-1]
case strings.HasPrefix(match, "${"):
name = match[2 : len(match)-1]
default:
name = match[1:]
}
if replacement, ok := os.LookupEnv(name); ok {
return replacement
}
return match
})
}
// resolveEnvironmentVariables resolves path-list values for each environment variable.
// A value that starts with the path separator is appended to the existing value.
// A value that ends with the path separator is prepended to the existing value.
// If no marker is present, the value is used unchanged.
func resolveEnvironmentVariables(env []*flat.EnvironmentVariableT) []*flat.EnvironmentVariableT {
sep := pathSeparator()
resolvedMap := make(map[string]string)
result := make([]*flat.EnvironmentVariableT, 0, len(env))
for _, ev := range env {
existing := resolvedMap[ev.Name]
if existing == "" {
existing = os.Getenv(ev.Name)
}
value := ev.Value
if strings.HasPrefix(value, sep) {
cleanValue := strings.TrimPrefix(value, sep)
if existing == "" {
value = cleanValue
} else {
value = existing + sep + cleanValue
}
} else if strings.HasSuffix(value, sep) {
cleanValue := strings.TrimSuffix(value, sep)
if existing == "" {
value = cleanValue
} else {
value = cleanValue + sep + existing
}
}
resolvedMap[ev.Name] = value
result = append(result, &flat.EnvironmentVariableT{
Name: ev.Name,
Value: value,
})
}
return result
}
// setTorchEnv appends a PATH/LD_LIBRARY_PATH entry pointing to the
// torch-archive lib directory, if it exists. The value begins with the
// platform path separator so resolveEnvironmentVariables appends it to the
// existing path.
func setTorchEnv(tomlPath string, env *[]*flat.EnvironmentVariableT) {
torchLibDir := findTorchLibDir(tomlPath)
if torchLibDir == "" {
return
}
varName := "LD_LIBRARY_PATH"
if runtime.GOOS == "windows" {
varName = "PATH"
}
for _, ev := range *env {
if ev.Name == varName {
return
}
}
sep := pathSeparator()
*env = append(*env, &flat.EnvironmentVariableT{
Name: varName,
Value: sep + torchLibDir,
})
}
func (botInfo BotInfo) ToPlayerConfig(team uint32) *flat.PlayerConfigurationT {
var runCommand string
if runtime.GOOS == "windows" {
runCommand = botInfo.Config.Settings.RunCommand
} else if runtime.GOOS == "linux" {
runCommand = botInfo.Config.Settings.RunCommandLinux
}
var loadout *flat.PlayerLoadoutT = nil
if botInfo.Loadout != nil {
var teamLoadout *TeamLoadoutConfig
if team == 0 {
teamLoadout = &botInfo.Loadout.Blue
} else {
teamLoadout = &botInfo.Loadout.Orange
}
loadout = teamLoadout.ToPlayerLoadout()
}
customBot := &flat.CustomBotT{
Name: botInfo.Config.Settings.Name,
AgentId: botInfo.Config.Settings.AgentId,
RootDir: botInfo.Config.Settings.RootDir,
RunCommand: runCommand,
Loadout: loadout,
Hivemind: botInfo.Config.Settings.Hivemind,
}
// Add environment variables from the bot's config toml first
for k, v := range botInfo.Config.Settings.Environment.Values() {
customBot.Environment = append(customBot.Environment, &flat.EnvironmentVariableT{
Name: k,
Value: v,
})
}
// Then append torch paths (if found) so they combine properly with any toml-specified paths
setTorchEnv(botInfo.TomlPath, &customBot.Environment)
customBot.Environment = resolveEnvironmentVariables(customBot.Environment)
return &flat.PlayerConfigurationT{
Variety: &flat.PlayerClassT{
Type: flat.PlayerClassCustomBot,
Value: customBot,
},
Team: team,
PlayerId: 0, // let core do this
}
}
type BotConfig struct {
Settings BotSettings `toml:"settings" json:"settings"`
Details BotDetails `toml:"details" json:"details"`
}
type BotSettings struct {
// In-game name of the bot
Name string `toml:"name" json:"name"`
// A unique string identifying this type of bot, typically on the form "<developer>/<botname>"
AgentId string `toml:"agent_id" json:"agentId"`
// Path to loadout.toml, describing the bots "loadout"
LoadoutFile string `toml:"loadout_file" json:"loadoutFile"`
// Optional working dir of the bot
RootDir string `toml:"root_dir" json:"rootDir"`
// Path to the logo of the bot, if ignored, RLBot will look for logo.png
LogoFile string `toml:"logo_file" json:"logoFile"`
// The command RLBot will call to start your bot on Windows
RunCommand string `toml:"run_command" json:"runCommand"`
// The command RLBot will call to start your bot on Linux
// If not defined, RLBot may try to run your bot under wine
RunCommandLinux string `toml:"run_command_linux" json:"runCommandLinux"`
// If bot can handle multiple agents with one client
Hivemind bool `toml:"hivemind" json:"hivemind"`
// Additional environment variables to set for the bot process
Environment BotEnvironment `toml:"environment" json:"environment"`
}
type BotDetails struct {
// Short description of thebot
Description string `toml:"description" json:"description"`
// A fun fact about the bot
FunFact string `toml:"fun_fact" json:"funFact"`
// Link to the source code of the bot (if its available)
SourceLink string `toml:"source_link" json:"sourceLink"` // TODO: Rename this field to repo?
// Name(s) of the bot developer(s)
Developer string `toml:"developer" json:"developer"`
// Programming language the bot is written in.
// (RLGym for example is also valid even though it is written in Python)
Language string `toml:"language" json:"language"`
// ALL POSSIBLE TAGS: 1v1, teamplay, goalie, hoops, dropshot, snow-day, spike-rush, heatseeker, memebot
// NOTE: Only add the goalie tag if your bot only plays as a goalie; this directly contrasts with the teamplay tag!
// NOTE: Only add a tag for a special game mode if you bot properly supports it
Tags []string `toml:"tags" json:"tags"`
}
func (a *App) GetBots(paths []string) []BotInfo {
potentialConfigs := []string{}
for _, path := range paths {
new, err := recursiveTomlSearch(path, "bot")
if err != nil {
println("WARN: failed to search path: " + path)
continue
}
potentialConfigs = append(potentialConfigs, new...)
}
infos := []BotInfo{}
for _, potentialConfigPath := range potentialConfigs {
data, err := os.ReadFile(potentialConfigPath)
if err != nil {
println("WARN: skipping config, couldn't read config at " + potentialConfigPath)
continue
}
var conf BotConfig
if _, err := toml.Decode(string(data), &conf); err != nil {
log.Printf("WARN: skipping config at %s: %v", potentialConfigPath, err)
continue
}
// make location path relative to parent of bot.toml
conf.Settings.RootDir = filepath.Join(filepath.Dir(potentialConfigPath), conf.Settings.RootDir)
var logo_file string
if conf.Settings.LogoFile == "" {
logo_file = filepath.Join(conf.Settings.RootDir, "logo.png")
} else {
logo_file = filepath.Join(conf.Settings.RootDir, conf.Settings.LogoFile)
}
// Read logo file and convert it to data url so the frontend can use it
var icon string
logo_data, err := os.ReadFile(logo_file)
if err != nil {
// only warn if the logo file was explicitly set
if conf.Settings.LogoFile != "" {
println("WARN: failed to read logo file at " + conf.Settings.LogoFile + " for " + conf.Settings.Name)
}
} else {
mtype := mimetype.Detect(logo_data)
b64data := base64.StdEncoding.EncodeToString(logo_data)
icon = "data:" + mtype.String() + ";base64," + b64data
}
var loadout *LoadoutConfig = nil
if conf.Settings.LoadoutFile != "" {
loadoutPath := filepath.Join(filepath.Dir(potentialConfigPath), conf.Settings.LoadoutFile)
loadout, err = a.GetLoadout(loadoutPath)
if err != nil {
println("WARN: failed to read loadout file at " + conf.Settings.LoadoutFile + " for " + conf.Settings.Name)
}
}
infos = append(infos, BotInfo{
Config: conf,
Loadout: loadout,
TomlPath: potentialConfigPath,
Icon: icon,
})
}
// sort infos by bot name
sort.Slice(infos, func(i, j int) bool {
return infos[i].Config.Settings.Name < infos[j].Config.Settings.Name
})
return infos
}
func (a *App) GetLoadout(path string) (*LoadoutConfig, error) {
loadoutData, err := os.ReadFile(path)
if err != nil {
return nil, err
}
var loadout *LoadoutConfig = nil
_, err = toml.Decode(string(loadoutData), &loadout)
if err != nil {
return nil, err
}
return loadout, nil
}
You are visitor 01402520 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.