Skip to content

Commit

Permalink
API doc for RAWG is wrong
Browse files Browse the repository at this point in the history
  • Loading branch information
spektor56 committed Feb 19, 2020
1 parent 8abc2b8 commit 9983812
Show file tree
Hide file tree
Showing 5 changed files with 102 additions and 28 deletions.
52 changes: 28 additions & 24 deletions RAWGMetadata/RawgLazyMetadataProvider.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,6 @@
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace RAWGMetadata
{
Expand All @@ -22,12 +20,8 @@ public class RawgLazyMetadataProvider : OnDemandMetadataProvider
private Rawg.Model.GameSingle _gameInfo;
private GamesApi _gamesApi = new GamesApi();

private List<MetadataField> availableFields;

public RawgLazyMetadataProvider(MetadataRequestOptions options, RawgMetadataPlugin plugin)
{
//Game object is in the options class
//This class will search for the game once (name + platform), then use gameid on subsequent lookups to load each metadata field.
this.options = options;
this.plugin = plugin;
}
Expand Down Expand Up @@ -101,22 +95,22 @@ public override string GetName()

return base.GetName();
}
/*

public override List<string> GetGenres()
{
var game = GetGame();
var gameInfo = GetGameInfo();

if (game != null)
if (gameInfo != null)
{
if (!string.IsNullOrWhiteSpace(game.Genres))
if (gameInfo.Genres != null)
{
return game.Genres.Split(';').Select(genre => genre.Trim()).ToList();
return gameInfo.Genres.Select(genre => genre.Name).ToList();
}
}

return base.GetGenres();
}
*/


public override DateTime? GetReleaseDate()
{
Expand All @@ -132,16 +126,16 @@ public override List<string> GetGenres()

return base.GetReleaseDate();
}
/*

public override List<string> GetDevelopers()
{
var game = GetGame();
var gameInfo = GetGameInfo();

if (game != null)
if (gameInfo != null)
{
if (!string.IsNullOrWhiteSpace(game.Developer))
if (gameInfo.Developers != null)
{
return game.Developer.Split(';').Select(developer => developer.Trim()).ToList();
return gameInfo.Developers.Select(developer => developer.Name).ToList();
}
}

Expand All @@ -150,19 +144,19 @@ public override List<string> GetDevelopers()

public override List<string> GetPublishers()
{
var game = GetGame();
var gameInfo = GetGameInfo();

if (game != null)
if (gameInfo != null)
{
if (!string.IsNullOrWhiteSpace(game.Publisher))
if (gameInfo.Publishers != null)
{
return game.Publisher.Split(';').Select(publisher => publisher.Trim()).ToList();
return gameInfo.Publishers.Select(publisher => publisher.Name).ToList();
}
}

return base.GetPublishers();
}
*/


public override string GetDescription()
{
Expand Down Expand Up @@ -280,12 +274,22 @@ public override MetadataFile GetIcon()

return base.GetCriticScore();
}
/*

public override List<string> GetTags()
{
var gameInfo = GetGameInfo();

if (gameInfo != null)
{
if (gameInfo.Tags != null)
{
return gameInfo.Tags.Select(tag => tag.Name).ToList();
}
}

return base.GetTags();
}
*/


public override List<MetadataField> AvailableFields
{
Expand Down
10 changes: 7 additions & 3 deletions RAWGMetadata/RawgMetadataPlugin.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,8 @@ public class RawgMetadataPlugin : MetadataPlugin
{
internal readonly RawgMetadataSettings Settings;
public bool initializing { get; private set; } = true;
public Dictionary<string,int> PlatformList { get; private set; }
public Dictionary<string, int> PlatformList { get; private set; }

public Dictionary<string, string> PlatformTranslationTable = new Dictionary<string, string>(StringComparer.OrdinalIgnoreCase) {
{ "3DO Interactive Multiplayer","3DO"},
{ "Adobe Flash","Web"},
Expand Down Expand Up @@ -68,12 +69,15 @@ public class RawgMetadataPlugin : MetadataPlugin
public RawgMetadataPlugin(IPlayniteAPI playniteAPI) : base(playniteAPI)
{
Settings = new RawgMetadataSettings(this);
PlatformList = Settings.PlatformList;
Task.Run(() => {
try
{
var platformApi = new PlatformsApi();
var platforms = platformApi.PlatformsList();
PlatformList = platforms.Results.ToDictionary(result => result.Name, result => (int)result.Id, StringComparer.OrdinalIgnoreCase);
Settings.PlatformList = PlatformList;
Settings.EndEdit();
}
finally
{
Expand Down Expand Up @@ -142,13 +146,13 @@ public override OnDemandMetadataProvider GetMetadataProvider(MetadataRequestOpti
MetadataField.ReleaseDate,
MetadataField.Developers,
MetadataField.Publishers,
//MetadataField.Tags,
MetadataField.Tags,
MetadataField.Description,
MetadataField.Links,
MetadataField.CriticScore,
MetadataField.CommunityScore,
MetadataField.Icon,
MetadataField.CoverImage,
//MetadataField.CoverImage,
MetadataField.BackgroundImage

};
Expand Down
53 changes: 53 additions & 0 deletions RAWGMetadata/RawgMetadataSettings.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,59 @@ public RawgMetadataSettings()
{
}

public Dictionary<string, int> PlatformList { get; set; } = new Dictionary<string, int>(StringComparer.OrdinalIgnoreCase)
{
{"PC", 4},
{"Xbox One", 1},
{"PlayStation 4", 18},
{"iOS", 3},
{"Android", 21},
{"macOS", 5},
{"Linux", 6},
{"Nintendo Switch", 7},
{"Nintendo 3DS", 8},
{"Nintendo DS", 9},
{"Nintendo DSi", 13},
{"Xbox 360", 14},
{"Xbox", 80},
{"PlayStation 3", 16},
{"PlayStation 2", 15},
{"PlayStation", 27},
{"PS Vita", 19},
{"PSP", 17},
{"Wii U", 10},
{"Wii", 11},
{"GameCube", 105},
{"Nintendo 64", 83},
{"Game Boy Advance", 24},
{"Game Boy Color", 43},
{"Game Boy", 26},
{"SNES", 79},
{"NES", 49},
{"Classic Macintosh", 55},
{"Apple II", 41},
{"Commodore / Amiga", 166},
{"Atari 7800", 28},
{"Atari 5200", 31},
{"Atari 2600", 23},
{"Atari Flashback", 22},
{"Atari 8-bit", 25},
{"Atari ST", 34},
{"Atari Lynx", 46},
{"Atari XEGS", 50},
{"Genesis", 167},
{"SEGA Saturn", 107},
{"SEGA CD", 119},
{"SEGA 32X", 117},
{"SEGA Master System", 74},
{"Dreamcast", 106},
{"3DO", 111},
{"Jaguar", 112},
{"Game Gear", 77},
{"Neo Geo", 12},
{"Web", 171}
};

public RawgMetadataSettings(RawgMetadataPlugin plugin)
{
this.plugin = plugin;
Expand Down
12 changes: 12 additions & 0 deletions Rawg/Model/GameSingle.cs
Original file line number Diff line number Diff line change
Expand Up @@ -287,6 +287,18 @@ protected GameSingle() { }
[DataMember(Name="game_series_count", EmitDefaultValue=false)]
public int? GameSeriesCount { get; private set; }

[DataMember(Name = "developers", EmitDefaultValue = false)]
public List<Developer> Developers { get; set; }

[DataMember(Name = "publishers", EmitDefaultValue = false)]
public List<Publisher> Publishers { get; set; }

[DataMember(Name = "genres", EmitDefaultValue = false)]
public List<Genre> Genres { get; set; }

[DataMember(Name = "tags", EmitDefaultValue = false)]
public List<Tag> Tags { get; set; }

/// <summary>
/// Returns the string presentation of the object
/// </summary>
Expand Down
3 changes: 2 additions & 1 deletion RawgTestApp/Form1.cs
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,8 @@ public Form1()

private async void button1_Click(object sender, EventArgs e)
{

var developerApi = new DevelopersApi();
var test = await developerApi.DevelopersListAsync(null, null);
var platformApi = new PlatformsApi();
var platforms = await platformApi.PlatformsListAsync();
var _platformList = platforms.Results.ToDictionary(result => result.Name, result => (int)result.Id, StringComparer.OrdinalIgnoreCase);
Expand Down

0 comments on commit 9983812

Please sign in to comment.