From e26f13c8bba24e6f966888d5909f2803665c55a0 Mon Sep 17 00:00:00 2001 From: Ilion Beyst Date: Fri, 26 Aug 2022 19:21:30 +0200 Subject: add maps to matches api --- planetwars-server/src/modules/matches.rs | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) (limited to 'planetwars-server/src/modules/matches.rs') diff --git a/planetwars-server/src/modules/matches.rs b/planetwars-server/src/modules/matches.rs index 3826abd..ecc7976 100644 --- a/planetwars-server/src/modules/matches.rs +++ b/planetwars-server/src/modules/matches.rs @@ -7,6 +7,7 @@ use tokio::task::JoinHandle; use crate::{ db::{ self, + maps::Map, matches::{MatchData, MatchResult}, }, util::gen_alphanumeric, @@ -18,6 +19,10 @@ pub struct RunMatch { players: Vec, config: Arc, is_public: bool, + // Map is mandatory for now. + // It would be nice to allow "anonymous" (eg. randomly generated) maps + // in the future, too. + map: Map, } pub enum MatchPlayer { @@ -32,9 +37,10 @@ pub enum MatchPlayer { impl RunMatch { // TODO: create a MatchParams struct - pub fn from_players( + pub fn new( config: Arc, is_public: bool, + map: Map, players: Vec, ) -> Self { let log_file_name = format!("{}.log", gen_alphanumeric(16)); @@ -43,13 +49,14 @@ impl RunMatch { log_file_name, players, is_public, + map, } } fn into_runner_config(self) -> runner::MatchConfig { runner::MatchConfig { - map_path: PathBuf::from(&self.config.maps_directory).join("hex.json"), - map_name: "hex".to_string(), + map_path: PathBuf::from(&self.config.maps_directory).join(self.map.file_path), + map_name: self.map.name, log_path: PathBuf::from(&self.config.match_logs_directory).join(&self.log_file_name), players: self .players @@ -88,6 +95,7 @@ impl RunMatch { state: db::matches::MatchState::Playing, log_path: &self.log_file_name, is_public: self.is_public, + map_id: Some(self.map.id), }; let new_match_players = self .players -- cgit v1.2.3