Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Changes to R2API's ContentPack System #338

Merged
merged 22 commits into from Feb 17, 2022
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
22 commits
Select commit Hold shift + click to select a range
09fe4f5
ArtifactCodeAPI changes
Nebby1999 Oct 26, 2021
0cf3172
Added hide in inspector attribute to ArtifactCompounds list
Nebby1999 Oct 26, 2021
c0f0044
Added a header with the constant that says how to find a list of acce…
Nebby1999 Dec 13, 2021
e19ece6
Merge branch 'risk-of-thunder:master' into master
Nebby1999 Feb 14, 2022
10f2982
Added R2API Content Manager
Nebby1999 Feb 14, 2022
82d6edb
Removed comments, added logger messages, modified UnlockableAPI.
Nebby1999 Feb 14, 2022
bbb04bf
Cleaned code.
Nebby1999 Feb 14, 2022
7d27eb0
Fixed typo and version issue
Nebby1999 Feb 14, 2022
05e4ef3
Added check to ensure there isnt an asset with whitespace, empty, or …
Nebby1999 Feb 15, 2022
0ff3268
Made LoadROR2ContentEarly public, Added Public methods to R2APIConten…
Nebby1999 Feb 15, 2022
3b5f0e8
Added missing documentation.
Nebby1999 Feb 15, 2022
1b76c20
Made it so ContentPacks can opt out from r2api loading the pack autom…
Nebby1999 Feb 15, 2022
dce6155
code cleanup
Nebby1999 Feb 15, 2022
bd9564a
Moved content related classes to R2APIContentManagment, fixed typos a…
Nebby1999 Feb 15, 2022
e54581a
Fixed silent letter typo
Nebby1999 Feb 15, 2022
55709f7
Marked a bunch of classes & methods as obsolete
Nebby1999 Feb 16, 2022
e6f562b
fixed another "entires" typo
Nebby1999 Feb 16, 2022
7b0a0d0
Added ContentAdditionHelpers
Nebby1999 Feb 16, 2022
a557ca5
Added missing documentation
Nebby1999 Feb 16, 2022
baf760e
Added CatalogBlockers
Nebby1999 Feb 16, 2022
e75a85d
updated obsolete messages to redirect to the ContentAdditionHelpers
Nebby1999 Feb 16, 2022
b254776
Moved 3.x changelogs to archived, Added my PR to the readme
Nebby1999 Feb 16, 2022
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
Prev Previous commit
Next Next commit
Removed comments, added logger messages, modified UnlockableAPI.
  • Loading branch information
Nebby1999 committed Feb 14, 2022
commit 82d6edb8933af7974683f411c65a256378a45ae1
17 changes: 3 additions & 14 deletions R2API/ArtifactAPI.cs
Expand Up @@ -14,8 +14,6 @@ namespace R2API {
[R2APISubmodule]
public static class ArtifactAPI {

//private static readonly List<ArtifactDef> Artifacts = new List<ArtifactDef>();

private static bool _artifactCatalogInitialized;

/// <summary>
Expand All @@ -32,22 +30,15 @@ public static class ArtifactAPI {

[R2APISubmoduleInit(Stage = InitStage.SetHooks)]
internal static void SetHooks() {
//R2APIContentPackProvider.WhenContentPackReady += AddArtifactsToGame;
R2APIContentPackProvider.WhenAddingContentPacks += AddArtifactsToGame;
R2APIContentPackProvider.WhenAddingContentPacks += AvoidNewEntries;
}

[R2APISubmoduleInit(Stage = InitStage.UnsetHooks)]
internal static void UnsetHooks() {
//R2APIContentPackProvider.WhenContentPackReady -= AddArtifactsToGame;
R2APIContentPackProvider.WhenAddingContentPacks -= AddArtifactsToGame;
R2APIContentPackProvider.WhenAddingContentPacks -= AvoidNewEntries;
}

private static void AddArtifactsToGame(/*ContentPack r2apiContentPack*/) {
/*foreach (var artifact in Artifacts) {
R2API.Logger.LogInfo($"Custom Artifact: {artifact.cachedName} added");
}

r2apiContentPack.artifactDefs.Add(Artifacts.ToArray());*/
private static void AvoidNewEntries() {
_artifactCatalogInitialized = true;
}

Expand All @@ -73,7 +64,6 @@ public static class ArtifactAPI {
}

R2APIContentManager.HandleContentAddition(Assembly.GetCallingAssembly(), artifactDef);
//Artifacts.Add(artifactDef);
return true;
}

Expand Down Expand Up @@ -108,7 +98,6 @@ public static class ArtifactAPI {
artifactDef.unlockableDef = unlockableDef;

R2APIContentManager.HandleContentAddition(Assembly.GetCallingAssembly(), artifactDef);
//Artifacts.Add(artifactDef);
return true;
}

Expand Down
17 changes: 3 additions & 14 deletions R2API/BuffAPI.cs
Expand Up @@ -37,25 +37,15 @@ public static class BuffAPI {

[R2APISubmoduleInit(Stage = InitStage.SetHooks)]
internal static void SetHooks() {
//R2APIContentPackProvider.WhenContentPackReady += AddBuffsToGame;
R2APIContentPackProvider.WhenAddingContentPacks += AddBuffsToGame;
R2APIContentPackProvider.WhenAddingContentPacks += AvoidNewEntires;
Nebby1999 marked this conversation as resolved.
Show resolved Hide resolved
}

[R2APISubmoduleInit(Stage = InitStage.UnsetHooks)]
internal static void UnsetHooks() {
//R2APIContentPackProvider.WhenContentPackReady -= AddBuffsToGame;
R2APIContentPackProvider.WhenAddingContentPacks -= AddBuffsToGame;
R2APIContentPackProvider.WhenAddingContentPacks -= AvoidNewEntires;
}

private static void AddBuffsToGame(/*ContentPack r2apiContentPack*/) {
/*var buffDefs = new List<BuffDef>();
foreach (var customBuff in BuffDefinitions) {
buffDefs.Add(customBuff.BuffDef);

R2API.Logger.LogInfo($"Custom Buff: {customBuff.BuffDef.name} added");
}

r2apiContentPack.buffDefs.Add(buffDefs.ToArray());*/
private static void AvoidNewEntires() {
_buffCatalogInitialized = true;
}

Expand Down Expand Up @@ -83,7 +73,6 @@ public static class BuffAPI {
}

R2APIContentManager.HandleContentAddition(Assembly.GetCallingAssembly(), buff.BuffDef);
//BuffDefinitions.Add(buff);
return true;
}

Expand Down
21 changes: 0 additions & 21 deletions R2API/EffectAPI.cs
Expand Up @@ -25,26 +25,6 @@ public static class EffectAPI {

private static bool _loaded;

//private static readonly List<EffectDef> AddedEffects = new List<EffectDef>();

[R2APISubmoduleInit(Stage = InitStage.SetHooks)]
internal static void SetHooks() {
//R2APIContentPackProvider.WhenContentPackReady += AddAdditionalEntries;
}

[R2APISubmoduleInit(Stage = InitStage.UnsetHooks)]
internal static void UnsetHooks() {
//R2APIContentPackProvider.WhenContentPackReady -= AddAdditionalEntries;
}

/*private static void AddAdditionalEntries(ContentPack r2apiContentPack) {
foreach (var customEffect in AddedEffects) {
R2API.Logger.LogInfo($"Custom Effect: {customEffect.prefabName} added");
}

r2apiContentPack.effectDefs.Add(AddedEffects.ToArray());
}*/

/// <summary>
/// Creates an EffectDef from a prefab and adds it to the EffectCatalog.
/// The prefab must have an the following components: EffectComponent, VFXAttributes
Expand Down Expand Up @@ -102,7 +82,6 @@ public static class EffectAPI {
}

R2APIContentManager.HandleContentAddition(Assembly.GetCallingAssembly(), effect.prefab);
//AddedEffects.Add(effect);
return true;
}
}
Expand Down
9 changes: 1 addition & 8 deletions R2API/EliteAPI.cs
Expand Up @@ -38,7 +38,6 @@ public static class EliteAPI {
IL.RoR2.CombatDirector.Init += RetrieveVanillaEliteTierCount;
On.RoR2.CombatDirector.Init += AddCustomEliteTiers;

//R2APIContentPackProvider.WhenContentPackReady += AddElitesToGame;
R2APIContentPackProvider.WhenAddingContentPacks += AddElitesToGame;
}

Expand All @@ -47,7 +46,6 @@ public static class EliteAPI {
IL.RoR2.CombatDirector.Init -= RetrieveVanillaEliteTierCount;
On.RoR2.CombatDirector.Init -= AddCustomEliteTiers;

//R2APIContentPackProvider.WhenContentPackReady -= AddElitesToGame;
R2APIContentPackProvider.WhenAddingContentPacks -= AddElitesToGame;
}

Expand All @@ -67,13 +65,10 @@ public static class EliteAPI {
CombatDirector.Init();
}

private static void AddElitesToGame(/*ContentPack r2apiContentPack*/) {
//var eliteDefs = new List<EliteDef>();

private static void AddElitesToGame() {
LazyInitVanillaEliteTiers();

foreach (var customElite in EliteDefinitions) {
//eliteDefs.Add(customElite.EliteDef);

var currentEliteTiers = GetCombatDirectorEliteTiers();

Expand All @@ -96,9 +91,7 @@ public static class EliteAPI {
}

OverrideCombatDirectorEliteTiers(currentEliteTiers);
//R2API.Logger.LogInfo($"Custom Elite: {customElite.EliteDef.modifierToken} added");
}
//r2apiContentPack.eliteDefs.Add(eliteDefs.ToArray());
_eliteCatalogInitialized = true;
}

Expand Down
36 changes: 8 additions & 28 deletions R2API/ItemAPI.cs
Expand Up @@ -7,7 +7,7 @@
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.Linq;
using System.Reflection;
using System.Reflection;
using System.Xml.Linq;
using UnityEngine;
using Object = UnityEngine.Object;
Expand Down Expand Up @@ -44,41 +44,23 @@ public static class ItemAPI {

[R2APISubmoduleInit(Stage = InitStage.SetHooks)]
internal static void SetHooks() {
//R2APIContentPackProvider.WhenContentPackReady += AddItemsToGame;
R2APIContentPackProvider.WhenAddingContentPacks += AddItemsToGame;
R2APIContentPackProvider.WhenAddingContentPacks += AvoidNewEntiresAndLoadRelatedAPIs;
IL.RoR2.CharacterModel.UpdateMaterials += MaterialFixForItemDisplayOnCharacter;
On.RoR2.ItemDisplayRuleSet.Init += AddingItemDisplayRulesToCharacterModels;
}

[R2APISubmoduleInit(Stage = InitStage.UnsetHooks)]
internal static void UnsetHooks() {
//R2APIContentPackProvider.WhenContentPackReady -= AddItemsToGame;
R2APIContentPackProvider.WhenAddingContentPacks += AddItemsToGame;
internal static void UnsetHooks() {
R2APIContentPackProvider.WhenAddingContentPacks += AvoidNewEntiresAndLoadRelatedAPIs;
IL.RoR2.CharacterModel.UpdateMaterials -= MaterialFixForItemDisplayOnCharacter;
On.RoR2.ItemDisplayRuleSet.Init -= AddingItemDisplayRulesToCharacterModels;
}

private static void AddItemsToGame(/*ContentPack r2apiContentPack*/) {
/*var itemDefs = new List<ItemDef>();
foreach (var customItem in ItemDefinitions) {
itemDefs.Add(customItem.ItemDef);

R2API.Logger.LogInfo($"Custom Item: {customItem.ItemDef.name} added");
}*

r2apiContentPack.itemDefs.Add(itemDefs.ToArray());*/
private static void AvoidNewEntiresAndLoadRelatedAPIs() {
Nebby1999 marked this conversation as resolved.
Show resolved Hide resolved
_itemCatalogInitialized = true;

/*var equipmentDefs = new List<EquipmentDef>();
foreach (var customEquipment in EquipmentDefinitions) {
equipmentDefs.Add(customEquipment.EquipmentDef);

R2API.Logger.LogInfo($"Custom Equipment: {customEquipment.EquipmentDef.name} added");
}*/

LoadRelatedAPIs();

//r2apiContentPack.equipmentDefs.Add(equipmentDefs.ToArray());
_equipmentCatalogInitialized = true;
}

Expand Down Expand Up @@ -144,8 +126,7 @@ public static class ItemAPI {
R2API.Logger.LogError($"Custom item '{item.ItemDef.name}' is not XMLsafe. Item not added.");
}
if (xmlSafe) {
R2APIContentManager.HandleContentAddition(Assembly.GetCallingAssembly(), item.ItemDef);
//ItemDefinitions.Add(item);
R2APIContentManager.HandleContentAddition(Assembly.GetCallingAssembly(), item.ItemDef);
return true;
}

Expand Down Expand Up @@ -196,9 +177,8 @@ public static class ItemAPI {
catch {
R2API.Logger.LogError($"Custom equipment '{item.EquipmentDef.name}' is not XMLsafe. Item not added.");
}
if (xmlSafe) {
R2APIContentManager.HandleContentAddition(Assembly.GetCallingAssembly(), item.EquipmentDef);
//EquipmentDefinitions.Add(item);
if (xmlSafe) {
R2APIContentManager.HandleContentAddition(Assembly.GetCallingAssembly(), item.EquipmentDef);
return true;
}

Expand Down
3 changes: 3 additions & 0 deletions R2API/LoadRoR2ContentEarly.cs
Expand Up @@ -16,6 +16,9 @@ namespace R2API {
internal static class LoadRoR2ContentEarly {
private static bool _ror2ContentLoaded;
private static RoR2Content RoR2Content;
/// <summary>
/// A ReadOnly version of RoR2's ContentPack.
/// </summary>
public static ReadOnlyContentPack ReadOnlyRoR2ContentPack { get; private set; }

internal static void Init() {
Expand Down
16 changes: 3 additions & 13 deletions R2API/ProjectileAPI.cs
Expand Up @@ -13,8 +13,6 @@ namespace R2API {
[R2APISubmodule]
public static class ProjectileAPI {

//private static readonly List<GameObject> Projectiles = new List<GameObject>();

private static bool _projectileCatalogInitialized;

/// <summary>
Expand All @@ -31,22 +29,15 @@ public static class ProjectileAPI {

[R2APISubmoduleInit(Stage = InitStage.SetHooks)]
internal static void SetHooks() {
//R2APIContentPackProvider.WhenContentPackReady += AddProjectilesToGame;
R2APIContentPackProvider.WhenAddingContentPacks += AddProjectilesToGame;
R2APIContentPackProvider.WhenAddingContentPacks += AvoidNewEntires;
}

[R2APISubmoduleInit(Stage = InitStage.UnsetHooks)]
internal static void UnsetHooks() {
//R2APIContentPackProvider.WhenContentPackReady -= AddProjectilesToGame;
R2APIContentPackProvider.WhenAddingContentPacks -= AddProjectilesToGame;
R2APIContentPackProvider.WhenAddingContentPacks -= AvoidNewEntires;
}

private static void AddProjectilesToGame(/*ContentPack r2apiContentPack*/) {
/*foreach (var projectile in Projectiles) {
R2API.Logger.LogInfo($"Custom Projectile: {projectile.name} added");
}

r2apiContentPack.projectilePrefabs.Add(Projectiles.ToArray());*/
private static void AvoidNewEntires() {
Nebby1999 marked this conversation as resolved.
Show resolved Hide resolved
_projectileCatalogInitialized = true;
}

Expand All @@ -72,7 +63,6 @@ public static class ProjectileAPI {
}

R2APIContentManager.HandleContentAddition(Assembly.GetCallingAssembly(), projectile);
//Projectiles.Add(projectile);
return true;
}

Expand Down