Esempio n. 1
0
        public static ImageAsset Parse(SpeedrunComClient client, dynamic imageElement)
        {
            if (imageElement == null)
            {
                return(null);
            }

            var image = new ImageAsset();

            var uri = imageElement.uri as string;

            image.Uri    = new Uri(uri);
            image.Width  = (int)imageElement.width;
            image.Height = (int)imageElement.height;

            return(image);
        }
Esempio n. 2
0
        public static Location Parse(SpeedrunComClient client, dynamic locationElement)
        {
            Location location = new Location();
            IDictionary <string, dynamic> properties = locationElement as IDictionary <string, dynamic>;

            if (properties != null)
            {
                location.Country = Country.Parse(client, properties["country"]);

                if (properties.ContainsKey("region"))
                {
                    location.Region = CountryRegion.Parse(client, properties["region"]);
                }
            }

            return(location);
        }
Esempio n. 3
0
        public static VariableValue ParseIDPair(SpeedrunComClient client, Variable variable, KeyValuePair <string, dynamic> valueElement)
        {
            var value = new VariableValue();

            value.VariableID = variable.ID;
            value.ID         = valueElement.Key as string;

            //Parse Links

            value.variable = new Lazy <Variable>(() => variable);

            var valueName = valueElement.Value as string;

            value.value = new Lazy <string>(() => valueName);

            return(value);
        }
        public static new Record Parse(SpeedrunComClient client, dynamic recordElement)
        {
            IDictionary <string, dynamic> properties = recordElement as IDictionary <string, dynamic>;

            Record record = new Record();

            if (properties.ContainsKey("place"))
            {
                recordElement.Rank = (int)properties["place"];
            }

            if (properties.ContainsKey("game"))
            {
                recordElement.run.game = recordElement.game;
            }

            if (properties.ContainsKey("category"))
            {
                recordElement.run.category = recordElement.category;
            }

            if (properties.ContainsKey("level"))
            {
                recordElement.run.level = recordElement.level;
            }

            if (properties.ContainsKey("players"))
            {
                recordElement.run.players = recordElement.players;
            }

            if (properties.ContainsKey("region"))
            {
                recordElement.run.region = recordElement.region;
            }

            if (properties.ContainsKey("platform"))
            {
                recordElement.run.platform = recordElement.platform;
            }

            Run.Parse(record, client, recordElement.run);

            return(record);
        }
Esempio n. 5
0
        public static VariableScope Parse(SpeedrunComClient client, dynamic scopeElement)
        {
            var scope = new VariableScope();

            scope.Type = parseType(scopeElement.type as string);

            if (scope.Type == VariableScopeType.SingleLevel)
            {
                scope.LevelID = scopeElement.level as string;
                scope.level   = new Lazy <Level>(() => client.Levels.GetLevel(scope.LevelID));
            }
            else
            {
                scope.level = new Lazy <Level>(() => null);
            }

            return(scope);
        }
Esempio n. 6
0
        public static Ruleset Parse(SpeedrunComClient client, dynamic rulesetElement)
        {
            var ruleset = new Ruleset();

            var properties = rulesetElement.Properties as IDictionary <string, dynamic>;

            ruleset.ShowMilliseconds     = properties["show-milliseconds"];
            ruleset.RequiresVerification = properties["require-verification"];
            ruleset.RequiresVideo        = properties["require-video"];

            Func <dynamic, TimingMethod> timingMethodParser = x => TimingMethodHelpers.FromString(x as string);

            ruleset.TimingMethods       = client.ParseCollection(properties["run-times"], timingMethodParser);
            ruleset.DefaultTimingMethod = TimingMethodHelpers.FromString(properties["default-time"]);

            ruleset.EmulatorsAllowed = properties["emulators-allowed"];

            return(ruleset);
        }
Esempio n. 7
0
        public static Player Parse(SpeedrunComClient client, dynamic playerElement)
        {
            var player = new Player();

            var properties = playerElement as IDictionary <string, dynamic>;

            if (properties.ContainsKey("uri"))
            {
                if (properties["rel"] == "user")
                {
                    player.UserID = properties["id"];
                    player.user   = new Lazy <User>(() => client.Users.GetUser(player.UserID));
                    player.guest  = new Lazy <Guest>(() => null);
                }
                else
                {
                    player.GuestName = properties["name"];
                    player.guest     = new Lazy <Guest>(() => client.Guests.GetGuest(player.GuestName));
                    player.user      = new Lazy <User>(() => null);
                }
            }
            else
            {
                if (properties["rel"] == "user")
                {
                    var user = User.Parse(client, properties) as User;
                    player.user   = new Lazy <User>(() => user);
                    player.UserID = user.ID;
                    player.guest  = new Lazy <Guest>(() => null);
                }
                else
                {
                    var guest = Guest.Parse(client, properties) as Guest;
                    player.guest     = new Lazy <Guest>(() => guest);
                    player.GuestName = guest.Name;
                    player.user      = new Lazy <User>(() => null);
                }
            }

            return(player);
        }
Esempio n. 8
0
        public static Assets Parse(SpeedrunComClient client, dynamic assetsElement)
        {
            var assets = new Assets();

            var properties = assetsElement.Properties as IDictionary <string, dynamic>;

            assets.Logo              = ImageAsset.Parse(client, assetsElement.logo) as ImageAsset;
            assets.CoverTiny         = ImageAsset.Parse(client, properties["cover-tiny"]) as ImageAsset;
            assets.CoverSmall        = ImageAsset.Parse(client, properties["cover-small"]) as ImageAsset;
            assets.CoverMedium       = ImageAsset.Parse(client, properties["cover-medium"]) as ImageAsset;
            assets.CoverLarge        = ImageAsset.Parse(client, properties["cover-large"]) as ImageAsset;
            assets.Icon              = ImageAsset.Parse(client, assetsElement.icon) as ImageAsset;
            assets.TrophyFirstPlace  = ImageAsset.Parse(client, properties["trophy-1st"]) as ImageAsset;
            assets.TrophySecondPlace = ImageAsset.Parse(client, properties["trophy-2nd"]) as ImageAsset;
            assets.TrophyThirdPlace  = ImageAsset.Parse(client, properties["trophy-3rd"]) as ImageAsset;
            assets.TrophyFourthPlace = ImageAsset.Parse(client, properties["trophy-4th"]) as ImageAsset;
            assets.BackgroundImage   = ImageAsset.Parse(client, assetsElement.background) as ImageAsset;
            assets.ForegroundImage   = ImageAsset.Parse(client, assetsElement.foreground) as ImageAsset;

            return(assets);
        }
Esempio n. 9
0
        public static Region Parse(SpeedrunComClient client, dynamic regionElement)
        {
            if (regionElement is ArrayList)
            {
                return(null);
            }

            var region = new Region();

            //Parse Attributes

            region.ID   = regionElement.id as string;
            region.Name = regionElement.name as string;

            //Parse Links

            region.Games = client.Games.GetGames(regionId: region.ID);
            region.Runs  = client.Runs.GetRuns(regionId: region.ID);

            return(region);
        }
Esempio n. 10
0
        public static Platform Parse(SpeedrunComClient client, dynamic platformElement)
        {
            if (platformElement is ArrayList)
            {
                return(null);
            }

            var platform = new Platform();

            //Parse Attributes

            platform.ID            = platformElement.id as string;
            platform.Name          = platformElement.name as string;
            platform.YearOfRelease = (int)platformElement.released;

            //Parse Links

            platform.Games = client.Games.GetGames(platformId: platform.ID);
            platform.Runs  = client.Runs.GetRuns(platformId: platform.ID);

            return(platform);
        }
Esempio n. 11
0
        public static RunVideos Parse(SpeedrunComClient client, dynamic videosElement)
        {
            if (videosElement == null)
            {
                return(null);
            }

            IDictionary <string, dynamic> properties = videosElement as IDictionary <string, dynamic>;

            RunVideos videos = new RunVideos();

            if (properties.ContainsKey("text"))
            {
                videos.Text = properties["text"];
            }

            if (properties.ContainsKey("links"))
            {
                videos.Links = client.ParseCollection(properties["links"], new Func <dynamic, Uri>(parseVideoLink));
            }


            return(videos);
        }
Esempio n. 12
0
 public PlatformsClient(SpeedrunComClient baseClient)
 {
     this.baseClient = baseClient;
 }
Esempio n. 13
0
 public VariablesClient(SpeedrunComClient baseClient)
 {
     this.baseClient = baseClient;
 }
Esempio n. 14
0
        public static User Parse(SpeedrunComClient client, dynamic userElement)
        {
            var user = new User();

            var properties = userElement.Properties as IDictionary <string, dynamic>;

            //Parse Attributes

            user.ID           = userElement.id as string;
            user.Name         = userElement.names.international as string;
            user.JapaneseName = userElement.names.japanese as string;
            user.WebLink      = new Uri(userElement.weblink as string);
            user.NameStyle    = UserNameStyle.Parse(client, properties["name-style"]) as UserNameStyle;
            user.Role         = parseUserRole(userElement.role as string);

            var signUpDate = userElement.signup as string;

            if (!string.IsNullOrEmpty(signUpDate))
            {
                user.SignUpDate = DateTime.Parse(signUpDate, CultureInfo.InvariantCulture, DateTimeStyles.AssumeUniversal);
            }

            user.Location = Location.Parse(client, userElement.location) as Location;

            var twitchLink = userElement.twitch;

            if (twitchLink != null)
            {
                user.TwitchProfile = new Uri(twitchLink.uri as string);
            }

            var hitboxLink = userElement.hitbox;

            if (hitboxLink != null)
            {
                user.HitboxProfile = new Uri(hitboxLink.uri as string);
            }

            var youtubeLink = userElement.youtube;

            if (youtubeLink != null)
            {
                user.YoutubeProfile = new Uri(youtubeLink.uri as string);
            }

            var twitterLink = userElement.twitter;

            if (twitterLink != null)
            {
                user.TwitterProfile = new Uri(twitterLink.uri as string);
            }

            var speedRunsLiveLink = userElement.speedrunslive;

            if (speedRunsLiveLink != null)
            {
                user.SpeedRunsLiveProfile = new Uri(speedRunsLiveLink.uri as string);
            }

            //Parse Links

            user.Runs           = client.Runs.GetRuns(userId: user.ID);
            user.ModeratedGames = client.Games.GetGames(moderatorId: user.ID);
            user.personalBests  = new Lazy <ReadOnlyCollection <Record> >(() =>
            {
                var records = client.Users.GetPersonalBests(userId: user.ID);
                var lazy    = new Lazy <User>(() => user);

                foreach (var record in records)
                {
                    var player = record.Players.FirstOrDefault(x => x.UserID == user.ID);
                    if (player != null)
                    {
                        player.user = lazy;
                    }
                }

                return(records);
            });

            return(user);
        }
Esempio n. 15
0
 public CategoriesClient(SpeedrunComClient baseClient)
 {
     this.baseClient = baseClient;
 }
Esempio n. 16
0
        public static Leaderboard Parse(SpeedrunComClient client, dynamic leaderboardElement)
        {
            var leaderboard = new Leaderboard();

            var properties = leaderboardElement.Properties as IDictionary <string, dynamic>;

            //Parse Attributes

            leaderboard.WebLink = new Uri(leaderboardElement.weblink as string);

            var emulators = leaderboardElement.emulators as string;

            if (emulators == "true")
            {
                leaderboard.EmulatorFilter = EmulatorsFilter.OnlyEmulators;
            }
            else if (emulators == "false")
            {
                leaderboard.EmulatorFilter = EmulatorsFilter.NoEmulators;
            }
            else
            {
                leaderboard.EmulatorFilter = EmulatorsFilter.NotSet;
            }

            leaderboard.AreRunsWithoutVideoFilteredOut = properties["video-only"];

            //TODO Not actually optional
            if (leaderboardElement.timing != null)
            {
                leaderboard.OrderedBy = TimingMethodHelpers.FromString(leaderboardElement.timing as string);
            }

            if (leaderboardElement.values is DynamicJsonObject)
            {
                var valueProperties = leaderboardElement.values.Properties as IDictionary <string, dynamic>;
                leaderboard.VariableFilters = valueProperties.Select(x => VariableValue.ParseValueDescriptor(client, x) as VariableValue).ToList().AsReadOnly();
            }
            else
            {
                leaderboard.VariableFilters = new List <VariableValue>().AsReadOnly();
            }

            Func <dynamic, Record> recordParser = x => Record.Parse(client, x) as Record;

            leaderboard.Records = client.ParseCollection(leaderboardElement.runs, recordParser);

            //Parse Links

            if (properties["game"] is string)
            {
                leaderboard.GameID = leaderboardElement.game as string;
                leaderboard.game   = new Lazy <Game>(() => client.Games.GetGame(leaderboard.GameID));
            }
            else
            {
                var game = Game.Parse(client, properties["game"].data) as Game;
                leaderboard.game   = new Lazy <Game>(() => game);
                leaderboard.GameID = game.ID;
            }

            if (properties["category"] is string)
            {
                leaderboard.CategoryID = leaderboardElement.category as string;
                leaderboard.category   = new Lazy <Category>(() => client.Categories.GetCategory(leaderboard.CategoryID));
            }
            else
            {
                var category = Category.Parse(client, properties["category"].data) as Category;
                leaderboard.category = new Lazy <Category>(() => category);
                if (category != null)
                {
                    leaderboard.CategoryID = category.ID;
                }
            }

            if (properties["level"] == null)
            {
                leaderboard.level = new Lazy <Level>(() => null);
            }
            else if (properties["level"] is string)
            {
                leaderboard.LevelID = leaderboardElement.level as string;
                leaderboard.level   = new Lazy <Level>(() => client.Levels.GetLevel(leaderboard.LevelID));
            }
            else
            {
                var level = Level.Parse(client, properties["level"].data) as Level;
                leaderboard.level = new Lazy <Level>(() => level);
                if (level != null)
                {
                    leaderboard.LevelID = level.ID;
                }
            }

            if (properties["platform"] == null)
            {
                leaderboard.platformFilter = new Lazy <Platform>(() => null);
            }
            else if (properties["platform"] is string)
            {
                leaderboard.PlatformIDOfFilter = properties["platform"] as string;
                leaderboard.platformFilter     = new Lazy <Platform>(() => client.Platforms.GetPlatform(leaderboard.PlatformIDOfFilter));
            }
            else
            {
                var platform = Platform.Parse(client, properties["platform"].data) as Platform;
                leaderboard.platformFilter = new Lazy <Platform>(() => platform);
                if (platform != null)
                {
                    leaderboard.PlatformIDOfFilter = platform.ID;
                }
            }

            if (properties["region"] == null)
            {
                leaderboard.regionFilter = new Lazy <Region>(() => null);
            }
            else if (properties["region"] is string)
            {
                leaderboard.RegionIDOfFilter = properties["region"] as string;
                leaderboard.regionFilter     = new Lazy <Region>(() => client.Regions.GetRegion(leaderboard.RegionIDOfFilter));
            }
            else
            {
                var region = Region.Parse(client, properties["region"].data) as Region;
                leaderboard.regionFilter = new Lazy <Region>(() => region);
                if (region != null)
                {
                    leaderboard.RegionIDOfFilter = region.ID;
                }
            }

            //Parse Embeds

            if (properties.ContainsKey("players"))
            {
                Func <dynamic, Player> playerParser = x => Player.Parse(client, x) as Player;
                var players = client.ParseCollection(leaderboardElement.players.data, playerParser) as ReadOnlyCollection <Player>;

                foreach (var record in leaderboard.Records)
                {
                    record.Players = record.Players.Select(x => players.FirstOrDefault(y => x.Equals(y))).ToList().AsReadOnly();
                }

                leaderboard.players = new Lazy <ReadOnlyCollection <Player> >(() => players);
            }
            else
            {
                leaderboard.players = new Lazy <ReadOnlyCollection <Player> >(() => leaderboard.Records.SelectMany(x => x.Players).ToList().Distinct().ToList().AsReadOnly());
            }

            if (properties.ContainsKey("regions"))
            {
                Func <dynamic, Region> regionParser = x => Region.Parse(client, x) as Region;
                var regions = client.ParseCollection(leaderboardElement.regions.data, regionParser) as ReadOnlyCollection <Region>;

                foreach (var record in leaderboard.Records)
                {
                    record.System.region = new Lazy <Region>(() => regions.FirstOrDefault(x => x.ID == record.System.RegionID));
                }

                leaderboard.usedRegions = new Lazy <ReadOnlyCollection <Region> >(() => regions);
            }
            else
            {
                leaderboard.usedRegions = new Lazy <ReadOnlyCollection <Region> >(() => leaderboard.Records.Select(x => x.Region).Distinct().Where(x => x != null).ToList().AsReadOnly());
            }

            if (properties.ContainsKey("platforms"))
            {
                Func <dynamic, Platform> platformParser = x => Platform.Parse(client, x) as Platform;
                var platforms = client.ParseCollection(leaderboardElement.platforms.data, platformParser) as ReadOnlyCollection <Platform>;

                foreach (var record in leaderboard.Records)
                {
                    record.System.platform = new Lazy <Platform>(() => platforms.FirstOrDefault(x => x.ID == record.System.PlatformID));
                }

                leaderboard.usedPlatforms = new Lazy <ReadOnlyCollection <Platform> >(() => platforms);
            }
            else
            {
                leaderboard.usedPlatforms = new Lazy <ReadOnlyCollection <Platform> >(() => leaderboard.Records.Select(x => x.Platform).Distinct().Where(x => x != null).ToList().AsReadOnly());
            }

            Action <ReadOnlyCollection <Variable> > patchVariablesOfRecords = variables =>
            {
                foreach (var record in leaderboard.Records)
                {
                    foreach (var value in record.VariableValues)
                    {
                        value.variable = new Lazy <Variable>(() => variables.FirstOrDefault(x => x.ID == value.VariableID));
                    }
                }
            };

            if (properties.ContainsKey("variables"))
            {
                Func <dynamic, Variable> variableParser = x => Variable.Parse(client, x) as Variable;
                var variables = client.ParseCollection(leaderboardElement.variables.data, variableParser) as ReadOnlyCollection <Variable>;

                patchVariablesOfRecords(variables);

                leaderboard.applicableVariables = new Lazy <ReadOnlyCollection <Variable> >(() => variables);
            }
            else if (string.IsNullOrEmpty(leaderboard.LevelID))
            {
                leaderboard.applicableVariables = new Lazy <ReadOnlyCollection <Variable> >(() =>
                {
                    var variables = leaderboard.Category.Variables;

                    patchVariablesOfRecords(variables);

                    return(variables);
                });
            }
            else
            {
                leaderboard.applicableVariables = new Lazy <ReadOnlyCollection <Variable> >(() =>
                {
                    var variables = leaderboard.Category.Variables.Concat(leaderboard.Level.Variables).ToList().Distinct().ToList().AsReadOnly();

                    patchVariablesOfRecords(variables);

                    return(variables);
                });
            }

            return(leaderboard);
        }
Esempio n. 17
0
        public static User Parse(SpeedrunComClient client, dynamic userElement)
        {
            var user = new User();

            var properties = userElement as IDictionary <string, dynamic>;

            //Parse Attributes

            user.ID        = properties["id"] as string;
            user.WebLink   = new Uri(properties["weblink"] as string);
            user.NameStyle = UserNameStyle.Parse(client, properties["name-style"]) as UserNameStyle;
            user.Role      = parseUserRole(properties["role"] as string);

            var nameProperties = properties["names"] as IDictionary <string, dynamic>;

            user.Name         = nameProperties["international"] as string;
            user.JapaneseName = nameProperties["japanese"] as string;
            if (properties.ContainsKey("signup"))
            {
                user.SignUpDate = (DateTime)userElement.signup;
            }
            user.Location = Location.Parse(client, properties["location"]) as Location;

            var twitchLink = properties["twitch"];

            if (twitchLink != null)
            {
                user.TwitchProfile = new Uri((string)twitchLink.uri);
            }

            var hitboxLink = properties["hitbox"];

            if (hitboxLink != null)
            {
                user.HitboxProfile = new Uri((string)hitboxLink.uri);
            }

            var youtubeLink = properties["youtube"];

            if (youtubeLink != null)
            {
                user.YoutubeProfile = new Uri((string)youtubeLink.uri);
            }

            var twitterLink = properties["twitter"];

            if (twitterLink != null)
            {
                user.TwitterProfile = new Uri((string)twitterLink.uri);
            }

            var speedRunsLiveLink = properties["speedrunslive"];

            if (speedRunsLiveLink != null)
            {
                user.SpeedRunsLiveProfile = new Uri((string)speedRunsLiveLink.uri);
            }

            //Parse Links

            user.Runs           = client.Runs.GetRuns(userId: user.ID);
            user.ModeratedGames = client.Games.GetGames(moderatorId: user.ID);
            user.personalBests  = new Lazy <ReadOnlyCollection <Record> >(() =>
            {
                var records = client.Users.GetPersonalBests(userId: user.ID);
                var lazy    = new Lazy <User>(() => user);

                foreach (var record in records)
                {
                    var player = record.Players.FirstOrDefault(x => x.UserID == user.ID);
                    if (player != null)
                    {
                        player.user = lazy;
                    }
                }

                return(records);
            });
            return(user);
        }
Esempio n. 18
0
        public static Category Parse(SpeedrunComClient client, dynamic categoryElement)
        {
            if (categoryElement is ArrayList)
            {
                return(null);
            }

            var category = new Category();

            //Parse Attributes

            category.ID              = categoryElement.id as string;
            category.Name            = categoryElement.name as string;
            category.WebLink         = new Uri(categoryElement.weblink as string);
            category.Type            = categoryElement.type == "per-game" ? CategoryType.PerGame : CategoryType.PerLevel;
            category.Rules           = categoryElement.rules as string;
            category.Players         = Players.Parse(client, categoryElement.players);
            category.IsMiscellaneous = categoryElement.miscellaneous;

            //Parse Links

            var properties = categoryElement.Properties as IDictionary <string, dynamic>;
            var links      = properties["links"] as IEnumerable <dynamic>;

            var gameUri = links.First(x => x.rel == "game").uri as string;

            category.GameID = gameUri.Substring(gameUri.LastIndexOf('/') + 1);

            if (properties.ContainsKey("game"))
            {
                var gameElement = properties["game"].data;
                var game        = Game.Parse(client, gameElement) as Game;
                category.game = new Lazy <Game>(() => game);
            }
            else
            {
                category.game = new Lazy <Game>(() => client.Games.GetGame(category.GameID));
            }

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

            category.Runs = client.Runs.GetRuns(categoryId: category.ID);

            if (category.Type == CategoryType.PerGame)
            {
                category.leaderboard = new Lazy <Leaderboard>(() =>
                {
                    var leaderboard = client.Leaderboards
                                      .GetLeaderboardForFullGameCategory(category.GameID, category.ID);

                    leaderboard.game     = new Lazy <Game>(() => category.Game);
                    leaderboard.category = new Lazy <Category>(() => category);

                    foreach (var record in leaderboard.Records)
                    {
                        record.game     = leaderboard.game;
                        record.category = leaderboard.category;
                    }

                    return(leaderboard);
                });
                category.worldRecord = new Lazy <Record>(() =>
                {
                    if (category.leaderboard.IsValueCreated)
                    {
                        return(category.Leaderboard.Records.FirstOrDefault());
                    }

                    var leaderboard = client.Leaderboards
                                      .GetLeaderboardForFullGameCategory(category.GameID, category.ID, top: 1);

                    leaderboard.game     = new Lazy <Game>(() => category.Game);
                    leaderboard.category = new Lazy <Category>(() => category);

                    foreach (var record in leaderboard.Records)
                    {
                        record.game     = leaderboard.game;
                        record.category = leaderboard.category;
                    }

                    return(leaderboard.Records.FirstOrDefault());
                });
            }
            else
            {
                category.leaderboard = new Lazy <Leaderboard>(() => null);
                category.worldRecord = new Lazy <Record>(() => null);
            }

            return(category);
        }
Esempio n. 19
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);
        }
Esempio n. 20
0
 public LeaderboardsClient(SpeedrunComClient baseClient)
 {
     this.baseClient = baseClient;
 }
Esempio n. 21
0
 public GamesClient(SpeedrunComClient baseClient)
 {
     this.baseClient = baseClient;
 }
 public static Uri GetRunsUri(string subUri)
 {
     return(SpeedrunComClient.GetAPIUri(string.Format("{0}{1}", Name, subUri)));
 }
Esempio n. 23
0
 public UsersClient(SpeedrunComClient baseClient)
 {
     this.baseClient = baseClient;
 }
Esempio n. 24
0
 public NotificationsClient(SpeedrunComClient baseClient)
 {
     this.baseClient = baseClient;
 }
 public RunsClient(SpeedrunComClient baseClient)
 {
     this.baseClient = baseClient;
 }
Esempio n. 26
0
        public static Series Parse(SpeedrunComClient client, dynamic seriesElement)
        {
            var series = new Series();

            //Parse Attributes

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

            var created = seriesElement.created as string;

            if (!string.IsNullOrEmpty(created))
            {
                series.CreationDate = DateTime.Parse(created, CultureInfo.InvariantCulture, DateTimeStyles.AssumeUniversal);
            }

            series.Assets = Assets.Parse(client, seriesElement.assets);

            //Parse Embeds

            if (seriesElement.moderators is DynamicJsonObject && seriesElement.moderators.Properties.ContainsKey("data"))
            {
                Func <dynamic, User>      userParser = x => User.Parse(client, x) as User;
                ReadOnlyCollection <User> users      = client.ParseCollection(seriesElement.moderators.data, userParser);
                series.moderatorUsers = new Lazy <ReadOnlyCollection <User> >(() => users);
            }
            else if (seriesElement.moderators is DynamicJsonObject)
            {
                var moderatorsProperties = seriesElement.moderators.Properties as IDictionary <string, dynamic>;
                series.Moderators = moderatorsProperties.Select(x => Moderator.Parse(client, x)).ToList().AsReadOnly();

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

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

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

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

            //Parse Links

            series.Games = client.Series.GetGames(series.ID).Select(game =>
            {
                game.series = new Lazy <Series>(() => series);
                return(game);
            }).Cache();

            return(series);
        }
Esempio n. 27
0
        internal static void Parse(Run run, SpeedrunComClient client, dynamic runElement)
        {
            //Parse Attributes

            run.ID      = runElement.id as string;
            run.WebLink = new Uri(runElement.weblink as string);
            run.Videos  = RunVideos.Parse(client, runElement.videos) as RunVideos;
            run.Comment = runElement.comment as string;
            run.Status  = RunStatus.Parse(client, runElement.status) as RunStatus;

            Func <dynamic, Player> parsePlayer = x => Player.Parse(client, x) as Player;

            if (runElement.players is IEnumerable <dynamic> )
            {
                run.Players = client.ParseCollection(runElement.players, parsePlayer);
            }
            else if (runElement.players is System.Collections.ArrayList && runElement.players.Count == 0)
            {
                run.Players = new List <Player>().AsReadOnly();
            }
            else
            {
                run.Players = client.ParseCollection(runElement.players.data, parsePlayer);
            }

            var runDate = runElement.date;

            if (!string.IsNullOrEmpty(runDate))
            {
                run.Date = DateTime.Parse(runDate, CultureInfo.InvariantCulture, DateTimeStyles.AssumeUniversal);
            }

            var dateSubmitted = runElement.submitted;

            if (!string.IsNullOrEmpty(dateSubmitted))
            {
                run.DateSubmitted = DateTime.Parse(dateSubmitted, CultureInfo.InvariantCulture, DateTimeStyles.AssumeUniversal);
            }

            run.Times  = RunTimes.Parse(client, runElement.times) as RunTimes;
            run.System = RunSystem.Parse(client, runElement.system) as RunSystem;

            var splits = runElement.splits;

            if (splits != null)
            {
                run.SplitsUri = new Uri(splits.uri as string);
            }

            if (runElement.values is DynamicJsonObject)
            {
                var valueProperties = runElement.values.Properties as IDictionary <string, dynamic>;
                run.VariableValues = valueProperties.Select(x => VariableValue.ParseValueDescriptor(client, x) as VariableValue).ToList().AsReadOnly();
            }
            else
            {
                run.VariableValues = new List <VariableValue>().AsReadOnly();
            }

            //Parse Links

            var properties = runElement.Properties as IDictionary <string, dynamic>;

            if (properties["game"] is string)
            {
                run.GameID = runElement.game as string;
                run.game   = new Lazy <Game>(() => client.Games.GetGame(run.GameID));
            }
            else
            {
                var game = Game.Parse(client, properties["game"].data) as Game;
                run.game   = new Lazy <Game>(() => game);
                run.GameID = game.ID;
            }

            if (properties["category"] == null)
            {
                run.category = new Lazy <Category>(() => null);
            }
            else if (properties["category"] is string)
            {
                run.CategoryID = runElement.category as string;
                run.category   = new Lazy <Category>(() => client.Categories.GetCategory(run.CategoryID));
            }
            else
            {
                var category = Category.Parse(client, properties["category"].data) as Category;
                run.category = new Lazy <Category>(() => category);
                if (category != null)
                {
                    run.CategoryID = category.ID;
                }
            }

            if (properties["level"] == null)
            {
                run.level = new Lazy <Level>(() => null);
            }
            else if (properties["level"] is string)
            {
                run.LevelID = runElement.level as string;
                run.level   = new Lazy <Level>(() => client.Levels.GetLevel(run.LevelID));
            }
            else
            {
                var level = Level.Parse(client, properties["level"].data) as Level;
                run.level = new Lazy <Level>(() => level);
                if (level != null)
                {
                    run.LevelID = level.ID;
                }
            }

            if (properties.ContainsKey("platform"))
            {
                var platform = Platform.Parse(client, properties["platform"].data) as Platform;
                run.System.platform = new Lazy <Platform>(() => platform);
            }

            if (properties.ContainsKey("region"))
            {
                var region = Region.Parse(client, properties["region"].data) as Region;
                run.System.region = new Lazy <Region>(() => region);
            }

            if (!string.IsNullOrEmpty(run.Status.ExaminerUserID))
            {
                run.examiner = new Lazy <User>(() => client.Users.GetUser(run.Status.ExaminerUserID));
            }
            else
            {
                run.examiner = new Lazy <User>(() => null);
            }
        }
Esempio n. 28
0
        public static Variable Parse(SpeedrunComClient client, dynamic variableElement)
        {
            var variable = new Variable();

            variable.client = client;
            var properties = variableElement as IDictionary <string, dynamic>;
            var links      = properties["links"] as IEnumerable <dynamic>;

            //Parse Attributes

            variable.ID                      = variableElement.id as string;
            variable.Name                    = variableElement.name as string;
            variable.Scope                   = VariableScope.Parse(client, variableElement.scope) as VariableScope;
            variable.IsMandatory             = (bool)(variableElement.mandatory ?? false);
            variable.IsUserDefined           = (bool)(properties["user-defined"] ?? false);
            variable.IsUsedForObsoletingRuns = (bool)variableElement.obsoletes;
            if (!(variableElement.values.choices is ArrayList))
            {
                var choiceElements = variableElement.values.choices as IDictionary <string, dynamic>;
                variable.Values = choiceElements.Select(x => VariableValue.ParseIDPair(client, variable, x) as VariableValue).ToList().AsReadOnly();
            }
            else
            {
                variable.Values = new ReadOnlyCollection <VariableValue>(new VariableValue[0]);
            }
            var valuesProperties = variableElement.values as IDictionary <string, dynamic>;
            var defaultValue     = valuesProperties["default"] as string;

            if (!string.IsNullOrEmpty(defaultValue))
            {
                variable.DefaultValue = variable.Values.FirstOrDefault(x => x.ID == defaultValue);
            }
            variable.IsSubcategory = (bool)(properties["is-subcategory"] ?? false);

            //Parse Links

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

            if (gameLink != null)
            {
                var gameUri = gameLink.uri as string;
                variable.GameID = gameUri.Substring(gameUri.LastIndexOf("/") + 1);
                variable.game   = new Lazy <Game>(() => client.Games.GetGame(variable.GameID));
            }
            else
            {
                variable.game = new Lazy <Game>(() => null);
            }
            variable.CategoryID = variableElement.category as string;
            if (!string.IsNullOrEmpty(variable.CategoryID))
            {
                variable.category = new Lazy <Category>(() => client.Categories.GetCategory(variable.CategoryID));
            }
            else
            {
                variable.category = new Lazy <Category>(() => null);
            }
            if (!string.IsNullOrEmpty(variable.Scope.LevelID))
            {
                variable.level = new Lazy <Level>(() => client.Levels.GetLevel(variable.Scope.LevelID));
            }
            else
            {
                variable.level = new Lazy <Level>(() => null);
            }
            return(variable);
        }
Esempio n. 29
0
        internal static void Parse(Run run, SpeedrunComClient client, dynamic runElement)
        {
            //Parse Attributes
            IDictionary <string, dynamic> properties = runElement as IDictionary <string, dynamic>;

            run.ID      = properties["id"] as string;
            run.WebLink = new Uri(properties["weblink"] as string);
            run.Videos  = RunVideos.Parse(client, properties["videos"]) as RunVideos;
            run.Comment = properties["comment"] as string;
            run.Status  = RunStatus.Parse(client, properties["status"]) as RunStatus;

            Func <dynamic, Player> parsePlayer = x => Player.Parse(client, x) as Player;

            if (properties["players"] is IEnumerable <dynamic> )
            {
                run.Players = client.ParseCollection(properties["players"], parsePlayer);
            }
            else if (properties["players"] is System.Collections.ArrayList && properties["players"].Count == 0)
            {
                run.Players = new List <Player>().AsReadOnly();
            }
            else
            {
                run.Players = client.ParseCollection(properties["players"].data, parsePlayer);
            }

            if (properties.ContainsKey("date"))
            {
                if (properties["date"] != null)
                {
                    run.Date = DateTime.ParseExact(properties["date"].ToString(), "yyyy-MM-dd", CultureInfo.InvariantCulture);
                }
            }

            if (properties.ContainsKey("submitted"))
            {
                if (runElement.submitted != null)
                {
                    run.DateSubmitted = (DateTime)runElement.submitted;
                }
            }

            run.Times  = RunTimes.Parse(client, properties["times"]);
            run.System = RunSystem.Parse(client, properties["system"]);

            var splits = properties["splits"];

            if (splits != null)
            {
                run.SplitsUri = new Uri(splits.uri as string);
            }

            if (properties.ContainsKey("values"))
            {
                var valueProperties = properties["values"] as IDictionary <string, dynamic>;

                run.VariableValues = valueProperties.Select(x => VariableValue.ParseValueDescriptor(client, x) as VariableValue).ToList().AsReadOnly();
            }
            else
            {
                run.VariableValues = new List <VariableValue>().AsReadOnly();
            }

            //Parse Links

            if (properties["game"] is string)
            {
                run.GameID = properties["game"] as string;
                run.game   = new Lazy <Game>(() => client.Games.GetGame(run.GameID));
            }
            else
            {
                var game = Game.Parse(client, properties["game"]["data"]) as Game;
                run.game   = new Lazy <Game>(() => game);
                run.GameID = game.ID;
            }

            if (properties["category"] == null)
            {
                run.category = new Lazy <Category>(() => null);
            }
            else if (properties["category"] is string)
            {
                run.CategoryID = properties["category"] as string;
                run.category   = new Lazy <Category>(() => client.Categories.GetCategory(run.CategoryID));
            }
            else
            {
                var category = Category.Parse(client, properties["category"].data) as Category;
                run.category = new Lazy <Category>(() => category);

                if (category != null)
                {
                    run.CategoryID = category.ID;
                }
            }

            if (properties["level"] == null)
            {
                run.level = new Lazy <Level>(() => null);
            }
            else if (properties["level"] is string)
            {
                run.LevelID = properties["level"] as string;
                run.level   = new Lazy <Level>(() => client.Levels.GetLevel(run.LevelID));
            }
            else
            {
                if (properties["level"].data as string != null)
                {
                    Level level = Level.Parse(client, properties["level"].data);

                    run.level = new Lazy <Level>(() => level);

                    if (level != null)
                    {
                        run.LevelID = level.ID;
                    }
                }
                else
                {
                    run.level = new Lazy <Level>(() => null);
                }
            }

            if (properties.ContainsKey("platform"))
            {
                Platform platform = Platform.Parse(client, properties["platform"].data);

                run.System.platform = new Lazy <Platform>(() => platform);
            }

            if (properties.ContainsKey("region"))
            {
                Region region = Region.Parse(client, properties["region"].data);

                run.System.region = new Lazy <Region>(() => region);
            }

            if (!string.IsNullOrEmpty(run.Status.ExaminerUserID))
            {
                run.examiner = new Lazy <User>(() => client.Users.GetUser(run.Status.ExaminerUserID));
            }
            else
            {
                run.examiner = new Lazy <User>(() => null);
            }
        }
Esempio n. 30
0
 public LevelsClient(SpeedrunComClient baseClient)
 {
     this.baseClient = baseClient;
 }