Abstract class representing a drawing operation.
Example #1
0
 IBrushInstance IBrush.MakeInstance( Player player, CommandReader cmd, DrawOperation op ) {
     if( ReadParams( cmd ) ) {
         return this;
     } else {
         return null;
     }
 }
Example #2
0
 public override Block NextBlock(DrawOperation op) {
     if (op == null) throw new ArgumentNullException("op");
     Block block = op.Map.GetBlock(op.Coords);
     for (int i = 0; i < Blocks.Length; i++) {
         if (block == Blocks[i]) {
             return Block.None;
         }
     }
     return Replacement;
 }
Example #3
0
 public bool Begin(Player player, DrawOperation state) {
     if (player == null) throw new ArgumentNullException("player");
     if (state == null) throw new ArgumentNullException("state");
     if (Blocks == null || Blocks.Length == 0) {
         if (player.LastUsedBlockType == Block.None) {
             player.Message("Cannot deduce desired block. Click a block or type out the block name.");
             return false;
         } else {
             Blocks = new[] {
                 player.GetBind(player.LastUsedBlockType)
             };
         }
     }
     return true;
 }
Example #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>();

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

            return new NormalBrush( blocks.ToArray() );
        }
        public virtual bool Begin( Player player, DrawOperation op ) {
            if( player == null ) throw new ArgumentNullException( "player" );
            if( op == null ) throw new ArgumentNullException( "op" );

            if( op.Bounds.Volume > 32 * 32 * 32 ) {
                player.Message( "{0} brush: Preparing, please wait...", Brush.Factory.Name );
            }

            noise3D = new PerlinNoise3D( new Random( Seed ) ) {
                Amplitude = 1,
                Frequency = Frequency,
                Octaves = Octaves,
                Persistence = Persistence
            };

            // generate and normalize the raw (float) data
            float[, ,] rawData = new float[op.Bounds.Width, op.Bounds.Length, op.Bounds.Height];
            for( int x = 0; x < op.Bounds.Width; x++ ) {
                for( int y = 0; y < op.Bounds.Length; y++ ) {
                    for( int z = 0; z < op.Bounds.Height; z++ ) {
                        rawData[x, y, z] = noise3D.Compute( x, y, z );
                    }
                }
            }
            Noise.Normalize( rawData, out normMultiplier, out normConstant );
            if( MapAllValues( rawData ) ) {
                Noise.Normalize( rawData, out normMultiplier, out normConstant );
            }

            // create a mapping of raw data to blocks
            int totalBlocks = BlockRatios.Sum();
            int blocksSoFar = BlockRatios[0];
            computedThresholds = new float[Blocks.Length];
            computedThresholds[0] = 0;
            for( int i = 1; i < Blocks.Length; i++ ) {
                float desiredCoverage = blocksSoFar / (float)totalBlocks;
                computedThresholds[i] = Noise.FindThreshold( rawData, desiredCoverage );
                blocksSoFar += BlockRatios[i];
            }
            return true;
        }
Example #6
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 );
        }
Example #7
0
 public bool Begin([NotNull] Player player, [NotNull] DrawOperation state)
 {
     if (player == null)
     {
         throw new ArgumentNullException("player");
     }
     if (state == null)
     {
         throw new ArgumentNullException("state");
     }
     if (Block == Block.Undefined)
     {
         if (player.LastUsedBlockType == Block.Undefined)
         {
             player.Message("Cannot deduce desired block. Click a block or type out the block name.");
             return(false);
         }
         else
         {
             Block = player.GetBind(player.LastUsedBlockType);
         }
     }
     return(true);
 }
Example #8
0
 /// <summary> Called after the DrawOperation has been prepared.
 /// Should be used to verify that the brush is ready for use.
 /// Resources used by the brush should be obtained here. </summary>
 /// <param name="player"> Player who started the DrawOperation. </param>
 /// <param name="op"> DrawOperation that will be using this brush. </param>
 /// <returns> Whether this brush instance has successfully began or not. </returns>
 public bool Begin(Player player, DrawOperation op)
 {
     if (player == null)
     {
         throw new ArgumentNullException("player");
     }
     if (op == null)
     {
         throw new ArgumentNullException("op");
     }
     if (Block == Block.None)
     {
         if (player.LastUsedBlockType == Block.None)
         {
             player.Message("Cannot deduce desired block. Click a block or type out the block name.");
             return(false);
         }
         else
         {
             Block = player.GetBind(player.LastUsedBlockType);
         }
     }
     return(true);
 }
Example #9
0
        public Block NextBlock( DrawOperation op ) {
            if( op == null ) throw new ArgumentNullException( "op" );
            Vector3I relativeCoords = op.Coords - op.Bounds.MinVertex;
            float value = noise3D.Compute( relativeCoords.X, relativeCoords.Y, relativeCoords.Z );

            // normalize value
            value = value * normMultiplier + normConstant;

            // find the right block type for given value
            for( int i = 1; i < Blocks.Length; i++ ) {
                if( computedThresholds[i] > value ) {
                    return Blocks[i - 1];
                }
            }
            return Blocks[Blocks.Length - 1];
        }
Example #10
0
 // Returns false if cancelled
 protected static bool RaiseBeginningEvent( DrawOperation op ) {
     var h = Beginning;
     if( h == null ) return true;
     var e = new DrawOperationBeginningEventArgs( op );
     h( null, e );
     return !e.Cancel;
 }
Example #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" );

            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 );
        }
Example #12
0
 Block IBrush.NextBlock(DrawOperation op)
 {
     return(NextBlock());
 }
Example #13
0
        public IBrushInstance MakeInstance([NotNull] Player player, [NotNull] Command cmd, [NotNull] 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 = 1;
                Block block = cmd.NextBlockWithParam(player, ref ratio);
                if (ratio < 0 || ratio > MaxRatio)
                {
                    player.Message("Invalid block ratio ({0}). Must be between 1 and {1}.",
                                   ratio, MaxRatio);
                    return(null);
                }
                if (block == Block.Undefined)
                {
                    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()));
            }
        }
 public bool Begin(Player player, DrawOperation state)
 {
     return(true);
 }
Example #15
0
        public IBrushInstance MakeInstance([NotNull] Player player, [NotNull] Command cmd, [NotNull] DrawOperation state)
        {
            if (player == null)
            {
                throw new ArgumentNullException("player");
            }
            if (cmd == null)
            {
                throw new ArgumentNullException("cmd");
            }
            if (state == null)
            {
                throw new ArgumentNullException("state");
            }
            Block block    = Block.Undefined,
                  altBlock = Block.Undefined;

            if (cmd.HasNext)
            {
                block = cmd.NextBlock(player);
                if (block == Block.Undefined)
                {
                    return(null);
                }

                if (cmd.HasNext)
                {
                    altBlock = cmd.NextBlock(player);
                    if (altBlock == Block.Undefined)
                    {
                        return(null);
                    }
                }
            }

            return(new NormalBrush(block, altBlock));
        }
Example #16
0
 bool IBrushInstance.Begin( Player player, DrawOperation op )
 {
     return true;
 }
Example #17
0
 protected static void RaiseEndedEvent(DrawOperation op)
 {
     EndedEvent.Raise(new DrawOperationEventArgs(op));
 }
Example #18
0
        public IBrushInstance MakeInstance([NotNull] Player player, [NotNull] Command cmd, [NotNull] 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> temp = new Stack <Block>();

            Block[] b;
            while (cmd.HasNext)
            {
                Block block = cmd.NextBlock(player);
                if (block == Block.Undefined)
                {
                    return(null);
                }
                temp.Push(block);
            }
            if (temp.Count > 0)
            {
                b = temp.ToArray();
            }
            else if (player.LastUsedBlockType != Block.Undefined)
            {
                b = new[] { player.LastUsedBlockType, Block.Air };
            }
            else
            {
                b = new[] { Block.Stone, Block.Air };
            }
            return(new DiagonalBrush(b));
        }
Example #19
0
 protected static void RaiseBeganEvent(DrawOperation op)
 {
     BeganEvent.Raise(new DrawOperationEventArgs(op));
 }
Example #20
0
        public IBrushInstance MakeInstance([NotNull] Player player, [NotNull] Command cmd, [NotNull] 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 = cmd.NextBlock(player);
                if (block == Block.Undefined)
                {
                    return(null);
                }
                Block altBlock = cmd.NextBlock(player);
                Block1 = block;
                Block2 = altBlock;
            }
            else if (Block1 == Block.Undefined)
            {
                player.Message("{0}: Please specify at least one block.", Factory.Name);
                return(null);
            }

            return(new CheckeredBrush(this));
        }
 public Block NextBlock(DrawOperation state)
 {
     return(BWRainbow[(state.Coords.X + state.Coords.Y + state.Coords.Z) % 8]);
 }
Example #22
0
 protected static void RaiseEndedEvent( DrawOperation op ) {
     var h = Ended;
     if( h != null ) h( null, new DrawOperationEventArgs( op ) );
 }
Example #23
0
 protected static void RaiseBeganEvent(DrawOperation op) {
     var h = Began;
     if (h != null)
         h(null, new DrawOperationEventArgs(op));
 }
Example #24
0
 public DrawOperationBeginningEventArgs( DrawOperation drawOp ) {
     DrawOp = drawOp;
 }
Example #25
0
 protected static void RaiseEndedEvent(DrawOperation op) {
     var h = Ended;
     if (h != null)
         h(null, new DrawOperationEventArgs(op));
 }
Example #26
0
 public bool Begin(Player player, DrawOperation op) {
     if (player == null)
         throw new ArgumentNullException("player");
     if (op == null)
         throw new ArgumentNullException("op");
     if (Blocks == null || Blocks.Length == 0) {
         throw new InvalidOperationException("No blocks given.");
     }
     if (Replacement == Block.None) {
         if (player.LastUsedBlockType == Block.None) {
             player.Message("Cannot deduce desired replacement block. Click a block or type out the block name.");
             return false;
         } else {
             Replacement = player.GetBind(player.LastUsedBlockType);
         }
     }
     op.Context |= BlockChangeContext.Replaced;
     return true;
 }
Example #27
0
        public IBrushInstance MakeInstance([NotNull] Player player, [NotNull] Command cmd, [NotNull] 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 = cmd.NextBlock(player);
                if (block == Block.Undefined)
                {
                    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));
        }
Example #28
0
 public bool Begin( Player player, DrawOperation state ) {
     if( player == null ) throw new ArgumentNullException( "player" );
     if( state == null ) throw new ArgumentNullException( "state" );
     return true;
 }
Example #29
0
 public bool Begin( Player player, DrawOperation op ) {
     if( player == null ) throw new ArgumentNullException( "player" );
     if( op == null ) throw new ArgumentNullException( "op" );
     if( Blocks == null || Blocks.Length == 0 ) {
         throw new InvalidOperationException( "No blocks given." );
     }
     return true;
 }
Example #30
0
 public UndoState( DrawOperation op ) {
     Op = op;
     Buffer = new List<UndoBlock>();
 }
Example #31
0
 public Block NextBlock( DrawOperation op ) {
     if( op == null ) throw new ArgumentNullException( "op" );
     int n = seed ^ (op.Coords.X + 1290 * op.Coords.Y + 1664510 * op.Coords.Z);
     n = (n << 13) ^ n;
     n = (n * (n * n * 15731 + 789221) + 1376312589) & 0x7FFFFFFF;
     double derp = (n / (double)0x7FFFFFFF) * actualBlocks.Length;
     return actualBlocks[(int)Math.Floor( derp )];
 }
Example #32
0
 bool IBrush.Begin(Player player, DrawOperation op)
 {
     return(true);
 }
Example #33
0
 public bool Begin( Player player, DrawOperation op ) {
     if( player == null ) throw new ArgumentNullException( "player" );
     if( op == null ) throw new ArgumentNullException( "op" );
     op.Context |= BlockChangeContext.Replaced;
     return ReplacementInstance.Begin( player, op );
 }
Example #34
0
        public bool Begin( Player player, DrawOperation op ) {
            if( player == null ) throw new ArgumentNullException( "player" );
            if( op == null ) throw new ArgumentNullException( "op" );

            bool extraLarge = ( op.Bounds.Volume > ExtraLargeThreshold );

            if( extraLarge ) {
                player.MessageNow( "{0} brush: Preparing, please wait...", Brush.Factory.Name );
            }

            noise3D = new PerlinNoise3D( new Random( Seed ) ) {
                Amplitude = 1,
                Frequency = Frequency,
                Octaves = Octaves,
                Persistence = Persistence
            };

            BoundingBox samplerBox = op.Bounds;
            int sampleScale = 1;
            if( extraLarge ) {
                samplerBox = new BoundingBox( op.Bounds.MinVertex, op.Bounds.Width / 2, op.Bounds.Length / 2,
                                              op.Bounds.Height / 2 );
                sampleScale = 2;
            }

            // generate and normalize the raw (float) data
            float[,,] rawData = new float[samplerBox.Width,samplerBox.Length,samplerBox.Height];
            for( int x = 0; x < samplerBox.Width; x++ ) {
                for( int y = 0; y < samplerBox.Length; y++ ) {
                    for( int z = 0; z < samplerBox.Height; z++ ) {
                        rawData[x, y, z] = noise3D.Compute( x * sampleScale, y * sampleScale, z * sampleScale );
                    }
                }
            }
            Noise.Normalize( rawData, out normMultiplier, out normConstant );

            // create a mapping of raw data to blocks
            int totalBlocks = BlockRatios.Sum();
            int blocksSoFar = BlockRatios[0];
            computedThresholds = new float[Blocks.Length];
            computedThresholds[0] = 0;
            for( int i = 1; i < Blocks.Length; i++ ) {
                float desiredCoverage = blocksSoFar / (float)totalBlocks;
                computedThresholds[i] = Noise.FindThreshold( rawData, desiredCoverage );
                blocksSoFar += BlockRatios[i];
            }
            return true;
        }
Example #35
0
 public Block NextBlock( DrawOperation op ) {
     if( op == null ) throw new ArgumentNullException( "op" );
     Block block = op.Map.GetBlock( op.Coords );
     if( block == Block ) {
         return ReplacementInstance.NextBlock( op );
     }
     return Block.None;
 }
Example #36
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() );
            }
        }
Example #37
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 );
        }
Example #38
0
 protected static void RaiseBeganEvent( DrawOperation op ) {
     var h = Began;
     if( h != null ) h( null, new DrawOperationEventArgs( op ) );
 }
Example #39
0
 //copy-paste from BuildingCommands
 private static void DrawOperationBegin(Player player, Command cmd, DrawOperation op)
 {
     IBrushInstance instance = player.Brush.MakeInstance(player, cmd, op);
     if (instance != null)
     {
         op.Brush = instance;
         player.SelectionStart(op.ExpectedMarks, new SelectionCallback(DrawOperationCallback), op, new Permission[] { Permission.DrawAdvanced });
         player.Message("{0}: Click {1} blocks or use &H/Mark&S to make a selection.", new object[] { op.Description, op.ExpectedMarks });
     }
 }
Example #40
0
 public DrawOperationEventArgs( DrawOperation drawOp ) {
     DrawOp = drawOp;
 }
Example #41
0
        public bool Begin(Player player, DrawOperation op)
        {
            if (player == null)
            {
                throw new ArgumentNullException("player");
            }
            if (op == null)
            {
                throw new ArgumentNullException("op");
            }

            bool extraLarge = (op.Bounds.Volume > ExtraLargeThreshold);

            if (extraLarge)
            {
                player.MessageNow("{0} brush: Preparing, please wait...", Brush.Factory.Name);
            }

            noise3D = new PerlinNoise3D(new Random(Seed))
            {
                Amplitude   = 1,
                Frequency   = Frequency,
                Octaves     = Octaves,
                Persistence = Persistence
            };

            BoundingBox samplerBox  = op.Bounds;
            int         sampleScale = 1;

            if (extraLarge)
            {
                samplerBox = new BoundingBox(op.Bounds.MinVertex, op.Bounds.Width / 2, op.Bounds.Length / 2,
                                             op.Bounds.Height / 2);
                sampleScale = 2;
            }

            // generate and normalize the raw (float) data
            float[,,] rawData = new float[samplerBox.Width, samplerBox.Length, samplerBox.Height];
            for (int x = 0; x < samplerBox.Width; x++)
            {
                for (int y = 0; y < samplerBox.Length; y++)
                {
                    for (int z = 0; z < samplerBox.Height; z++)
                    {
                        rawData[x, y, z] = noise3D.Compute(x * sampleScale, y * sampleScale, z * sampleScale);
                    }
                }
            }
            Noise.Normalize(rawData, out normMultiplier, out normConstant);

            // create a mapping of raw data to blocks
            int totalBlocks = BlockRatios.Sum();
            int blocksSoFar = BlockRatios[0];

            computedThresholds    = new float[Blocks.Length];
            computedThresholds[0] = 0;
            for (int i = 1; i < Blocks.Length; i++)
            {
                float desiredCoverage = blocksSoFar / (float)totalBlocks;
                computedThresholds[i] = Noise.FindThreshold(rawData, desiredCoverage);
                blocksSoFar          += BlockRatios[i];
            }
            return(true);
        }
Example #42
0
        public IBrushInstance MakeInstance([NotNull] Player player, [NotNull] Command cmd, [NotNull] 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 = cmd.NextBlock(player);
                if (block == Block.Undefined)
                {
                    return(null);
                }
                blocks.Push(block);
            }

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

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

            return(new ReplaceBrush(this));
        }
Example #43
0
 public IBrushInstance MakeInstance(Player player, CommandReader cmd, DrawOperation op)
 {
     return(this);
 }
Example #44
0
 Block IBrushInstance.NextBlock( DrawOperation op )
 {
     return NextBlock();
 }
Example #45
0
 public Block NextBlock(DrawOperation state) {
     if (state == null) throw new ArgumentNullException("state");
     if (state.AlternateBlockIndex < Blocks.Length) {
         return Blocks[state.AlternateBlockIndex];
     } else {
         return Block.None;
     }
 }
Example #46
0
 public IBrushInstance MakeInstance( Player player, Command cmd, DrawOperation state )
 {
     return this;
 }
Example #47
0
 internal UndoState([CanBeNull] DrawOperation op)
 {
     Op     = op;
     Buffer = new List <UndoBlock>();
 }
Example #48
0
 public IBrushInstance MakeInstance(Player player, Command cmd, DrawOperation state)
 {
     return(this);
 }
Example #49
0
 Block IBrushInstance.NextBlock(DrawOperation op)
 {
     return(NextBlock());
 }
Example #50
0
 public Block NextBlock( DrawOperation state ) {
     if( state == null ) throw new ArgumentNullException( "state" );
     if( ((state.Coords.X + state.Coords.Y + state.Coords.Z) & 1) == 1 ) {
         return Block1;
     } else {
         return Block2;
     }
 }
Example #51
0
 /// <summary> Creates a new UndoState for the given DrawOperation. <param name="op"/> can be null. </summary>
 public UndoState([CanBeNull] DrawOperation op)
 {
     Op = op;
 }
Example #52
0
        static void DrawOperationBegin( Player player, CommandReader cmd, DrawOperation op ) {
            // try to create instance of player's currently selected brush
            // all command parameters are passed to the brush
            IBrushInstance brush = player.Brush.MakeInstance( player, cmd, op );

            // MakeInstance returns null if there were problems with syntax, abort
            if( brush == null ) return;
            op.Brush = brush;
            player.SelectionStart( op.ExpectedMarks, DrawOperationCallback, op, Permission.Draw );
            player.Message( "{0}: Click or &H/Mark&S {1} blocks.",
                            op.Description, op.ExpectedMarks );
        }
Example #53
0
 public UndoState(DrawOperation op)
 {
     Op     = op;
     Buffer = new List <UndoBlock>();
 }