예제 #1
0
        public static BaseSheet GetTile(TileFrame tileTex)
        {
            BaseSheet sheet;

            if (tileCache.TryGetValue(tileTex, out sheet))
            {
                return(sheet);
            }

            long tilePos = TileIndex.GetPosition(tileTex.Sheet, tileTex.TexLoc);

            if (tilePos > 0)
            {
                try
                {
                    using (FileStream stream = new FileStream(String.Format(TILE_PATTERN, tileTex.Sheet), FileMode.Open, FileAccess.Read, FileShare.Read))
                    {
                        using (BinaryReader reader = new BinaryReader(stream))
                        {
                            // Seek to the location of the tile
                            reader.BaseStream.Seek(tilePos, SeekOrigin.Begin);

                            sheet = BaseSheet.Load(reader);
                            tileCache.Add(tileTex, sheet);
                            return(sheet);
                        }
                    }
                }
                catch (Exception ex)
                {
                    DiagManager.Instance.LogError(new Exception("Error retrieving tile " + tileTex.TexLoc.X + ", " + tileTex.TexLoc.Y + " from Tileset #" + tileTex.Sheet + "\n", ex));
                }
            }

            BaseSheet newSheet = BaseSheet.LoadError();

            tileCache.Add(tileTex, newSheet);
            return(newSheet);
        }