refactor games utils

This commit is contained in:
cyber-dream 2022-10-26 21:43:21 +03:00
parent d132e4a6be
commit 52908484d0
7 changed files with 117 additions and 136 deletions

23
.gitignore vendored
View File

@ -1,23 +0,0 @@
# ---> Go
# If you prefer the allow list template instead of the deny list, see community template:
# https://github.com/github/gitignore/blob/main/community/Golang/Go.AllowList.gitignore
#
# Binaries for programs and plugins
*.exe
*.exe~
*.dll
*.so
*.dylib
# Test binary, built with `go test -c`
*.test
# Output of the go coverage tool, specifically when used with LiteIDE
*.out
# Dependency directories (remove the comment below to include it)
# vendor/
# Go workspace file
go.work

View File

@ -1,2 +0,0 @@
# skirda-go-utils

View File

@ -1,28 +0,0 @@
package skirdaGoUtils
var garrysmodGame = Game{
GameId: "garrysmod",
SteamId: "",
Executable: "",
Args: []string{"steam://rungameid/4000"},
Platforms: map[string]bool{"linux": true},
Assets: GameInterfaceAssets{
Title: "Garry's Mod",
Image: "gmod.png",
Description: "",
},
}
var openarena = Game{
GameId: "openarena",
SteamId: "",
Executable: "/usr/games/openarena",
Args: []string{},
Assets: GameInterfaceAssets{
Title: "Open Arena",
Image: "openarena.jpg",
Description: "asdadasd",
},
}
var FakeGamesList = []Game{garrysmodGame, openarena}

27
game/fakeGames.go Normal file
View File

@ -0,0 +1,27 @@
package game
var garrysmodGame = SteamGame{
GameId: "garrysmod",
SteamId: "4000",
Args: []string{},
Platforms: map[string]bool{"linux": true},
Assets: GameInterfaceAssets{
Title: "Garry's Mod",
Image: "gmod.png",
Description: "",
},
}
var openarena = SteamGame{
GameId: "openarena",
SteamId: "",
//Executable: "/usr/games/openarena",
Args: []string{},
Assets: GameInterfaceAssets{
Title: "Open Arena",
Image: "openarena.jpg",
Description: "asdadasd",
},
}
var FakeGamesList = []SteamGame{garrysmodGame, openarena}

19
game/gamesTypes.go Normal file
View File

@ -0,0 +1,19 @@
package gamestypes
type SteamGame struct {
GameId string
SteamId string
Args []string
Assets GameInterfaceAssets
Platforms map[string]bool
}
type GameInterfaceAssets struct {
Title string
Image string
Description string
}
type Games struct {
SteamGames []SteamGame
}

71
game/gamesUtils.go Normal file
View File

@ -0,0 +1,71 @@
package game
// type SteamGame struct {
// GameId string
// SteamId string
// Args []string
// Assets GameInterfaceAssets
// Platforms map[string]bool
// }
// type Games struct {
// SteamGames []SteamGame
// }
// type GameInterfaceAssets struct {
// Title string
// Image string
// Description string
// }
// type JSGameInterface struct {
// GameID string `json:"gameId"`
// Title string `json:"title"`
// Image string `json:"image"`
// Description string `json:"description"`
// }
// var GamesList = []SteamGame{garrysmodGame, openarena}
// func GetJSGameInterface(game SteamGame) JSGameInterface {
// newInterface := JSGameInterface{
// GameID: game.GameId,
// Title: game.Assets.Title,
// Image: game.Assets.Image,
// Description: game.Assets.Description,
// }
// return newInterface
// }
// func findGameByID(id string) SteamGame {
// for _, game := range GamesList {
// if game.GameId == id {
// return game
// }
// }
// var temp SteamGame = SteamGame{}
// return temp
// }
// func findSteamGameByID(id string) SteamGame {
// for _, game := range localGames.St {
// if game.GameId == id {
// return game
// }
// }
// var game SteamGame = SteamGame{}
// return game
// }
func FindGameByID() {}
func GetJSGameInterface(game SteamGame) JSGameInterface {
newInterface := JSGameInterface{
GameID: game.GameId,
Title: game.Assets.Title,
Image: game.Assets.Image,
Description: game.Assets.Description,
}
return newInterface
}

View File

@ -1,83 +0,0 @@
package skirdaGoUtils
type Game struct {
GameId string
SteamId string
//GameType string
Executable string
Args []string
Assets GameInterfaceAssets
Platforms map[string]bool
}
type GameInterfaceAssets struct {
Title string
Image string
Description string
}
type JSGameInterface struct {
Id int `json:"id"`
GameID string `json:"gameId"`
Title string `json:"title"`
Image string `json:"image"`
Description string `json:"description"`
}
var GamesList = []Game{garrysmodGame, openarena}
func GetGamesListInterface() []JSGameInterface {
var gamesInterfacesList = []JSGameInterface{}
for _, Game := range GamesList {
gamesInterfacesList = append(gamesInterfacesList, GetJSGameInterface(Game))
}
return gamesInterfacesList
}
func GetJSGameInterface(game Game) JSGameInterface {
newInterface := JSGameInterface{
//Id: game.Id,
GameID: game.GameId,
Title: game.Assets.Title,
Image: game.Assets.Image,
Description: game.Assets.Description,
}
return newInterface
}
func findGameByID(id string) Game {
for _, game := range GamesList {
if game.GameId == id {
return game
}
}
var temp Game = Game{}
return temp
}
// var garrysmodGame = Game{
// GameId: "garrysmod",
// GameType: "steam",
// Title: "Garry's Mod",
// Executable: "steam",
// Args: []string{"steam://rungameid/4000"},
// Assets: GameInterfaceAssets{
// Image: "gmod.png",
// Description: "",
// },
// }
// var openarena = Game{
// GameId: "openarena",
// GameType: "file",
// Title: "Open Arena",
// Executable: "/usr/games/openarena",
// Args: []string{},
// Assets: GameInterfaceAssets{
// Image: "openarena.jpg",
// Description: "asdadasd",
// },
// }