private static void PopulateSpawnerEntries() { foreach (KeyValuePair <ItemSpawnerV2.PageMode, List <string> > PageLists in IM.Instance.PageItemLists) { foreach (string ItemID in PageLists.Value) { ItemSpawnerID SpawnerID = IM.Instance.SpawnerIDDic[ItemID]; ItemSpawnerEntry SpawnerEntry = ScriptableObject.CreateInstance <ItemSpawnerEntry>(); SpawnerEntry.LegacyPopulateFromID(PageLists.Key, SpawnerID, false); ItemLoader.PopulateEntryPaths(SpawnerEntry, SpawnerID); } } }
private void LoadSpawnerIDs(UnityEngine.Object[] allAssets) { foreach (ItemSpawnerID id in allAssets) { OtherLogger.Log("Adding Itemspawner ID! Category: " + id.Category + ", SubCategory: " + id.SubCategory, OtherLogger.LogType.Loading); //Try to set the main object of this ID as a secondary if the main is null (so that it gets tagged properly) if (id.MainObject == null && id.Secondaries.Length > 0) { id.MainObject = id.Secondaries.Select(o => o.MainObject).FirstOrDefault(o => o != null); if (id.MainObject == null) { OtherLogger.Log("Could not select a secondary object for ItemSpawnerID, it will not appear in spawner: Display Name: " + id.DisplayName, OtherLogger.LogType.Loading); } else { id.ItemID = id.MainObject.ItemID; } } if (id.MainObject != null) { if (id.UnlockCost == 0) { id.UnlockCost = id.MainObject.CreditCost; } IM.RegisterItemIntoMetaTagSystem(id); if (!id.IsDisplayedInMainEntry) { HideItemFromCategories(id); } } if (IM.CD.ContainsKey(id.Category) && IM.SCD.ContainsKey(id.SubCategory)) { IM.CD[id.Category].Add(id); IM.SCD[id.SubCategory].Add(id); if (!ManagerSingleton <IM> .Instance.SpawnerIDDic.ContainsKey(id.ItemID)) { ManagerSingleton <IM> .Instance.SpawnerIDDic[id.ItemID] = id; //Now we will try to convert this SpawnerID into a spawner entry ItemSpawnerEntry SpawnerEntry = ScriptableObject.CreateInstance <ItemSpawnerEntry>(); //If the category is defined, we can try to add it based on what page it was given if (Enum.IsDefined(typeof(ItemSpawnerID.EItemCategory), id.Category)) { //TODO this should be done without having to loop through potentially all spawner entries, I bet this could become expensive bool added = false; foreach (KeyValuePair <ItemSpawnerV2.PageMode, List <string> > pageItems in IM.Instance.PageItemLists) { if (pageItems.Value.Contains(id.ItemID)) { OtherLogger.Log("Adding SpawnerID to spawner entry tree", OtherLogger.LogType.Loading); SpawnerEntry.LegacyPopulateFromID(pageItems.Key, id, true); PopulateEntryPaths(SpawnerEntry, id); added = true; break; } } if (added) { continue; } //If we make it to this point, we failed to add the entry to the tree structure, but should still populate the entries data OtherLogger.Log("ItemSpawnerID could not be converted for new spawner because of metadata issues! ItemID: " + id.ItemID, OtherLogger.LogType.Loading); SpawnerEntry.LegacyPopulateFromID(ItemSpawnerV2.PageMode.Firearms, id, true); } //Otherwise, all custom category items go under the firearms page else { OtherLogger.Log("Adding SpawnerID to spawner entry tree under custom category", OtherLogger.LogType.Loading); SpawnerEntry.LegacyPopulateFromID(ItemSpawnerV2.PageMode.Firearms, id, true); PopulateEntryPaths(SpawnerEntry, id); } } } else { OtherLogger.LogError("ItemSpawnerID could not be added, because either the main category or subcategory were not loaded! Item will not appear in the itemspawner! Item Display Name: " + id.DisplayName); } } }