logs, particles, and cooldowns now automatically load

This commit is contained in:
GinYuH committed 2024-02-03 19:56:11 -08:00
1 parent 0f7622a970
commit 4a144285bf
6 files changed
+51 -50

No files matched your search

-1
View File
@@ -383,7 +383,6 @@ namespace CalamityMod
return Color.Lerp(player.hairColor, new Color(186, 85, 211), stealthInterpolant);
}));
PopupGUIManager.LoadGUIs();
InvasionProgressUIManager.LoadGUIs();
}
#endregion
+16 -16
View File
@@ -23,9 +23,6 @@ namespace CalamityMod.Cooldowns
registry = new Cooldown[defaultSize];
nameToNetID = new Dictionary<string, ushort>(defaultSize);
// TODO -- CooldownHandlers should be ILoadable in 1.4
RegisterModCooldowns(CalamityMod.Instance);
#region Unused manual registration left here as backup
// Vanilla cooldowns represented by the interface
//var potionSickness = Register<PotionSickness>(PotionSickness.ID);
@@ -63,26 +60,29 @@ namespace CalamityMod.Cooldowns
#endregion
}
public static void RegisterModCooldowns(Mod mod)
public static void RegisterModCooldowns()
{
Type baseHandlerType = typeof(CooldownHandler);
foreach (Type type in AssemblyManager.GetLoadableTypes(mod.Code))
foreach (Mod mod in ModLoader.Mods)
{
if (type.IsSubclassOf(baseHandlerType) && !type.IsAbstract && type != baseHandlerType)
foreach (Type type in AssemblyManager.GetLoadableTypes(mod.Code))
{
//Get the static property ID of the handler
string handlerID = (string)type.GetProperty("ID").GetValue(null);
if (type.IsSubclassOf(baseHandlerType) && !type.IsAbstract && type != baseHandlerType)
{
//Get the static property ID of the handler
string handlerID = (string)type.GetProperty("ID").GetValue(null);
//If for whatever reason the ID is not set, create an ID from the mod and handler name
if (handlerID == null)
handlerID = mod.Name + "_" + type.Name;
//If for whatever reason the ID is not set, create an ID from the mod and handler name
if (handlerID == null)
handlerID = mod.Name + "_" + type.Name;
//Use reflection to call the method. You can't use the type as the generic type argument of register here
MethodInfo methodInfo = typeof(CooldownRegistry).GetMethod("Register", BindingFlags.Public | BindingFlags.Static);
Type[] genericArguments = new Type[] { type };
//Use reflection to call the method. You can't use the type as the generic type argument of register here
MethodInfo methodInfo = typeof(CooldownRegistry).GetMethod("Register", BindingFlags.Public | BindingFlags.Static);
Type[] genericArguments = new Type[] { type };
MethodInfo genericRegister = methodInfo.MakeGenericMethod(genericArguments);
genericRegister.Invoke(null, new object[] { handlerID });
MethodInfo genericRegister = methodInfo.MakeGenericMethod(genericArguments);
genericRegister.Invoke(null, new object[] { handlerID });
}
}
}
}
-14
View File
@@ -1981,20 +1981,6 @@ namespace CalamityMod
BossRushEvent.BossDeathEffects[npcType5] = deathEffect;
return null;
case "LoadParticleInstances":
if (args.Length != 2 || !(args[1] is Mod))
return new ArgumentNullException("ERROR: Must specify a Mod instance to load particles from.");
GeneralParticleHandler.LoadModParticleInstances(args[1] as Mod);
return null;
case "RegisterModCooldowns":
if (args.Length != 2 || !(args[1] is Mod))
return new ArgumentNullException("ERROR: Must specify a Mod instance to register cooldowns from.");
CooldownRegistry.RegisterModCooldowns(args[1] as Mod);
return null;
case "GetSummonerNerfDisabledByItem":
if (args.Length != 2 || !isValidItemArg(args[1]))
return new ArgumentException("ERROR: Must specify a valid item to check status of.");
+10
View File
@@ -2,6 +2,7 @@
using System.Collections.Generic;
using System.Linq;
using CalamityMod.Buffs.Summon;
using CalamityMod.Cooldowns;
using CalamityMod.Events;
using CalamityMod.Items;
using CalamityMod.Items.Armor.Vanity;
@@ -55,9 +56,11 @@ using CalamityMod.NPCs.SunkenSea;
using CalamityMod.NPCs.SupremeCalamitas;
using CalamityMod.NPCs.TownNPCs;
using CalamityMod.NPCs.Yharon;
using CalamityMod.Particles;
using CalamityMod.Projectiles.DraedonsArsenal;
using CalamityMod.Projectiles.Summon;
using CalamityMod.Projectiles.Summon.Umbrella;
using CalamityMod.UI;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Graphics;
using Terraria;
@@ -188,6 +191,13 @@ namespace CalamityMod
FargosSupport();
DialogueTweakSupport();
SummonersAssociationSupport();
// done here to assure that all other mods have already loaded so that Calamity can automatically grab any of these types they may have
if (!Main.dedServ)
{
GeneralParticleHandler.LoadModParticleInstances();
CooldownRegistry.RegisterModCooldowns();
PopupGUIManager.LoadGUIs();
}
}
#region WikiThis
+14 -13
View File
@@ -26,23 +26,26 @@ namespace CalamityMod.Particles
private static List<Particle> batchedNonPremultipliedParticles;
private static List<Particle> batchedAdditiveBlendParticles;
public static void LoadModParticleInstances(Mod mod)
public static void LoadModParticleInstances()
{
Type baseParticleType = typeof(Particle);
foreach (Type type in AssemblyManager.GetLoadableTypes(mod.Code))
foreach (Mod mod in ModLoader.Mods)
{
if (type.IsSubclassOf(baseParticleType) && !type.IsAbstract && type != baseParticleType)
foreach (Type type in AssemblyManager.GetLoadableTypes(mod.Code))
{
int ID = particleTypes.Count; //Get the ID of the particle
particleTypes[type] = ID;
if (type.IsSubclassOf(baseParticleType) && !type.IsAbstract && type != baseParticleType)
{
int ID = particleTypes.Count; //Get the ID of the particle
particleTypes[type] = ID;
Particle instance = (Particle)FormatterServices.GetUninitializedObject(type);
particleInstances.Add(instance);
Particle instance = (Particle)FormatterServices.GetUninitializedObject(type);
particleInstances.Add(instance);
string texturePath = type.Namespace.Replace('.', '/') + "/" + type.Name;
if (instance.Texture != "")
texturePath = instance.Texture;
particleTextures[ID] = ModContent.Request<Texture2D>(texturePath, AssetRequestMode.ImmediateLoad).Value;
string texturePath = type.Namespace.Replace('.', '/') + "/" + type.Name;
if (instance.Texture != "")
texturePath = instance.Texture;
particleTextures[ID] = ModContent.Request<Texture2D>(texturePath, AssetRequestMode.ImmediateLoad).Value;
}
}
}
}
@@ -58,8 +61,6 @@ namespace CalamityMod.Particles
batchedAlphaBlendParticles = new List<Particle>();
batchedNonPremultipliedParticles = new List<Particle>();
batchedAdditiveBlendParticles = new List<Particle>();
LoadModParticleInstances(CalamityMod.Instance);
}
internal static void Unload()
+11 -6
View File
@@ -3,6 +3,8 @@ using System;
using System.Collections.Generic;
using System.Linq;
using Terraria;
using Terraria.ModLoader;
using Terraria.ModLoader.Core;
namespace CalamityMod.UI
{
@@ -58,13 +60,16 @@ namespace CalamityMod.UI
public static void LoadGUIs()
{
// Look through every type in the mod, and check if it's derived from PopupGUI. If it is, create a copy and save it in the static list.
foreach (Type type in typeof(CalamityMod).Assembly.GetTypes())
foreach (Mod mod in ModLoader.Mods)
{
// Don't load abstract classes since they cannot have instances.
if (type.IsAbstract)
continue;
if (type.IsSubclassOf(typeof(PopupGUI)))
gUIs.Add(Activator.CreateInstance(type) as PopupGUI);
foreach (Type type in AssemblyManager.GetLoadableTypes(mod.Code))
{
// Don't load abstract classes since they cannot have instances.
if (type.IsAbstract)
continue;
if (type.IsSubclassOf(typeof(PopupGUI)))
gUIs.Add(Activator.CreateInstance(type) as PopupGUI);
}
}
}
public static void UnloadGUIs() => gUIs.Clear();