From c20f1310fb3417cb1b0bf41e2d31db373751e392 Mon Sep 17 00:00:00 2001 From: Iago Garrido Date: Tue, 12 Nov 2019 16:53:13 +0100 Subject: get player name from env --- src/main.rs | 9 ++++++++- src/state.rs | 3 +-- 2 files changed, 9 insertions(+), 3 deletions(-) (limited to 'src') diff --git a/src/main.rs b/src/main.rs index b59d587..ab93eb5 100644 --- a/src/main.rs +++ b/src/main.rs @@ -16,16 +16,23 @@ use pancurses::{ Input, noecho }; +use std::env; use state::State; use world::{Dungeon}; +fn get_player_name() -> String { + match env::var_os("USER") { + Some(val) => val.into_string().unwrap(), + None => String::from("Kshar") + } +} fn main() { let window = initscr(); let mut state = State::new( Player::new( - "Kshar".to_string(), + get_player_name(), "Warrior".to_string(), 30, 10, diff --git a/src/state.rs b/src/state.rs index 8d0b164..7553f58 100644 --- a/src/state.rs +++ b/src/state.rs @@ -1,5 +1,4 @@ use pancurses::Window; -use std::env; use crate::entities::{Character, Entity, Render}; use crate::world::{Dungeon, Generatable, Level}; @@ -32,7 +31,7 @@ impl State { } pub fn show_character(&self, window: &Window) { - self.character.render(window); + self.player.render(window); } fn current_level(&self) -> &Level { -- cgit v1.2.3