当前位置: 首页>>代码示例>>C#>>正文


C# World.Validate方法代码示例

本文整理汇总了C#中TEditXNA.Terraria.World.Validate方法的典型用法代码示例。如果您正苦于以下问题:C# World.Validate方法的具体用法?C# World.Validate怎么用?C# World.Validate使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在TEditXNA.Terraria.World的用法示例。


在下文中一共展示了World.Validate方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: Save

        public static void Save(World world, string filename, bool resetTime = false)
        {
            try
            {
                OnProgressChanged(world, new ProgressChangedEventArgs(0, "Validating World..."));
                world.Validate();
            }
            catch (ArgumentOutOfRangeException err)
            {
                string msg = string.Format("There is a problem in your world.\r\n" + 
                                           "{0}\r\nThis world will not open in Terraria\r\n" + 
                                           "Would you like to save anyways??\r\n"
                                           , err.ParamName);
                if (MessageBox.Show(msg, "World Error", MessageBoxButton.YesNo, MessageBoxImage.Error) !=
                    MessageBoxResult.Yes)
                    return;
            }
            lock (_fileLock)
            {
                

                if (resetTime)
                {
                    OnProgressChanged(world, new ProgressChangedEventArgs(0, "Resetting Time..."));
                    world.ResetTime();
                }

                if (filename == null)
                    return;

                string temp = filename + ".tmp";
                using (var fs = new FileStream(temp, FileMode.Create))
                {
                    using (var bw = new BinaryWriter(fs))
                    {
                        if (world.Version > 87)
                            SaveV2(world, bw);
                        else
                            SaveV1(world, bw);

                        bw.Close();
                        fs.Close();

                        // make a backup of current file if it exists
                        if (File.Exists(filename))
                        {
                            string backup = filename + ".TEdit";
                            File.Copy(filename, backup, true);
                        }
                        // replace actual file with temp save file
                        File.Copy(temp, filename, true);
                        // delete temp save file
                        File.Delete(temp);
                        OnProgressChanged(null, new ProgressChangedEventArgs(0, "World Save Complete."));
                    }
                }

                world._lastSave = File.GetLastWriteTimeUtc(filename);
            }
        }
开发者ID:liquidradio,项目名称:Terraria-Map-Editor,代码行数:60,代码来源:World.cs

示例2: SaveV2

        private static void SaveV2(World world, BinaryWriter bw)
        {
            world.Validate();

            // initialize tileframeimportance array if empty
            if (TileFrameImportant == null || TileFrameImportant.Length < TileCount)
            {
                TileFrameImportant = new bool[TileCount];
                for (int i = 0; i < TileCount; i++)
                {
                    if (World.TileProperties.Count > i)
                    {
                        TileFrameImportant[i] = World.TileProperties[i].IsFramed;
                    }
                }
            }

            int[] sectionPointers = new int[SectionCount];

            OnProgressChanged(null, new ProgressChangedEventArgs(0, "Save headers..."));
            sectionPointers[0] = SaveSectionHeader(world, bw);
            sectionPointers[1] = SaveHeaderFlags(world, bw);
            OnProgressChanged(null, new ProgressChangedEventArgs(0, "Save UndoTiles..."));
            sectionPointers[2] = SaveTiles(world.Tiles, world.TilesWide, world.TilesHigh, bw);

            OnProgressChanged(null, new ProgressChangedEventArgs(100, "Save Chests..."));
            sectionPointers[3] = SaveChests(world.Chests, bw);
            OnProgressChanged(null, new ProgressChangedEventArgs(100, "Save Signs..."));
            sectionPointers[4] = SaveSigns(world.Signs, bw);
            OnProgressChanged(null, new ProgressChangedEventArgs(100, "Save NPCs..."));
            sectionPointers[5] = SaveNPCs(world.NPCs, bw);
            OnProgressChanged(null, new ProgressChangedEventArgs(100, "Save Mobs..."));
            sectionPointers[5] = SaveMobs(world.Mobs, bw);
            OnProgressChanged(null, new ProgressChangedEventArgs(100, "Save Tile Entities Section..."));
            sectionPointers[6] = SaveTileEntities(world, bw);
            OnProgressChanged(null, new ProgressChangedEventArgs(100, "Save Footers..."));
            SaveFooter(world, bw);
            UpdateSectionPointers(sectionPointers, bw);
            OnProgressChanged(null, new ProgressChangedEventArgs(100, "Save Complete."));
        }
开发者ID:liquidradio,项目名称:Terraria-Map-Editor,代码行数:40,代码来源:World.FileV2.cs

示例3: Save

        public static void Save(World world, string filename, bool resetTime = false)
        {
            lock (_fileLock)
            {
                OnProgressChanged(world, new ProgressChangedEventArgs(0, "Validating World..."));
                world.Validate();

                if (resetTime)
                {
                    OnProgressChanged(world, new ProgressChangedEventArgs(0, "Resetting Time..."));
                    world.ResetTime();
                }

                if (filename == null)
                    return;

                string temp = filename + ".tmp";
                using (var fs = new FileStream(temp, FileMode.Create))
                {
                    using (var bw = new BinaryWriter(fs))
                    {
                        if (CompatibleVersion > 87)
                            SaveV2(world, bw);
                        else
                            SaveV1(world, bw);

                        bw.Close();
                        fs.Close();

                        // make a backup of current file if it exists
                        if (File.Exists(filename))
                        {
                            string backup = filename + ".TEdit";
                            File.Copy(filename, backup, true);
                        }
                        // replace actual file with temp save file
                        File.Copy(temp, filename, true);
                        // delete temp save file
                        File.Delete(temp);
                        OnProgressChanged(null, new ProgressChangedEventArgs(0, "World Save Complete."));
                    }
                }

                world._lastSave = File.GetLastWriteTimeUtc(filename);
            }
        }
开发者ID:reaperx420,项目名称:Terraria-Map-Editor,代码行数:46,代码来源:World.cs

示例4: WriteAnalyzeWorld

        private static void WriteAnalyzeWorld(StreamWriter sb, World world, bool fullAnalysis = false)
        {
            world.Validate();
            WriteHeader(sb, world);
            WriteFlags(sb, world);

            if (!fullAnalysis) return;

            sb.WriteLine("===SECTION: Tiles===");

            var tileCounts = new Dictionary<int, int>();

            int activeTiles = 0;
            for (int x = 0; x < world.TilesWide; x++)
            {
                for (int y = 0; y < world.TilesHigh; y++)
                {

                    var tile = world.Tiles[x, y];

                    if (tile.IsActive)
                    {
                        if (tileCounts.ContainsKey(tile.Type))
                        {
                            tileCounts[tile.Type] += 1;
                        }
                        else
                        {
                            tileCounts.Add(tile.Type, 1);
                        }
                        activeTiles++;
                    }

                }
            }

            float totalTiles = world.TilesWide * world.TilesHigh;
            int airTiles = (int)(totalTiles - activeTiles);
            sb.WriteLine("Air: {0} ({1:P2})", airTiles, airTiles / totalTiles);

            var tiles = tileCounts.OrderByDescending(kvp => kvp.Value);
            foreach (var tilePair in tiles)
            {
                string name = tilePair.Key.ToString();
                if (World.TileProperties.Count >= tilePair.Key)
                {
                    var prop = World.TileProperties[tilePair.Key];
                    if (prop != null)
                    {
                        name = prop.Name;
                    }
                }

                sb.WriteLine("{0}: {1} ({2:P2})", name, tilePair.Value, tilePair.Value / totalTiles);
            }

            sb.WriteLine("===SECTION: Chests===");
            sb.WriteProperty("Chest Count", world.Chests.Count);
            sb.WriteProperty("Chest Max Items", Chest.MaxItems);

            foreach (var chest in world.Chests)
            {
                sb.Write("[{0}, {1}] {2} - Contents: ", chest.X, chest.Y, chest.Name);

                for (int i = 0; i < Chest.MaxItems; i++)
                {
                    Item item = chest.Items[i];
                    if (item == null)
                        sb.Write("[{0}]: Empty,", i.ToString());
                    else
                    {
                        sb.Write("[{0}]: {1} - {2}{3},", i.ToString(), item.StackSize, item.PrefixName, item.Name);
                    }
                }

                sb.WriteLine();
            }

            sb.WriteLine("===SECTION: Signs===");
            sb.WriteProperty("Sign Count", world.Signs.Count);

            foreach (var sign in world.Signs)
            {
                sb.Write("[{0}, {1}] {2}\r\n", sign.X, sign.Y, sign.Text);
            }

            sb.WriteLine("===SECTION: NPCs===");
            sb.WriteProperty("NPC Count", world.NPCs.Count);
            foreach (var npc in world.NPCs)
            {
                sb.Write("ID: {0}, Name: {1}, Position: [{2:0.00}, {3:0.00}], {4}: [{5}, {6}]\r\n", npc.Name, npc.DisplayName, npc.Position.X, npc.Position.Y, npc.IsHomeless ? "Homeless" : "Home", npc.Home.X, npc.Home.Y);
            }

            sb.WriteLine("===SECTION: Tile Entities===");
            sb.WriteProperty("Tile Entities Count", world.TileEntities.Count);
            foreach (var entity in world.TileEntities)
            {
                switch (entity.Type)
                {
                    case 0:
//.........这里部分代码省略.........
开发者ID:TEdit,项目名称:Terraria-Map-Editor,代码行数:101,代码来源:WorldAnalysis.cs


注:本文中的TEditXNA.Terraria.World.Validate方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。