public static DateTime GetAttributeFromElementAndRemoveLastCharactersAsDate(this IElement element, string querySelector, string attributeName, int numberOfTrailingCharactersToRemove)
        {
            var value = element.GetAttributeFromElement(querySelector, attributeName);

            value = value.Substring(0, value.Length - numberOfTrailingCharactersToRemove);
            return(ParsingMethods.ToDate(value, "yyyyMMdd"));
        }
Example #2
0
        public Overtime(string value)
        {
            if (string.IsNullOrWhiteSpace(value))
            {
                Count = 0;
                return;
            }

            value = value.Trim().ToLower(CultureInfo.InvariantCulture);

            if (value.Length == 2 && value == "ot")
            {
                Count = 1;
                return;
            }

            value = value.Replace("ot", "");

            if (!value.Any(char.IsDigit))
            {
                throw new ArgumentException("Overtime value is formatted incorrectly");
            }

            Count = ParsingMethods.ToInt(value);
        }
        public static int GetTextContentAsIntAndRemoveSpecialCharacters(this IElement element, string querySelector)
        {
            var value = element.GetTextContent(querySelector);

            value = value.Replace(",", "");

            return(string.IsNullOrWhiteSpace(value) ? default : ParsingMethods.ToInt(value));
        }
        public NumberOfYearInLeague(string value)
        {
            _ = value.DiscardNullOrWhitespaceCheck() ?? throw new ArgumentNullException(nameof(value));

            value = value.Trim();

            Value = value.ToUpper() == "R"
                ? 1
                : ParsingMethods.ToInt(value) + 1;
        }
Example #5
0
        public PlusMinusScore(string value)
        {
            _ = value.DiscardNullOrWhitespaceCheck() ?? throw new ArgumentNullException(nameof(value));

            value = value.Trim();

            var sign  = value.Substring(0, 1);
            var score = value.Substring(1, value.Length - 1);

            Score = sign == "+"
                ? Math.Abs(ParsingMethods.ToDouble(score))
                : -Math.Abs(ParsingMethods.ToDouble(score));
        }
        public static int Measure_Word_Pixel_Length(SocialLinkerCommand sl_command, string input_word)
        {
            // Create an int to keep track of how many pixels a glyph is wide in.
            int pixel_counter = 0;

            // Create another int to count the number of times a character comes up null from the font sheet.
            // We'll want to keep track of this number so we can ensure there's only one error message sent.
            int error_counter = 0;

            // Take the input string and turn it into a char array.
            char[] char_array = input_word.ToCharArray();

            // Now, let's iterate through the char array.
            for (int i = 0; i < char_array.Length; i++)
            {
                // Retrieve glyph information for the current character from the JSON file.
                var glyph = ParsingMethods.Get_P2EP_PS1_Glyph(char_array[i]);

                // Make sure that the glyph info doesn't return null.
                if (glyph != null)
                {
                    // Check if the current character is a line break.
                    // If it is, do nothing. Line breaks take up no pixel width space.
                    if (char_array[i] == '\u000a')
                    {
                        // Do nothing
                    }
                    else
                    {
                        // Set the pixel counter to the appropriate width of the string so far.
                        pixel_counter += glyph.RightCut - glyph.LeftCut;
                    }
                }
                // If the character returns null, it's not supported by the template's font set.
                // Send a warning message to the user.
                else
                {
                    // Increase the error counter by one.
                    error_counter++;

                    // If the error counter is at exactly 1, send a warning message to the user.
                    if (error_counter == 1)
                    {
                        _ = ErrorHandling.Unsupported_Character(sl_command);
                    }
                }
            }

            return(pixel_counter);
        }
Example #7
0
        private static IEnumerable <OvertimeScoreData> GetOvertimeScores(IParentNode element)
        {
            var overtimeScores = new List <OvertimeScoreData>();

            foreach (var overtimeElement in element.Children.Where(x => x.GetAttribute("data-stat").EndsWith("OT")))
            {
                var overtime = new Overtime(overtimeElement.GetAttribute("data-stat"));
                var score    = ParsingMethods.ToInt(overtimeElement.TextContent);

                overtimeScores.Add(new OvertimeScoreData(overtime.Count, score));
            }

            return(overtimeScores);
        }
Example #8
0
        public MinutesPlayedInGame(string value)
        {
            _ = value.DiscardNullOrWhitespaceCheck() ?? throw new ArgumentNullException(nameof(value));

            value = value.Trim();

            var split = value.Split(":");

            if (split.Length != 2)
            {
                throw new ArgumentException("MinutesPlayedInGame value is not formatted correctly");
            }

            Minutes = ParsingMethods.ToInt(split[0]);
            Seconds = ParsingMethods.ToInt(split[1]);
        }
Example #9
0
        public BoxScoreLink(string value)
        {
            _ = value.DiscardNullOrWhitespaceCheck() ?? throw new ArgumentNullException(nameof(value));

            value = value.Trim();

            value = value.Replace(".html", "");

            if (!value.StartsWith("/boxscores/"))
            {
                throw new ArgumentException("BoxScoreLink is not formatted correctly. Missing '/boxscores/' at the start of the string");
            }

            GameId   = value.Substring(11, value.Length - 11);
            GameDate = ParsingMethods.ToDate(GameId.Substring(0, 8), "yyyyMMdd");
        }
Example #10
0
        public HeightInFeetAndInches(string value)
        {
            _ = value.DiscardNullOrWhitespaceCheck() ?? throw new ArgumentNullException(nameof(value));

            value = value.Trim();

            var split = value.Split("-");

            if (split.Length != 2)
            {
                throw new ArgumentException("Height in feet and inches is incorrectly formatted");
            }

            _feet   = ParsingMethods.ToInt(split[0]);
            _inches = ParsingMethods.ToInt(split[1]);

            Value = value;
        }
        public TeamNameAndStandings(string value)
        {
            _ = value.DiscardNullOrWhitespaceCheck() ?? throw new ArgumentNullException(nameof(value));

            value = value.Trim();

            var firstIndexOfBracket = value.IndexOf("(", StringComparison.InvariantCulture);
            var lastIndexOfBracket  = value.LastIndexOf(")", StringComparison.InvariantCulture);

            TeamName = value.Substring(0, firstIndexOfBracket - 1);

            var winsAndLosses = value.Substring(firstIndexOfBracket + 1, lastIndexOfBracket - firstIndexOfBracket - 1);

            var split = winsAndLosses.Split("-");

            if (split.Length != 2)
            {
                throw new ArgumentException("TeamNameAndStandings is not formatted correctly");
            }

            Wins   = ParsingMethods.ToInt(split[0]);
            Losses = ParsingMethods.ToInt(split[1]);
        }
 protected override void Init()
 {
     ParsingMethods.Insert(0, EvaluateDateTimeSyntax);
     ParsingMethods.Add(EvaluateSpecialTernaryOperator);
 }
Example #13
0
        public WeightInPounds(string value)
        {
            _ = value.DiscardNullOrWhitespaceCheck() ?? throw new ArgumentNullException(nameof(value));

            Value = ParsingMethods.ToInt(value);
        }
Example #14
0
        public static Bitmap Render_Name(BustupData bustup_data)
        {
            // Create a bitmap as large as the template.
            Bitmap base_template = new Bitmap(1920, 1080);

            // Establish an int for the width and height glyphs should be rendered at.
            int multiplier = 64;

            // Load the bitmap font.
            string font_sheet = $@"{AssetDirectoryConfig.assetDirectory.assetFolderPath}//SceneMaker//Templates//P4G//Font//p4g_font_sheet.png";

            // Create a variable to iterate through sections of the bitmap font.
            Bitmap current_glyph;

            // Specify X and Y coordinates for where the glyphs should start rendering on the template.
            int render_position_x = 102;
            int render_position_y = 748;

            char[] charArr = bustup_data.Default_Name_EN.ToCharArray();

            for (int i = 0; i < charArr.Length; i++)
            {
                // Retrieve glyph information from the JSON file.
                var glyph = ParsingMethods.Get_P4G_Glyph(charArr[i]);

                // Check if the character is a line break.
                if (charArr[i] == '\u000a')
                {
                    // Set the X coordinate to the start of the row.
                    render_position_x = 124;
                    // Move the Y coordinate down to the next line.
                    render_position_y += 68;
                }
                else
                {
                    int x = multiplier * glyph.Column;
                    int y = multiplier * glyph.Row;

                    using (Graphics graphics = Graphics.FromImage(base_template))
                    {
                        using (var originalImage = new Bitmap(font_sheet))
                        {
                            // Copy the section of the bitmap font needed.
                            Rectangle crop = new Rectangle(x, y, multiplier, multiplier);
                            current_glyph = originalImage.Clone(crop, originalImage.PixelFormat);

                            // Draw the glyph to the base bitmap.
                            graphics.DrawImage(current_glyph, (render_position_x - glyph.LeftCut), render_position_y, multiplier, multiplier);
                        }
                    }

                    // Set the next X value at the end of the current glyph's right width.
                    render_position_x += (glyph.RightCut - glyph.LeftCut);

                    // Check if the current iterated index is less than the number of indicies available.
                    if (i < charArr.Length - 1)
                    {
                        // If so, edit the position of the X coordinate according to specific kerning pairs.
                        if (charArr[i] == 'Y' && Char.IsLower(charArr[i + 1]))
                        {
                            render_position_x += -6;
                        }
                        else if (charArr[i] == 'v' && Char.IsLower(charArr[i + 1]))
                        {
                            render_position_x += -1;
                        }
                        else if (charArr[i] == 'T' && Char.IsLower(charArr[i + 1]) && charArr[i + 1] != 'h')
                        {
                            render_position_x += -6;
                        }
                    }
                }
            }

            return(base_template);
        }
Example #15
0
        public static Bitmap Render_Dialogue(List <string>[] dialogue_lines)
        {
            //Create a bitmap as large as the template
            Bitmap bitmap = new Bitmap(1920, 1080);

            // Create an int to keep track of rendering errors. This is neccessary to inform the user of any potential issues.
            int error_counter = 0;

            //Establish an int for the width and height glyphs should be rendered at
            int multiplier = 64;

            string font_sheet = $@"{AssetDirectoryConfig.assetDirectory.assetFolderPath}//SceneMaker//Templates//P4D//Font//p4d_font_sheet.png";
            Bitmap current_glyph;

            for (int i = 0; i < dialogue_lines.Length; i++)
            {
                //Establish variables for where the glyphs should be rendered on the template
                int render_position_x = 124;
                int render_position_y = 836 + (68 * i);

                char[] char_array = String_List_To_String(dialogue_lines[i]).ToCharArray();

                for (int j = 0; j < char_array.Length; j++)
                {
                    //Retrieve glyph information from the JSON file
                    var glyph = ParsingMethods.GetGlyph(char_array[j]);

                    // If the glyph info returns null, we have a rendering error.
                    // If this occurs and the error counter is at zero, increase the error counter and send a message to the user.
                    if (glyph == null && error_counter == 0)
                    {
                        error_counter++;
                        //message.Channel.SendMessageAsync(":warning: One or more of the characters entered is not supported by this template's font set and will not be rendered.");
                    }

                    if (glyph != null)
                    {
                        int x = multiplier * glyph.Column;
                        int y = multiplier * glyph.Row;

                        using (Graphics graphics = Graphics.FromImage(bitmap))
                        {
                            using (var originalImage = new Bitmap(font_sheet))
                            {
                                //Copy the section of the bitmap font needed
                                Rectangle crop = new Rectangle(x, y, multiplier, multiplier);
                                current_glyph = originalImage.Clone(crop, originalImage.PixelFormat);

                                //Draw the glyph to the base bitmap
                                graphics.DrawImage(current_glyph, (render_position_x - glyph.LeftCut), render_position_y, multiplier, multiplier);
                            }
                        }

                        //Set the next X value at the end of the current glyph's right width
                        render_position_x += (glyph.RightCut - glyph.LeftCut);

                        // Check if the current iterated index is less than the number of indicies available.
                        if (j < char_array.Length - 1)
                        {
                            // If so, edit the position of the X coordinate according to specific kerning pairs.
                            if (char_array[j] == 'Y' && Char.IsLower(char_array[j + 1]))
                            {
                                render_position_x += -6;
                            }
                            else if (char_array[j] == 'v' && Char.IsLower(char_array[j + 1]))
                            {
                                render_position_x += -1;
                            }
                            else if (char_array[j] == 'T' && (Char.IsLower(char_array[j + 1]) && char_array[j + 1] != 'h'))
                            {
                                render_position_x += -6;
                            }
                        }
                    }
                }
            }

            return(bitmap);
        }
 public static DateTime ToDate(this IElement element, string querySelector)
 {
     return(element.ParseTextContent(querySelector, x => ParsingMethods.ToDate(x, "yyyy")));
 }
        public static Bitmap Render_Name(BustupData bustup_data)
        {
            // Create variables to store the width and height of the template.
            int template_width  = 320;
            int template_height = 240;

            Bitmap base_template = new Bitmap(template_width, template_height);

            // Establish ints for the width and height of glyphs.
            int x_multiplier = 8;
            int y_multiplier = 12;

            // Load the bitmap font.
            string font_sheet = $@"{AssetDirectoryConfig.assetDirectory.assetFolderPath}//SceneMaker//Templates//P2EP-PS1//Font//p2ep-ps1_font_sheet.png";

            // Create a variable to iterate through sections of the bitmap font.
            Bitmap current_glyph;

            // Specify X and Y coordinates for where the glyphs should start rendering on the template.
            int render_position_x = 16;
            int render_position_y = 171;

            // Take the sprite's display name and convert it into a char array.
            char[] char_array = bustup_data.Default_Name_EN.ToCharArray();

            // Iterate through each character of the array.
            for (int i = 0; i < char_array.Length; i++)
            {
                // Retrieve glyph information from the JSON file.
                var glyph = ParsingMethods.Get_P2EP_PS1_Glyph(char_array[i]);

                // Check if the character is a line break.
                if (char_array[i] == '\u000a')
                {
                    // Set the X coordinate to the start of the row.
                    render_position_x = 16;
                    // Move the Y coordinate down to the next line.
                    render_position_y += 14;
                }
                else
                {
                    int x = x_multiplier * glyph.Column;
                    int y = y_multiplier * glyph.Row;

                    using (Graphics graphics = Graphics.FromImage(base_template))
                    {
                        using (var originalImage = new Bitmap(font_sheet))
                        {
                            // Copy the section of the bitmap font needed.
                            Rectangle crop = new Rectangle(x, y, x_multiplier, y_multiplier);
                            current_glyph = originalImage.Clone(crop, originalImage.PixelFormat);

                            // Draw the glyph to the base bitmap. Some hanging letters will need to be drawn a bit lower to appear natural.
                            if (char_array[i] == 'g' || char_array[i] == 'j' || char_array[i] == 'p' || char_array[i] == 'q' || char_array[i] == 'y')
                            {
                                graphics.DrawImage(current_glyph, (render_position_x - glyph.LeftCut), render_position_y + 1, x_multiplier, y_multiplier);
                            }
                            else
                            {
                                graphics.DrawImage(current_glyph, (render_position_x - glyph.LeftCut), render_position_y, x_multiplier, y_multiplier);
                            }
                        }
                    }

                    // Set the next X value at the end of the current glyph's right width.
                    render_position_x += (glyph.RightCut - glyph.LeftCut) + 1;
                }
            }

            return(base_template);
        }
        public static DateTime GetAttributeFromElementAsDate(this IElement element, string querySelector, string attributeName)
        {
            var value = element.GetAttributeFromElement(querySelector, attributeName);

            return(ParsingMethods.ToDate(value, "yyyyMMdd"));
        }
        public static Bitmap Render_Dialogue(List <string>[] dialogue_lines)
        {
            // Create variables to store the width and height of the template.
            int template_width  = 320;
            int template_height = 240;

            Bitmap base_template = new Bitmap(template_width, template_height);

            // Establish ints for the width and height of glyphs.
            int x_multiplier = 8;
            int y_multiplier = 12;

            string font_sheet = $@"{AssetDirectoryConfig.assetDirectory.assetFolderPath}//SceneMaker//Templates//P2EP-PS1//Font//p2ep-ps1_font_sheet.png";
            Bitmap current_glyph;

            // Iterate over each line of the dialogue string list with a loop.
            for (int i = 0; i < dialogue_lines.Length; i++)
            {
                // Specify X and Y coordinates for where the glyphs should start rendering on the template.
                int render_position_x = 21;
                int render_position_y = 185 + (14 * i);

                // Take the input dialogue and convert it into a char array.
                char[] char_array = String_List_To_String(dialogue_lines[i]).ToCharArray();

                // Iterate through each character of the array.
                for (int j = 0; j < char_array.Length; j++)
                {
                    //Retrieve glyph information from the JSON file
                    var glyph = ParsingMethods.Get_P2EP_PS1_Glyph(char_array[j]);

                    // If the glyph info returns null, we have a rendering error.
                    // A warning message should have already been sent to the user in the Measure_Word_Pixel_Length method.
                    if (glyph == null)
                    {
                        // Do nothing
                    }

                    if (glyph != null)
                    {
                        int x = x_multiplier * glyph.Column;
                        int y = y_multiplier * glyph.Row;

                        using (Graphics graphics = Graphics.FromImage(base_template))
                        {
                            using (var originalImage = new Bitmap(font_sheet))
                            {
                                // Copy the section of the bitmap font needed.
                                Rectangle crop = new Rectangle(x, y, x_multiplier, y_multiplier);
                                current_glyph = originalImage.Clone(crop, originalImage.PixelFormat);

                                // Draw the glyph to the base bitmap. Some hanging letters will need to be drawn a bit lower to appear natural.
                                if (char_array[j] == 'g' || char_array[j] == 'j' || char_array[j] == 'p' || char_array[j] == 'q' || char_array[j] == 'y')
                                {
                                    graphics.DrawImage(current_glyph, (render_position_x - glyph.LeftCut), render_position_y + 1, x_multiplier, y_multiplier);
                                }
                                else
                                {
                                    graphics.DrawImage(current_glyph, (render_position_x - glyph.LeftCut), render_position_y, x_multiplier, y_multiplier);
                                }
                            }
                        }

                        // Set the next X value at the end of the current glyph's right width.
                        render_position_x += (glyph.RightCut - glyph.LeftCut) + 1;
                    }
                }
            }

            return(base_template);
        }
Example #20
0
 protected override void Init()
 {
     ParsingMethods.Add(EvaluateDollarAsCmdOperator);
 }