Display map, most of the time
This commit is contained in:
parent
e0a634464e
commit
eb8f4d514f
5 changed files with 17 additions and 32 deletions
|
@ -37,14 +37,13 @@ mod planetwars;
|
|||
mod routes;
|
||||
mod util;
|
||||
use util::Games;
|
||||
use util::COLOURS;
|
||||
|
||||
use rocket_contrib::templates::{Template, Engines};
|
||||
use rocket_contrib::templates::tera::{self, Value};
|
||||
|
||||
use std::collections::HashMap;
|
||||
|
||||
const COLOURS: [&'static str; 9] = ["grey", "blue", "cyan", "green", "yellow", "orange", "red", "pink", "purple"];
|
||||
|
||||
fn calc_viewbox(value: Value, _: HashMap<String, Value>) -> tera::Result<Value> {
|
||||
let mut min_x = std::f64::MAX;
|
||||
let mut min_y = std::f64::MAX;
|
||||
|
@ -79,7 +78,6 @@ async fn main() {
|
|||
pool.spawn_ok(fut.map(|_| ()));
|
||||
let gm = create_game_manager("0.0.0.0:9142", pool.clone()).await;
|
||||
|
||||
|
||||
let mut routes = Vec::new();
|
||||
routes::fuel(&mut routes);
|
||||
|
||||
|
@ -88,7 +86,6 @@ async fn main() {
|
|||
engines.tera.register_filter("get_colour", get_colour);
|
||||
});
|
||||
|
||||
|
||||
rocket::ignite()
|
||||
.manage(gm)
|
||||
.manage(pool)
|
||||
|
|
|
@ -23,10 +23,11 @@ pub struct PlanetWarsGame {
|
|||
log_file: File,
|
||||
turns: u64,
|
||||
name: String,
|
||||
map: String,
|
||||
}
|
||||
|
||||
impl PlanetWarsGame {
|
||||
pub fn new(state: pw_rules::PlanetWars, location: &str, name: &str) -> Self {
|
||||
pub fn new(state: pw_rules::PlanetWars, location: &str, name: &str, map: &str) -> Self {
|
||||
let planet_map = state
|
||||
.planets
|
||||
.iter()
|
||||
|
@ -46,6 +47,7 @@ impl PlanetWarsGame {
|
|||
log_file: file,
|
||||
turns: 0,
|
||||
name: name.to_string(),
|
||||
map: map.to_string(),
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -197,8 +199,9 @@ impl game::Controller for PlanetWarsGame {
|
|||
Some(json!({
|
||||
"winners": self.state.living_players(),
|
||||
"turns": self.state.turn_num,
|
||||
"name": self.name.clone(),
|
||||
"file": self.log_file_loc.clone(),
|
||||
"name": self.name,
|
||||
"map": self.map,
|
||||
"file": self.log_file_loc,
|
||||
}))
|
||||
} else {
|
||||
None
|
||||
|
@ -212,5 +215,6 @@ pub struct FinishedState {
|
|||
pub turns: u64,
|
||||
pub name: String,
|
||||
pub file: String,
|
||||
pub map: String,
|
||||
pub players: Vec<(u64, String)>,
|
||||
}
|
||||
|
|
|
@ -165,7 +165,7 @@ fn build_builder(
|
|||
};
|
||||
|
||||
let game =
|
||||
planetwars::PlanetWarsGame::new(config.create_game(number_of_clients as usize), &generate_string_id(), name);
|
||||
planetwars::PlanetWarsGame::new(config.create_game(number_of_clients as usize), &generate_string_id(), name, map);
|
||||
|
||||
let players: Vec<PlayerId> = (0..number_of_clients).collect();
|
||||
|
||||
|
|
|
@ -94,17 +94,18 @@ impl Ord for GameState {
|
|||
}
|
||||
}
|
||||
|
||||
use std::path::PathBuf;
|
||||
impl From<FinishedState> for GameState {
|
||||
fn from(mut state: FinishedState) -> Self {
|
||||
state.players.sort_by_key(|x| x.0);
|
||||
|
||||
GameState::Finished {
|
||||
map: String::new(),
|
||||
players: state
|
||||
.players
|
||||
.iter()
|
||||
.map(|(id, name)| (name.clone(), state.winners.contains(&id)))
|
||||
.collect(),
|
||||
.players
|
||||
.iter()
|
||||
.map(|(id, name)| (name.clone(), state.winners.contains(&id)))
|
||||
.collect(),
|
||||
map: PathBuf::from(state.map).file_stem().and_then(|x| x.to_str()).unwrap().to_string(),
|
||||
name: state.name,
|
||||
turns: state.turns,
|
||||
file: state.file,
|
||||
|
@ -112,23 +113,6 @@ impl From<FinishedState> for GameState {
|
|||
}
|
||||
}
|
||||
|
||||
/// Visualiser game option
|
||||
#[derive(Serialize)]
|
||||
pub struct GameOption {
|
||||
name: String,
|
||||
location: String,
|
||||
turns: u64,
|
||||
}
|
||||
impl GameOption {
|
||||
pub fn new(name: &str, location: &str, turns: u64) -> Self {
|
||||
Self {
|
||||
name: name.to_string(),
|
||||
location: location.to_string(),
|
||||
turns,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Serialize)]
|
||||
struct Link {
|
||||
name: String,
|
||||
|
@ -218,7 +202,7 @@ use futures::stream::StreamExt;
|
|||
pub async fn get_games() -> Vec<GameState> {
|
||||
match fs::File::open("games.ini").await {
|
||||
Ok(file) => {
|
||||
let mut file = BufReader::new(file);
|
||||
let file = BufReader::new(file);
|
||||
file.lines()
|
||||
.filter_map(move |maybe| async {
|
||||
maybe
|
||||
|
|
|
@ -4,7 +4,7 @@
|
|||
<h2 class="handle">
|
||||
<label for="handle_{{loop.index}}">
|
||||
<span>{{state.name}} ({{state.map}})</span>
|
||||
<span style="float: right">{% if state.type == "Finished" %}Done{% else %}{{ state.connected }}/{{state.total}}{% endif %}</span>
|
||||
<span style="float: right">{% if state.type == "Playing" %}{{ state.connected }}/{{state.total}}{% endif %}</span>
|
||||
</label>
|
||||
</h2>
|
||||
<div class="content">
|
||||
|
|
Loading…
Reference in a new issue