From 1cbb70f29459c0e42dfc0c2f8fa01c6f1df91ebd Mon Sep 17 00:00:00 2001 From: Timothy Warren Date: Thu, 20 Jan 2022 16:31:03 -0500 Subject: [PATCH] Add new components for dynamically created particle effects --- src/components.rs | 16 +++++++++++++++- src/main.rs | 3 ++- src/map_builders/town.rs | 1 + src/saveload_system.rs | 39 ++++++++++++++++++++------------------- 4 files changed, 38 insertions(+), 21 deletions(-) diff --git a/src/components.rs b/src/components.rs index 114e02f..db9d403 100644 --- a/src/components.rs +++ b/src/components.rs @@ -3,7 +3,7 @@ mod tags; use std::collections::HashMap; -use ::rltk::{Point, RGB}; +use ::rltk::{FontCharType, Point, RGB}; use ::serde::{Deserialize, Serialize}; use ::specs::error::NoError; use ::specs::prelude::*; @@ -366,6 +366,20 @@ pub struct IdentifiedItem { pub name: String, } +#[derive(Component, Serialize, Deserialize, Clone)] +pub struct SpawnParticleLine { + pub glyph: FontCharType, + pub color: RGB, + pub lifetime_ms: f32, +} + +#[derive(Component, Serialize, Deserialize, Clone)] +pub struct SpawnParticleBurst { + pub glyph: FontCharType, + pub color: RGB, + pub lifetime_ms: f32, +} + // Serialization helper code. We need to implement ConvertSaveLoad for each type that contains an // Entity. diff --git a/src/main.rs b/src/main.rs index 4daa2bb..943f69a 100644 --- a/src/main.rs +++ b/src/main.rs @@ -103,7 +103,8 @@ fn init_state() -> State { SimpleMarker, SingleActivation, Skills, - SufferDamage, + SpawnParticleBurst, + SpawnParticleLine, TeleportTo, TownPortal, Vendor, diff --git a/src/map_builders/town.rs b/src/map_builders/town.rs index 4049bd5..6b44e41 100644 --- a/src/map_builders/town.rs +++ b/src/map_builders/town.rs @@ -416,6 +416,7 @@ impl TownBuilder { // Place items let mut to_place: Vec<&str> = vec![ "Priest", + "Altar", "Parishioner", "Parishioner", "Chair", diff --git a/src/saveload_system.rs b/src/saveload_system.rs index 7f728d1..1c5664c 100644 --- a/src/saveload_system.rs +++ b/src/saveload_system.rs @@ -1,5 +1,4 @@ -use std::fs; -use std::fs::File; +use std::fs::{self, File}; use std::path::Path; use ::rltk::Point; @@ -16,13 +15,13 @@ use crate::spatial; macro_rules! serialize_individually { ($ecs:expr, $ser:expr, $data:expr, $( $type:ty),*,) => { $( - SerializeComponents::>::serialize( - &( $ecs.read_storage::<$type>(), ), - &$data.0, - &$data.1, - &mut $ser, - ) - .unwrap(); + SerializeComponents::>::serialize( + &( $ecs.read_storage::<$type>(), ), + &$data.0, + &$data.1, + &mut $ser, + ) + .unwrap(); )* }; } @@ -108,7 +107,8 @@ pub fn save_game(ecs: &mut World) { SerializationHelper, SingleActivation, Skills, - SufferDamage, + SpawnParticleBurst, + SpawnParticleLine, TeleportTo, TownPortal, Vendor, @@ -138,14 +138,14 @@ pub fn does_save_exist() -> bool { macro_rules! deserialize_individually { ($ecs:expr, $de:expr, $data:expr, $( $type:ty),*,) => { $( - DeserializeComponents::::deserialize( - &mut ( &mut $ecs.write_storage::<$type>(), ), - &$data.0, // entities - &mut $data.1, // marker - &mut $data.2, // allocater - &mut $de, - ) - .unwrap(); + DeserializeComponents::::deserialize( + &mut ( &mut $ecs.write_storage::<$type>(), ), + &$data.0, // entities + &mut $data.1, // marker + &mut $data.2, // allocater + &mut $de, + ) + .unwrap(); )* }; } @@ -224,7 +224,8 @@ pub fn load_game(ecs: &mut World) { SerializationHelper, SingleActivation, Skills, - SufferDamage, + SpawnParticleBurst, + SpawnParticleLine, TeleportTo, TownPortal, Vendor,