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


C# Terraria.World类代码示例

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


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

示例1: LoadWorld

 public static World LoadWorld(string filename)
 {
     var w = new World();
     try
     {
         lock (_fileLock)
         {
             using (var b = new BinaryReader(File.OpenRead(filename)))
             {
                 w.Version = b.ReadUInt32();
                 if (w.Version > 87)
                     LoadV2(b, filename, w);
                 else
                     LoadV1(b, filename, w);
             }
             w.LastSave = File.GetLastWriteTimeUtc(filename);
         }
     }
     catch (Exception err)
     {
         string msg =
             "There was an error reading the world file, do you wish to force it to load anyway?\r\n\r\n" +
             "WARNING: This may have unexpected results including corrupt world files and program crashes.\r\n\r\n" +
             "The error is :\r\n";
         if (MessageBox.Show(msg + err, "World File Error", MessageBoxButton.YesNo, MessageBoxImage.Error) !=
             MessageBoxResult.Yes)
             return null;
     }
     return w;
 }
开发者ID:reaperx420,项目名称:Terraria-Map-Editor,代码行数:30,代码来源:World.cs

示例2: WriteTally

        private static void WriteTally(StreamWriter sb, World world)
        {
            int index = 0;
            int killcount = 0;
            int bannercount = 0;
            int uniquecount = 0;

            foreach (int count in world.KilledMobs)
            {
                if (count > 0)
                {
                    int banners = (int)Math.Floor((double)count / 50f);
                    // sb.WriteProperty(index.ToString(), count.ToString());
                    sb.WriteLine("{0} {1}: {2} ({3} earned)", index, World.TallyNames[index], count, banners);
                    killcount = killcount + count;
                    if (banners > 0)
                        uniquecount = uniquecount + 1;
                    bannercount = bannercount + banners;
                }
                index++;
            }
            sb.Write(Environment.NewLine);
            sb.WriteLine("Total kills counted: {0}", killcount);
            sb.WriteLine("Total banners awarded: {0}", bannercount);
            sb.WriteLine("Total unique banners: {0}", uniquecount);
        }
开发者ID:ppally3,项目名称:Terraria-Map-Editor,代码行数:26,代码来源:KillTally.cs

示例3: 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

示例4: Render

        public static WriteableBitmap Render(World w)
        {
            WriteableBitmap bmp = new WriteableBitmap(w.TilesWide / Resolution, w.TilesHigh / Resolution, 96, 96, PixelFormats.Bgra32, null);

            UpdateMinimap(w, ref bmp);

            return bmp;
        }
开发者ID:liquidradio,项目名称:Terraria-Map-Editor,代码行数:8,代码来源:RenderMiniMap.cs

示例5: AnalyzeWorld

        public static void AnalyzeWorld(World world, string file)
        {
            if (world == null) return;

            using (var writer = new StreamWriter(file, false))
            {
                WriteAnalyzeWorld(writer, world, true);
            }
        }
开发者ID:TEdit,项目名称:Terraria-Map-Editor,代码行数:9,代码来源:WorldAnalysis.cs

示例6: SaveTally

        public static void SaveTally(World world, string file)
        {
            if (world == null) return;

            using (var writer = new StreamWriter(file, false))
            {
                WriteTallyCount(writer, world, true);
            }
        }
开发者ID:ppally3,项目名称:Terraria-Map-Editor,代码行数:9,代码来源:KillTally.cs

示例7: NewWorldView

 public NewWorldView()
 {
     InitializeComponent();
     _newWorld = new World(1200, 4300, "TEdit World");
     _newWorld.Version = World.CompatibleVersion;
     _newWorld.GroundLevel = 350;
     _newWorld.RockLevel = 480;
     _newWorld.ResetTime();
     AddCharNames();
     this.DataContext = NewWorld;
 }
开发者ID:KeviinSkyline,项目名称:Terraria-Map-Editor,代码行数:11,代码来源:NewWorldView.xaml.cs

示例8: 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

示例9: LoadWorld

        public static World LoadWorld(string filename)
        {
            var w = new World();
            uint curVersion = 0;
            try
            {
                lock (_fileLock)
                {
                    using (var b = new BinaryReader(File.OpenRead(filename)))
                    {
                        w.Version = b.ReadUInt32();
                        curVersion = w.Version;
                        if (w.Version > 87)
                            LoadV2(b, filename, w);
                        else
                            LoadV1(b, filename, w);
                    }
                    w.LastSave = File.GetLastWriteTimeUtc(filename);
                }
            }
            catch (Exception err)
            {

                string msg =
                    string.Format("There was an error reading the world file. This is usually caused by a corrupt save file or a world version newer than supported.\r\n\r\n" +
                                  "TEdit v{0}\r\n" +
                                  "TEdit Max World: {1}    Current World: {2}\r\n\r\n" +
                                  "Do you wish to force it to load anyway?\r\n\r\n" +
                                  "WARNING: This may have unexpected results including corrupt world files and program crashes.\r\n\r\n" +
                                   "The error is :\r\n{3}\r\n\r\n{4}\r\n"
                    , TEditXna.App.Version.FileVersion, World.CompatibleVersion, curVersion, err.Message, err);
                if (MessageBox.Show(msg, "World File Error", MessageBoxButton.YesNo, MessageBoxImage.Error) !=
                    MessageBoxResult.Yes)
                    return null;
            }
            return w;
        }
开发者ID:TEdit,项目名称:Terraria-Map-Editor,代码行数:37,代码来源:World.cs

示例10: UpdateMinimap

        public static void UpdateMinimap(World w, ref WriteableBitmap bmp)
        {
            bmp.Lock();
            unsafe
            {
                int pixelCount = bmp.PixelHeight * bmp.PixelWidth;
                var pixels = (int*)bmp.BackBuffer;

                for (int i = 0; i < pixelCount; i++)
                {
                    int x = i % bmp.PixelWidth;
                    int y = i / bmp.PixelWidth;

                    int worldX = x * Resolution;
                    int worldY = y * Resolution;



                    pixels[i] = XnaColorToWindowsInt(PixelMap.GetTileColor(w.Tiles[worldX, worldY], Microsoft.Xna.Framework.Color.Transparent));
                }
            }
            bmp.AddDirtyRect(new Int32Rect(0, 0, bmp.PixelWidth, bmp.PixelHeight));
            bmp.Unlock();
        }
开发者ID:liquidradio,项目名称:Terraria-Map-Editor,代码行数:24,代码来源:RenderMiniMap.cs

示例11: LoadFooter

        public static void LoadFooter(BinaryReader r, World w)
        {
            if (!r.ReadBoolean())
                throw new FileFormatException("Invalid Footer");

            if (r.ReadString() != w.Title)
                throw new FileFormatException("Invalid Footer");

            if (r.ReadInt32() != w.WorldId)
                throw new FileFormatException("Invalid Footer");
        }
开发者ID:liquidradio,项目名称:Terraria-Map-Editor,代码行数:11,代码来源:World.FileV2.cs

示例12: LoadMobsData

        public static void LoadMobsData(BinaryReader r, World w)
        {
            int totalMobs = 0;
            bool flag = r.ReadBoolean();
            while (flag)            
            {
                NPC npc = new NPC();
                npc.Name = r.ReadString();                    
                npc.Position = new Vector2(r.ReadSingle(), r.ReadSingle());

                if (NpcIds.ContainsKey(npc.Name))
                    npc.SpriteId = NpcIds[npc.Name];

                w.Mobs.Add(npc);
                totalMobs++;
                flag = r.ReadBoolean();
            }
        }
开发者ID:liquidradio,项目名称:Terraria-Map-Editor,代码行数:18,代码来源:World.FileV2.cs

示例13: LoadWorld

        public static World LoadWorld(string filename)
        {
            var w = new World();
            try
            {
                lock (_fileLock)
                {
                    using (var b = new BinaryReader(File.OpenRead(filename)))
                    {
                        w.Version = b.ReadUInt32(); //now we care about the version
                        w.Title = b.ReadString();
                        w.WorldId = b.ReadInt32();

                        w.Rand = new Random(w.WorldId);

                        w.LeftWorld = (float)b.ReadInt32();
                        w.RightWorld = (float)b.ReadInt32();
                        w.TopWorld = (float)b.ReadInt32();
                        w.BottomWorld = (float)b.ReadInt32();
                        w.TilesHigh = b.ReadInt32();
                        w.TilesWide = b.ReadInt32();

                        //if (w.TilesHigh > 10000 || w.TilesWide > 10000 || w.TilesHigh <= 0 || w.TilesWide <= 0)
                        //    throw new FileLoadException(string.Format("Invalid File: {0}", filename));

                        if (w.Version >= 63)
                            w.MoonType = (int)b.ReadByte();
                        else
                            w.MoonType = w.Rand.Next(MaxMoons);

                        if (w.Version >= 44)
                        {
                            w.TreeX[0] = b.ReadInt32();
                            w.TreeX[1] = b.ReadInt32();
                            w.TreeX[2] = b.ReadInt32();
                            w.TreeStyle[0] = b.ReadInt32();
                            w.TreeStyle[1] = b.ReadInt32();
                            w.TreeStyle[2] = b.ReadInt32();
                            w.TreeStyle[3] = b.ReadInt32();
                        }
                        if (w.Version >= 60)
                        {
                            w.CaveBackX[0] = b.ReadInt32();
                            w.CaveBackX[1] = b.ReadInt32();
                            w.CaveBackX[2] = b.ReadInt32();
                            w.CaveBackStyle[0] = b.ReadInt32();
                            w.CaveBackStyle[1] = b.ReadInt32();
                            w.CaveBackStyle[2] = b.ReadInt32();
                            w.CaveBackStyle[3] = b.ReadInt32();
                            w.IceBackStyle = b.ReadInt32();
                            if (w.Version >= 61)
                            {
                                w.JungleBackStyle = b.ReadInt32();
                                w.HellBackStyle = b.ReadInt32();
                            }
                        }
                        else
                        {
                            w.CaveBackX[0] = w.TilesWide / 2;
                            w.CaveBackX[1] = w.TilesWide;
                            w.CaveBackX[2] = w.TilesWide;
                            w.CaveBackStyle[0] = 0;
                            w.CaveBackStyle[1] = 1;
                            w.CaveBackStyle[2] = 2;
                            w.CaveBackStyle[3] = 3;
                            w.IceBackStyle = 0;
                            w.JungleBackStyle = 0;
                            w.HellBackStyle = 0;
                        }

                        w.SpawnX = b.ReadInt32();
                        w.SpawnY = b.ReadInt32();
                        w.GroundLevel = (int)b.ReadDouble();
                        w.RockLevel = (int)b.ReadDouble();

                        // read world flags
                        w.Time = b.ReadDouble();
                        w.DayTime = b.ReadBoolean();
                        w.MoonPhase = b.ReadInt32();
                        w.BloodMoon = b.ReadBoolean();

                        if (w.Version >= 70)
                        {
                            w.IsEclipse = b.ReadBoolean();
                        }

                        w.DungeonX = b.ReadInt32();
                        w.DungeonY = b.ReadInt32();

                        if (w.Version >= 56)
                        {
                            w.IsCrimson = b.ReadBoolean();
                        }
                        else
                        {
                            w.IsCrimson = false;
                        }

                        w.DownedBoss1 = b.ReadBoolean();
                        w.DownedBoss2 = b.ReadBoolean();
//.........这里部分代码省略.........
开发者ID:RandomSheep,项目名称:Terraria-Map-Editor,代码行数:101,代码来源:World.cs

示例14: LoadSectionHeader

        public static bool LoadSectionHeader(BinaryReader r, out bool[] tileFrameImportant, out int[] sectionPointers, World w)
        {
            tileFrameImportant = null;
            sectionPointers = null;
            int versionNumber = r.ReadInt32();
            if(versionNumber > 140)
            {
                UInt64 versionTypecheck = r.ReadUInt64();
                if (versionTypecheck != 0x026369676f6c6572ul )
                    throw new FileFormatException("Invalid Header");

                w.FileRevision = r.ReadUInt32();
                UInt64 temp = r.ReadUInt64();//I have no idea what this is for...
                w.IsFavorite = ((temp & 1uL) == 1uL);
            }

            // read file section stream positions
            short fileSectionCount = r.ReadInt16();
            sectionPointers = new int[fileSectionCount];
            for (int i = 0; i < fileSectionCount; i++)
            {
                sectionPointers[i] = r.ReadInt32();
            }

            // Read tile frame importance from bit-packed data
            tileFrameImportant = ReadBitArray(r);

            return true;
        }
开发者ID:liquidradio,项目名称:Terraria-Map-Editor,代码行数:29,代码来源:World.FileV2.cs

示例15: LoadTileEntities

        public static void LoadTileEntities(BinaryReader r, World w)
        {
            w.TileEntitiesNumber = r.ReadInt32();

            for (int counter = 0; counter < w.TileEntitiesNumber; counter++ )
            {
                TileEntity entity = new TileEntity();
                entity.Type = r.ReadByte();
                entity.Id = r.ReadInt32();
                entity.PosX = r.ReadInt16();
                entity.PosY = r.ReadInt16();
                switch (entity.Type)
                {
                    case 0: //it is a dummy
                        entity.Npc = r.ReadInt16();
                        break;
                    case 1: //it is a item frame
                        entity.ItemNetId = r.ReadInt16();
                        entity.Prefix = r.ReadByte();
                        entity.Stack = r.ReadInt16();
                        break;
                }
                w.TileEntities.Add(entity);
            }
        }
开发者ID:liquidradio,项目名称:Terraria-Map-Editor,代码行数:25,代码来源:World.FileV2.cs


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