using CalamityMod.Enums;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Graphics;
using ReLogic.Content;
namespace CalamityMod.Particles
{
public abstract class Particle
{
///
/// The ID of the particle type as registered by when the mod loads.
///
This field is set automatically when a particle instance is spawned in the world. This should NOT be set outside of that context.
///
public int Type;
///
/// The amount of frames this particle has existed for. You shouldn't have to touch this manually.
///
public int Time;
///
/// The maximum amount of frames a particle may stay alive if Particle.SetLifeTime is set to true
///
public int Lifetime = 0;
///
/// The offset of the particle in relation to the origin of the set it belongs to. This is only used in the context of a .
///
public Vector2 RelativeOffset;
///
/// The inworld position of a particle. Keep in mind this isn't used in the context of a , since all the particles work off their relative position to the set's origin
///
public Vector2 Position;
public Vector2 Velocity;
public Vector2 Origin;
public Color Color;
public float Rotation;
public float Scale;
///
/// The current Y-frame of this particle's spritesheet.
///
public int Variant = 0;
///
/// Whether your particle is affected by light levels.
///
public bool AffectedByLight = false;
///
/// Whether or not your particle should be drawn with a pixelated effect to match Terraria's pixel size.
///
Defaults to false.
///
public bool Pixelate = false;
///
/// The "layer" or point at which you'd like your particle to draw in Terraria's internal draw order.
///
Defaults to .
///
public GeneralDrawLayer DrawLayer = GeneralDrawLayer.AfterDusts;
///
/// An 0-1 interpolant representing how close this particle is from its .
///
public float LifetimeCompletion => Lifetime != 0 ? Time / (float)Lifetime : 0;
///
/// The path to this particle's autoloaded texture.
///
///
/// Can be accessed via .
///
public virtual string Texture => "";
///
/// for how should be autoloaded.
/// Defaults to
///
public virtual AssetRequestMode TextureRequestMode => AssetRequestMode.AsyncLoad;
///
/// The maximum amount of frames this particle's spritesheet has vertically.
///
public virtual int FrameVariants => 1;
///
/// Set this to true if you NEED the particle to render even if the particle cap is reached.
///
public virtual bool Important => false;
///
/// Set this to true if you want your particle to automatically get removed when its time reaches its maximum lifetime
///
public virtual bool SetLifetime => false;
///
/// Set this to true to make your particle use additive blending instead of alphablend.
///
public virtual bool UseAdditiveBlend => false;
///
/// Set this to true to make your particles work with semi transparent pixels. Is overriden if UseAdditiveBlend is set to true.
///
public virtual bool UseHalfTransparency => false;
///
/// Set this to true to disable default particle drawing, thus calling Particle.CustomDraw() instead.
///
public virtual bool UseCustomDraw => false;
///
/// An optional shader parameter for this paricle to be drawn with.
/// Use to set shader parameters accordingly.
///
public virtual Effect CustomShader => null;
///
/// Use this method if you want to handle the particle drawing yourself. Only called if is set to true.
///
public virtual void CustomDraw(SpriteBatch spriteBatch) { }
///
/// Use this method if you want to handle particle drawing yourself in the context of a .
///
/// The base position of the particle set.
public virtual void CustomDraw(SpriteBatch spriteBatch, Vector2 basePosition) { }
///
/// Use this method if you're using a custom shader effect with this particle type to set shader parameters accordingly.
///
public virtual void PrepareCustomShader(Effect shader) { }
///
/// Called every frame in .
/// The particle's velocity gets automatically added to its position, and its time automatically increases.
///
public virtual void Update() { }
///
/// Removes the particle from the handler
///
public void Kill() => GeneralParticleHandler.RemoveParticle(this);
}
}