sharedutils/sharedDistribution/games.go
2023-01-15 00:17:27 +03:00

159 lines
3.4 KiB
Go

package sharedDistribution
type SkirdaGame interface {
// SkirdaGameId string
GetSkirdaGameId() string
GetInterfaceAsset(gameId string) JSGameInterface
GetLaunchArgs() []string
// Launch(gameId string) error
}
type SkirdaGames struct {
Steam []SteamGame
Minecraft MinecraftGame //TODO: To slice
}
func (games SkirdaGames) GetGameTypeById(skirdaGameId string) (string, error) {
if games.Minecraft.GetSkirdaGameId() == skirdaGameId {
return "minecraft", nil
}
for _, game := range games.Steam {
if game.GetSkirdaGameId() == skirdaGameId {
return "steam", nil
}
}
return "", nil //TODO: Right error return
}
func (games SkirdaGames) Test(skirdaGameId string) (interface{}, error) {
return games.Minecraft, nil
}
func (games SkirdaGames) GetInterfaceAssets() []JSGameInterface {
assets := []JSGameInterface{}
assets = append(assets, games.Minecraft.GetInterfaceAsset())
for _, game := range games.Steam {
assets = append(assets, game.GetInterfaceAsset())
}
return assets
}
func (games SteamGame) Test(skirdaGameId string) (interface{}, error) {
return SteamGame{}, nil
}
func (game SteamGame) GetSkirdaGameId() string {
return game.SkirdaGameId
}
func (game MinecraftGame) GetSkirdaGameId() string {
return game.SkirdaGameId
}
func (game MinecraftGame) GetMinecraftVersion() string {
return game.CurrentVersion
}
func (games SkirdaGames) GetLaunchCmd(skirdaGameId string, os string) (string, []string, error) {
gameType, err := games.GetGameTypeById(skirdaGameId)
if err != nil {
return "", nil, nil
}
switch gameType {
case "minecraft":
switch os {
case "windows":
return "notepad", []string{""}, nil
default:
return "", []string{}, nil
}
default:
return "", nil, nil
}
}
// func (games SkirdaGames) FindGameByID(gameId string) (SkirdaGame, error) {
// for _, game := range games {
// if game.GetSkirdaGameId() == gameId {
// return game, nil
// }
// }
// kek := SkirdaGame
// return game, nil //TODO: Right error return
// }
// func (game MinecraftGame) GetLaunchArgs() (string, []string, error) {
// switch os := runtime.GOOS; os {
// case "windows":
// return "java", []string{"-version"}, nil
// default:
// return "", []string{}, nil
// }
// }
func (game SteamGame) GetInterfaceAsset() JSGameInterface {
return JSGameInterface{
GameID: game.SkirdaGameId,
Title: game.Assets.Title,
Icon: game.Assets.Icon,
Description: game.Assets.Description,
}
}
func (game MinecraftGame) GetInterfaceAsset() JSGameInterface {
return JSGameInterface{
GameID: game.SkirdaGameId,
Title: game.Assets.Title,
Icon: game.Assets.Icon,
Description: game.Assets.Description,
}
}
type MinecraftGame struct {
SkirdaGameId string
Assets GameInterfaceAssets
CurrentVersion string
}
type SteamGame struct {
SkirdaGameId string
SteamId string
Args []Argument
OptionalArgs []Argument
//TODO: Settings??
Assets GameInterfaceAssets
Platforms map[string]bool
}
type LocalGame struct {
GameId string
}
type GameInterfaceAssets struct {
Title string
Icon string
Description string
Backgrounds []GameInterfaceBackground
}
type GameInterfaceBackground struct {
File string
}
type JSGameInterface struct {
GameID string `json:"gameId"`
Title string `json:"title"`
Icon string `json:"icon"`
Description string `json:"description"`
}
type Argument struct {
Body string
Value string
}