Skip to content

Commit

Permalink
Changes to R2API's ContentPack System (#338)
Browse files Browse the repository at this point in the history
* ArtifactCodeAPI changes

* Added hide in inspector attribute to ArtifactCompounds list

* Added a header with the constant that says how to find a list of accepted vanilla compound values-

* Added R2API Content Manager

* Removed comments, added logger messages, modified UnlockableAPI.

* Cleaned code.

* Fixed typo and version issue

* Added check to ensure there isnt an asset with whitespace, empty, or null as its name

* Made LoadROR2ContentEarly public, Added Public methods to R2APIContentManager

* Added missing documentation.

* Made it so ContentPacks can opt out from r2api loading the pack automatically.

* code cleanup

* Moved content related classes to R2APIContentManagment, fixed typos and issues.

* Fixed silent letter typo

* Marked a bunch of classes & methods as obsolete

* fixed another "entires" typo

* Added ContentAdditionHelpers

Also removed AddContent() and AddentityState() from R2APIContentManager

* Added missing documentation

* Added CatalogBlockers

* updated obsolete messages to redirect to the ContentAdditionHelpers

* Moved 3.x changelogs to archived, Added my PR to the readme
  • Loading branch information
Nebby1999 authored Feb 17, 2022
1 parent 82577d2 commit 3730bc1
Show file tree
Hide file tree
Showing 37 changed files with 1,708 additions and 644 deletions.
95 changes: 94 additions & 1 deletion Archived changelogs.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,97 @@
All changelogs before 3.0.0 version
All changelogs before 4.0.0 version

**3.0.71**

* [ItemAPI now warns that ItemDef/EquipmentDef.pickupModelPrefab should have an ItemDisplay attached to them when they have ParentedPrefab display rules linked to them](https://github.com/risk-of-thunder/R2API/pull/311)
* [EliteAPI now exposes the default elite tiers array (through VanillaEliteTiers) before any changes are made to it for modder that want to change the vanilla elite tiers. Also, adding to the custom elite tier array now by default insert based on the cost multiplier of the elite tier.](https://github.com/risk-of-thunder/R2API/pull/308)
* [RecalculateStatsAPI now warns modders that the submodule could be not loaded](https://github.com/risk-of-thunder/R2API/pull/307)
* [Added Curse, Shield Multiplier, All Cooldown Reductions, Jump Power, Level Scaling, and Root to RecalculateStatsAPI](https://github.com/risk-of-thunder/R2API/pull/322)
* [Fix SoundAPI throwing on dedicated server](https://github.com/risk-of-thunder/R2API/pull/306)
* [Fix SoundAPI's music implementation stopping all music when an instance of a MusicTrackOverride gets destroyed](https://github.com/risk-of-thunder/R2API/pull/319)
* [Added TempVisualEffectAPI](https://github.com/risk-of-thunder/R2API/pull/313)
* [ArtifactCodeAPI's ArtifactCode Scriptable object now uses 3 Vector3Int for inputting the code, instead of a List of Ints](https://github.com/risk-of-thunder/R2API/pull/310)
* [Added aditional overloads for AddUnlockable that accept a type parameter instead of using generics](https://github.com/risk-of-thunder/R2API/pull/317)
* [UnlockableAPI can now add AchievementDefs directly](https://github.com/risk-of-thunder/R2API/pull/321)
* [DotAPI no longer throws an error when no BuffDef is provided for the asociated BuffDef parameter](https://github.com/risk-of-thunder/R2API/pull/325)

**3.0.59**

* [Extended SoundAPI for adding custom music](https://github.com/risk-of-thunder/R2API/pull/305)
* [Added support for using existing UnlockableDefs in UnlockableAPI](https://github.com/risk-of-thunder/R2API/pull/304)
* [fixing server unlockables](https://github.com/risk-of-thunder/R2API/pull/302)

**3.0.52**

* [Add NetworkSoundEventDef registration to SoundAPI](https://github.com/risk-of-thunder/R2API/pull/301)

**3.0.50**

* [Added ArtifactCodeAPI](https://github.com/risk-of-thunder/R2API/pull/299)
* [Added support for new Artifact Code compounds](https://github.com/risk-of-thunder/R2API/pull/300)

**3.0.48**

* [Documentation for ItemDropAPI](https://github.com/risk-of-thunder/R2API/blob/master/ItemDropAPI%20Instructions%20For%20Use.txt)
* [ItemDropAPI Overhall](https://github.com/risk-of-thunder/R2API/pull/295)
* [Added MonsterItemsAPI back in](https://github.com/risk-of-thunder/R2API/pull/295)

**3.0.44**

* [Fixed PrefabAPI network registration](https://github.com/risk-of-thunder/R2API/pull/294)

**3.0.43**

* **IMPORTANT FOR MOD DEVS:** [R2API will no longer register mods to network if they don't depend on it with HardDependecy](https://github.com/risk-of-thunder/R2API/pull/286)
* [Added DeployableAPI](https://github.com/risk-of-thunder/R2API/pull/279)
* [Added DamageAPI](https://github.com/risk-of-thunder/R2API/pull/284)
* [Added RecalcStatsAPI, migrated from TILER2](https://github.com/risk-of-thunder/R2API/pull/287)
* [Updated DifficultyAPI, now has sprite ref overload](https://github.com/risk-of-thunder/R2API/pull/288)
* [RecalcStatsAPI fixes](https://github.com/risk-of-thunder/R2API/pull/290)
* [Missing MMHOOK/Publicized Assembly methods fixes](https://github.com/risk-of-thunder/R2API/pull/289)

**3.0.30**

* Fixes for current patch

**3.0.25**

* **IMPORTANT FOR MOD DEVS:** [R2API will no longer register mods to network if they don't depend on it](https://github.com/risk-of-thunder/R2API/pull/269)
* [DotAPI fixes](https://github.com/risk-of-thunder/R2API/pull/270)
* [EliteAPI fixes](https://github.com/risk-of-thunder/R2API/pull/271)

**3.0.13**

* [Updated UnlockableAPI, ItemDropAPI Overhall](https://github.com/risk-of-thunder/R2API/pull/265)
* [Update internals for 1.1.1.2 game version](https://github.com/risk-of-thunder/R2API/pull/267)
* Removed MonsterItemsAPI
* Removed `patchers` folder

**3.0.11**

* [Updated ResourceAPI error messages](https://github.com/risk-of-thunder/R2API/pull/258)
* SurvivorAPI Fixes: [A](https://github.com/risk-of-thunder/R2API/pull/259) [B](https://github.com/risk-of-thunder/R2API/pull/261)

**3.0.7**

* [Added ArtifactAPI and ProjectileAPI, BuffAPI fix](https://github.com/risk-of-thunder/R2API/pull/256)

**3.0.1**

* [Fixes for EffectAPI, LoadoutAPI and SoundAPI](https://github.com/risk-of-thunder/R2API/pull/254)

**3.0.0**

* Updated for the game `Anniversary Update`
* No longer include `monomod` folder
* [Various API Fixes. Removed AssetsAPI, InvetoryAPI. Moved MMHook to separate mod called (HookGenPatcher)](https://github.com/risk-of-thunder/R2API/pull/252)
* Removed obsolete APIs and methods: [A](https://github.com/risk-of-thunder/R2API/pull/249) [B](https://github.com/risk-of-thunder/R2API/pull/243)
* ItemAPI, ItemDropApi overhall. Added MonsterItemAPI: [A](https://github.com/risk-of-thunder/R2API/pull/214) [B](https://github.com/risk-of-thunder/R2API/pull/223) [C](https://github.com/risk-of-thunder/R2API/pull/228) [D](https://github.com/risk-of-thunder/R2API/pull/233) [E](https://github.com/risk-of-thunder/R2API/pull/234) [F](https://github.com/risk-of-thunder/R2API/pull/240) [G](https://github.com/risk-of-thunder/R2API/pull/245)
* LanguageAPI refactoring and fixes: [A](https://github.com/risk-of-thunder/R2API/pull/229) [B](https://github.com/risk-of-thunder/R2API/pull/244)
* [Added ILLine](https://github.com/risk-of-thunder/R2API/pull/230)
* [Fix for networked achievements](https://github.com/risk-of-thunder/R2API/pull/208)
* [Added SceneAssetAPI](https://github.com/risk-of-thunder/R2API/pull/210)
* [Added InteractablesAPI](https://github.com/risk-of-thunder/R2API/pull/216)


**2.5.14**

Expand Down
4 changes: 2 additions & 2 deletions R2API.Test/Tests/ReflectionTests.cs
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
using R2API.Utils;
using RoR2;
using System;
using System.Collections;
using System.Collections.Generic;
using R2API.Utils;
using RoR2;
using Xunit;

namespace R2API.Test {
Expand Down
4 changes: 2 additions & 2 deletions R2API.Test/Tests/UnbundledResourcesProviderTests.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
using System;
using R2API.Utils;
using R2API.Utils;
using System;
using UnityEngine;
using Xunit;

Expand Down
49 changes: 12 additions & 37 deletions R2API/ArtifactAPI.cs
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
using R2API.Utils;
using R2API.ContentManagement;
using R2API.Utils;
using RoR2;
using RoR2.ContentManagement;
using System;
using System.Collections.Generic;
using System.Reflection;
using UnityEngine;

namespace R2API {
Expand All @@ -11,12 +11,8 @@ namespace R2API {
/// API for adding custom artifact to the game.
/// </summary>
[R2APISubmodule]
[Obsolete($"The {nameof(ArtifactAPI)} is obsolete, please add your ArtifactDefs via R2API.ContentManagement.ContentAdditionHelpers.AddArtifactDef()")]
public static class ArtifactAPI {

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

private static bool _artifactCatalogInitialized;

/// <summary>
/// Return true if the submodule is loaded.
/// </summary>
Expand All @@ -27,29 +23,6 @@ public static bool Loaded {

private static bool _loaded;

#region ModHelper Events and Hooks

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

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

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

r2apiContentPack.artifactDefs.Add(Artifacts.ToArray());
_artifactCatalogInitialized = true;
}

#endregion ModHelper Events and Hooks

#region Add Methods

/// <summary>
Expand All @@ -58,18 +31,19 @@ private static void AddArtifactsToGame(ContentPack r2apiContentPack) {
/// </summary>
/// <param name="artifactDef">The artifactDef to add.</param>
/// <returns>true if added, false otherwise</returns>
[Obsolete($"Add is obsolete, please add your ArtifactDefs via R2API.ContentManagement.ContentAdditionHelpers.AddArtifactDef()")]
public static bool Add(ArtifactDef? artifactDef) {
if (!Loaded) {
throw new InvalidOperationException($"{nameof(ArtifactAPI)} is not loaded. Please use [{nameof(R2APISubmoduleDependency)}(nameof({nameof(ArtifactAPI)})]");
}

if (_artifactCatalogInitialized) {
if (!CatalogBlockers.GetAvailability<ArtifactDef>()) {
R2API.Logger.LogError(
$"Too late ! Tried to add artifact: {artifactDef.cachedName} after the artifact list was created");
$"Too late ! Tried to add artifact: {artifactDef.cachedName} after the ArtifactCatalog has initialized!");
return false;
}

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

Expand All @@ -78,6 +52,7 @@ public static bool Add(ArtifactDef? artifactDef) {
/// If this is called after the ArtifactCatalog inits then this will return false and ignore the custom artifact.
/// </summary>
/// <returns>true if added, false otherwise</returns>
[Obsolete($"Add is obsolete, please add your ArtifactDefs via R2API.ContentManagement.ContentAdditionHelpers.AddArtifactDef()")]
public static bool Add(
string name,
string descriptionToken, string nameToken,
Expand All @@ -88,9 +63,9 @@ public static bool Add(
throw new InvalidOperationException($"{nameof(ArtifactAPI)} is not loaded. Please use [{nameof(R2APISubmoduleDependency)}(nameof({nameof(ArtifactAPI)})]");
}

if (_artifactCatalogInitialized) {
if (!CatalogBlockers.GetAvailability<ArtifactDef>()) {
R2API.Logger.LogError(
$"Too late ! Tried to add artifact: {name} after the artifact list was created");
$"Too late ! Tried to add artifact: {name} after the ArtifactCatalog has initialized!");
return false;
}

Expand All @@ -103,7 +78,7 @@ public static bool Add(
artifactDef.smallIconSelectedSprite = smallIconSelectedSprite;
artifactDef.unlockableDef = unlockableDef;

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

Expand Down
6 changes: 6 additions & 0 deletions R2API/IgnoreAccessModifiers.cs → R2API/AssemblyInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,3 +12,9 @@
[assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)]
#pragma warning restore CS0618 // Type or member is obsolete
[module: UnverifiableCode]

//This allows us to use the SystemInitializer attribute
//the attribute will call whatever method it's attached to once ror2 starts loading.
//We can add dependencies to the SystemInitializer attribute, an example would be run
//a piece of code that gets automatically ran once the ItemCatalog is initialized
[assembly: HG.Reflection.SearchableAttribute.OptIn]
42 changes: 8 additions & 34 deletions R2API/BuffAPI.cs
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
using MonoMod.Cil;
using R2API.ContentManagement;
using R2API.Utils;
using RoR2;
using RoR2.ContentManagement;
using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.Reflection;
using UnityEngine;

namespace R2API {
Expand All @@ -13,15 +12,15 @@ namespace R2API {
/// API for adding custom buffs to the game. Previously included in ItemAPI.
/// </summary>
[R2APISubmodule]
[Obsolete($"The {nameof(BuffAPI)} is obsolete, please add your BuffDefs via R2API.ContentManagement.ContentAdditionHelpers.AddBuffDef()")]
public static class BuffAPI {

/// <summary>
/// All custom buffs added by the API.
/// </summary>
[Obsolete($"This observable collection is obsolete, if you want to look at the buffDefs added by R2API, look at R2API.ContentManagement.R2APIContentManager.ManagedContentPacks and do a SelectMany on the buffDefs.")]
public static ObservableCollection<CustomBuff?>? BuffDefinitions = new ObservableCollection<CustomBuff>();

private static bool _buffCatalogInitialized;

/// <summary>
/// Return true if the submodule is loaded.
/// </summary>
Expand All @@ -32,32 +31,6 @@ public static bool Loaded {

private static bool _loaded;

#region ModHelper Events and Hooks

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

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

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());
_buffCatalogInitialized = true;
}

#endregion ModHelper Events and Hooks

#region Add Methods

/// <summary>
Expand All @@ -68,18 +41,19 @@ private static void AddBuffsToGame(ContentPack r2apiContentPack) {
/// </summary>
/// <param name="buff">The buff to add.</param>
/// <returns>true if added, false otherwise</returns>
[Obsolete($"Add is obsolete, please add your BuffDefs via R2API.ContentManagement.ContentAdditionHelpers.AddBuffDef()")]
public static bool Add(CustomBuff? buff) {
if (!Loaded) {
throw new InvalidOperationException($"{nameof(BuffAPI)} is not loaded. Please use [{nameof(R2APISubmoduleDependency)}(nameof({nameof(BuffAPI)})]");
}

if (_buffCatalogInitialized) {
if (!CatalogBlockers.GetAvailability<BuffDef>()) {
R2API.Logger.LogError(
$"Too late ! Tried to add buff: {buff.BuffDef.name} after the buff list was created");
$"Too late ! Tried to add buff: {buff.BuffDef.name} after the BuffCatalog has initialized!");
return false;
}

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

Expand Down
Loading

0 comments on commit 3730bc1

Please sign in to comment.