Represents a palette of Minecraft blocks, that allows matching RGB colors to their closest block equivalents.
Inheritance: IEnumerable
示例#1
0
 public ImageDrawOperation([NotNull] Player player, [NotNull] BlockPalette palette, [NotNull] Uri imageUrl)
     : base(player)
 {
     if (palette == null)
     {
         throw new ArgumentNullException("palette");
     }
     if (imageUrl == null)
     {
         throw new ArgumentNullException("imageUrl");
     }
     Palette  = palette;
     ImageUrl = imageUrl;
 }
示例#2
0
 public ImageDrawOperation([NotNull] Player player, [NotNull] BlockPalette palette, [NotNull] Bitmap bitmap)
     : base(player)
 {
     if (palette == null)
     {
         throw new ArgumentNullException("palette");
     }
     if (bitmap == null)
     {
         throw new ArgumentNullException("bitmap");
     }
     Palette     = palette;
     ImageBitmap = bitmap;
 }
示例#3
0
        static BlockPalette DefineLayeredGray()
        {
            BlockPalette palette = new BlockPalette("LayeredGray", 2);

            foreach (var pair in Gray.palette)
            {
                palette.Add(pair.Key, new[] { Block.None, pair.Value[0] });
            }
            foreach (var pair in DarkGray.palette)
            {
                palette.Add(pair.Key, new[] { pair.Value[0], Block.Air });
            }
            return(palette);
        }
示例#4
0
        public override bool ReadParams(CommandReader cmd)
        {
            // get image URL
            string urlstr = cmd.Next();

            if (!WorldCommands.parseUrl(ref urlstr, Player))
            {
                return(false);
            }

            // validate the image URL
            Uri url;

            if (!Uri.TryCreate(urlstr, UriKind.Absolute, out url))
            {
                Player.Message("DrawImage: Invalid URL given.");
                return(false);
            }
            else if (!url.Scheme.Equals(Uri.UriSchemeHttp) && !url.Scheme.Equals(Uri.UriSchemeHttps))
            {
                Player.Message("DrawImage: Invalid URL given. Only HTTP and HTTPS links are allowed.");
                return(false);
            }

            ImageUrl = url;

            // Check if player gave optional second argument (palette name)
            string paletteName = cmd.Next();

            if (paletteName != null)
            {
                Palette = BlockPalette.FindPalette(paletteName);
                if (Palette == null)
                {
                    Player.Message("DrawImage: Unrecognized palette \"{0}\". Available palettes are: \"{1}\"",
                                   paletteName, BlockPalette.Palettes.JoinToString(pal => pal.Name));
                    return(false);
                }
            }
            else
            {
                // default to "Light" (lit single-layer) palette
                Palette = BlockPalette.FindPalette("Light");
            }

            // All set
            return(true);
        }
示例#5
0
        static BlockPalette DefineLayered()
        {
            BlockPalette palette = new BlockPalette("Layered", 2);

            foreach (var pair in Light.palette)
            {
                palette.Add(pair.Key, new[] { Block.None, pair.Value[0] });
            }
            foreach (var pair in Dark.palette)
            {
                palette.Add(pair.Key, new[] { pair.Value[0], Block.Air });
            }
            palette.Add(RgbColor.FromArgb(61, 74, 167), new[] { Block.White, Block.StillWater });
            palette.Add(RgbColor.FromArgb(47, 59, 152), new[] { Block.Gray, Block.StillWater });
            palette.Add(RgbColor.FromArgb(34, 47, 140), new[] { Block.Black, Block.StillWater });
            return(palette);
        }
示例#6
0
        public override bool ReadParams(Command cmd)
        {
            // get image URL
            string urlString = cmd.Next();

            if (String.IsNullOrEmpty(urlString))
            {
                return(false);
            }

            // if string starts with "++", load image from imgur
            if (urlString.StartsWith("++"))
            {
                urlString = "http://i.imgur.com/" + urlString.Substring(2);
            }

            // prepend the protocol, if needed (assume http)
            if (!urlString.StartsWith("http://", StringComparison.OrdinalIgnoreCase))
            {
                urlString = "http://" + urlString;
            }

            // validate the image URL
            Uri url;

            if (!Uri.TryCreate(urlString, UriKind.Absolute, out url))
            {
                Player.Message("DrawImage: Invalid URL given.");
                return(false);
            }
            else if (!url.Scheme.Equals(Uri.UriSchemeHttp) && !url.Scheme.Equals(Uri.UriSchemeHttps))
            {
                Player.Message("DrawImage: Invalid URL given. Only HTTP and HTTPS links are allowed.");
                return(false);
            }
            ImageUrl = url;

            // Check if player gave optional second argument (palette name)
            string paletteName = cmd.Next();

            if (paletteName != null)
            {
                StandardBlockPalettes paletteType;
                if (EnumUtil.TryParse(paletteName, out paletteType, true))
                {
                    Palette = BlockPalette.GetPalette(paletteType);
                }
                else
                {
                    Player.Message("DrawImage: Unrecognized palette \"{0}\". Available palettes are: \"{1}\"",
                                   paletteName,
                                   Enum.GetNames(typeof(StandardBlockPalettes)).JoinToString());
                    return(false);
                }
            }
            else
            {
                // default to "Light" (lit single-layer) palette
                Palette = BlockPalette.Light;
            }

            // All set
            return(true);
        }
示例#7
0
 static BlockPalette DefineLayeredGray()
 {
     BlockPalette palette = new BlockPalette("LayeredGray", 2);
     foreach (var pair in Gray.palette)
     {
         palette.Add(pair.Key, new[] { Block.None, pair.Value[0] });
     }
     foreach (var pair in DarkGray.palette)
     {
         palette.Add(pair.Key, new[] { pair.Value[0], Block.Air });
     }
     return palette;
 }
示例#8
0
 static BlockPalette DefineLayered2() {
     BlockPalette palette = new BlockPalette("Layered2", 2);
     foreach (var pair in Light2.palette) {
         palette.Add(pair.Key, new[] { Block.None, pair.Value[0] });
     }
     foreach (var pair in Dark2.palette) {
         palette.Add(pair.Key, new[] { pair.Value[0], Block.Air });
     }
     palette.Add(RgbColor.FromArgb(61, 74, 167), new[] { Block.White, Block.StillWater });
     palette.Add(RgbColor.FromArgb(47, 59, 152), new[] { Block.Gray, Block.StillWater });
     palette.Add(RgbColor.FromArgb(34, 47, 140), new[] { Block.Black, Block.StillWater });
     palette.Add(RgbColor.FromArgb(22, 38, 131), new[] { Block.Obsidian, Block.StillWater });
     return palette;
 }
        public override bool ReadParams(CommandReader cmd)
        {
            // get image URL
            string str = cmd.Next();

            if (str.NullOrWhiteSpace())
            {
                return(false);
            }

            // if string starts with "++", load image from imgur
            if (str.StartsWith("++"))
            {
                str = "http://i.imgur.com/" + str.Substring(2) + ".png";
            }
            // prepend the protocol, if needed (assume http)
            if (!str.CaselessStarts("http://") && !str.CaselessStarts("https://"))
            {
                str = "http://" + str;
            }

            // Convert imgur web page url to direct image url
            if (str.StartsWith("http://imgur.com/"))
            {
                str = "http://i.imgur.com/" + str.Substring("http://imgur.com/".Length) + ".png";
            }
            if (str.StartsWith("https://imgur.com/"))
            {
                str = "https://i.imgur.com/" + str.Substring("https://imgur.com/".Length) + ".png";
            }

            if (!str.CaselessEnds(".png") && !str.CaselessEnds(".jpg") && !str.CaselessEnds(".gif"))
            {
                Player.Message("URL must be a link to an image");
                return(false);
            }

            // validate the image URL
            Uri url;

            if (!Uri.TryCreate(str, UriKind.Absolute, out url))
            {
                Player.Message("DrawImage: Invalid URL given.");
                return(false);
            }
            else if (!url.Scheme.Equals(Uri.UriSchemeHttp) && !url.Scheme.Equals(Uri.UriSchemeHttps))
            {
                Player.Message("DrawImage: Invalid URL given. Only HTTP and HTTPS links are allowed.");
                return(false);
            }
            else if (!url.Host.CaselessEquals("i.imgur.com"))
            {
                Player.Message("For safety reasons we only accept images uploaded to &9http://imgur.com/ &SSorry for this inconvenience.");
                return(false);
            }
            ImageUrl = url;

            // Check if player gave optional second argument (palette name)
            string paletteName = cmd.Next();

            if (paletteName != null)
            {
                Palette = BlockPalette.FindPalette(paletteName);
                if (Palette == null)
                {
                    Player.Message("DrawImage: Unrecognized palette \"{0}\". Available palettes are: \"{1}\"",
                                   paletteName, BlockPalette.Palettes.JoinToString(pal => pal.Name));
                    return(false);
                }
            }
            else
            {
                // default to "Light" (lit single-layer) palette
                Palette = BlockPalette.FindPalette("Light");
            }

            // All set
            return(true);
        }
示例#10
0
        public override bool ReadParams( Command cmd )
        {
            // get image URL
            string urlString = cmd.Next();
            if( String.IsNullOrEmpty( urlString ) ) {
                return false;
            }

            // if string starts with "++", load image from imgur
            if( urlString.StartsWith( "++" ) ) {
                urlString = "http://i.imgur.com/" + urlString.Substring( 2 );
            }

            // prepend the protocol, if needed (assume http)
            if( !urlString.StartsWith( "http://", StringComparison.OrdinalIgnoreCase ) ) {
                urlString = "http://" + urlString;
            }

            // validate the image URL
            Uri url;
            if( !Uri.TryCreate( urlString, UriKind.Absolute, out url ) ) {
                Player.Message( "DrawImage: Invalid URL given." );
                return false;
            } else if( !url.Scheme.Equals( Uri.UriSchemeHttp ) && !url.Scheme.Equals( Uri.UriSchemeHttps ) ) {
                Player.Message( "DrawImage: Invalid URL given. Only HTTP and HTTPS links are allowed." );
                return false;
            }
            ImageUrl = url;

            // Check if player gave optional second argument (palette name)
            string paletteName = cmd.Next();
            if( paletteName != null ) {
                StandardBlockPalettes paletteType;
                if( EnumUtil.TryParse( paletteName, out paletteType, true ) ) {
                    Palette = BlockPalette.GetPalette( paletteType );
                } else {
                    Player.Message( "DrawImage: Unrecognized palette \"{0}\". Available palettes are: \"{1}\"",
                                    paletteName,
                                    Enum.GetNames( typeof( StandardBlockPalettes ) ).JoinToString() );
                    return false;
                }
            } else {
                // default to "Light" (lit single-layer) palette
                Palette = BlockPalette.Light;
            }

            // All set
            return true;
        }