From d277384cc5147ee061653295e3ddd15848d0bd74 Mon Sep 17 00:00:00 2001 From: Llywelwyn Date: Mon, 21 Aug 2023 23:12:49 +0100 Subject: [PATCH] animation framework stuff --- raws/items.json | 8 ++++---- src/components.rs | 3 +++ src/effects/particles.rs | 13 +++++++------ src/raws/rawmaster.rs | 21 ++++++++++++--------- 4 files changed, 26 insertions(+), 19 deletions(-) diff --git a/raws/items.json b/raws/items.json index 328a9c0..cf3519c 100644 --- a/raws/items.json +++ b/raws/items.json @@ -26,7 +26,7 @@ "weight": 0.5, "value": 50, "flags": ["CONSUMABLE", "DESTRUCTIBLE"], - "effects": { "particle_line": "*;#53f06d;75.0;#f9ff9f;100.0", "ranged": "12", "healing": "1d4+2" }, + "effects": { "particle_line": "*;-;#53f06d;75.0;#f9ff9f;100.0", "ranged": "12", "healing": "1d4+2" }, "magic": { "class": "uncommon", "naming": "scroll" } }, { @@ -46,7 +46,7 @@ "weight": 0.5, "value": 50, "flags": ["CONSUMABLE", "DESTRUCTIBLE"], - "effects": { "particle_line": "*;#00b7ff;75.0;#f4fc83;100.0", "ranged": "12", "damage": "3d4+3" }, + "effects": { "particle_line": "*;-;#00b7ff;75.0;#f4fc83;100.0", "ranged": "12", "damage": "3d4+3" }, "magic": { "class": "uncommon", "naming": "scroll" } }, { @@ -67,7 +67,7 @@ "value": 200, "flags": ["CONSUMABLE", "DESTRUCTIBLE"], "effects": { - "particle_burst": "*;#FFA500;#000000;600.0;#ff9595;75.0", + "particle_burst": "▓;*;~;#FFA500;#000000;500.0;#ffd381;60.0", "ranged": "10", "damage": "8d6", "aoe": "3" @@ -81,7 +81,7 @@ "weight": 0.5, "value": 100, "flags": ["CONSUMABLE", "DESTRUCTIBLE"], - "effects": { "particle_line": "*;#ad56a6;75.0;#cacaca;100.0", "ranged": "10", "confusion": "4" }, + "effects": { "particle_line": "*;-;#ad56a6;75.0;#cacaca;100.0", "ranged": "10", "confusion": "4" }, "magic": { "class": "uncommon", "naming": "scroll" } }, { diff --git a/src/components.rs b/src/components.rs index a4d9220..341701d 100644 --- a/src/components.rs +++ b/src/components.rs @@ -413,6 +413,7 @@ pub struct Charges { #[derive(Component, Serialize, Deserialize, Clone)] pub struct SpawnParticleLine { pub glyph: rltk::FontCharType, + pub tail_glyph: rltk::FontCharType, pub colour: RGB, pub lifetime_ms: f32, pub trail_colour: RGB, @@ -429,6 +430,8 @@ pub struct SpawnParticleSimple { #[derive(Component, Serialize, Deserialize, Clone)] pub struct SpawnParticleBurst { pub glyph: rltk::FontCharType, + pub head_glyph: rltk::FontCharType, + pub tail_glyph: rltk::FontCharType, pub colour: RGB, pub lerp: RGB, pub lifetime_ms: f32, diff --git a/src/effects/particles.rs b/src/effects/particles.rs index 4cb05cd..6b7e491 100644 --- a/src/effects/particles.rs +++ b/src/effects/particles.rs @@ -40,11 +40,12 @@ pub fn handle_burst_particles(ecs: &World, entity: Entity, target: &Targets) { start_pos, end_pos, &SpawnParticleLine { - glyph: part.glyph, + glyph: part.head_glyph, + tail_glyph: part.tail_glyph, colour: part.colour, - trail_colour: part.colour, + trail_colour: part.trail_colour, lifetime_ms: part.trail_lifetime_ms, // 75.0 is good here. - trail_lifetime_ms: part.trail_lifetime_ms + 25.0, + trail_lifetime_ms: part.trail_lifetime_ms, }, ); let map = ecs.fetch::(); @@ -53,7 +54,7 @@ pub fn handle_burst_particles(ecs: &World, entity: Entity, target: &Targets) { Point::new(start_pos % map.width, start_pos / map.width), Point::new(end_pos % map.width, end_pos / map.width), ); - let burst_delay = line.len() as f32 * 75.0; + let burst_delay = line.len() as f32 * part.trail_lifetime_ms; for i in 0..10 { add_effect( None, @@ -62,7 +63,7 @@ pub fn handle_burst_particles(ecs: &World, entity: Entity, target: &Targets) { fg: part.colour.lerp(part.lerp, i as f32 * 0.1), bg: RGB::named(BLACK), lifespan: part.lifetime_ms / 10.0, // ~50-80 is good here. - delay: burst_delay + (i as f32 * part.lifetime_ms / 10.0), + delay: burst_delay + (i as f32 * part.lifetime_ms / 10.0), // above + burst_delay }, target.clone(), ); @@ -148,7 +149,7 @@ fn spawn_line_particles(ecs: &World, start: i32, end: i32, part: &SpawnParticleL add_effect( None, EffectType::Particle { - glyph: to_cp437('-'), + glyph: part.tail_glyph, fg: part.trail_colour, bg: RGB::named(BLACK), lifespan: part.trail_lifetime_ms, diff --git a/src/raws/rawmaster.rs b/src/raws/rawmaster.rs index 41aae0a..bada954 100644 --- a/src/raws/rawmaster.rs +++ b/src/raws/rawmaster.rs @@ -883,10 +883,11 @@ fn parse_particle_line(n: &str) -> SpawnParticleLine { let tokens: Vec<_> = n.split(';').collect(); SpawnParticleLine { glyph: to_cp437(tokens[0].chars().next().unwrap()), - colour: RGB::from_hex(tokens[1]).expect("Invalid RGB"), - lifetime_ms: tokens[2].parse::().unwrap(), - trail_colour: RGB::from_hex(tokens[3]).expect("Invalid trail RGB"), - trail_lifetime_ms: tokens[4].parse::().unwrap(), + tail_glyph: to_cp437(tokens[1].chars().next().unwrap()), + colour: RGB::from_hex(tokens[2]).expect("Invalid RGB"), + lifetime_ms: tokens[3].parse::().unwrap(), + trail_colour: RGB::from_hex(tokens[4]).expect("Invalid trail RGB"), + trail_lifetime_ms: tokens[5].parse::().unwrap(), } } @@ -903,10 +904,12 @@ fn parse_particle_burst(n: &str) -> SpawnParticleBurst { let tokens: Vec<_> = n.split(';').collect(); SpawnParticleBurst { glyph: to_cp437(tokens[0].chars().next().unwrap()), - colour: RGB::from_hex(tokens[1]).expect("Invalid RGB"), - lerp: RGB::from_hex(tokens[2]).expect("Invalid LERP RGB"), - lifetime_ms: tokens[3].parse::().unwrap(), - trail_colour: RGB::from_hex(tokens[4]).expect("Invalid trail RGB"), - trail_lifetime_ms: tokens[5].parse::().unwrap(), + head_glyph: to_cp437(tokens[1].chars().next().unwrap()), + tail_glyph: to_cp437(tokens[2].chars().next().unwrap()), + colour: RGB::from_hex(tokens[3]).expect("Invalid RGB"), + lerp: RGB::from_hex(tokens[4]).expect("Invalid LERP RGB"), + lifetime_ms: tokens[5].parse::().unwrap(), + trail_colour: RGB::from_hex(tokens[6]).expect("Invalid trail RGB"), + trail_lifetime_ms: tokens[7].parse::().unwrap(), } }