Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion R2API.ContentManagement/CatalogBlockers.cs
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,8 @@ internal static class CatalogBlockers
{typeof(EntityState), true },
{typeof(ExpansionDef), true },
{typeof(EntitlementDef), true },
{typeof(MiscPickupDef), true }
{typeof(MiscPickupDef), true },
{typeof(CraftableDef), true }

//The rest are catalogs that arent added by scriptable objects or game objects yet.
};
Expand Down Expand Up @@ -144,5 +145,8 @@ private static void SetAvailability<T>(bool availability)
[SystemInitializer(typeof(MiscPickupCatalog))]
private static void BlockMiscPickupDefs() => SetAvailability<MiscPickupDef>(false);

[SystemInitializer(typeof(CraftableCatalog))]
private static void BlockMiscCraftableDefs() => SetAvailability<CraftableDef>(false);

#endregion
}
17 changes: 17 additions & 0 deletions R2API.ContentManagement/ContentAddition.cs
Original file line number Diff line number Diff line change
Expand Up @@ -696,6 +696,23 @@ public static SerializableEntityStateType AddEntityState(Type entityStateType, o
wasAdded = false;
return new SerializableEntityStateType();
}

/// <summary>
/// Adds a CraftableDef to your Mod's ContentPack
/// </summary>
/// <param name="craftableDef">The CraftableDef to Add</param>
/// <returns>true if valid and added, false if one of the requirements is not met</returns>
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

highly recommend confirming what an invalid CraftableDef involves (things are often assumed to be not null)

public static bool AddCraftableDef(CraftableDef craftableDef)
{
var asm = GetNonAPICaller();
if (CatalogBlockers.GetAvailability<CraftableDef>())
{
R2APIContentManager.HandleContentAddition(asm, craftableDef);
return true;
}
RejectContent(craftableDef, asm, "craftableDef", "But the CraftableCatalog has already initailized!");
return false;
}
#endregion

#region Util Methods
Expand Down
1 change: 1 addition & 0 deletions R2API.ContentManagement/R2APIContentManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -308,6 +308,7 @@ internal static void HandleContentAddition(Assembly assembly, UnityObject conten
case ExpansionDef exd: AddSafe(ref scp.expansionDefs, exd, scp.name); added = true; break;
case EntitlementDef end: AddSafe(ref scp.entitlementDefs, end, scp.name); added = true; break;
case MiscPickupDef mpd: AddSafe(ref scp.miscPickupDefs, mpd, scp.name); added = true; break;
case CraftableDef cd: AddSafe(ref scp.craftableDefs, cd, scp.name); added = true; break;
}
if (!added)
{
Expand Down
1 change: 1 addition & 0 deletions R2API.ContentManagement/R2APIContentPackProvider.cs
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,7 @@ private void LogContentsFromContentPack()
log.AddRange(contentPack.expansionDefs.assetInfos.Select(ai => $"{ai.assetName} ({ai.asset.GetType().Name})"));
log.AddRange(contentPack.entitlementDefs.assetInfos.Select(ai => $"{ai.assetName} ({ai.asset.GetType().Name})"));
log.AddRange(contentPack.miscPickupDefs.assetInfos.Select(ai => $"{ai.assetName} ({ai.asset.GetType().Name})"));
log.AddRange(contentPack.craftableDefs.assetInfos.Select(ai => $"{ai.assetName} ({ai.asset.GetType().Name})"));
ContentManagementPlugin.Logger.LogDebug(string.Join("\n", log));
}
}
Expand Down
3 changes: 3 additions & 0 deletions R2API.ContentManagement/R2APISerializableContentPack.cs
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,8 @@ public class R2APISerializableContentPack : ScriptableObject
public GameEndingDef[] gameEndingDefs = Array.Empty<GameEndingDef>();

public MiscPickupDef[] miscPickupDefs = Array.Empty<MiscPickupDef>();

public CraftableDef[] craftableDefs = Array.Empty<CraftableDef>();
#endregion

#region Entity States
Expand Down Expand Up @@ -129,6 +131,7 @@ private ContentPack CreateContentPackPrivate()
cp.entityStateConfigurations.Add(entityStateConfigurations);
cp.expansionDefs.Add(expansionDefs);
cp.entitlementDefs.Add(entitlementDefs);
cp.craftableDefs.Add(craftableDefs);

List<Type> list = new List<Type>();
for (int i = 0; i < entityStateTypes.Length; i++)
Expand Down