diff --git a/backend/src/planetwars/mod.rs b/backend/src/planetwars/mod.rs index aad2c55..184db66 100644 --- a/backend/src/planetwars/mod.rs +++ b/backend/src/planetwars/mod.rs @@ -23,6 +23,7 @@ pub struct PlanetWarsGame { log_file: File, turns: u64, name: String, + logged: bool, } impl PlanetWarsGame { @@ -41,6 +42,7 @@ impl PlanetWarsGame { log_file: file, turns: 0, name: name.to_string(), + logged: false, } } @@ -192,15 +194,20 @@ impl game::Controller for PlanetWarsGame { fn is_done(&mut self) -> bool { if self.state.is_finished() { + if !self.logged { - let mut f = match OpenOptions::new().create(true).append(true).open("games.ini") { Err(_) => return true, Ok(f) => f }; - let mut conf = Ini::new(); - conf.with_section(Some(self.log_file_loc.clone())) + let mut f = match OpenOptions::new().create(true).append(true).open("games.ini") { Err(_) => return true, Ok(f) => f }; + + let mut conf = Ini::new(); + conf.with_section(Some(self.log_file_loc.clone())) .set("name", &self.name) .set("turns", format!("{}", self.turns)); - conf.write_to(&mut f).unwrap(); + conf.write_to(&mut f).unwrap(); + + self.logged = true; + } true } else { diff --git a/backend/src/routes.rs b/backend/src/routes.rs index 575c0cb..bf76d48 100644 --- a/backend/src/routes.rs +++ b/backend/src/routes.rs @@ -65,6 +65,12 @@ async fn builder_get() -> Result { Ok(Template::render("mapbuilder", &context)) } +#[get("/debug")] +async fn debug_get() -> Result { + let context = Context::new("Debug Station"); + Ok(Template::render("debug", &context)) +} + #[get("/visualizer")] async fn visualizer_get() -> Result { let game_options = get_games().await?; @@ -107,7 +113,7 @@ async fn game_post(game_req: Json, tp: State<'_, ThreadPool>, gm: State } pub fn fuel(routes: &mut Vec) { - routes.extend(routes![files, index, map_post, map_get, lobby_get, builder_get, visualizer_get, game_post, state_get]); + routes.extend(routes![files, index, map_post, map_get, lobby_get, builder_get, visualizer_get, game_post, state_get, debug_get]); } diff --git a/backend/src/util.rs b/backend/src/util.rs index 94b5a0f..ee82c7f 100644 --- a/backend/src/util.rs +++ b/backend/src/util.rs @@ -1,7 +1,7 @@ use async_std::prelude::*; use async_std::fs; -static NAV: [(&'static str, &'static str); 4] = [("/", "Home"), ("/lobby", "Lobby"), ("/mapbuilder", "Map Builder"), ("/visualizer", "Visualizer")]; +static NAV: [(&'static str, &'static str); 5] = [("/", "Home"), ("/lobby", "Lobby"), ("/mapbuilder", "Map Builder"), ("/visualizer", "Visualizer"), ("/debug", "Debug Station")]; #[derive(Serialize)] pub struct Map { diff --git a/backend/templates/debug.html.tera b/backend/templates/debug.html.tera new file mode 100644 index 0000000..2d30e65 --- /dev/null +++ b/backend/templates/debug.html.tera @@ -0,0 +1,102 @@ +{% extends "base" %} + +{% block content %} + + + + +
+ + +{% endblock %}