diff --git a/src/components.rs b/src/components.rs index 348ce99..dffe888 100644 --- a/src/components.rs +++ b/src/components.rs @@ -1,4 +1,4 @@ -use rltk::RGB; +use rltk::{Point, RGB}; use serde::{Deserialize, Serialize}; use specs::error::NoError; use specs::prelude::*; @@ -11,6 +11,33 @@ pub struct Position { pub y: i32, } +impl From<(i32, i32)> for Position { + fn from(f: (i32, i32)) -> Self { + Position { + x: f.0, + y: f.1, + } + } +} + +impl From for Position { + fn from(p: Point) -> Self { + Position { + x: p.x, + y: p.y, + } + } +} + +impl Into for Position { + fn into(self) -> Point { + Point { + x: self.x, + y: self.y, + } + } +} + #[derive(Component, ConvertSaveload, Clone)] pub struct Renderable { pub glyph: rltk::FontCharType, @@ -24,7 +51,7 @@ pub struct Player {} #[derive(Component, ConvertSaveload, Clone)] pub struct Viewshed { - pub visible_tiles: Vec, + pub visible_tiles: Vec, pub range: i32, pub dirty: bool, } @@ -134,7 +161,7 @@ pub struct WantsToPickupItem { #[derive(Component, Debug, ConvertSaveload)] pub struct WantsToUseItem { pub item: Entity, - pub target: Option, + pub target: Option, } #[derive(Component, Debug, ConvertSaveload)] diff --git a/src/main.rs b/src/main.rs index c1944db..a83d20a 100644 --- a/src/main.rs +++ b/src/main.rs @@ -476,14 +476,13 @@ impl State { builder.spawn_entities(&mut self.ecs); // Place the player and update resources - let (player_x, player_y) = (player_start.x, player_start.y); let mut player_position = self.ecs.write_resource::(); - *player_position = Point::new(player_x, player_y); + *player_position = player_start.into(); let mut position_components = self.ecs.write_storage::(); let player_entity = self.ecs.fetch::(); if let Some(player_pos_comp) = position_components.get_mut(*player_entity) { - player_pos_comp.x = player_x; - player_pos_comp.y = player_y; + player_pos_comp.x = player_start.x; + player_pos_comp.y = player_start.y; } // Mark the player's visibility as dirty @@ -546,12 +545,9 @@ fn main() -> rltk::BError { gs.ecs.insert(SimpleMarkerAllocator::::new()); gs.ecs.insert(Map::new(1)); - gs.ecs.insert(Point::new(0, 0)); + gs.ecs.insert(Point::zero()); gs.ecs.insert(rltk::RandomNumberGenerator::new()); - - let player_entity = spawner::player(&mut gs.ecs, 0, 0); - gs.ecs.insert(player_entity); - + gs.ecs.insert(spawner::player(&mut gs.ecs, 0, 0)); gs.ecs.insert(RunState::MapGeneration {}); gs.ecs.insert(GameLog::new("Welcome to Rusty Roguelike")); gs.ecs.insert(particle_system::ParticleBuilder::new());