|  | @@ -1,57 +1,9 @@
 | 
											
												
													
														|  | -extern crate argparse;
 |  | 
 | 
											
												
													
														|  | -extern crate pancurses;
 |  | 
 | 
											
												
													
														|  | -extern crate yaml_rust;
 |  | 
 | 
											
												
													
														|  |  
 |  |  
 | 
											
												
													
														|  | -use std::fs::{File};
 |  | 
 | 
											
												
													
														|  | -use std::io::prelude::*;
 |  | 
 | 
											
												
													
														|  | -use std::process::exit;
 |  | 
 | 
											
												
													
														|  | -use std::{thread, time};
 |  | 
 | 
											
												
													
														|  | -use std::env;
 |  | 
 | 
											
												
													
														|  | -
 |  | 
 | 
											
												
													
														|  | -use argparse::{ArgumentParser, Store};
 |  | 
 | 
											
												
													
														|  | -use pancurses::{
 |  | 
 | 
											
												
													
														|  | -    initscr, endwin, noecho, has_colors, start_color, init_pair,
 |  | 
 | 
											
												
													
														|  | -    Window,
 |  | 
 | 
											
												
													
														|  | -    COLOR_GREEN, COLOR_BLACK
 |  | 
 | 
											
												
													
														|  | -};
 |  | 
 | 
											
												
													
														|  | -use yaml_rust::{YamlLoader, YamlEmitter, Yaml};
 |  | 
 | 
											
												
													
														|  | 
 |  | +mod config;
 | 
											
												
													
														|  | 
 |  | +mod screen;
 | 
											
												
													
														|  |  
 |  |  
 | 
											
												
													
														|  |  fn main() {
 |  |  fn main() {
 | 
											
												
													
														|  |  
 |  |  
 | 
											
												
													
														|  | -    // Argument handling
 |  | 
 | 
											
												
													
														|  | -    let mut difficulty = String::from("");
 |  | 
 | 
											
												
													
														|  | -    // TODO can't use ? ?
 |  | 
 | 
											
												
													
														|  | -    let foo = env::var("HOME")?.add(".config/");
 |  | 
 | 
											
												
													
														|  | -    let config_dir = match env::var("XDG_CONFIG_HOME") {
 |  | 
 | 
											
												
													
														|  | -        Ok(dir) => dir,
 |  | 
 | 
											
												
													
														|  | -        Err(_) => String::from("foo"),
 |  | 
 | 
											
												
													
														|  | -    };
 |  | 
 | 
											
												
													
														|  | -    let mut config_location = String::from("~/.config/fallout-terminal.yaml");
 |  | 
 | 
											
												
													
														|  | -    let config_help = format!("Config file location, default {}", config_location);
 |  | 
 | 
											
												
													
														|  | -    {
 |  | 
 | 
											
												
													
														|  | -        let mut ap = ArgumentParser::new();
 |  | 
 | 
											
												
													
														|  | -        ap.set_description("A Fallout terminal minigame inspired game.");
 |  | 
 | 
											
												
													
														|  | -        ap.refer(&mut difficulty)
 |  | 
 | 
											
												
													
														|  | -            .add_option(&["--difficulty"], Store, "The game's difficulty (veryEasy [default], \
 |  | 
 | 
											
												
													
														|  | -                                                   easy, average, hard, or veryHard)");
 |  | 
 | 
											
												
													
														|  | -
 |  | 
 | 
											
												
													
														|  | -        ap.refer(&mut config_location)
 |  | 
 | 
											
												
													
														|  | -            .add_option(
 |  | 
 | 
											
												
													
														|  | -                &["--config"],
 |  | 
 | 
											
												
													
														|  | -                Store,
 |  | 
 | 
											
												
													
														|  | -                config_help.as_str()
 |  | 
 | 
											
												
													
														|  | -            );
 |  | 
 | 
											
												
													
														|  | -        ap.parse_args_or_exit();
 |  | 
 | 
											
												
													
														|  | -    }
 |  | 
 | 
											
												
													
														|  | -
 |  | 
 | 
											
												
													
														|  | -    match difficulty.as_str() {
 |  | 
 | 
											
												
													
														|  | -        "" | "veryEasy" => {
 |  | 
 | 
											
												
													
														|  | -            println!("veryEasy");
 |  | 
 | 
											
												
													
														|  | -        },
 |  | 
 | 
											
												
													
														|  | -        _ => println!("Invalid difficulty, see --help")
 |  | 
 | 
											
												
													
														|  | -    }
 |  | 
 | 
											
												
													
														|  | -
 |  | 
 | 
											
												
													
														|  | -
 |  | 
 | 
											
												
													
														|  |      // Config file handling
 |  |      // Config file handling
 | 
											
												
													
														|  |      let mut config_file = match File::open(config_location.as_str()) {
 |  |      let mut config_file = match File::open(config_location.as_str()) {
 | 
											
												
													
														|  |          Ok(config_file) => config_file,
 |  |          Ok(config_file) => config_file,
 | 
											
										
											
												
													
														|  | @@ -77,45 +29,16 @@ fn main() {
 | 
											
												
													
														|  |          }
 |  |          }
 | 
											
												
													
														|  |      };
 |  |      };
 | 
											
												
													
														|  |  
 |  |  
 | 
											
												
													
														|  | 
 |  | +    // DEBUG: seeing yaml values
 | 
											
												
													
														|  |      let mut out_str = String::new();
 |  |      let mut out_str = String::new();
 | 
											
												
													
														|  |      let mut emitter = YamlEmitter::new(&mut out_str);
 |  |      let mut emitter = YamlEmitter::new(&mut out_str);
 | 
											
												
													
														|  |      for x in &config {
 |  |      for x in &config {
 | 
											
												
													
														|  |          println!("{:?}", emitter.dump(x).unwrap());
 |  |          println!("{:?}", emitter.dump(x).unwrap());
 | 
											
												
													
														|  |      }
 |  |      }
 | 
											
												
													
														|  |  
 |  |  
 | 
											
												
													
														|  | -    let window = initscr();
 |  | 
 | 
											
												
													
														|  | -    noecho();
 |  | 
 | 
											
												
													
														|  | -    window.printw("Hello from Rust");
 |  | 
 | 
											
												
													
														|  | -    window_prep();
 |  | 
 | 
											
												
													
														|  | -    intro(&window);
 |  | 
 | 
											
												
													
														|  | 
 |  | +    let window = screen::init_window();
 | 
											
												
													
														|  | 
 |  | +    screen::intro(&window);
 | 
											
												
													
														|  |      window.refresh();
 |  |      window.refresh();
 | 
											
												
													
														|  |      window.getch();
 |  |      window.getch();
 | 
											
												
													
														|  | -    endwin();
 |  | 
 | 
											
												
													
														|  | -}
 |  | 
 | 
											
												
													
														|  | -
 |  | 
 | 
											
												
													
														|  | -fn window_prep () {
 |  | 
 | 
											
												
													
														|  | -    if has_colors() {
 |  | 
 | 
											
												
													
														|  | -        start_color();
 |  | 
 | 
											
												
													
														|  | -        init_pair(1,COLOR_GREEN, COLOR_BLACK);
 |  | 
 | 
											
												
													
														|  | -    }
 |  | 
 | 
											
												
													
														|  | -}
 |  | 
 | 
											
												
													
														|  | -
 |  | 
 | 
											
												
													
														|  | -fn intro (w: &Window) {
 |  | 
 | 
											
												
													
														|  | -    fn slow_print(w: &Window, line: i32, string: String) {
 |  | 
 | 
											
												
													
														|  | -        w.mv(line, 0);
 |  | 
 | 
											
												
													
														|  | -        for c in string.chars() {
 |  | 
 | 
											
												
													
														|  | -            w.addch(c);
 |  | 
 | 
											
												
													
														|  | -            w.refresh();
 |  | 
 | 
											
												
													
														|  | -            // TODO keyboard skip
 |  | 
 | 
											
												
													
														|  | -            thread::sleep(time::Duration::from_millis(20));
 |  | 
 | 
											
												
													
														|  | -        }
 |  | 
 | 
											
												
													
														|  | -    }
 |  | 
 | 
											
												
													
														|  | -
 |  | 
 | 
											
												
													
														|  | -    w.clear();
 |  | 
 | 
											
												
													
														|  | -    thread::sleep(time::Duration::from_millis(250));
 |  | 
 | 
											
												
													
														|  | -    slow_print(&w, 0, String::from("WELCOME TO ROBCO INDUSTRIES (TM) TERMLINK"));
 |  | 
 | 
											
												
													
														|  | -
 |  | 
 | 
											
												
													
														|  | -    w.mv(1, 0);
 |  | 
 | 
											
												
													
														|  | -    w.refresh();
 |  | 
 | 
											
												
													
														|  | -    thread::sleep(time::Duration::from_millis(30));
 |  | 
 | 
											
												
													
														|  | 
 |  | +    screen::end_window();
 | 
											
												
													
														|  |  }
 |  |  }
 |