use ::specs::prelude::*; use super::{EffectSpawner, EffectType}; use crate::components::{ParticleAnimation, ParticleLifetime, Position, Renderable}; use crate::map::Map; use crate::systems::particle_system::ParticleBuilder; pub fn particle_to_tile(ecs: &mut World, tile_idx: i32, effect: &EffectSpawner) { if let EffectType::Particle { glyph, fg, bg, lifespan, } = effect.effect_type { let map = ecs.fetch::(); let mut particle_builder = ecs.fetch_mut::(); particle_builder.request( tile_idx % map.width, tile_idx / map.width, fg, bg, glyph, lifespan, ); } } pub fn projectile(ecs: &mut World, tile_idx: i32, effect: &EffectSpawner) { if let EffectType::ParticleProjectile { glyph, fg, bg, lifespan: _, speed, path, } = &effect.effect_type { let x: i32; let y: i32; { let map = ecs.fetch::(); x = tile_idx % map.width; y = tile_idx / map.width; } ecs.create_entity() .with(Position { x, y }) .with(Renderable { fg: *fg, bg: *bg, glyph: *glyph, render_order: 0, }) .with(ParticleLifetime { lifetime_ms: path.len() as f32 * speed, animation: Some(ParticleAnimation { step_time: *speed, path: path.to_vec(), current_step: 0, timer: 0.0, }), }) .build(); } }