/// <summary>Parse JSON string and return token arguments.</summary>
        public static RecolorTokenArguments Parse(string input)
        {
            if (string.IsNullOrWhiteSpace(input))
            {
                throw new ArgumentException("Argument list required");
            }

            string[] tempInput = input.Split(',');

            if (tempInput.Length < 5)
            {
                throw new ArgumentException($"Wrong number of items in argument list, at least 5 required, {tempInput.Length} found");
            }

            return(new RecolorTokenArguments {
                ContentPackName = tempInput[0].Trim(),
                AssetName = tempInput[1].Trim(),
                SourcePath = tempInput[2].Trim(),
                MaskPath = tempInput[3].Trim(),
                BlendColor = Utility.ColorFromHtml(tempInput[4].Trim()),
                DesaturationMode = tempInput.Length > 5
                                 ? Desaturation.ParseEnum(tempInput[5].Trim())
                                 : Desaturation.Mode.None,
                FlipMode = tempInput.Length > 6
                         ? Flip.ParseEnum(tempInput[6].Trim())
                         : Flip.Mode.None,
                Brightness = tempInput.Length > 7
                           ? float.Parse(tempInput[7].Trim(), System.Globalization.CultureInfo.InvariantCulture)
                           : 1.0f
            });
        }
Exemple #2
0
 /// <summary>Flipping is special: We can't just flip the overlay, we need the whole image!</summary>
 private Texture2D FlipImage(Texture2D baseImage, Texture2D overlay, Flip.Mode flipMode)
 {
     if (flipMode == Flip.Mode.None)
     {
         // Return a copy so it can be disposed safely.
         return(Utility.ArrayToTexture(Utility.TextureToArray(overlay), overlay.Width, overlay.Height));
     }
     else
     {
         // Flip the whole image.
         using (Texture2D image = AlphaBlend(baseImage, overlay)) {
             return(Flip.FlipImage(image, flipMode));
         }
     }
 }