public unsafe static TagCompound SaveStructure(Rectangle target) { TagCompound tag = new TagCompound(); tag.Add("Version", StructureHelper.Instance.Version.ToString()); tag.Add("Width", target.Width); tag.Add("Height", target.Height); List <TileSaveData> data = new List <TileSaveData>(); for (int x = target.X; x <= target.X + target.Width; x++) { for (int y = target.Y; y <= target.Y + target.Height; y++) { Tile tile = Framing.GetTileSafely(x, y); string tileName; string wallName; string teName; if (tile.TileType >= TileID.Count) { tileName = ModContent.GetModTile(tile.TileType).Mod.Name + " " + ModContent.GetModTile(tile.TileType).Name; } else { tileName = tile.TileType.ToString(); } if (tile.WallType >= WallID.Count) { wallName = ModContent.GetModWall(tile.WallType).Mod.Name + " " + ModContent.GetModWall(tile.WallType).Name; } else { wallName = tile.WallType.ToString(); } TileEntity teTarget = null; //grabbing TE data TagCompound entityTag = new TagCompound(); if (TileEntity.ByPosition.ContainsKey(new Point16(x, y))) { teTarget = TileEntity.ByPosition[new Point16(x, y)]; } if (teTarget != null) { if (teTarget.type < 2) { teName = teTarget.type.ToString(); } else { ModTileEntity entityTarget = teTarget as ModTileEntity; if (entityTarget != null) { teName = entityTarget.Mod.Name + " " + entityTarget.Name; (teTarget as ModTileEntity).SaveData(entityTag); } else { teName = ""; } } } else { teName = ""; } int wallWireData; short packedLiquidData; fixed(void *ptr = &tile.Get <TileWallWireStateData>()) { var intPtr = (int *)(ptr); intPtr++; wallWireData = *intPtr; } fixed(void *ptr = &tile.Get <LiquidData>()) { var shortPtr = (short *)ptr; packedLiquidData = *shortPtr; } data.Add( new TileSaveData( tileName, wallName, tile.TileFrameX, tile.TileFrameY, wallWireData, packedLiquidData, teName, entityTag )); } } tag.Add("TileData", data); return(tag); }
public void SaveStructure(Rectangle target, string targetPath = null) { string path = ModLoader.ModPath.Replace("Mods", "SavedStructures"); if (!Directory.Exists(path)) { Directory.CreateDirectory(path); } string thisPath = targetPath ?? Path.Combine(path, "SavedStructure_" + DateTime.Now.ToString("d-M-y----H-m-s-f")); Main.NewText("Structure saved as " + thisPath, Color.Yellow); FileStream stream = File.Create(thisPath); stream.Close(); TagCompound tag = new TagCompound(); tag.Add("Width", Width); tag.Add("Height", Height); List <TileSaveData> data = new List <TileSaveData>(); for (int x = target.X; x <= target.X + target.Width; x++) { for (int y = target.Y; y <= target.Y + target.Height; y++) { Tile tile = Framing.GetTileSafely(x, y); string tileName; string wallName; string teName; if (tile.type >= TileID.Count) { tileName = ModContent.GetModTile(tile.type).mod.Name + " " + ModContent.GetModTile(tile.type).Name; } else { tileName = tile.type.ToString(); } if (tile.wall >= WallID.Count) { wallName = ModContent.GetModWall(tile.wall).mod.Name + " " + ModContent.GetModWall(tile.wall).Name; } else { wallName = tile.wall.ToString(); } TileEntity teTarget = null; //grabbing TE data TagCompound entityTag = null; if (TileEntity.ByPosition.ContainsKey(new Point16(x, y))) { teTarget = TileEntity.ByPosition[new Point16(x, y)]; } if (teTarget != null) { if (teTarget.type < 2) { teName = teTarget.type.ToString(); } else { ModTileEntity entityTarget = ModTileEntity.GetTileEntity(teTarget.type); if (entityTarget != null) { teName = entityTarget.mod.Name + " " + entityTarget.Name; entityTag = (teTarget as ModTileEntity).Save(); } else { teName = ""; } } } else { teName = ""; } byte[] wireArray = new byte[] { (byte)tile.wire().ToInt(), (byte)tile.wire2().ToInt(), (byte)tile.wire3().ToInt(), (byte)tile.wire4().ToInt() }; data.Add(new TileSaveData(tile.active(), tileName, wallName, tile.frameX, tile.frameY, (short)tile.wallFrameX(), (short)tile.wallFrameY(), tile.slope(), tile.halfBrick(), tile.actuator(), !tile.nactive(), tile.liquid, tile.liquidType(), tile.color(), tile.wallColor(), wireArray, teName, entityTag)); } } tag.Add("TileData", data); TagIO.ToFile(tag, thisPath); }
public void SaveStructure(Rectangle target) { TagCompound tag = new TagCompound(); tag.Add("Width", Width); tag.Add("Height", Height); List <TileSaveData> data = new List <TileSaveData>(); for (int x = target.X; x <= target.X + target.Width; x++) { for (int y = target.Y; y <= target.Y + target.Height; y++) { Tile tile = Framing.GetTileSafely(x, y); string tileName; string wallName; string teName; if (tile.type >= TileID.Count) { tileName = ModContent.GetModTile(tile.type).mod.Name + " " + ModContent.GetModTile(tile.type).Name; } else { tileName = tile.type.ToString(); } if (tile.wall >= WallID.Count) { wallName = ModContent.GetModWall(tile.wall).mod.Name + " " + ModContent.GetModWall(tile.wall).Name; } else { wallName = tile.wall.ToString(); } TileEntity teTarget = null; //grabbing TE data TagCompound entityTag = null; if (TileEntity.ByPosition.ContainsKey(new Point16(x, y))) { teTarget = TileEntity.ByPosition[new Point16(x, y)]; } if (teTarget != null) { if (teTarget.type < 2) { teName = teTarget.type.ToString(); } else { ModTileEntity entityTarget = ModTileEntity.GetTileEntity(teTarget.type); if (entityTarget != null) { teName = entityTarget.mod.Name + " " + entityTarget.Name; entityTag = (teTarget as ModTileEntity).Save(); } else { teName = ""; } } } else { teName = ""; } byte[] wireArray = new byte[] { (byte)tile.wire().ToInt(), (byte)tile.wire2().ToInt(), (byte)tile.wire3().ToInt(), (byte)tile.wire4().ToInt() }; data.Add(new TileSaveData(tile.active(), tileName, wallName, tile.frameX, tile.frameY, (short)tile.wallFrameX(), (short)tile.wallFrameY(), tile.slope(), tile.halfBrick(), tile.actuator(), !tile.nactive(), tile.liquid, tile.liquidType(), tile.color(), tile.wallColor(), wireArray, teName, entityTag)); } } tag.Add("TileData", data); StructureCache.Add(tag); Main.NewText("Structure added. Total structure count: " + StructureCache.Count, Color.Cyan); TopLeft = default; SecondPoint = false; Width = 0; Height = 0; }