Skip to content

Commit

Permalink
Items in ammo page are now placed in proper categories
Browse files Browse the repository at this point in the history
  • Loading branch information
devyndamonster committed Feb 16, 2022
1 parent 062621f commit 7208fcb
Show file tree
Hide file tree
Showing 5 changed files with 57 additions and 10 deletions.
26 changes: 21 additions & 5 deletions Scripts/Loaders.cs
Original file line number Diff line number Diff line change
Expand Up @@ -435,7 +435,7 @@ private void LoadSpawnerEntries(UnityEngine.Object[] allAssets)
PopulateEntryPaths(entry);
OtherLoader.SpawnerEntriesByID[entry.MainObjectID] = entry;

if (!entry.IsReward && OtherLoader.UnlockSaveData.AutoUnlockNonRewards) OtherLoader.UnlockSaveData.UnlockItem(entry.MainObjectID);
if (OtherLoader.UnlockSaveData.ShouldAutoUnlockItem(entry)) OtherLoader.UnlockSaveData.UnlockItem(entry.MainObjectID);
RegisterItemIntoMetaTagSystem(entry);

convertedSpawnerIDs.Add(AddEntryToLegacySpawner(entry));
Expand Down Expand Up @@ -877,11 +877,27 @@ public static void PopulateEntryPaths(ItemSpawnerEntry entry, ItemSpawnerID spaw
//Now this section below is for legacy support
if(spawnerID != null)
{
//If this is meatfortress category, do that
if (i == 1 && spawnerID.Category == ItemSpawnerID.EItemCategory.MeatFortress)
//For some legacy categories, we must perform this disgustingly bad search for their icons
if (i == 1 &&
(spawnerID.Category == ItemSpawnerID.EItemCategory.MeatFortress ||
spawnerID.Category == ItemSpawnerID.EItemCategory.Magazine ||
spawnerID.Category == ItemSpawnerID.EItemCategory.Cartridge ||
spawnerID.Category == ItemSpawnerID.EItemCategory.Clip ||
spawnerID.Category == ItemSpawnerID.EItemCategory.Speedloader))
{
node.entry.EntryIcon = IM.CDefInfo[ItemSpawnerID.EItemCategory.MeatFortress].Sprite;
node.entry.DisplayName = IM.CDefInfo[ItemSpawnerID.EItemCategory.MeatFortress].DisplayName;

foreach (ItemSpawnerCategoryDefinitionsV2.SpawnerPage page in IM.CatDef.Pages)
{
foreach (ItemSpawnerCategoryDefinitionsV2.SpawnerPage.SpawnerTagGroup tagGroup in page.TagGroups)
{
if (tagGroup.TagT == TagType.Category && tagGroup.Tag == spawnerID.Category.ToString())
{
node.entry.EntryIcon = tagGroup.Icon;
node.entry.DisplayName = tagGroup.DisplayName;
}
}
}

}

//If this is a modded main category, do that
Expand Down
8 changes: 6 additions & 2 deletions Scripts/ObjectTemplates/ItemSpawnerEntry.cs
Original file line number Diff line number Diff line change
Expand Up @@ -155,8 +155,12 @@ private string CreatePath(ItemSpawnerV2.PageMode Page, ItemSpawnerID ID)
{
string path = Page.ToString();

//If the category is meatfortress, include it
if (ID.Category == ItemSpawnerID.EItemCategory.MeatFortress)
//Some categories should still be included in the path
if (ID.Category == ItemSpawnerID.EItemCategory.MeatFortress ||
ID.Category == ItemSpawnerID.EItemCategory.Magazine ||
ID.Category == ItemSpawnerID.EItemCategory.Cartridge ||
ID.Category == ItemSpawnerID.EItemCategory.Clip ||
ID.Category == ItemSpawnerID.EItemCategory.Speedloader)
{
path += "/" + ID.Category.ToString();
}
Expand Down
30 changes: 29 additions & 1 deletion Scripts/ObjectTemplates/UnlockedItemSaveData.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using System;
using FistVR;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
Expand Down Expand Up @@ -39,6 +40,33 @@ public bool UnlockItem(string itemID)

return false;
}

public bool ShouldAutoUnlockItem(ItemSpawnerID spawnerID)
{
return spawnerID.MainObject == null || ShouldAutoUnlockItem(spawnerID.MainObject, spawnerID.IsReward);
}

public bool ShouldAutoUnlockItem(ItemSpawnerEntry spawnerEntry)
{
FVRObject item;
IM.OD.TryGetValue(spawnerEntry.MainObjectID, out item);

return item == null || ShouldAutoUnlockItem(item, spawnerEntry.IsReward);
}

public bool ShouldAutoUnlockItem(FVRObject item, bool isReward)
{
if(isReward ||
(!AutoUnlockNonRewards &&
(item.Category == FVRObject.ObjectCategory.Firearm ||
item.Category == FVRObject.ObjectCategory.Thrown ||
item.Category == FVRObject.ObjectCategory.MeleeWeapon)))
{
return false;
}

return true;
}
}

public enum ItemUnlockMode
Expand Down
2 changes: 1 addition & 1 deletion Scripts/OtherLoader.cs
Original file line number Diff line number Diff line change
Expand Up @@ -371,7 +371,7 @@ public static bool UnlockInteractedItem(FVRPhysicalObject __instance)
private static void MetaTagPatch(ItemSpawnerID ID)
{
//If this item is not a reward, unlock it by default
if(UnlockSaveData.AutoUnlockNonRewards && !ID.IsReward && ID.MainObject != null)
if(UnlockSaveData.ShouldAutoUnlockItem(ID))
{
UnlockSaveData.UnlockItem(ID.MainObject.ItemID);
}
Expand Down
1 change: 0 additions & 1 deletion Scripts/Patches/ItemSpawnerV2Patch.cs
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,6 @@ private static bool BeforeAwakePatch(ItemSpawnerV2 __instance)
}



private static IEnumerator HandleLoadingText(ItemSpawnerV2 instance)
{
//First create the loading text
Expand Down

0 comments on commit 7208fcb

Please sign in to comment.