예제 #1
0
        public override void ExecuteSynchronizePhase(DimensionEntity <Dimension> entity)
        {
            var locationToLoad = entity.Location;

            var minX = locationToLoad.X;
            var maxX = locationToLoad.X + entity.Width;
            var minY = locationToLoad.Y;
            var maxY = locationToLoad.Y + entity.Height;

            var stampTiles = new Tile[maxX - minX, maxY - minY];

            for (var i = 0; i < maxX - minX; i++)
            {
                for (var j = 0; j < maxY - minY; j++)
                {
                    stampTiles[i, j] = new Tile();
                }
            }

            for (var x = minX; x < maxX; x++)
            {
                for (var y = minY; y < maxY; y++)
                {
                    if (WorldGen.InWorld(x, y))
                    {
                        if (Main.tile[x, y].active())
                        {
                            WorldGen.TileFrame(x, y);
                        }

                        if (Main.tile[x, y].wall > 0)
                        {
                            Framing.WallFrame(x, y);
                        }

                        var target = Framing.GetTileSafely(x, y);
                        stampTiles[x - minX, y - minY].CopyFrom(target);
                    }
                }
            }

            entity.Dimension.Tiles = stampTiles;
        }
예제 #2
0
        public static Tile[,] LoadTilesFromBase64(string data)
        {
            int oldX = Main.maxTilesX;
            int oldY = Main.maxTilesY;

            Tile[,] oldTiles    = Main.tile;
            Tile[,] loadedTiles = new Tile[0, 0];
            try
            {
                TagCompound tagCompound = TagIO.FromStream(new MemoryStream(Convert.FromBase64String(data)));
                if (LoadTilesMethodInfo == null)
                {
                    LoadTilesMethodInfo = typeof(Main).Assembly.GetType("Terraria.ModLoader.IO.TileIO").GetMethod("LoadTiles", BindingFlags.Static | BindingFlags.NonPublic);
                }
                if (LoadWorldTilesVanillaMethodInfo == null)
                {
                    LoadWorldTilesVanillaMethodInfo = typeof(Main).Assembly.GetType("Terraria.IO.WorldFile").GetMethod("LoadWorldTiles", BindingFlags.Static | BindingFlags.NonPublic);
                }
                bool[] importance = new bool[TileID.Count];
                for (int i = 0; i < TileID.Count; i++)
                {
                    importance[i] = Main.tileFrameImportant[i];
                }

                Point16 dimensions = tagCompound.Get <Point16>("d");
                Main.maxTilesX = dimensions.X;
                Main.maxTilesY = dimensions.Y;
                loadedTiles    = new Tile[Main.maxTilesX, Main.maxTilesY];
                for (int i = 0; i < Main.maxTilesX; i++)
                {
                    for (int j = 0; j < Main.maxTilesY; j++)
                    {
                        loadedTiles[i, j] = new Tile();
                    }
                }
                Main.tile = loadedTiles;

                using (MemoryStream memoryStream = new MemoryStream(tagCompound.GetByteArray("v")))
                {
                    using (BinaryReader binaryReader = new BinaryReader(memoryStream))
                    {
                        LoadWorldTilesVanillaMethodInfo.Invoke(null, new object[] { binaryReader, importance });
                    }
                }

                if (tagCompound.ContainsKey("m"))
                {
                    LoadTilesMethodInfo.Invoke(null, new object[] { tagCompound["m"] });
                }

                // Expand because TileFrame ignores edges of map.
                Main.maxTilesX = dimensions.X + 12;
                Main.maxTilesY = dimensions.Y + 12;
                Tile[,] loadedTilesExpanded = new Tile[Main.maxTilesX, Main.maxTilesY];
                for (int i = 0; i < Main.maxTilesX; i++)
                {
                    for (int j = 0; j < Main.maxTilesY; j++)
                    {
                        if (i < 6 || i >= Main.maxTilesX - 6 || j < 6 || j >= Main.maxTilesY - 6)
                        {
                            loadedTilesExpanded[i, j] = new Tile();
                        }
                        else
                        {
                            loadedTilesExpanded[i, j] = Main.tile[i - 6, j - 6];
                        }
                    }
                }
                Main.tile = loadedTilesExpanded;

                for (int i = 0; i < Main.maxTilesX; i++)
                {
                    for (int j = 0; j < Main.maxTilesY; j++)
                    {
                        //WorldGen.TileFrame(i, j, true, false);

                        //if (i > 5 && j > 5 && i < Main.maxTilesX - 5 && j < Main.maxTilesY - 5
                        // 0 needs to be 6 ,   MaxX == 5, 4 index,
                        // need tp add 6?       4(10) < 5(11) - 5

                        if (Main.tile[i, j].active())
                        {
                            WorldGen.TileFrame(i, j, true, false);
                        }
                        if (Main.tile[i, j].wall > 0)
                        {
                            Framing.WallFrame(i, j, true);
                        }
                    }
                }
            }
            catch { }
            Main.maxTilesX = oldX;
            Main.maxTilesY = oldY;
            Main.tile      = oldTiles;
            return(loadedTiles);
        }
예제 #3
0
        public void Update2()
        {
            Player player = Main.LocalPlayer;

            if (selected && (EyeDropperActive || StampToolActive))
            {
                //			player.mouseInterface = true;
                //			player.showItemIcon = true;
                if (EyeDropperActive)
                {
                    //		Main.LocalPlayer.showItemIconText = "Click to select pallete";
                    player.showItemIcon2 = ItemID.EmptyDropper;
                    if (leftMouseDown)
                    {
                        Point point = (Main.MouseWorld).ToTileCoordinates();
                        //Point point = (Main.MouseWorld + (brushSize % 2 == 0 ? Vector2.One * 8 : Vector2.Zero)).ToTileCoordinates();
                        //point.X -= brushSize / 2;
                        //point.Y -= brushSize / 2;
                        if (startTileX == -1)
                        {
                            startTileX     = point.X;
                            startTileY     = point.Y;
                            lastMouseTileX = -1;
                            lastMouseTileY = -1;
                        }

                        //if (lastMouseTileX != point.X && lastMouseTileY != point.Y)
                        {
                            //for (int x = 0; x < brushSize; x++)
                            //{
                            //	for (int y = 0; y < brushSize; y++)
                            //	{
                            //		if (WorldGen.InWorld(x + point.X, y + point.Y))
                            //		{
                            //			Tile target = Framing.GetTileSafely(x + point.X, y + point.Y);
                            //			BrushTiles[x, y].CopyFrom(target);
                            //			//	Main.NewText("{x}, {y}");
                            //		}
                            //	}
                            //}
                            lastMouseTileX = point.X;
                            lastMouseTileY = point.Y;
                        }
                    }
                    if (justLeftMouseDown)
                    {
                        if (startTileX != -1 && startTileY != -1 && lastMouseTileX != -1 && lastMouseTileY != -1)
                        {
                            Vector2 upperLeft  = new Vector2(Math.Min(startTileX, lastMouseTileX), Math.Min(startTileY, lastMouseTileY));
                            Vector2 lowerRight = new Vector2(Math.Max(startTileX, lastMouseTileX), Math.Max(startTileY, lastMouseTileY));

                            int minX = (int)upperLeft.X;
                            int maxX = (int)lowerRight.X + 1;
                            int minY = (int)upperLeft.Y;
                            int maxY = (int)lowerRight.Y + 1;

                            //ErrorLogger.Log(string.Format("JustDown2 {0} {1} {2} {3}", minX, minY, maxX, maxY));

                            StampTiles = new Tile[maxX - minX, maxY - minY];

                            for (int i = 0; i < maxX - minX; i++)
                            {
                                for (int j = 0; j < maxY - minY; j++)
                                {
                                    StampTiles[i, j] = new Tile();
                                }
                            }

                            for (int x = minX; x < maxX; x++)
                            {
                                for (int y = minY; y < maxY; y++)
                                {
                                    if (WorldGen.InWorld(x, y))
                                    {
                                        if (Main.tile[x, y].type == TileID.Count)
                                        {
                                        }
                                        if (Main.tile[x, y].active())
                                        {
                                            WorldGen.TileFrame(x, y, true, false);
                                        }
                                        if (Main.tile[x, y].wall > 0)
                                        {
                                            Framing.WallFrame(x, y, true);
                                        }

                                        Tile target = Framing.GetTileSafely(x, y);
                                        StampTiles[x - minX, y - minY].CopyFrom(target);
                                        if (Main.tile[x, y].type == TileID.Count)
                                        {
                                            StampTiles[x - minX, y - minY].ClearTile();
                                        }
                                        if (Main.tileContainer[Main.tile[x, y].type])
                                        {
                                            StampTiles[x - minX, y - minY].ClearTile();
                                        }
                                    }
                                }
                            }

                            //Main.NewText("EyeDropper: width height" + (maxX - minX) + " " + (maxY - minY));
                            CheatSheet.instance.paintToolsUI.AddSlot(PaintToolsEx.GetStampInfo(StampTiles));
                            //CalculateItemCost(StampTiles);
                        }
                        //Main.NewText("EyeDropper: x,y,min max " + minX + " " + maxX + " " + minY + " " + maxY);

                        startTileX        = -1;
                        startTileY        = -1;
                        lastMouseTileX    = -1;
                        lastMouseTileY    = -1;
                        justLeftMouseDown = false;
                    }
                }
                if (StampToolActive)
                {
                    player.showItemIcon2 = ItemID.Paintbrush;
                    //		Main.LocalPlayer.showItemIconText = "Click to paint";
                    if (leftMouseDown && stampInfo != null)
                    {
                        int width  = StampTiles.GetLength(0);
                        int height = StampTiles.GetLength(1);
                        //Vector2 brushsize = new Vector2(width, height);
                        //Vector2 evenOffset = Vector2.Zero;
                        //if (width % 2 == 0)
                        //{
                        //	evenOffset.X = 1;
                        //}
                        //if (height % 2 == 0)
                        //{
                        //	evenOffset.Y = 1;
                        //}
                        //Point point = (Main.MouseWorld + evenOffset * 8).ToTileCoordinates();
                        ////Point point = (Main.MouseWorld + (brushSize % 2 == 0 ? Vector2.One * 8 : Vector2.Zero)).ToTileCoordinates();
                        //point.X -= width / 2;
                        //point.Y -= height / 2;
                        ////Vector2 vector = new Vector2(point.X, point.Y) * 16f;
                        ////vector -= Main.screenPosition;
                        ////if (Main.LocalPlayer.gravDir == -1f)
                        ////{
                        ////	vector.Y = (float)Main.screenHeight - vector.Y - 16f;
                        ////}

                        Point point = Snap.GetSnapPosition(CheatSheet.instance.paintToolsUI.SnapType, width, height, constrainToAxis, constrainedX, constrainedY, true).ToPoint();

                        if (startTileX == -1)
                        {
                            startTileX     = point.X;
                            startTileY     = point.Y;
                            lastMouseTileX = -1;
                            lastMouseTileY = -1;
                        }

                        if (Main.keyState.IsKeyDown(Keys.LeftShift))
                        {
                            constrainToAxis = true;
                            if (constrainedStartX == -1 && constrainedStartY == -1)
                            {
                                constrainedStartX = point.X;
                                constrainedStartY = point.Y;
                            }

                            if (constrainedX == -1 && constrainedY == -1)
                            {
                                if (constrainedStartX != point.X)
                                {
                                    constrainedY = point.Y;
                                }
                                else if (constrainedStartY != point.Y)
                                {
                                    constrainedX = point.X;
                                }
                            }
                            if (constrainedX != -1)
                            {
                                point.X = constrainedX;
                            }
                            if (constrainedY != -1)
                            {
                                point.Y = constrainedY;
                            }
                        }
                        else
                        {
                            constrainToAxis   = false;
                            constrainedX      = -1;
                            constrainedY      = -1;
                            constrainedStartX = -1;
                            constrainedStartY = -1;
                        }

                        if (lastMouseTileX != point.X || lastMouseTileY != point.Y)
                        {
                            lastMouseTileX = point.X;
                            lastMouseTileY = point.Y;
                            //Main.NewText("StartTileX " + startTileX);
                            UndoHistory.Push(Tuple.Create(point, new Tile[width, height]));
                            UpdateUndoTooltip();
                            for (int x = 0; x < width; x++)
                            {
                                for (int y = 0; y < height; y++)
                                {
                                    if (WorldGen.InWorld(x + point.X, y + point.Y) && StampTiles[x, y] != null)
                                    {
                                        Tile target = Framing.GetTileSafely(x + point.X, y + point.Y);
                                        UndoHistory.Peek().Item2[x, y] = new Tile(target);
                                        int cycledX = ((x + point.X - startTileX) % width + width) % width;
                                        int cycledY = ((y + point.Y - startTileY) % height + height) % height;
                                        if (TransparentSelectionEnabled)                                         // What about just walls?
                                        {
                                            if (StampTiles[cycledX, cycledY].active())
                                            {
                                                target.CopyFrom(StampTiles[cycledX, cycledY]);
                                            }
                                        }
                                        else
                                        {
                                            target.CopyFrom(StampTiles[cycledX, cycledY]);
                                        }
                                    }
                                }
                            }
                            for (int i = point.X; i < point.X + width; i++)
                            {
                                for (int j = 0; j < point.Y + height; j++)
                                {
                                    WorldGen.SquareTileFrame(i, j, false);                                     // Need to do this after stamp so neighbors are correct.
                                    if (Main.netMode == 1 && Framing.GetTileSafely(i, j).liquid > 0)
                                    {
                                        NetMessage.sendWater(i, j);                                         // Does it matter that this is before sendtilesquare?
                                    }
                                }
                            }
                            if (Main.netMode == 1)
                            {
                                NetMessage.SendTileSquare(-1, point.X + width / 2, point.Y + height / 2, Math.Max(width, height));
                            }
                        }
                    }
                    else
                    {
                        startTileX        = -1;
                        startTileY        = -1;
                        constrainToAxis   = false;
                        constrainedX      = -1;
                        constrainedY      = -1;
                        constrainedStartX = -1;
                        constrainedStartY = -1;
                    }
                }
                Main.LocalPlayer.showItemIcon = true;
            }
        }