Пример #1
0
        public static GameHeader Parse(SpeedrunComClient client, dynamic gameHeaderElement)
        {
            var gameHeader = new GameHeader();

            gameHeader.ID           = gameHeaderElement.id as string;
            gameHeader.Name         = gameHeaderElement.names.international as string;
            gameHeader.JapaneseName = gameHeaderElement.names.japanese as string;
            gameHeader.WebLink      = new Uri(gameHeaderElement.weblink as string);
            gameHeader.Abbreviation = gameHeaderElement.abbreviation as string;

            return(gameHeader);
        }
Пример #2
0
        public static GameHeader Parse(SpeedrunComClient client, dynamic gameHeaderElement)
        {
            var gameHeader = new GameHeader();

            gameHeader.ID = gameHeaderElement.id as string;
            gameHeader.Name = gameHeaderElement.names.international as string;
            gameHeader.JapaneseName = gameHeaderElement.names.japanese as string;
            gameHeader.WebLink = new Uri(gameHeaderElement.weblink as string);
            gameHeader.Abbreviation = gameHeaderElement.abbreviation as string;

            return gameHeader;
        }
        public static GameHeader Parse(SpeedrunComClient client, dynamic gameHeaderElement)
        {
            var gameHeader = new GameHeader()
            {
                ID           = gameHeaderElement.id as string,
                Name         = gameHeaderElement.names.international as string,
                JapaneseName = gameHeaderElement.names.japanese as string,
                WebLink      = new Uri(gameHeaderElement.weblink.ToString()),
                Abbreviation = gameHeaderElement.abbreviation as string,
            };

            return(gameHeader);
        }
Пример #4
0
        public IEnumerable <GameHeader> GetGameHeaders(int elementsPerPage = 1000, GamesOrdering orderBy = default)
        {
            var parameters = new List <string>()
            {
                "_bulk=yes"
            };

            parameters.AddRange(orderBy.ToParameters());
            parameters.Add(string.Format("max={0}", elementsPerPage));

            var uri = GetGamesUri(parameters.ToParameters());

            return(baseClient.DoPaginatedRequest(uri, x => GameHeader.Parse(baseClient, x) as GameHeader));
        }
Пример #5
0
        public static Game Parse(SpeedrunComClient client, dynamic gameElement)
        {
            var game = new Game();

            //Parse Attributes
            var properties = gameElement as IDictionary <string, dynamic>;

            game.Header        = GameHeader.Parse(client, gameElement);
            game.YearOfRelease = (int)properties["released"];
            game.Ruleset       = Ruleset.Parse(client, properties["ruleset"]);
            game.IsRomHack     = properties["romhack"];
            game.CreationDate  = properties["created"];
            game.Assets        = Assets.Parse(client, properties["assets"]);

            //Parse Embeds

            if (properties.ContainsKey("moderators"))
            {
                IDictionary <string, dynamic> moderatorsProperties = properties["moderators"] as IDictionary <string, dynamic>;

                if (moderatorsProperties.ContainsKey("data"))
                {
                    ReadOnlyCollection <User> users = client.ParseCollection(moderatorsProperties["data"], new Func <dynamic, User>(x => User.Parse(client, x) as User));
                    game.moderatorUsers = new Lazy <ReadOnlyCollection <User> >(() => users);
                }
                else
                {
                    game.Moderators = moderatorsProperties.Select(x => Moderator.Parse(client, x)).ToList().AsReadOnly();

                    game.moderatorUsers = new Lazy <ReadOnlyCollection <User> >(
                        () =>
                    {
                        ReadOnlyCollection <User> users;

                        if (game.Moderators.Count(x => !x.user.IsValueCreated) > 1)
                        {
                            users = client.Games.GetGame(game.ID, embeds: new GameEmbeds(embedModerators: true)).ModeratorUsers;

                            foreach (var user in users)
                            {
                                var moderator = game.Moderators.FirstOrDefault(x => x.UserID == user.ID);
                                if (moderator != null)
                                {
                                    moderator.user = new Lazy <User>(() => user);
                                }
                            }
                        }
                        else
                        {
                            users = game.Moderators.Select(x => x.User).ToList().AsReadOnly();
                        }

                        return(users);
                    });
                }
            }
            else
            {
                game.Moderators     = new ReadOnlyCollection <Moderator>(new Moderator[0]);
                game.moderatorUsers = new Lazy <ReadOnlyCollection <User> >(() => new List <User>().AsReadOnly());
            }

            if (properties["platforms"] is IList)
            {
                game.PlatformIDs = client.ParseCollection <string>(properties["platforms"]);

                if (game.PlatformIDs.Count > 1)
                {
                    game.platforms = new Lazy <ReadOnlyCollection <Platform> >(
                        () => client.Games.GetGame(game.ID, embeds: new GameEmbeds(embedPlatforms: true)).Platforms);
                }
                else
                {
                    game.platforms = new Lazy <ReadOnlyCollection <Platform> >(
                        () => game.PlatformIDs.Select(x => client.Platforms.GetPlatform(x)).ToList().AsReadOnly());
                }
            }
            else
            {
                Func <dynamic, Platform>      platformParser = x => Platform.Parse(client, x) as Platform;
                ReadOnlyCollection <Platform> platforms      = client.ParseCollection(properties["regions"]["data"], platformParser);
                game.platforms   = new Lazy <ReadOnlyCollection <Platform> >(() => platforms);
                game.PlatformIDs = platforms.Select(x => x.ID).ToList().AsReadOnly();
            }

            if (properties["regions"] is IList)
            {
                game.RegionIDs = client.ParseCollection <string>(properties["regions"]);

                if (game.RegionIDs.Count > 1)
                {
                    game.regions = new Lazy <ReadOnlyCollection <Region> >(
                        () => client.Games.GetGame(game.ID, embeds: new GameEmbeds(embedRegions: true)).Regions);
                }
                else
                {
                    game.regions = new Lazy <ReadOnlyCollection <Region> >(
                        () => game.RegionIDs.Select(x => client.Regions.GetRegion(x)).ToList().AsReadOnly());
                }
            }
            else
            {
                ReadOnlyCollection <Region> regions = client.ParseCollection(properties["regions"]["data"], new Func <dynamic, Region>(x => Region.Parse(client, x) as Region));
                game.regions   = new Lazy <ReadOnlyCollection <Region> >(() => regions);
                game.RegionIDs = regions.Select(x => x.ID).ToList().AsReadOnly();
            }

            //Parse Links

            game.Runs = client.Runs.GetRuns(gameId: game.ID);

            if (properties.ContainsKey("levels"))
            {
                Func <dynamic, Level>      levelParser = x => Level.Parse(client, x) as Level;
                ReadOnlyCollection <Level> levels      = client.ParseCollection(properties["levels"]["data"], levelParser);
                game.levels = new Lazy <ReadOnlyCollection <Level> >(() => levels);
            }
            else
            {
                game.levels = new Lazy <ReadOnlyCollection <Level> >(() => client.Games.GetLevels(game.ID));
            }

            if (properties.ContainsKey("categories"))
            {
                Func <dynamic, Category>      categoryParser = x => Category.Parse(client, x) as Category;
                ReadOnlyCollection <Category> categories     = client.ParseCollection(properties["categories"]["data"], categoryParser);


                foreach (var category in categories)
                {
                    category.game = new Lazy <Game>(() => game);
                }

                game.categories = new Lazy <ReadOnlyCollection <Category> >(() => categories);
            }
            else
            {
                game.categories = new Lazy <ReadOnlyCollection <Category> >(() =>
                {
                    var categories = client.Games.GetCategories(game.ID);

                    foreach (var category in categories)
                    {
                        category.game = new Lazy <Game>(() => game);
                    }

                    return(categories);
                });
            }

            if (properties.ContainsKey("variables"))
            {
                Func <dynamic, Variable>      variableParser = x => Variable.Parse(client, x) as Variable;
                ReadOnlyCollection <Variable> variables      = client.ParseCollection(properties["variables"]["data"], variableParser);
                game.variables = new Lazy <ReadOnlyCollection <Variable> >(() => variables);
            }
            else
            {
                game.variables = new Lazy <ReadOnlyCollection <Variable> >(() => client.Games.GetVariables(game.ID));
            }

            var links      = properties["links"] as IEnumerable <dynamic>;
            var seriesLink = links.FirstOrDefault(x => x.rel == "series");

            if (seriesLink != null)
            {
                var parentUri = seriesLink.uri.ToString();
                game.SeriesID = parentUri.Substring(parentUri.LastIndexOf('/') + 1);
                game.series   = new Lazy <Series>(() => client.Series.GetSingleSeries(game.SeriesID));
            }
            else
            {
                game.series = new Lazy <Series>(() => null);
            }

            var originalGameLink = links.FirstOrDefault(x => x.rel == "game");

            if (originalGameLink != null)
            {
                var originalGameUri = originalGameLink.uri as string;
                game.OriginalGameID = originalGameUri.Substring(originalGameUri.LastIndexOf('/') + 1);
                game.originalGame   = new Lazy <Game>(() => client.Games.GetGame(game.OriginalGameID));
            }
            else
            {
                game.originalGame = new Lazy <Game>(() => null);
            }

            game.romHacks = new Lazy <ReadOnlyCollection <Game> >(() =>
            {
                var romHacks = client.Games.GetRomHacks(game.ID);

                if (romHacks != null)
                {
                    foreach (var romHack in romHacks)
                    {
                        romHack.originalGame = new Lazy <Game>(() => game);
                    }
                }

                return(romHacks);
            });

            return(game);
        }