public static bool SaveToStream(BinaryWriter outputWriter, Entity entity) { EntityStorage storage = new EntityStorage(string.Empty, entity); if (!storage.Write(outputWriter)) { Debug.Assert(false, "Cannot write an entity file!"); return(false); } return(true); }
public static Entity LoadFromStream(BinaryReader inputReader, string name) { EntityStorage storage = new EntityStorage(); if (!storage.Parse(inputReader)) { return(null); } Texture texture = new Texture(name, storage.Pixels, storage.Width, storage.Height); return(new Entity(name, texture, storage.OFFI, storage.OFFS)); }
public static bool SaveToFile(string filePath, Entity entity) { EntityStorage storage = new EntityStorage(filePath, entity); using (FileStream outputStream = new FileStream(filePath, FileMode.Create, FileAccess.Write)) { using (BinaryWriter outputWriter = new BinaryWriter(outputStream, storage.Encoding)) { if (!storage.Write(outputWriter)) { Debug.Assert(false, "Cannot write an entity file!"); return(false); } } } return(true); }
public static Entity LoadFromFile(string filePath) { EntityStorage storage = new EntityStorage(filePath); using (FileStream inputStream = new FileStream(storage.LibraryPath, FileMode.Open, FileAccess.Read)) { using (BinaryReader inputReader = new BinaryReader(inputStream, storage.Encoding)) { if (!storage.Parse(inputReader)) { return(null); } } } string name = Path.GetFileNameWithoutExtension(filePath); Texture texture = new Texture(name, storage.Pixels, storage.Width, storage.Height); return(new Entity(name, texture, storage.OFFI, storage.OFFS)); }