Ejemplo n.º 1
0
        /// <summary> Creates an instance for this configured brush, for use with a specific DrawOperation. </summary>
        /// <param name="player"> Player who will be using this brush.
        /// Errors and warnings about the brush creation should be communicated by messaging the player. </param>
        /// <param name="cmd"> Parameters passed to the DrawOperation.
        /// If any are given, these parameters should generally replace any stored configuration. </param>
        /// <param name="op"> DrawOperation that will be using this brush. </param>
        /// <returns> A newly-made brush, or null if there was some problem with parameters/permissions. </returns>
        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");
            }
            Block block    = Block.None,
                  altBlock = Block.None;

            if (cmd.HasNext)
            {
                if (!cmd.NextBlock(player, true, out block))
                {
                    return(null);
                }
                if (cmd.HasNext)
                {
                    if (!cmd.NextBlock(player, true, out altBlock))
                    {
                        return(null);
                    }
                }
            }

            return(new NormalBrush(block, altBlock));
        }
Ejemplo n.º 2
0
        public IBrush MakeBrush(Player player, CommandReader cmd)
        {
            if (player == null)
            {
                throw new ArgumentNullException("player");
            }
            if (cmd == null)
            {
                throw new ArgumentNullException("cmd");
            }

            Block block, altBlock;

            // first block type is required
            if (!cmd.NextBlock(player, true, out block))
            {
                player.Message("{0}: Please specify at least one block type.", Name);
                return(null);
            }

            // second block type is optional
            if (cmd.HasNext)
            {
                if (!cmd.NextBlock(player, true, out altBlock))
                {
                    return(null);
                }
            }
            else
            {
                altBlock = Block.None;
            }

            return(new CheckeredBrush(block, altBlock));
        }
Ejemplo n.º 3
0
 public IBrush MakeBrush( Player player, CommandReader cmd ) {
     if( player == null ) throw new ArgumentNullException( "player" );
     if( cmd == null ) throw new ArgumentNullException( "cmd" );
     Block block, altBlock;
     cmd.NextBlock( player, true, out block );
     cmd.NextBlock( player, true, out altBlock );
     return new CheckeredBrush( block, altBlock );
 }
Ejemplo n.º 4
0
        public override bool ReadParams(CommandReader cmd)
        {
            if (Player.GetCopyState() == null)
            {
                Player.Message("Nothing to paste! Copy something first.");
                return(false);
            }
            List <Block> blocks = new List <Block>();

            while (cmd.HasNext)
            {
                Block block;
                if (!cmd.NextBlock(Player, false, out block))
                {
                    return(false);
                }
                blocks.Add(block);
            }
            if (blocks.Count > 0)
            {
                Blocks = blocks.ToArray();
            }
            else if (Not)
            {
                Player.Message("PasteNot requires at least 1 block.");
                return(false);
            }
            Brush = this;
            return(true);
        }
Ejemplo n.º 5
0
        public IBrush MakeBrush(Player player, CommandReader cmd) {
            if (player == null) throw new ArgumentNullException("player");
            if (cmd == null) throw new ArgumentNullException("cmd");

            // read the block filter list
            HashSet<Block> blocks = new HashSet<Block>();
            while (cmd.HasNext) {
                Block block;
                if (!cmd.NextBlock(player, false, out block)) {
                    return null;
                }
                if (!blocks.Add(block)) {
                    // just a warning -- don't abort
                    player.Message("{0}: {1} was specified twice!", Name, block);
                }
            }

            // create a brush
            if (blocks.Count > 0) {
                return new PasteBrush(blocks.ToArray(), Not);
            } else if (Not) {
                player.Message("PasteNot brush requires at least 1 block.");
                return null;
            } else {
                return new PasteBrush();
            }
        }
Ejemplo n.º 6
0
        public IBrush MakeBrush(Player player, CommandReader cmd)
        {
            if (player == null)
            {
                throw new ArgumentNullException("player");
            }
            if (cmd == null)
            {
                throw new ArgumentNullException("cmd");
            }
            Block block, altBlock;

            cmd.NextBlock(player, true, out block);
            cmd.NextBlock(player, true, out altBlock);
            return(new CheckeredBrush(block, altBlock));
        }
Ejemplo n.º 7
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>();

            while (cmd.HasNext)
            {
                Block block;
                if (!cmd.NextBlock(player, true, out block))
                {
                    return(null);
                }
                blocks.Add(block);
            }

            return(new NormalBrush(blocks.ToArray()));
        }
Ejemplo n.º 8
0
        public IBrush MakeBrush(Player player, CommandReader cmd) {
            if (player == null)
                throw new ArgumentNullException("player");
            if (cmd == null)
                throw new ArgumentNullException("cmd");

            Stack<Block> blocks = new Stack<Block>();
            while (cmd.HasNext) {
                Block block;
                if (!cmd.NextBlock(player, false, out block))
                    return null;
                blocks.Push(block);
            }
            switch (blocks.Count) {
                case 0:
                    player.Message("{0} brush: Please specify the replacement block type.", Name);
                    return null;
                case 1:
                    return new ReplaceNotBrush(blocks.ToArray(), Block.None);
                default: {
                        Block replacement = blocks.Pop();
                        return new ReplaceNotBrush(blocks.ToArray(), replacement);
                    }
            }
        }
Ejemplo n.º 9
0
        public IBrush MakeBrush( Player player, CommandReader cmd ) {
            if( player == null ) throw new ArgumentNullException( "player" );
            if( cmd == null ) throw new ArgumentNullException( "cmd" );

            if( !cmd.HasNext ) {
                player.Message( "ReplaceBrush usage: &H/Brush rb <Block> <BrushName>" );
                return null;
            }

            Block block;
            if( !cmd.NextBlock( player, false, out block ) ) return null;

            string brushName = cmd.Next();
            if( brushName == null || !CommandManager.IsValidCommandName( brushName ) ) {
                player.Message( "ReplaceBrush usage: &H/Brush rb <Block> <BrushName>" );
                return null;
            }
            IBrushFactory brushFactory = BrushManager.GetBrushFactory( brushName );

            if( brushFactory == null ) {
                player.Message( "Unrecognized brush \"{0}\"", brushName );
                return null;
            }

            IBrush newBrush = brushFactory.MakeBrush( player, cmd );
            if( newBrush == null ) {
                return null;
            }

            return new ReplaceBrushBrush( block, newBrush );
        }
Ejemplo n.º 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");
            }

            if (cmd.HasNext)
            {
                Block block, altBlock;
                if (!cmd.NextBlock(player, true, out block))
                {
                    return(null);
                }
                if (cmd.HasNext)
                {
                    if (!cmd.NextBlock(player, true, out altBlock))
                    {
                        return(null);
                    }
                }
                else
                {
                    altBlock = Block.None;
                }

                Block1 = block;
                Block2 = altBlock;
            }
            else if (Block1 == Block.None)
            {
                player.Message("{0}: Please specify one or two blocks.", Factory.Name);
                return(null);
            }

            return(new CheckeredBrush(this));
        }
Ejemplo n.º 11
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");
            }

            if (cmd.HasNext)
            {
                Block block;
                if (!cmd.NextBlock(player, false, out block))
                {
                    return(null);
                }

                string brushName = cmd.Next();
                if (brushName == null || !CommandManager.IsValidCommandName(brushName))
                {
                    player.Message("ReplaceBrush usage: &H/Brush rb <Block> <BrushName>");
                    return(null);
                }
                IBrushFactory brushFactory = BrushManager.GetBrushFactory(brushName);

                if (brushFactory == null)
                {
                    player.Message("Unrecognized brush \"{0}\"", brushName);
                    return(null);
                }

                IBrush replacement = brushFactory.MakeBrush(player, cmd);
                if (replacement == null)
                {
                    return(null);
                }
                Block       = block;
                Replacement = replacement;
            }

            ReplacementInstance = Replacement.MakeInstance(player, cmd, op);
            if (ReplacementInstance == null)
            {
                return(null);
            }

            return(new ReplaceBrushBrush(this));
        }
Ejemplo n.º 12
0
 public override bool ReadParams( CommandReader cmd ) {
     if( cmd.HasNext ) {
         Block replacement;
         if( cmd.NextBlock( Player, false, out replacement ) ) {
             ReplacementBlock = replacement;
         } else {
             return false;
         }
     }
     Brush = this;
     return true;
 }
Ejemplo n.º 13
0
        public IBrush MakeBrush(Player player, CommandReader cmd) {
            if (player == null) throw new ArgumentNullException("player");
            if (cmd == null) throw new ArgumentNullException("cmd");

            Block block, altBlock;

            // first block type is required
            if (!cmd.NextBlock(player, true, out block)) {
                player.Message("{0}: Please specify at least one block type.", Name);
                return null;
            }

            // second block type is optional
            if (cmd.HasNext) {
                if (!cmd.NextBlock(player, true, out altBlock)) return null;
            } else {
                altBlock = Block.None;
            }

            return new CheckeredBrush(block, altBlock);
        }
Ejemplo n.º 14
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" );

            if( cmd.HasNext ) {
                Block block, altBlock;
                if( !cmd.NextBlock( player, true, out block ) ) return null;
                if( cmd.HasNext ) {
                    if( !cmd.NextBlock( player, true, out altBlock ) ) return null;
                } else {
                    altBlock = Block.None;
                }
                Block1 = block;
                Block2 = altBlock;

            } else if( Block1 == Block.None ) {
                player.Message( "{0}: Please specify one or two blocks.", Factory.Name );
                return null;
            }

            return new CheckeredBrush( this );
        }
Ejemplo n.º 15
0
        public IBrush MakeBrush(Player player, CommandReader cmd)
        {
            if (player == null)
            {
                throw new ArgumentNullException("player");
            }
            if (cmd == null)
            {
                throw new ArgumentNullException("cmd");
            }

            if (!cmd.HasNext)
            {
                player.Message("ReplaceBrush usage: &H/Brush rb <Block> <BrushName>");
                return(null);
            }

            Block block;

            if (!cmd.NextBlock(player, false, out block))
            {
                return(null);
            }

            string brushName = cmd.Next();

            if (brushName == null || !CommandManager.IsValidCommandName(brushName))
            {
                player.Message("ReplaceBrush usage: &H/Brush rb <Block> <BrushName>");
                return(null);
            }
            IBrushFactory brushFactory = BrushManager.GetBrushFactory(brushName);

            if (brushFactory == null)
            {
                player.Message("Unrecognized brush \"{0}\"", brushName);
                return(null);
            }

            IBrush newBrush = brushFactory.MakeBrush(player, cmd);

            if (newBrush == null)
            {
                return(null);
            }

            return(new ReplaceBrushBrush(block, newBrush));
        }
Ejemplo n.º 16
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>();

            while (cmd.HasNext) {
                Block block;
                if (!cmd.NextBlock(player, true, out block)) {
                    return null;
                }
                blocks.Add(block);
            }

            return new NormalBrush(blocks.ToArray());
        }
Ejemplo n.º 17
0
 public override bool ReadParams(CommandReader cmd)
 {
     if (cmd.HasNext)
     {
         Block replacement;
         if (cmd.NextBlock(Player, false, out replacement))
         {
             ReplacementBlock = replacement;
         }
         else
         {
             return(false);
         }
     }
     Brush = this;
     return(true);
 }
Ejemplo n.º 18
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");
            }

            Stack <Block> blocks = new Stack <Block>();

            while (cmd.HasNext)
            {
                Block block;
                if (!cmd.NextBlock(player, false, out block))
                {
                    return(null);
                }
                blocks.Push(block);
            }

            if (blocks.Count == 0 && Blocks == null)
            {
                player.Message("ReplaceNot brush requires at least 1 block.");
                return(null);
            }

            if (blocks.Count > 0)
            {
                if (blocks.Count > 1)
                {
                    Replacement = blocks.Pop();
                }
                Blocks = blocks.ToArray();
            }

            return(new ReplaceNotBrush(this));
        }
Ejemplo n.º 19
0
        public IBrush MakeBrush( Player player, CommandReader cmd ) {
            if( player == null ) throw new ArgumentNullException( "player" );
            if( cmd == null ) throw new ArgumentNullException( "cmd" );

            Stack<Block> blocks = new Stack<Block>();
            while( cmd.HasNext ) {
                Block block;
                if( !cmd.NextBlock( player, false, out block ) ) return null;
                blocks.Push( block );
            }
            if( blocks.Count == 0 ) {
                return new ReplaceNotBrush();
            } else if( blocks.Count == 1 ) {
                return new ReplaceNotBrush( blocks.ToArray(), Block.None );
            } else {
                Block replacement = blocks.Pop();
                return new ReplaceNotBrush( blocks.ToArray(), replacement );
            }
        }
Ejemplo n.º 20
0
        public IBrush MakeBrush(Player player, CommandReader cmd)
        {
            if (player == null)
            {
                throw new ArgumentNullException("player");
            }
            if (cmd == null)
            {
                throw new ArgumentNullException("cmd");
            }

            // read the block filter list
            HashSet <Block> blocks = new HashSet <Block>();

            while (cmd.HasNext)
            {
                Block block;
                if (!cmd.NextBlock(player, false, out block))
                {
                    return(null);
                }
                if (!blocks.Add(block))
                {
                    // just a warning -- don't abort
                    player.Message("{0}: {1} was specified twice!", Name, block);
                }
            }

            // create a brush
            if (blocks.Count > 0)
            {
                return(new PasteBrush(blocks.ToArray(), Not));
            }
            else if (Not)
            {
                player.Message("PasteNot brush requires at least 1 block.");
                return(null);
            }
            else
            {
                return(new PasteBrush());
            }
        }
Ejemplo n.º 21
0
        public IBrush MakeBrush(Player player, CommandReader cmd)
        {
            if (player == null)
            {
                throw new ArgumentNullException("player");
            }
            if (cmd == null)
            {
                throw new ArgumentNullException("cmd");
            }

            Stack <Block> blocks = new Stack <Block>();

            while (cmd.HasNext)
            {
                Block block;
                if (!cmd.NextBlock(player, false, out block))
                {
                    return(null);
                }
                blocks.Push(block);
            }
            switch (blocks.Count)
            {
            case 0:
                player.Message("{0} brush: Please specify the replacement block type.", Name);
                return(null);

            case 1:
                return(new ReplaceNotBrush(blocks.ToArray(), Block.None));

            default: {
                Block replacement = blocks.Pop();
                return(new ReplaceNotBrush(blocks.ToArray(), replacement));
            }
            }
        }
Ejemplo n.º 22
0
        public IBrush MakeBrush(Player player, CommandReader cmd)
        {
            if (player == null)
            {
                throw new ArgumentNullException("player");
            }
            if (cmd == null)
            {
                throw new ArgumentNullException("cmd");
            }

            Stack <Block> blocks = new Stack <Block>();

            while (cmd.HasNext)
            {
                Block block;
                if (!cmd.NextBlock(player, false, out block))
                {
                    return(null);
                }
                blocks.Push(block);
            }
            if (blocks.Count == 0)
            {
                return(new ReplaceNotBrush());
            }
            else if (blocks.Count == 1)
            {
                return(new ReplaceNotBrush(blocks.ToArray(), Block.None));
            }
            else
            {
                Block replacement = blocks.Pop();
                return(new ReplaceNotBrush(blocks.ToArray(), replacement));
            }
        }
Ejemplo n.º 23
0
 public override bool ReadParams(CommandReader cmd) {
     if (Player.GetCopyState() == null) {
         Player.Message("Nothing to paste! Copy something first.");
         return false;
     }
     List<Block> blocks = new List<Block>();
     while (cmd.HasNext) {
         Block block;
         if (!cmd.NextBlock(Player, false, out block)) return false;
         blocks.Add(block);
     }
     if (blocks.Count > 0) {
         Blocks = blocks.ToArray();
     } else if (Not) {
         Player.Message("PasteNot requires at least 1 block.");
         return false;
     }
     Brush = this;
     return true;
 }
Ejemplo n.º 24
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" );

            Stack<Block> blocks = new Stack<Block>();
            while( cmd.HasNext ) {
                Block block;
                if( !cmd.NextBlock( player, false, out block ) ) return null;
                blocks.Push( block );
            }

            if( blocks.Count == 0 && Blocks == null ) {
                player.Message( "ReplaceNot brush requires at least 1 block." );
                return null;
            }

            if( blocks.Count > 0 ) {
                if( blocks.Count > 1 ) Replacement = blocks.Pop();
                Blocks = blocks.ToArray();
            }

            return new ReplaceNotBrush( this );
        }
Ejemplo n.º 25
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" );

            if( cmd.HasNext ) {
                Block block;
                if( !cmd.NextBlock( player, false, out block ) ) return null;

                string brushName = cmd.Next();
                if( brushName == null || !CommandManager.IsValidCommandName( brushName ) ) {
                    player.Message( "ReplaceBrush usage: &H/Brush rb <Block> <BrushName>" );
                    return null;
                }
                IBrushFactory brushFactory = BrushManager.GetBrushFactory( brushName );

                if( brushFactory == null ) {
                    player.Message( "Unrecognized brush \"{0}\"", brushName );
                    return null;
                }

                IBrush replacement = brushFactory.MakeBrush( player, cmd );
                if( replacement == null ) {
                    return null;
                }
                Block = block;
                Replacement = replacement;
            }

            ReplacementInstance = Replacement.MakeInstance( player, cmd, op );
            if( ReplacementInstance == null ) return null;

            return new ReplaceBrushBrush( this );
        }