public Picture LoadPIC(string filename, bool noCache = false) { string key = filename.ToUpper(); if (_cache.ContainsKey(key)) { if (!noCache) { return(_cache[key]); } _cache.Remove(key); } Picture output = null; PicFile picFile = new PicFile(filename); if ((Settings.Instance.GraphicsMode == GraphicsMode.Graphics256 && picFile.GetPicture256 != null) || picFile.GetPicture16 == null) { output = new Picture(picFile.GetPicture256, picFile.GetPalette256); } else { output = new Picture(picFile.GetPicture16, picFile.GetPalette16); } if (!noCache) { _cache.Add(key, output); } return(output); }
public Picture this[string filename] { get { string key = filename.ToUpper(); if (_cache.ContainsKey(key)) { return(new Picture(_cache[key].Bitmap, _cache[key].Palette)); } Picture output = null; PicFile picFile = new PicFile(filename); if ((Settings.GraphicsMode == GraphicsMode.Graphics256 && picFile.GetPicture256 != null) || picFile.GetPicture16 == null) { output = new Picture(picFile.GetPicture256, picFile.GetPalette256); } else { output = new Picture(picFile.GetPicture16, picFile.GetPalette16); } if (!_cache.ContainsKey(key)) { _cache.Add(key, output); } return(new Picture(_cache[key].Bitmap, _cache[key].Palette)); } }
public bool Exists(string filename) { if (RuntimeHandler.Runtime.Settings.Free) { return(false); } return(PicFile.Exists(filename)); }
public static void ClearInstance() { _instance = null; _worldMapTiles = null; _palacePart = null; PicFile.ClearCache(); TextFile.ClearInstance(); Sprites.Cursor.ClearCache(); }
public ushort SaveMap(string filename) { Log($"Map: Saving {filename} - Random seed: {_terrainMasterWord}"); using (Bytemap bitmap = Resources["SP299"].Bitmap) { // Save terrainlayer for (int x = 0; x < WIDTH; x++) { for (int y = 0; y < HEIGHT; y++) { byte b; switch (_tiles[x, y].Type) { case Terrain.Forest: b = 2; break; case Terrain.Swamp: b = 3; break; case Terrain.Plains: b = 6; break; case Terrain.Tundra: b = 7; break; case Terrain.River: b = 9; break; case Terrain.Grassland1: case Terrain.Grassland2: b = 10; break; case Terrain.Jungle: b = 11; break; case Terrain.Hills: b = 12; break; case Terrain.Mountains: b = 13; break; case Terrain.Desert: b = 14; break; case Terrain.Arctic: b = 15; break; default: b = 1; break; // Ocean } bitmap[x, y] = b; } } // Save improvement layer for (int x = 0; x < WIDTH; x++) { for (int y = 0; y < HEIGHT; y++) { byte b = 0; if (_tiles[x, y].City != null) { b |= 0x01; } if (_tiles[x, y].Irrigation) { b |= 0x02; } if (_tiles[x, y].Mine) { b |= 0x04; } if (_tiles[x, y].Road) { b |= 0x08; } bitmap[x, y + (HEIGHT * 2)] = b; bitmap[x + (WIDTH * 1), y + (HEIGHT * 2)] = b; // Visibility layer } } // Save improvement layer 2 for (int x = 0; x < WIDTH; x++) { for (int y = 0; y < HEIGHT; y++) { byte b = 0; if (_tiles[x, y].RailRoad) { b |= 0x01; } bitmap[x, y + (HEIGHT * 3)] = b; bitmap[x + (WIDTH * 1), y + (HEIGHT * 3)] = b; // Visibility layer } } // Save explored layer for (int x = 0; x < WIDTH; x++) { for (int y = 0; y < HEIGHT; y++) { bitmap[x + (WIDTH * 2), y] = _tiles[x, y].Visited; } } using (Picture picture = new Picture(bitmap, Resources["SP299"].Palette)) { PicFile picFile = new PicFile(picture) { HasPalette256 = false }; using (BinaryWriter bw = new BinaryWriter(File.Open(filename, FileMode.Create))) { bw.Write(picFile.GetBytes()); } return((ushort)_terrainMasterWord); } } }
public void SaveData() { var userInDb = dbContext.Users.Single(u => u.Id == UserId); if (!string.IsNullOrEmpty(PhoneNumber)) { userInDb.PhoneNumber = PhoneNumber; IsPhoneNumberValid = true; } if (!string.IsNullOrEmpty(DSNPhone)) { userInDb.DSNPhone = DSNPhone; IsDsnPhoneValid = true; } if (!string.IsNullOrEmpty(CarePointName)) { userInDb.CarePointName = CarePointName; IsCarepointNameValid = true; } if (!string.IsNullOrEmpty(Bio)) { userInDb.Bio = Bio; IsBioValid = true; } if (PicFile != null && PicFile.ContentLength > 0) { string fileExt = Path.GetExtension(PicFile.FileName).ToLower(); if (fileExt == ".jpg" || fileExt == ".png" || fileExt == ".jpeg" || fileExt == ".gif") { string originalFileName = PicFile.FileName; string picGuid = Guid.NewGuid().ToString().Replace("-", ""); string newFileName = string.Concat(picGuid, "-id-", UserId); string imageFilePath = Path.Combine(HttpContext.Current.Server.MapPath(@"~\Content\Images\Profile_Pics"), newFileName + fileExt); //Compress & archive old pictures if (userInDb.ProfilePic != null) { string oldPicUrl = HttpContext.Current.Server.MapPath(userInDb.ProfilePic); FileInfo oldFile = new FileInfo(oldPicUrl); FileInfo zipFile; DirectoryInfo archiveDestination = new DirectoryInfo(HttpContext.Current.Server.MapPath(@"~\Content\Images\Profile_Pics\ArchivedPics")); using (FileStream stream = oldFile.OpenRead()) { using (FileStream zipStream = File.Create(oldFile.FullName + ".gz")) { using (GZipStream compressionStream = new GZipStream(zipStream, CompressionMode.Compress)) { stream.CopyTo(compressionStream); zipFile = new FileInfo(oldFile.FullName + ".gz"); } } zipFile.MoveTo(archiveDestination.FullName + Path.DirectorySeparatorChar + Path.GetFileName(zipFile.FullName)); File.Delete(oldFile.FullName + ".gz"); } File.Delete(oldFile.FullName); } PicFile.SaveAs(imageFilePath); userInDb.ProfilePic = Path.Combine(@"\Content\Images\Profile_Pics", newFileName + fileExt); ProfilePicUrl = userInDb.ProfilePic; } } dbContext.SaveChanges(); }
public ushort SaveMap(string filename) { Console.WriteLine($"Map: Saving {filename} - Random seed: {_terrainMasterWord}"); byte[,] bitmap = Resources.Instance.LoadPIC("SP299").GetBitmap; // Save terrainlayer for (int x = 0; x < WIDTH; x++) { for (int y = 0; y < HEIGHT; y++) { byte b; switch (_tiles[x, y].Type) { case Terrain.Forest: b = 2; break; case Terrain.Swamp: b = 3; break; case Terrain.Plains: b = 6; break; case Terrain.Tundra: b = 7; break; case Terrain.River: b = 9; break; case Terrain.Grassland1: case Terrain.Grassland2: b = 10; break; case Terrain.Jungle: b = 11; break; case Terrain.Hills: b = 12; break; case Terrain.Mountains: b = 13; break; case Terrain.Desert: b = 14; break; case Terrain.Arctic: b = 15; break; default: b = 1; break; // Ocean } bitmap[x, y] = b; } } // Save improvement layer for (int x = 0; x < WIDTH; x++) { for (int y = 0; y < HEIGHT; y++) { byte b = 0; // 0x01 = CITY ? if (_tiles[x, y].Irrigation) { b |= 0x02; } if (_tiles[x, y].Mine) { b |= 0x04; } if (_tiles[x, y].Road) { b |= 0x08; } bitmap[x, y + (HEIGHT * 2)] = b; } } // Save explored layer (unfinished) for (int x = 0; x < WIDTH; x++) { for (int y = 0; y < HEIGHT; y++) { // Right now, we don't record where units have moved so this step is not saved correctly // At the moment, only save active unit location IUnit unit = Game.Instance.GetUnits(x, y).FirstOrDefault(); if (unit == null) { continue; } bitmap[x + (WIDTH * 2), y] = (byte)(unit.Owner + 8); } } PicFile picFile = new PicFile(new Picture(bitmap, Resources.Instance.LoadPIC("SP299").Palette)) { HasPalette256 = false }; using (BinaryWriter bw = new BinaryWriter(File.Open(filename, FileMode.Create))) { bw.Write(picFile.GetBytes()); } return((ushort)_terrainMasterWord); }