Created
April 13, 2018 19:04
-
-
Save TuckerBMorgan/0c80b751514e20f8145f8f80fc9327cf to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| use std::io; | |
| use std::usize; | |
| use std::collections::HashMap; | |
| use storm::input::message::*; | |
| use storm::cgmath::Vector2; | |
| use storm::render::message::*; | |
| use tactics::Controller; | |
| use tactics::overworldmap::OverworldMap; | |
| use tactics::system::ExitCodes; | |
| pub enum MapControllerState { | |
| Movement, | |
| Menu, | |
| } | |
| pub struct MapController { | |
| map: OverworldMap, | |
| waiting_for_input: bool, | |
| map_controller_state: MapControllerState, | |
| holder: HashMap<String, fn(&mut MapController, InputFrame) -> ()>, | |
| //when not in use, it is set to usize:MAX as a flag value, telling the system to disreguard input | |
| } | |
| impl MapController { | |
| pub fn new() -> MapController { | |
| MapController { | |
| map: OverworldMap::new(), | |
| map_controller_state: MapControllerState::Menu, | |
| waiting_for_input: false, | |
| holder: HashMap::new(), | |
| } | |
| } | |
| pub fn new_map(&mut self, render: &mut RenderProducer) { | |
| self.map = OverworldMap::new(); | |
| self.map.start_new_game(render); | |
| } | |
| pub fn test(&mut self) -> fn(&mut MapController) -> i32 { | |
| let i = &MapController::foo; | |
| i(self); | |
| let k = Some(i); | |
| *i | |
| } | |
| pub fn add_function_to_handler(&mut self, name: String, pass_function: fn(&mut MapController, InputFrame) -> ()) { | |
| self.holder.insert(name, pass_function); | |
| } | |
| pub fn get_input_handler(&mut self, ) -> Option<fn(&mut MapController, InputFrame) -> ()> { | |
| if self.waiting_for_input { | |
| return Some(*self.holder.get(&String::from("foo")).unwrap()); | |
| } | |
| None | |
| } | |
| pub fn input_handler(&mut self, input_frame: InputFrame) { | |
| } | |
| pub fn foo(&mut self) -> i32 { | |
| 0 | |
| } | |
| fn set_state(&mut self, new_state: MapControllerState) { | |
| self.map_controller_state = new_state; | |
| } | |
| pub fn update(&mut self, render: &mut RenderProducer) -> ExitCodes { | |
| self.map.layout_map(render); | |
| // self.input_handlers.push(Box::new(MapController::test.clone())); | |
| match self.map_controller_state { | |
| MapControllerState::Menu => { | |
| return self.menu(); | |
| }, | |
| MapControllerState::Movement => { | |
| self.movement_mode(); | |
| } | |
| } | |
| ExitCodes::Ok | |
| } | |
| #[inline] | |
| pub fn menu(&mut self) -> ExitCodes{ | |
| println!("Which mode would you like to be in"); | |
| println!("1. Movement"); | |
| println!("2. To Party Manager"); | |
| println!("3. Exit"); | |
| let mut input_raw = String::new(); | |
| let input; | |
| match io::stdin().read_line(&mut input_raw) { | |
| Ok(_n) => { | |
| input = input_raw.trim(); | |
| }, | |
| Err(e) => { | |
| panic!("{} HEMIDALL ERROR with the input for movement direction selection", e); | |
| } | |
| } | |
| if input == "1" { | |
| self.set_state(MapControllerState::Movement); | |
| return ExitCodes::Ok; | |
| } | |
| else if input == "2" { | |
| return ExitCodes::ToPartyManagerController; | |
| } | |
| else if input == "3" { | |
| return ExitCodes::Exit; | |
| } | |
| ExitCodes::Exit | |
| } | |
| #[inline] | |
| pub fn movement_mode(&mut self) { | |
| let directions = OverworldMap::find_available_movement_direction_for_party(self.map.get_party_position()); | |
| for dir in directions { | |
| println!("{:?}", dir); | |
| } | |
| println!("Exit"); | |
| let mut input_raw = String::new(); | |
| let input; | |
| match io::stdin().read_line(&mut input_raw) { | |
| Ok(_n) => { | |
| input = input_raw.trim(); | |
| }, | |
| Err(e) => { | |
| panic!("{} HEMIDALL ERROR with the input for movement direction selection", e); | |
| } | |
| } | |
| if input == "Up" { | |
| self.map.move_party_from_tile_to_tile(Vector2::new(0, 1), true); | |
| } | |
| else if input == "Down" { | |
| self.map.move_party_from_tile_to_tile(Vector2::new(0, 1), false); | |
| } | |
| else if input == "Left" { | |
| self.map.move_party_from_tile_to_tile(Vector2::new(1, 0), true); | |
| } | |
| else if input == "Right" { | |
| self.map.move_party_from_tile_to_tile(Vector2::new(1, 0), false); | |
| } | |
| else if input == "Exit" { | |
| self.set_state(MapControllerState::Menu); | |
| } | |
| } | |
| //there should be a load map function in the future | |
| } | |
| impl Controller for MapController { | |
| fn input_handler(&mut self, input: InputFrame) { | |
| let k = self.get_input_handler(); | |
| let k = k.unwrap(); | |
| k(self, input); | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment