From f22bcad817ee354b355d29b6b289894e2d15cfaa Mon Sep 17 00:00:00 2001 From: Griffin Smith Date: Sat, 27 Jul 2019 22:16:23 -0400 Subject: Add a generic text-prompt system Add a generic text-prompt system to the Game, and use it to prompt the character for their name on startup. There's also a Promise type in util, which is used for the result of the prompt. --- src/entities/character.rs | 13 +++++++++++++ 1 file changed, 13 insertions(+) (limited to 'src/entities/character.rs') diff --git a/src/entities/character.rs b/src/entities/character.rs index 7bcb8b5c87e4..b917f140e635 100644 --- a/src/entities/character.rs +++ b/src/entities/character.rs @@ -13,6 +13,8 @@ pub struct Character { /// The position of the character, relative to the game pub position: Position, + + pub o_name: Option, } impl Character { @@ -20,6 +22,7 @@ impl Character { Character { id: None, position: Position { x: 0, y: 0 }, + o_name: None, } } @@ -31,6 +34,16 @@ impl Character { // TODO 1 } + + pub fn name<'a>(&'a self) -> &'a str { + self.o_name + .as_ref() + .expect("Character name not initialized") + } + + pub fn set_name(&mut self, name: String) { + self.o_name = Some(name); + } } entity!(Character); -- cgit 1.4.1