public SaveManager(string gameDir) { this.GameDir = gameDir; if (!Directory.Exists(gameDir)) Directory.CreateDirectory(gameDir); foreach (var dir in Directory.EnumerateDirectories(gameDir)) { try { var idStr = Path.GetFileName(dir); var id = Guid.Parse(idStr); SaveEntry entry; using (var stream = File.OpenRead(Path.Combine(dir, "intro.json"))) using (var serializer = new Dwarrowdelf.SaveGameDeserializer(stream)) entry = serializer.Deserialize<SaveEntry>(); if (id != entry.ID) throw new Exception(); m_entries.Add(entry); } catch (Exception) { Trace.TraceError("Broken save dir {0}", dir); continue; } } }
public static void Load(World world, string dataStr) { Trace.TraceInformation("Loading client data"); var watch = Stopwatch.StartNew(); ClientSaveData data; using (var reader = new StringReader(dataStr)) { var deserializer = new Dwarrowdelf.SaveGameDeserializer(reader, new[] { new ClientObjectRefResolver(world) }); data = deserializer.Deserialize<ClientSaveData>(); } // Note that BaseObjects are deserialized by the NetSerializer, so we don't need to do anything for them here. watch.Stop(); Trace.TraceInformation("Loading game took {0}", watch.Elapsed); }
public static void Load(World world, string dataStr) { Trace.TraceInformation("Loading client data"); var watch = Stopwatch.StartNew(); ClientSaveData data; using (var reader = new StringReader(dataStr)) { var deserializer = new Dwarrowdelf.SaveGameDeserializer(reader, new[] { new ClientObjectRefResolver(world) }); data = deserializer.Deserialize <ClientSaveData>(); } // Note that BaseObjects are deserialized by the SaveGameDeserializer, so we don't need to do anything for them here. watch.Stop(); Trace.TraceInformation("Loading game took {0}", watch.Elapsed); }
public static GameEngine Load(string gameDir, Guid id) { var savePath = Path.Combine(gameDir, id.ToString(), "server.json"); Trace.TraceInformation("Loading game {0}", savePath); var watch = Stopwatch.StartNew(); GameEngine engine; using (var stream = File.OpenRead(savePath)) using (var deserializer = new Dwarrowdelf.SaveGameDeserializer(stream)) engine = deserializer.Deserialize <GameEngine>(); watch.Stop(); Trace.TraceInformation("Loading game took {0}", watch.Elapsed); engine.SetupAfterLoad(gameDir); return(engine); }
public SaveManager(string gameDir) { this.GameDir = gameDir; if (!Directory.Exists(gameDir)) { Directory.CreateDirectory(gameDir); } foreach (var dir in Directory.EnumerateDirectories(gameDir)) { try { var idStr = Path.GetFileName(dir); var id = Guid.Parse(idStr); SaveEntry entry; using (var stream = File.OpenRead(Path.Combine(dir, "intro.json"))) using (var serializer = new Dwarrowdelf.SaveGameDeserializer(stream)) entry = serializer.Deserialize <SaveEntry>(); if (id != entry.ID) { throw new Exception(); } m_entries.Add(entry); } catch (Exception) { Trace.TraceError("Broken save dir {0}", dir); continue; } } }
public static GameEngine Load(string gameDir, Guid id) { var savePath = Path.Combine(gameDir, id.ToString(), "server.json"); Trace.TraceInformation("Loading game {0}", savePath); var watch = Stopwatch.StartNew(); GameEngine engine; using (var stream = File.OpenRead(savePath)) using (var deserializer = new Dwarrowdelf.SaveGameDeserializer(stream)) engine = deserializer.Deserialize<GameEngine>(); watch.Stop(); Trace.TraceInformation("Loading game took {0}", watch.Elapsed); engine.SetupAfterLoad(gameDir); return engine; }