Exemple #1
0
        public IBrush MakeBrush( Player player, CommandReader cmd ) {
            if( player == null ) throw new ArgumentNullException( "player" );
            if( cmd == null ) throw new ArgumentNullException( "cmd" );

            List<Block> blocks = new List<Block>();
            List<int> blockRatios = new List<int>();
            while( cmd.HasNext ) {
                int ratio;
                Block block;
                if( !cmd.NextBlockWithParam( player, true, out block, out ratio ) ) return null;
                if( block == Block.None ) return null;
                if( ratio < 0 || ratio > 1000 ) {
                    player.Message( "{0} brush: Invalid block ratio ({1}). Must be between 1 and 1000.",
                                    Name, ratio );
                    return null;
                }
                blocks.Add( block );
                blockRatios.Add( ratio );
            }

            switch( blocks.Count ) {
                case 0:
                    return new RandomBrush();
                case 1:
                    return new RandomBrush( blocks[0], blockRatios[0] );
                default:
                    return new RandomBrush( blocks.ToArray(), blockRatios.ToArray() );
            }
        }
Exemple #2
0
        public IBrush MakeBrush( Player player, CommandReader cmd ) {
            if( player == null ) throw new ArgumentNullException( "player" );
            if( cmd == null ) throw new ArgumentNullException( "cmd" );

            List<Block> blocks = new List<Block>();
            List<int> blockRatios = new List<int>();
            while( cmd.HasNext ) {
                int ratio;
                Block block;
                if( !cmd.NextBlockWithParam( player, true, out block, out ratio ) ) return null;
                if( ratio < 1 || ratio > RandomBrush.MaxRatio ) {
                    player.Message( "Random brush: Invalid block ratio ({0}). Must be between 1 and {1}.",
                                    ratio, RandomBrush.MaxRatio );
                    return null;
                }
                blocks.Add( block );
                blockRatios.Add( ratio );
            }

            if( blocks.Count == 0 ) {
                return new RandomBrush();
            } else if( blocks.Count == 1 ) {
                return new RandomBrush( blocks[0], blockRatios[0] );
            } else {
                return new RandomBrush( blocks.ToArray(), blockRatios.ToArray() );
            }
        }
Exemple #3
0
        public IBrushInstance MakeInstance(Player player, CommandReader cmd, DrawOperation op)
        {
            if (player == null)
            {
                throw new ArgumentNullException("player");
            }
            if (cmd == null)
            {
                throw new ArgumentNullException("cmd");
            }
            if (op == null)
            {
                throw new ArgumentNullException("op");
            }

            List <Block> blocks      = new List <Block>();
            List <int>   blockRatios = new List <int>();

            while (cmd.HasNext)
            {
                int   ratio;
                Block block;
                if (!cmd.NextBlockWithParam(player, true, out block, out ratio))
                {
                    return(null);
                }
                if (ratio < 0 || ratio > 1000)
                {
                    player.Message("Invalid block ratio ({0}). Must be between 1 and 1000.", ratio);
                    return(null);
                }
                if (block == Block.None)
                {
                    return(null);
                }
                blocks.Add(block);
                blockRatios.Add(ratio);
            }

            switch (blocks.Count)
            {
            case 0:
                if (Blocks.Length == 0)
                {
                    player.Message("{0} brush: Please specify at least one block.", Factory.Name);
                    return(null);
                }
                else
                {
                    return(new MarbledBrush(this));
                }

            case 1:
                return(new MarbledBrush(blocks[0], blockRatios[0]));

            default:
                return(new MarbledBrush(blocks.ToArray(), blockRatios.ToArray()));
            }
        }
Exemple #4
0
        public IBrushInstance MakeInstance(Player player, CommandReader cmd, DrawOperation state)
        {
            if (player == null)
            {
                throw new ArgumentNullException("player");
            }
            if (cmd == null)
            {
                throw new ArgumentNullException("cmd");
            }
            if (state == null)
            {
                throw new ArgumentNullException("state");
            }

            List <Block> blocks      = new List <Block>();
            List <int>   blockRatios = new List <int>();

            while (cmd.HasNext)
            {
                int   ratio;
                Block block;
                if (!cmd.NextBlockWithParam(player, true, out block, out ratio))
                {
                    return(null);
                }
                if (ratio < 1 || ratio > MaxRatio)
                {
                    player.Message("RandomBrush: Invalid block ratio ({0}). Must be between 1 and {1}.",
                                   ratio, MaxRatio);
                    return(null);
                }
                blocks.Add(block);
                blockRatios.Add(ratio);
            }

            if (blocks.Count == 0)
            {
                if (Blocks.Length == 0)
                {
                    player.Message("{0} brush: Please specify at least one block.", Factory.Name);
                    return(null);
                }
                else
                {
                    return(new RandomBrush(this));
                }
            }
            else if (blocks.Count == 1)
            {
                return(new RandomBrush(blocks[0], blockRatios[0]));
            }
            else
            {
                return(new RandomBrush(blocks.ToArray(), blockRatios.ToArray()));
            }
        }
Exemple #5
0
        public IBrush MakeBrush(Player player, CommandReader cmd)
        {
            if (player == null)
            {
                throw new ArgumentNullException("player");
            }
            if (cmd == null)
            {
                throw new ArgumentNullException("cmd");
            }

            List <Block> blocks      = new List <Block>();
            List <int>   blockRatios = new List <int>();

            while (cmd.HasNext)
            {
                int   ratio;
                Block block;
                if (!cmd.NextBlockWithParam(player, true, out block, out ratio))
                {
                    return(null);
                }
                if (block == Block.None)
                {
                    return(null);
                }
                if (ratio < 0 || ratio > 1000)
                {
                    player.Message("{0} brush: Invalid block ratio ({1}). Must be between 1 and 1000.",
                                   Name, ratio);
                    return(null);
                }
                blocks.Add(block);
                blockRatios.Add(ratio);
            }

            switch (blocks.Count)
            {
            case 0:
                return(new MarbledBrush());

            case 1:
                return(new MarbledBrush(blocks[0], blockRatios[0]));

            default:
                return(new MarbledBrush(blocks.ToArray(), blockRatios.ToArray()));
            }
        }
Exemple #6
0
        public IBrush MakeBrush(Player player, CommandReader cmd)
        {
            if (player == null)
            {
                throw new ArgumentNullException("player");
            }
            if (cmd == null)
            {
                throw new ArgumentNullException("cmd");
            }

            List <Block> blocks      = new List <Block>();
            List <int>   blockRatios = new List <int>();

            while (cmd.HasNext)
            {
                int   ratio;
                Block block;
                if (!cmd.NextBlockWithParam(player, true, out block, out ratio))
                {
                    return(null);
                }
                if (ratio < 1 || ratio > RandomBrush.MaxRatio)
                {
                    player.Message("RandomBrush: Invalid block ratio ({0}). Must be between 1 and {1}.",
                                   ratio,
                                   RandomBrush.MaxRatio);
                    return(null);
                }
                blocks.Add(block);
                blockRatios.Add(ratio);
            }

            switch (blocks.Count)
            {
            case 0:
                player.Message("{0} brush: Please specify at least one block.", Name);
                return(null);

            case 1:
                return(new RandomBrush(blocks[0], blockRatios[0]));

            default:
                return(new RandomBrush(blocks.ToArray(), blockRatios.ToArray()));
            }
        }
Exemple #7
0
        public IBrush MakeBrush(Player player, CommandReader cmd)
        {
            if (player == null)
            {
                throw new ArgumentNullException("player");
            }
            if (cmd == null)
            {
                throw new ArgumentNullException("cmd");
            }

            List <Block> blocks      = new List <Block>();
            List <int>   blockRatios = new List <int>();

            while (cmd.HasNext)
            {
                int   ratio;
                Block block;
                if (!cmd.NextBlockWithParam(player, true, out block, out ratio))
                {
                    return(null);
                }
                if (ratio < 1 || ratio > MarbledBrush.MaxRatio)
                {
                    player.Message("Marbled brush: Invalid block ratio ({0}). Must be between 1 and {1}.",
                                   ratio, MarbledBrush.MaxRatio);
                    return(null);
                }
                blocks.Add(block);
                blockRatios.Add(ratio);
            }

            if (blocks.Count == 0)
            {
                return(new MarbledBrush());
            }
            else if (blocks.Count == 1)
            {
                return(new MarbledBrush(blocks[0], blockRatios[0]));
            }
            else
            {
                return(new MarbledBrush(blocks.ToArray(), blockRatios.ToArray()));
            }
        }
Exemple #8
0
        public IBrushInstance MakeInstance( Player player, CommandReader cmd, DrawOperation state ) {
            if( player == null ) throw new ArgumentNullException( "player" );
            if( cmd == null ) throw new ArgumentNullException( "cmd" );
            if( state == null ) throw new ArgumentNullException( "state" );

            List<Block> blocks = new List<Block>();
            List<int> blockRatios = new List<int>();
            while( cmd.HasNext ) {
                int ratio;
                Block block;
                if( !cmd.NextBlockWithParam( player, true, out block, out ratio ) ) return null;
                if( ratio < 1 || ratio > MaxRatio ) {
                    player.Message( "Cloudy brush: Invalid block ratio ({0}). Must be between 1 and {1}.",
                                    ratio, MaxRatio );
                    return null;
                }
                blocks.Add( block );
                blockRatios.Add( ratio );
            }

            if( blocks.Count == 0 ) {
                if( Blocks.Length == 0 ) {
                    player.Message( "{0} brush: Please specify at least one block.", Factory.Name );
                    return null;
                } else {
                    return new CloudyBrush( this );
                }
            } else if( blocks.Count == 1 ) {
                return new CloudyBrush( blocks[0], blockRatios[0] );
            } else {
                return new CloudyBrush( blocks.ToArray(), blockRatios.ToArray() );
            }
        }
Exemple #9
0
        public IBrush MakeBrush( Player player, CommandReader cmd ) {
            if( player == null ) throw new ArgumentNullException( "player" );
            if( cmd == null ) throw new ArgumentNullException( "cmd" );

            List<Block> blocks = new List<Block>();
            List<int> blockRatios = new List<int>();
            bool scaleSpecified = false,
                 turbulenceSpecified = false,
                 seedSpecified = false;
            int scale = 100,
                turbulence = 100;
            UInt16 seed = CloudyBrush.NextSeed();

            while( true ) {
                int offset = cmd.Offset;
                string rawNextParam = cmd.Next();
                if( rawNextParam == null ) break;

                if( rawNextParam.EndsWith( "%" ) ) {
                    string numPart = rawNextParam.Substring( 0, rawNextParam.Length - 1 );
                    int tempScale;
                    if( !Int32.TryParse( numPart, out tempScale ) ) {
                        player.Message( "Cloudy brush: To specify scale, write a number followed by a percentage (e.g. 100%)." );
                        return null;
                    }
                    if( scaleSpecified ) {
                        player.Message( "Cloudy brush: Scale has been specified twice." );
                        return null;
                    }
                    if( scale < 1 || tempScale > CloudyBrush.MaxScale ) {
                        player.Message( "Cloudy brush: Invalid scale ({0}). Must be between 1 and {1}",
                                        scale, CloudyBrush.MaxScale );
                        return null;
                    }
                    scale = tempScale;
                    scaleSpecified = true;
                    continue;

                } else if( rawNextParam.EndsWith( "T", StringComparison.OrdinalIgnoreCase ) ) {
                    string numPart = rawNextParam.Substring( 0, rawNextParam.Length - 1 );
                    int tempTurbulence;
                    if( Int32.TryParse( numPart, out tempTurbulence ) ) {
                        if( turbulenceSpecified ) {
                            player.Message( "Cloudy brush: Turbulence has been specified twice." );
                            return null;
                        }
                        if( turbulence < 1 || tempTurbulence > CloudyBrush.MaxScale ) {
                            player.Message( "Cloudy brush: Invalid turbulence ({0}). Must be between 1 and {1}",
                                            turbulence, CloudyBrush.MaxScale );
                            return null;
                        }
                        turbulence = tempTurbulence;
                        turbulenceSpecified = true;
                        continue;
                    }

                } else if( rawNextParam.EndsWith( "S", StringComparison.OrdinalIgnoreCase ) ) {
                    string numPart = rawNextParam.Substring( 0, rawNextParam.Length - 1 );
                    try {
                        seed = UInt16.Parse( numPart, System.Globalization.NumberStyles.HexNumber );
                        if( seedSpecified ) {
                            player.Message( "Cloudy brush: Seed has been specified twice." );
                            return null;
                        }
                        seedSpecified = true;
                        continue;
                    } catch {
                        seed = CloudyBrush.NextSeed();
                    }
                }

                cmd.Offset = offset;
                int ratio;
                Block block;
                if( !cmd.NextBlockWithParam( player, true, out block, out ratio ) ) return null;
                if( ratio < 1 || ratio > CloudyBrush.MaxRatio ) {
                    player.Message( "Cloudy brush: Invalid block ratio ({0}). Must be between 1 and {1}.",
                                    ratio, CloudyBrush.MaxRatio );
                    return null;
                }
                blocks.Add( block );
                blockRatios.Add( ratio );
            }

            CloudyBrush madeBrush;
            if( blocks.Count == 0 ) {
                madeBrush = new CloudyBrush();
            } else if( blocks.Count == 1 ) {
                madeBrush = new CloudyBrush( blocks[0], blockRatios[0] );
            } else {
                madeBrush = new CloudyBrush( blocks.ToArray(), blockRatios.ToArray() );
            }

            madeBrush.Frequency /= ( scale / 100f );
            madeBrush.Persistence *= ( turbulence / 100f );
            madeBrush.Seed = seed;

            return madeBrush;
        }
Exemple #10
0
        public IBrushInstance MakeInstance( Player player, CommandReader cmd, DrawOperation op ) {
            if( player == null ) throw new ArgumentNullException( "player" );
            if( cmd == null ) throw new ArgumentNullException( "cmd" );
            if( op == null ) throw new ArgumentNullException( "op" );

            List<Block> blocks = new List<Block>();
            List<int> blockRatios = new List<int>();
            while( cmd.HasNext ) {
                int ratio;
                Block block;
                if( !cmd.NextBlockWithParam( player, true, out block, out ratio ) ) return null;
                if( ratio < 0 || ratio > 1000 ) {
                    player.Message( "Invalid block ratio ({0}). Must be between 1 and 1000.", ratio );
                    return null;
                }
                if( block == Block.None ) return null;
                blocks.Add( block );
                blockRatios.Add( ratio );
            }

            switch( blocks.Count ) {
                case 0:
                    if( Blocks.Length == 0 ) {
                        player.Message( "{0} brush: Please specify at least one block.", Factory.Name );
                        return null;
                    } else {
                        return new RandomBrush( this );
                    }
                case 1:
                    return new RandomBrush( blocks[0], blockRatios[0] );
                default:
                    return new RandomBrush( blocks.ToArray(), blockRatios.ToArray() );
            }
        }
Exemple #11
0
        public IBrush MakeBrush(Player player, CommandReader cmd)
        {
            if (player == null)
            {
                throw new ArgumentNullException("player");
            }
            if (cmd == null)
            {
                throw new ArgumentNullException("cmd");
            }

            List <Block> blocks              = new List <Block>();
            List <int>   blockRatios         = new List <int>();
            bool         scaleSpecified      = false,
                         turbulenceSpecified = false,
                         seedSpecified       = false;
            int scale      = 100,
                turbulence = 100;
            UInt16 seed    = CloudyBrush.NextSeed();

            while (true)
            {
                int    offset       = cmd.Offset;
                string rawNextParam = cmd.Next();
                if (rawNextParam == null)
                {
                    break;
                }

                if (rawNextParam.EndsWith("%"))
                {
                    string numPart = rawNextParam.Substring(0, rawNextParam.Length - 1);
                    int    tempScale;
                    if (!Int32.TryParse(numPart, out tempScale))
                    {
                        player.Message("Cloudy brush: To specify scale, write a number followed by a percentage (e.g. 100%).");
                        return(null);
                    }
                    if (scaleSpecified)
                    {
                        player.Message("Cloudy brush: Scale has been specified twice.");
                        return(null);
                    }
                    if (scale < 1 || tempScale > CloudyBrush.MaxScale)
                    {
                        player.Message("Cloudy brush: Invalid scale ({0}). Must be between 1 and {1}",
                                       scale, CloudyBrush.MaxScale);
                        return(null);
                    }
                    scale          = tempScale;
                    scaleSpecified = true;
                    continue;
                }
                else if (rawNextParam.EndsWith("T", StringComparison.OrdinalIgnoreCase))
                {
                    string numPart = rawNextParam.Substring(0, rawNextParam.Length - 1);
                    int    tempTurbulence;
                    if (Int32.TryParse(numPart, out tempTurbulence))
                    {
                        if (turbulenceSpecified)
                        {
                            player.Message("Cloudy brush: Turbulence has been specified twice.");
                            return(null);
                        }
                        if (turbulence < 1 || tempTurbulence > CloudyBrush.MaxScale)
                        {
                            player.Message("Cloudy brush: Invalid turbulence ({0}). Must be between 1 and {1}",
                                           turbulence, CloudyBrush.MaxScale);
                            return(null);
                        }
                        turbulence          = tempTurbulence;
                        turbulenceSpecified = true;
                        continue;
                    }
                }
                else if (rawNextParam.EndsWith("S", StringComparison.OrdinalIgnoreCase))
                {
                    string numPart = rawNextParam.Substring(0, rawNextParam.Length - 1);
                    try {
                        seed = UInt16.Parse(numPart, System.Globalization.NumberStyles.HexNumber);
                        if (seedSpecified)
                        {
                            player.Message("Cloudy brush: Seed has been specified twice.");
                            return(null);
                        }
                        seedSpecified = true;
                        continue;
                    } catch {
                        seed = CloudyBrush.NextSeed();
                    }
                }

                cmd.Offset = offset;
                int   ratio;
                Block block;
                if (!cmd.NextBlockWithParam(player, true, out block, out ratio))
                {
                    return(null);
                }
                if (ratio < 1 || ratio > CloudyBrush.MaxRatio)
                {
                    player.Message("Cloudy brush: Invalid block ratio ({0}). Must be between 1 and {1}.",
                                   ratio, CloudyBrush.MaxRatio);
                    return(null);
                }
                blocks.Add(block);
                blockRatios.Add(ratio);
            }

            CloudyBrush madeBrush;

            if (blocks.Count == 0)
            {
                madeBrush = new CloudyBrush();
            }
            else if (blocks.Count == 1)
            {
                madeBrush = new CloudyBrush(blocks[0], blockRatios[0]);
            }
            else
            {
                madeBrush = new CloudyBrush(blocks.ToArray(), blockRatios.ToArray());
            }

            madeBrush.Frequency   /= (scale / 100f);
            madeBrush.Persistence *= (turbulence / 100f);
            madeBrush.Seed         = seed;

            return(madeBrush);
        }