Skip to content

Commit

Permalink
Added the possibility to associate stores with a game (#86)
Browse files Browse the repository at this point in the history
  • Loading branch information
Leo-Peyronnet committed May 9, 2021
1 parent f27171d commit bc1a43c
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 10 deletions.
4 changes: 3 additions & 1 deletion Gavilya/Windows/AddGame.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ public partial class AddGame : Window
public string GameIconLocation = string.Empty;
public string GameDescription = string.Empty; // The description of the game
public List<SDK.RAWG.Platform> Platforms = new();
public List<SDK.RAWG.Store> Stores = new();
public int RAWGID = -1;
public AddGame()
{
Expand Down Expand Up @@ -163,7 +164,8 @@ private void AddBtn_Click(object sender, RoutedEventArgs e)
Platforms = (Platforms.Count == 0) ? new List<SDK.RAWG.Platform> { Definitions.DefaultPlatform } : Platforms, // Get platforms
LastTimePlayed = 0, // Never played
TotalTimePlayed = 0, // Never played
ProcessName = string.Empty // Default
ProcessName = string.Empty, // Default
Stores = Stores
}; // Create a GameInfo class

Definitions.GamesCardsPages.GamePresenter.Children.Add(new GameCard(gameInfo, GavilyaPages.Cards)); // Add the game
Expand Down
2 changes: 2 additions & 0 deletions Gavilya/Windows/EditGame.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ public partial class EditGame : Window
public int RAWGID = -1; // The Game RAWG Id
public string GameDescription = string.Empty; // The description of the game
public List<SDK.RAWG.Platform> Platforms = new(); // Create a new list
public List<SDK.RAWG.Store> Stores = new();
GameCard GameCard; // The game card
/// <summary>
/// Window where the user can edit a game
Expand Down Expand Up @@ -114,6 +115,7 @@ private async void AddBtn_Click(object sender, RoutedEventArgs e)
Description = GameDescription,
ProcessName = GameCard.GameInfo.ProcessName,
Platforms = (platforms.Count == 0) ? new List<SDK.RAWG.Platform> { Definitions.DefaultPlatform } : platforms, // Get platforms
Stores = (Stores.Count == 0) ? new List<SDK.RAWG.Store>() : Stores
};

foreach (GameInfo gameInfo in Definitions.Games.ToList()) // For each game
Expand Down
28 changes: 19 additions & 9 deletions Gavilya/Windows/SearchGameCover.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -65,18 +65,26 @@ public SearchGameCover(EditGame editGame, GameAssociationActions gameAssociation

private async void Button_Click(object sender, RoutedEventArgs e)
{
ResultPresenter.Children.Clear(); // Remove all the controls
var client = new RestClient(); // Create a REST Client
client.BaseUrl = new Uri("https://api.rawg.io/api/games?"); // Configure the client
var request = new RestRequest(Method.GET); // Create a request
request.AddQueryParameter("search", GameSearchName.Text); // Config the request
var response = await client.ExecuteAsync(request); // Execute the request and store the result
try
{
ResultPresenter.Children.Clear(); // Remove all the controls
var client = new RestClient(); // Create a REST Client
client.BaseUrl = new Uri("https://api.rawg.io/api/games?"); // Configure the client
var request = new RestRequest(Method.GET); // Create a request
request.AddQueryParameter("search", GameSearchName.Text); // Config the request
request.AddQueryParameter("key", APIKeys.RAWGAPIKey);
var response = await client.ExecuteAsync(request); // Execute the request and store the result

var gameResults = JsonSerializer.Deserialize<GamesResults>(response.Content); // Deserialize the content of the reponse
var gameResults = JsonSerializer.Deserialize<GamesResults>(response.Content); // Deserialize the content of the reponse

foreach (Gavilya.SDK.RAWG.Game game in gameResults.results) // For each result
foreach (Gavilya.SDK.RAWG.Game game in gameResults.results) // For each result
{
ResultPresenter.Children.Add(new GameResult(game.name, game.id)); // Add the game
}
}
catch (Exception ex)
{
ResultPresenter.Children.Add(new GameResult(game.name, game.id)); // Add the game
MessageBox.Show(ex.Message, Properties.Resources.Error, MessageBoxButton.OK, MessageBoxImage.Error);
}
}

Expand Down Expand Up @@ -136,13 +144,15 @@ private async void Associate(int id)
addGame1.RAWGID = id; // Set the id
addGame1.GameDescription = await Global.GetGameDescriptionAsync(id); // Get the description
addGame1.Platforms = await Global.GetGamePlatformsAsync(id); // Get the platforms
addGame1.Stores = await Global.GetStoresAsync(id); // Get stores
}
else // If is from EditGame
{
string description = await Global.GetGameDescriptionAsync(id); // Get the description
editGame1.RAWGID = id; // Set the id
editGame1.GameDescription = description;
editGame1.Platforms = await Global.GetGamePlatformsAsync(id); // Get the platforms
editGame1.Stores = await Global.GetStoresAsync(id); // Get stores
}
}

Expand Down

0 comments on commit bc1a43c

Please sign in to comment.