示例#1
0
        public static UserNameStyle Parse(SpeedrunComClient client, dynamic styleElement)
        {
            UserNameStyle style = new UserNameStyle();
            IDictionary <string, dynamic> properties = styleElement as IDictionary <string, dynamic>;

            style.IsGradient = styleElement.style == "gradient";

            if (style.IsGradient)
            {
                IDictionary <string, dynamic> colorFromProperties = properties["color-from"] as IDictionary <string, dynamic>;
                IDictionary <string, dynamic> colorToProperties   = properties["color-to"] as IDictionary <string, dynamic>;

                style.LightGradientStartColorCode = colorFromProperties["light"] as string;
                style.LightGradientEndColorCode   = colorToProperties["light"] as string;
                style.DarkGradientStartColorCode  = colorFromProperties["dark"] as string;
                style.DarkGradientEndColorCode    = colorToProperties["dark"] as string;
            }
            else
            {
                IDictionary <string, dynamic> colorProperties = properties["color"] as IDictionary <string, dynamic>;

                style.LightSolidColorCode = colorProperties["light"] as string;
                style.DarkSolidColorCode  = colorProperties["dark"] as string;
            }

            return(style);
        }
示例#2
0
        public static UserNameStyle Parse(SpeedrunComClient client, dynamic styleElement)
        {
            var style = new UserNameStyle();

            style.IsGradient = styleElement.style == "gradient";

            if (style.IsGradient)
            {
                var properties = styleElement.Properties as IDictionary <string, dynamic>;
                var colorFrom  = properties["color-from"];
                var colorTo    = properties["color-to"];

                style.LightGradientStartColorCode = colorFrom.light as string;
                style.LightGradientEndColorCode   = colorTo.light as string;
                style.DarkGradientStartColorCode  = colorFrom.dark as string;
                style.DarkGradientEndColorCode    = colorTo.dark as string;
            }
            else
            {
                style.LightSolidColorCode = styleElement.color.light as string;
                style.DarkSolidColorCode  = styleElement.color.dark as string;
            }

            return(style);
        }
示例#3
0
        public static UserNameStyle Parse(SpeedrunComClient client, dynamic styleElement)
        {
            var style = new UserNameStyle();

            style.IsGradient = styleElement.style == "gradient";

            if (style.IsGradient)
            {
                var properties = styleElement.Properties as IDictionary<string, dynamic>;
                var colorFrom = properties["color-from"];
                var colorTo = properties["color-to"];

                style.LightGradientStartColorCode = colorFrom.light as string;
                style.LightGradientEndColorCode = colorTo.light as string;
                style.DarkGradientStartColorCode = colorFrom.dark as string;
                style.DarkGradientEndColorCode = colorTo.dark as string;
            }
            else
            {
                style.LightSolidColorCode = styleElement.color.light as string;
                style.DarkSolidColorCode = styleElement.color.dark as string;
            }

            return style;
        }
示例#4
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);
        }
示例#5
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);
        }