cloud-game/pkg/config/emulator.go
Sergey Stepanov 1831e44eef Add new saveStateFs config param
Used when you need a copy of FS for new game sessions (i.e. DOSBox uniqueSaveDir=true).
2024-11-26 19:35:31 +03:00

124 lines
2.6 KiB
Go

package config
import (
"path"
"path/filepath"
"strings"
)
type Emulator struct {
Threads int
Storage string
LocalPath string
Libretro LibretroConfig
AutosaveSec int
}
type LibretroConfig struct {
Cores struct {
Paths struct {
Libs string
}
Repo struct {
Sync bool
ExtLock string
Main LibretroRepoConfig
Secondary LibretroRepoConfig
}
List map[string]LibretroCoreConfig
}
DebounceMs int
Dup bool
SaveCompression bool
LogLevel int
}
type LibretroRepoConfig struct {
Type string
Url string
Compression string
}
type LibretroCoreConfig struct {
AltRepo bool
AutoGlContext bool // hack: keep it here to pass it down the emulator
CoreAspectRatio bool
Folder string
Hacks []string
Height int
Hid map[int][]int
IsGlAllowed bool
KbMouseSupport bool
Lib string
NonBlockingSave bool
Options map[string]string
Options4rom map[string]map[string]string // <(^_^)>
Roms []string
SaveStateFs string
Scale float64
UniqueSaveDir bool
UsesLibCo bool
VFR bool
Width int
}
type CoreInfo struct {
Id string
Name string
AltRepo bool
}
// GetLibretroCoreConfig returns a core config with expanded paths.
func (e Emulator) GetLibretroCoreConfig(emulator string) LibretroCoreConfig {
cores := e.Libretro.Cores
conf := cores.List[emulator]
conf.Lib = path.Join(cores.Paths.Libs, conf.Lib)
return conf
}
// GetEmulator tries to find a suitable emulator.
// !to remove quadratic complexity
func (e Emulator) GetEmulator(rom string, path string) string {
found := ""
for emu, core := range e.Libretro.Cores.List {
for _, romName := range core.Roms {
if rom == romName {
found = emu
if p := strings.SplitN(filepath.ToSlash(path), "/", 2); len(p) > 1 {
folder := p[0]
if (folder != "" && folder == core.Folder) || folder == emu {
return emu
}
}
}
}
}
return found
}
func (e Emulator) GetSupportedExtensions() []string {
var extensions []string
for _, core := range e.Libretro.Cores.List {
extensions = append(extensions, core.Roms...)
}
return extensions
}
func (e Emulator) SessionStoragePath() string {
return e.Storage
}
func (l *LibretroConfig) GetCores() (cores []CoreInfo) {
for k, core := range l.Cores.List {
cores = append(cores, CoreInfo{Id: k, Name: core.Lib, AltRepo: core.AltRepo})
}
return
}
func (l *LibretroConfig) GetCoresStorePath() string {
pth, err := filepath.Abs(l.Cores.Paths.Libs)
if err != nil {
return ""
}
return pth
}