Beispiel #1
0
        public static void SaveMultistructureToFile(ref List <TagCompound> toSave, string targetPath = null)
        {
            string path = ModLoader.ModPath.Replace("Mods", "SavedStructures");

            if (!Directory.Exists(path))
            {
                Directory.CreateDirectory(path);
            }

            string thisPath = targetPath ?? Path.Combine(path, "SavedMultiStructure_" + 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("Structures", toSave);
            tag.Add("Version", StructureHelper.Instance.Version.ToString());

            TagIO.ToFile(tag, thisPath);

            toSave.Clear();
        }
Beispiel #2
0
        public override void Save(TDimension dimension)
        {
            if (!Directory.Exists(ResourceFolderName))
            {
                Directory.CreateDirectory(ResourceFolderName);
            }
            if (File.Exists(FileResourcePath))
            {
                File.Delete(FileResourcePath);
            }

            var tag = (TagCompound)TagIO.Serialize(dimension);

            TagIO.ToFile(tag, FileResourcePath);
        }
Beispiel #3
0
 public byte[] this[string filename]
 {
     get
     {
         CheckNull();
         return(savable.Get <byte[]>(filename));
     }
     set
     {
         if (filename == "/achievements-steam.dat")
         {
             return;
         }
         CheckNull();
         savable[filename] = value;
         TagIO.ToFile(savable, Path.Combine(Main.PlayerPath, sscfile));
     }
 }
        public void SaveChestRulesFile()
        {
            string path = ModLoader.ModPath.Replace("Mods", "SavedStructures");

            if (!Directory.Exists(path))
            {
                Directory.CreateDirectory(path);
            }
            string thisPath = Path.Combine(path, "SavedChest_" + DateTime.Now.ToString("d-M-y----H-m-s-f"));

            Main.NewText("Chest data saved as " + thisPath, Color.Yellow);
            FileStream stream = File.Create(thisPath);

            stream.Close();

            TagCompound tag = SaveChestRules();

            TagIO.ToFile(tag, thisPath);
        }
Beispiel #5
0
        public static void SaveToFile(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();

            var tag = SaveStructure(target);

            TagIO.ToFile(tag, thisPath);
        }
Beispiel #6
0
        internal void SaveMeForGood(string targetPath = null)
        {
            string path = ModLoader.ModPath.Replace("Mods", "SavedStructures");

            if (!Directory.Exists(path))
            {
                Directory.CreateDirectory(path);
            }
            string thisPath = targetPath ?? Path.Combine(path, "SavedMultiStructure_" + 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("Structures", StructureCache);

            TagIO.ToFile(tag, thisPath);

            StructureCache.Clear();
        }
Beispiel #7
0
        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);
        }