Skip to content

Commit

Permalink
closee
Browse files Browse the repository at this point in the history
  • Loading branch information
amylizzle committed Feb 19, 2025
1 parent 582f7d5 commit dda9e5e
Show file tree
Hide file tree
Showing 3 changed files with 41 additions and 8 deletions.
29 changes: 21 additions & 8 deletions OpenDreamClient/Rendering/ClientDreamParticlesSystem.cs
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
using JetBrains.Annotations;
using OpenDreamShared.Rendering;
using Pidgin;
using Robust.Client.Graphics;
using Robust.Client.ResourceManagement;
using Robust.Shared.Random;
using Robust.Shared.Timing;
using Vector3 = Robust.Shared.Maths.Vector3;

namespace OpenDreamClient.Rendering;
Expand All @@ -12,13 +14,19 @@ public sealed class ClientDreamParticlesSystem : SharedDreamParticlesSystem
{
[Dependency] private readonly ParticlesManager _particlesManager = default!;
[Dependency] private readonly IResourceCache _resourceCache = default!;
[Dependency] private readonly IGameTiming _gameTiming = default!;
[Dependency] private readonly ClientAppearanceSystem _appearanceSystem = default!;
[Dependency] private readonly IClyde _clyde = default!;
public RenderTargetPool RenderTargetPool = default!;
private Random random = new();
private RendererMetaData defaultRenderMetaData = new(); //used for icon GetTexture(), never needs anything but default settings

public override void Initialize() {
base.Initialize();
SubscribeLocalEvent<DreamParticlesComponent, ComponentChange>(OnDreamParticlesComponentChange);
SubscribeLocalEvent<DreamParticlesComponent, ComponentAdd>(HandleComponentAdd);
SubscribeLocalEvent<DreamParticlesComponent, ComponentRemove>(HandleComponentRemove);
RenderTargetPool = new(_clyde);
}

private void OnDreamParticlesComponentChange(EntityUid uid, DreamParticlesComponent component, ref ComponentChange args)
Expand All @@ -42,20 +50,25 @@ private ParticleSystemArgs GetParticleSystemArgs(DreamParticlesComponent compone
Func<Texture> textureFunc;
if(component.TextureList is null || component.TextureList.Length == 0)
textureFunc = () => Texture.White;
else
textureFunc = () => _resourceCache.GetResource<TextureResource>(new Random().Pick(component.TextureList)); //TODO

else{
List<DreamIcon> icons = new(component.TextureList.Length);
foreach(var appearance in component.TextureList){
DreamIcon icon = new DreamIcon(RenderTargetPool, _gameTiming, _clyde, _appearanceSystem);
icon.SetAppearance(appearance.MustGetId());
icons.Add(icon);
}
textureFunc = () => random.Pick(icons).GetTexture(null!, null!, defaultRenderMetaData, null)!; //oh god, so hacky
}
var result = new ParticleSystemArgs(textureFunc, new Vector2i(component.Width, component.Height), (uint)component.Count, component.Spawning);

GeneratorFloat lifespan = new();
result.Lifespan = GetGeneratorFloat(component.LifespanLow, component.LifespanHigh, component.LifespanType);
result.Fadein = GetGeneratorFloat(component.FadeInLow, component.FadeInHigh, component.FadeInType);
result.Fadeout = GetGeneratorFloat(component.FadeOutLow, component.FadeOutHigh, component.FadeOutType);
if(component.ColorList.Length > 0)
if(component.Gradient.Length > 0)
result.Color = (float lifetime) => {
var colorIndex = (int)(lifetime * component.ColorList.Length);
colorIndex = Math.Clamp(colorIndex, 0, component.ColorList.Length - 1);
return component.ColorList[colorIndex];
var colorIndex = (int)(lifetime * component.Gradient.Length);
colorIndex = Math.Clamp(colorIndex, 0, component.Gradient.Length - 1);
return component.Gradient[colorIndex];
};
else
result.Color = (float lifetime) => Color.White;
Expand Down
20 changes: 20 additions & 0 deletions TestGame/code.dm
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,25 @@
spawn(20)
toggleBlink()

/particles/swarm/bees
icon = 'icons/bee.dmi'
icon_state = list("mini-bee"=1, "mini-bee2"=1)
friction = 0.1
count = 10
spawning = 0.35
fade = 5
fadein = 5
lifespan = generator("num", 50, 80, LINEAR_RAND)
width = 64
position = generator("box", list(-10,-10,0), list(10,10,50))
bound1 = list(-32, -32, -100)
bound2 = list(32, 32, 100)
gravity = list(0, -0.1)
drift = generator("box", list(-0.4, -0.1, 0), list(0.4, 0.15, 0))
velocity = generator("box", list(-2, -0.1, 0), list(2, 0.5, 0))
height = 64


/mob
icon = 'icons/mob.dmi'
icon_state = "mob"
Expand All @@ -62,6 +81,7 @@
desc = "Such a beautiful smile."
gender = MALE
see_invisible = 101
particles = new /particles/swarm/bees

New()
..()
Expand Down
Binary file added TestGame/icons/bee.dmi
Binary file not shown.

0 comments on commit dda9e5e

Please sign in to comment.