public void SaveAndLoad() { database.PutSojo(new Sojo("id1", "Name1", SojoType.SoundEffect, "Content1")); database.PutSojo(new Sojo("id2", "Name2", SojoType.ParticleEffect, "Content2")); database.PutSojo(new Sojo("id3", "Name3", SojoType.SoundEffect, "Content3")); SojoDatabase.Saved saved = database.Save(); database = new SojoDatabase(); database.Load(saved); Assert.AreEqual("Name1", database.GetSojoById("id1").name); Assert.AreEqual("Name2", database.GetSojoById("id2").name); Assert.AreEqual("Name3", database.GetSojoById("id3").name); Assert.AreEqual(SojoType.SoundEffect, database.GetSojoById("id1").contentType); Assert.AreEqual(SojoType.ParticleEffect, database.GetSojoById("id2").contentType); }
public void Load(Saved database) { Reset(); string builtinSojoJson = Resources.Load <TextAsset>(BUILTIN_SOJOS_RESOURCE_FILE).text; SojoDatabase.Saved builtIn = JsonUtility.FromJson <SojoDatabase.Saved>(builtinSojoJson); foreach (Sojo.Saved saved in builtIn.sojos) { PutSojo(Sojo.Load(saved)); } foreach (Sojo.Saved saved in database.sojos) { PutSojo(Sojo.Load(saved)); } }
public void LoadDatabase(SojoDatabase.Saved saved) { // Issue a Sojo delete event for each sojo (because they are going away // in the load). foreach (Sojo sojo in database.GetAllSojos()) { onSojoDelete?.Invoke(sojo); } // Now load the DB. This deletes all previous SOJOs. database.Load(saved); // Issue a Sojo put event for each sojo in the database (because it's as if // they had all been just put in the database). foreach (Sojo sojo in database.GetAllSojos()) { onSojoPut?.Invoke(sojo); } onSojoSystemLoaded?.Invoke(); }