public override void Load(TagCompound tag) { CodexState = tag.GetInt(nameof(CodexState)); Entries = new List <CodexEntry>(); var entriesToLoad = tag.GetList <TagCompound>(nameof(Entries)); foreach (Type type in mod.Code.GetTypes().Where(t => t.IsSubclassOf(typeof(CodexEntry)))) { CodexEntry ThisEntry = (CodexEntry)Activator.CreateInstance(type); Entries.Add(ThisEntry); } if (entriesToLoad == null || entriesToLoad.Count == 0) { return; } foreach (TagCompound tagc in entriesToLoad) { CodexEntry entry = CodexEntry.DeserializeData(tagc); if (entry != null && Entries.FirstOrDefault(n => n.GetType() == entry.GetType()) != null) //find and replace needed entries with save data { int index = Entries.IndexOf(Entries.FirstOrDefault(n => n.GetType() == entry.GetType())); Entries[index] = entry; } } }
public static CodexEntry DeserializeData(TagCompound tag) { try { Type t = Type.GetType(tag.GetString("Name")); CodexEntry entry = (CodexEntry)Activator.CreateInstance(t); entry.Locked = tag.GetBool("Locked"); return(entry); } catch { return(null); } }
public override void OnEnterWorld(Player player) { if (Entries.Count == 0) //failsafe incase the player dosent load for some reason { foreach (Type type in mod.Code.GetTypes().Where(t => t.IsSubclassOf(typeof(CodexEntry)))) { CodexEntry ThisEntry = (CodexEntry)Activator.CreateInstance(type); Entries.Add(ThisEntry); } } UILoader.ReloadState <Content.GUI.Codex>(); }
public override void OnEnterWorld(Player player) { if (Entries.Count == 0) //failsafe incase the player dosent load for some reason { foreach (Type type in mod.Code.GetTypes().Where(t => t.IsSubclassOf(typeof(CodexEntry)))) { CodexEntry ThisEntry = (CodexEntry)Activator.CreateInstance(type); Entries.Add(ThisEntry); } } (mod as StarlightRiver).codex = new GUI.Codex(); (mod as StarlightRiver).CodexUserInterface.SetState((mod as StarlightRiver).codex); }
public override void Load(TagCompound tag) { CodexState = tag.GetInt(nameof(CodexState)); Entries = new List <CodexEntry>(); List <bool> UnlockStates = (List <bool>)tag.GetList <bool>(nameof(Entries)); foreach (Type type in mod.Code.GetTypes().Where(t => t.IsSubclassOf(typeof(CodexEntry)))) { CodexEntry ThisEntry = (CodexEntry)Activator.CreateInstance(type); ThisEntry.Locked = (UnlockStates.Count > Entries.Count && UnlockStates.Count != 0) ? UnlockStates.ElementAt(Entries.Count) : true; Entries.Add(ThisEntry); } }