Particle as ILoadable
This commit is contained in:
1 parent
dc5733dcd5
commit
f4e75425ab
2 files changed
+21
-18
No files matched your search
@@ -1,7 +1,6 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Runtime.CompilerServices;
|
||||
using CalamityMod.Enums;
|
||||
using CalamityMod.Systems.Graphic.PixelationSystem;
|
||||
using Microsoft.Xna.Framework;
|
||||
@@ -64,25 +63,18 @@ namespace CalamityMod.Particles
|
||||
#endregion
|
||||
|
||||
#region Loading and Unloading
|
||||
public override void PostSetupContent()
|
||||
|
||||
internal static void RegisterParticleType(Particle particle)
|
||||
{
|
||||
Type baseParticleType = typeof(Particle);
|
||||
ReflectionHelper.IterateEveryModsTypes<Particle>(action: type =>
|
||||
{
|
||||
int ID = particleIDsByTypes.Count; //Get the ID of the particle
|
||||
particleIDsByTypes[type] = ID;
|
||||
var type = particle.GetType();
|
||||
int ID = particleIDsByTypes.Count; //Get the ID of the particle
|
||||
particleIDsByTypes[type] = ID;
|
||||
|
||||
// Flow: 2024/09/17
|
||||
// 'UnintializedObject' is allowed to use here as it's only read for Texture string Property
|
||||
// But do NOT EVER use it's instance as they are literally Uninitialized.
|
||||
// It might cause unintended behaviour if we do that.
|
||||
Particle instance = (Particle)RuntimeHelpers.GetUninitializedObject(type);
|
||||
string texturePath = particle.Texture;
|
||||
if (string.IsNullOrEmpty(texturePath))
|
||||
texturePath = type.Namespace.Replace('.', '/') + "/" + type.Name;
|
||||
|
||||
string texturePath = type.Namespace.Replace('.', '/') + "/" + type.Name;
|
||||
if (instance.Texture != "")
|
||||
texturePath = instance.Texture;
|
||||
particleTexturesByIDs[ID] = ModContent.Request<Texture2D>(texturePath, instance.TextureRequestMode);
|
||||
});
|
||||
particleTexturesByIDs[ID] = ModContent.Request<Texture2D>(texturePath, particle.TextureRequestMode);
|
||||
}
|
||||
|
||||
public override void Load()
|
||||
|
||||
+12
-1
@@ -2,10 +2,11 @@
|
||||
using Microsoft.Xna.Framework;
|
||||
using Microsoft.Xna.Framework.Graphics;
|
||||
using ReLogic.Content;
|
||||
using Terraria.ModLoader;
|
||||
|
||||
namespace CalamityMod.Particles
|
||||
{
|
||||
public class Particle
|
||||
public class Particle : ILoadable
|
||||
{
|
||||
/// <summary>
|
||||
/// The ID of the particle type as registered by <see cref="GeneralParticleHandler"/> when the mod loads.
|
||||
@@ -146,5 +147,15 @@ namespace CalamityMod.Particles
|
||||
/// Removes the particle from the handler
|
||||
/// </summary>
|
||||
public void Kill() => GeneralParticleHandler.RemoveParticle(this);
|
||||
|
||||
public void Load(Mod mod)
|
||||
{
|
||||
GeneralParticleHandler.RegisterParticleType(this);
|
||||
}
|
||||
|
||||
public void Unload()
|
||||
{
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user