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 routes;
|
||||||
mod util;
|
mod util;
|
||||||
use util::Games;
|
use util::Games;
|
||||||
|
use util::COLOURS;
|
||||||
|
|
||||||
use rocket_contrib::templates::{Template, Engines};
|
use rocket_contrib::templates::{Template, Engines};
|
||||||
use rocket_contrib::templates::tera::{self, Value};
|
use rocket_contrib::templates::tera::{self, Value};
|
||||||
|
|
||||||
use std::collections::HashMap;
|
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> {
|
fn calc_viewbox(value: Value, _: HashMap<String, Value>) -> tera::Result<Value> {
|
||||||
let mut min_x = std::f64::MAX;
|
let mut min_x = std::f64::MAX;
|
||||||
let mut min_y = std::f64::MAX;
|
let mut min_y = std::f64::MAX;
|
||||||
|
@ -79,7 +78,6 @@ async fn main() {
|
||||||
pool.spawn_ok(fut.map(|_| ()));
|
pool.spawn_ok(fut.map(|_| ()));
|
||||||
let gm = create_game_manager("0.0.0.0:9142", pool.clone()).await;
|
let gm = create_game_manager("0.0.0.0:9142", pool.clone()).await;
|
||||||
|
|
||||||
|
|
||||||
let mut routes = Vec::new();
|
let mut routes = Vec::new();
|
||||||
routes::fuel(&mut routes);
|
routes::fuel(&mut routes);
|
||||||
|
|
||||||
|
@ -88,7 +86,6 @@ async fn main() {
|
||||||
engines.tera.register_filter("get_colour", get_colour);
|
engines.tera.register_filter("get_colour", get_colour);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
||||||
rocket::ignite()
|
rocket::ignite()
|
||||||
.manage(gm)
|
.manage(gm)
|
||||||
.manage(pool)
|
.manage(pool)
|
||||||
|
|
|
@ -23,10 +23,11 @@ pub struct PlanetWarsGame {
|
||||||
log_file: File,
|
log_file: File,
|
||||||
turns: u64,
|
turns: u64,
|
||||||
name: String,
|
name: String,
|
||||||
|
map: String,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl PlanetWarsGame {
|
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
|
let planet_map = state
|
||||||
.planets
|
.planets
|
||||||
.iter()
|
.iter()
|
||||||
|
@ -46,6 +47,7 @@ impl PlanetWarsGame {
|
||||||
log_file: file,
|
log_file: file,
|
||||||
turns: 0,
|
turns: 0,
|
||||||
name: name.to_string(),
|
name: name.to_string(),
|
||||||
|
map: map.to_string(),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -197,8 +199,9 @@ impl game::Controller for PlanetWarsGame {
|
||||||
Some(json!({
|
Some(json!({
|
||||||
"winners": self.state.living_players(),
|
"winners": self.state.living_players(),
|
||||||
"turns": self.state.turn_num,
|
"turns": self.state.turn_num,
|
||||||
"name": self.name.clone(),
|
"name": self.name,
|
||||||
"file": self.log_file_loc.clone(),
|
"map": self.map,
|
||||||
|
"file": self.log_file_loc,
|
||||||
}))
|
}))
|
||||||
} else {
|
} else {
|
||||||
None
|
None
|
||||||
|
@ -212,5 +215,6 @@ pub struct FinishedState {
|
||||||
pub turns: u64,
|
pub turns: u64,
|
||||||
pub name: String,
|
pub name: String,
|
||||||
pub file: String,
|
pub file: String,
|
||||||
|
pub map: String,
|
||||||
pub players: Vec<(u64, String)>,
|
pub players: Vec<(u64, String)>,
|
||||||
}
|
}
|
||||||
|
|
|
@ -165,7 +165,7 @@ fn build_builder(
|
||||||
};
|
};
|
||||||
|
|
||||||
let game =
|
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();
|
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 {
|
impl From<FinishedState> for GameState {
|
||||||
fn from(mut state: FinishedState) -> Self {
|
fn from(mut state: FinishedState) -> Self {
|
||||||
state.players.sort_by_key(|x| x.0);
|
state.players.sort_by_key(|x| x.0);
|
||||||
|
|
||||||
GameState::Finished {
|
GameState::Finished {
|
||||||
map: String::new(),
|
|
||||||
players: state
|
players: state
|
||||||
.players
|
.players
|
||||||
.iter()
|
.iter()
|
||||||
.map(|(id, name)| (name.clone(), state.winners.contains(&id)))
|
.map(|(id, name)| (name.clone(), state.winners.contains(&id)))
|
||||||
.collect(),
|
.collect(),
|
||||||
|
map: PathBuf::from(state.map).file_stem().and_then(|x| x.to_str()).unwrap().to_string(),
|
||||||
name: state.name,
|
name: state.name,
|
||||||
turns: state.turns,
|
turns: state.turns,
|
||||||
file: state.file,
|
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)]
|
#[derive(Serialize)]
|
||||||
struct Link {
|
struct Link {
|
||||||
name: String,
|
name: String,
|
||||||
|
@ -218,7 +202,7 @@ use futures::stream::StreamExt;
|
||||||
pub async fn get_games() -> Vec<GameState> {
|
pub async fn get_games() -> Vec<GameState> {
|
||||||
match fs::File::open("games.ini").await {
|
match fs::File::open("games.ini").await {
|
||||||
Ok(file) => {
|
Ok(file) => {
|
||||||
let mut file = BufReader::new(file);
|
let file = BufReader::new(file);
|
||||||
file.lines()
|
file.lines()
|
||||||
.filter_map(move |maybe| async {
|
.filter_map(move |maybe| async {
|
||||||
maybe
|
maybe
|
||||||
|
|
|
@ -4,7 +4,7 @@
|
||||||
<h2 class="handle">
|
<h2 class="handle">
|
||||||
<label for="handle_{{loop.index}}">
|
<label for="handle_{{loop.index}}">
|
||||||
<span>{{state.name}} ({{state.map}})</span>
|
<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>
|
</label>
|
||||||
</h2>
|
</h2>
|
||||||
<div class="content">
|
<div class="content">
|
||||||
|
|
Loading…
Reference in a new issue