Beispiel #1
0
        public void Erase(int gx, int gy, int layer)
        {
            Chunk chunk = Layers[layer].GetOrCreateChunk(gx, gy, false);

            if (chunk == null)
            {
                return;
            }
            int chunkGridX = (gx < 0 ? -gx - 1 : gx) % CHUNK_SIZE;
            int chunkGridY = (gy < 0 ? -gy - 1 : gy) % CHUNK_SIZE;

            if (gx < 0)
            {
                chunkGridX = CHUNK_SIZE - 1 - chunkGridX;
            }
            if (gy < 0)
            {
                chunkGridY = CHUNK_SIZE - 1 - chunkGridY;
            }

            if (chunk.GetTile(chunkGridX, chunkGridY) == 0)
            {
                return;
            }

            if (UndoEnabled && IsRecordingCommand)
            {
                if (currentRecordingCommand == null)
                {
                    currentRecordingCommand = new Command();
                }

                var oldID = chunk.GetTile(chunkGridX, chunkGridY);

                var match = currentRecordingCommand.TileChanges.Find(n => n != null && n.Layer == layer && n.Position.x == gx && n.Position.y == gy);

                if (match == null)
                {
                    match = new Command.TileData()
                    {
                        Position = new Vector2Int(gx, gy),
                        LastTile = oldID,
                        NewTile  = 0,
                        Layer    = layer
                    };
                    currentRecordingCommand.TileChanges.Add(match);
                }
                else
                {
                    match.NewTile = 0;
                }
            }

            chunk.Erase(chunkGridX, chunkGridY);

            UpdateBitmask(gx, gy, layer);
            UpdateAllNeighborsBitmask(gx, gy, layer);
            SetVariation(gx, gy, 0, layer);

            if (AutoTrim)
            {
                Layers[layer].TrimInvoke = true;
            }
        }
Beispiel #2
0
        public void SetTile(int gx, int gy, byte idx, int layer)
        {
            if (Layers[layer].Tileset.GetTile(idx) == null)
            {
                return;
            }

            Chunk chunk      = Layers[layer].GetOrCreateChunk(gx, gy);
            int   chunkGridX = (gx < 0 ? -gx - 1 : gx) % CHUNK_SIZE;
            int   chunkGridY = (gy < 0 ? -gy - 1 : gy) % CHUNK_SIZE;

            if (gx < 0)
            {
                chunkGridX = CHUNK_SIZE - 1 - chunkGridX;
            }
            if (gy < 0)
            {
                chunkGridY = CHUNK_SIZE - 1 - chunkGridY;
            }

            if (chunk.GetTile(chunkGridX, chunkGridY) == idx)
            {
                return;
            }

            var genVariation = chunk.GetTile(chunkGridX, chunkGridY) != idx;

            if (UndoEnabled && IsRecordingCommand)
            {
                if (currentRecordingCommand == null)
                {
                    currentRecordingCommand = new Command();
                }

                var oldID = chunk.GetTile(chunkGridX, chunkGridY);

                var newID = idx;

                var match = currentRecordingCommand.TileChanges.Find(n => n != null && n.Layer == layer && n.Position.x == gx && n.Position.y == gy);

                if (match == null)
                {
                    match = new Command.TileData()
                    {
                        Position = new Vector2Int(gx, gy),
                        LastTile = oldID,
                        NewTile  = idx,
                        Layer    = layer
                    };
                    currentRecordingCommand.TileChanges.Add(match);
                }
                else
                {
                    match.NewTile = idx;
                }
            }

            chunk.SetTile(chunkGridX, chunkGridY, idx);

            if (Layers[layer].Tileset.GetTile(idx).Type == BlockType.Overlap)
            {
                UpdateBitmask(gx, gy, layer);
                UpdateAllNeighborsBitmask(gx, gy, layer);
            }

            if (genVariation)
            {
                GenVariation(gx, gy, layer);
            }

            Layers[layer].TrimInvoke = true;
        }