From b0bdd44e18f9e767560ba55730e65b2752651406 Mon Sep 17 00:00:00 2001 From: Timothy Warren Date: Wed, 19 Jan 2022 09:38:41 -0500 Subject: [PATCH] Add MagicItem component --- src/components.rs | 5 +++++ src/components/enums.rs | 7 +++++++ src/main.rs | 40 +++++++++++++++++++++------------------- src/saveload_system.rs | 2 ++ 4 files changed, 35 insertions(+), 19 deletions(-) diff --git a/src/components.rs b/src/components.rs index 02288c1..3060ae3 100644 --- a/src/components.rs +++ b/src/components.rs @@ -374,6 +374,11 @@ pub struct ApplyTeleport { pub dest_depth: i32, } +#[derive(Component, Debug, Serialize, Deserialize, Clone)] +pub struct MagicItem { + pub class: MagicItemClass, +} + // Serialization helper code. We need to implement ConvertSaveLoad for each type that contains an // Entity. diff --git a/src/components/enums.rs b/src/components/enums.rs index 67469cd..18de847 100644 --- a/src/components/enums.rs +++ b/src/components/enums.rs @@ -41,3 +41,10 @@ pub enum WeaponAttribute { Might, Quickness, } + +#[derive(Debug, Serialize, Deserialize, Clone, Eq, PartialEq, Hash)] +pub enum MagicItemClass { + Common, + Rare, + Legendary, +} diff --git a/src/main.rs b/src/main.rs index 6a62712..a14c86d 100644 --- a/src/main.rs +++ b/src/main.rs @@ -30,7 +30,6 @@ mod visibility_system; #[macro_use] extern crate lazy_static; -use ::rltk::{Point, RandomNumberGenerator}; use ::specs::prelude::*; use ::specs::saveload::{SimpleMarker, SimpleMarkerAllocator}; use components::*; @@ -41,11 +40,11 @@ pub use state::*; /// Cut down on the amount of syntax to register components macro_rules! register { - // $gs is needed to get the scope at the usage point + // $state is needed to get the scope at the usage point // $Type is the Component type that is being registered - ($gs: ident <- $( $Type: ty ),*,) => { + ($state: ident <- $( $Type: ty ),*,) => { $( - $gs.ecs.register::<$Type>(); + $state.ecs.register::<$Type>(); )* } } @@ -56,10 +55,10 @@ fn main() -> ::rltk::BError { .with_title("Roguelike Tutorial") .build()?; - let mut gs = State::new(); + let mut state = State::new(); register!( - gs <- + state <- ApplyMove, ApplyTeleport, AreaOfEffect, @@ -85,6 +84,7 @@ fn main() -> ::rltk::BError { Item, LightSource, LootTable, + MagicItem, MagicMapper, MeleeWeapon, MoveMode, @@ -120,24 +120,26 @@ fn main() -> ::rltk::BError { Wearable, ); - gs.ecs.insert(SimpleMarkerAllocator::::new()); + state + .ecs + .insert(SimpleMarkerAllocator::::new()); raws::load_raws(); - gs.ecs.insert(map::MasterDungeonMap::new()); - gs.ecs.insert(Map::new(1, 64, 64, "New Map")); - gs.ecs.insert(Point::zero()); - gs.ecs.insert(RandomNumberGenerator::new()); + state.ecs.insert(MasterDungeonMap::new()); + state.ecs.insert(Map::new(1, 64, 64, "New Map")); + state.ecs.insert(::rltk::Point::zero()); + state.ecs.insert(::rltk::RandomNumberGenerator::new()); - let player_entity = spawner::player(&mut gs.ecs, 0, 0); - gs.ecs.insert(player_entity); + let player_entity = spawner::player(&mut state.ecs, 0, 0); + state.ecs.insert(player_entity); - gs.ecs.insert(RunState::MapGeneration {}); - gs.ecs.insert(GameLog::new("Welcome to Rusty Roguelike")); - gs.ecs.insert(particle_system::ParticleBuilder::new()); - gs.ecs.insert(rex_assets::RexAssets::new()); + state.ecs.insert(RunState::MapGeneration {}); + state.ecs.insert(GameLog::new("Welcome to Rusty Roguelike")); + state.ecs.insert(particle_system::ParticleBuilder::new()); + state.ecs.insert(rex_assets::RexAssets::new()); - gs.generate_world_map(1, 0); + state.generate_world_map(1, 0); - ::rltk::main_loop(context, gs) + ::rltk::main_loop(context, state) } diff --git a/src/saveload_system.rs b/src/saveload_system.rs index 7ee3183..484a06b 100644 --- a/src/saveload_system.rs +++ b/src/saveload_system.rs @@ -86,6 +86,7 @@ pub fn save_game(ecs: &mut World) { Item, LightSource, LootTable, + MagicItem, MagicMapper, MeleeWeapon, MoveMode, @@ -199,6 +200,7 @@ pub fn load_game(ecs: &mut World) { Item, LightSource, LootTable, + MagicItem, MagicMapper, MeleeWeapon, MoveMode,