aboutsummaryrefslogtreecommitdiff
path: root/planetwars-cli/src/commands
diff options
context:
space:
mode:
authorIlion Beyst <ilion.beyst@gmail.com>2021-12-28 14:57:41 +0100
committerIlion Beyst <ilion.beyst@gmail.com>2021-12-28 14:57:41 +0100
commitdacc05a41b77bf2e86e27ac354db9b047c661a7d (patch)
tree3d71fa60ff3449f73ec8bb6066ae82733eb46ee4 /planetwars-cli/src/commands
parent5ca8dd4c842ee681ce81a6a7bbd5005cd5b98d3c (diff)
downloadplanetwars.dev-dacc05a41b77bf2e86e27ac354db9b047c661a7d.tar.xz
planetwars.dev-dacc05a41b77bf2e86e27ac354db9b047c661a7d.zip
refactor workspace code
Diffstat (limited to 'planetwars-cli/src/commands')
-rw-r--r--planetwars-cli/src/commands/init.rs4
-rw-r--r--planetwars-cli/src/commands/run_match.rs42
-rw-r--r--planetwars-cli/src/commands/serve.rs7
3 files changed, 19 insertions, 34 deletions
diff --git a/planetwars-cli/src/commands/init.rs b/planetwars-cli/src/commands/init.rs
index 3c9cf08..c95626b 100644
--- a/planetwars-cli/src/commands/init.rs
+++ b/planetwars-cli/src/commands/init.rs
@@ -31,8 +31,8 @@ impl InitCommand {
// create files
copy_asset!(path, "pw_workspace.toml");
copy_asset!(path.join("maps"), "hex.json");
- copy_asset!(path.join("bots/simplebot"), "simplebot.py");
-
+ copy_asset!(path.join("bots/"), "simplebot/botconfig.toml");
+ copy_asset!(path.join("bots/"), "simplebot/simplebot.py");
Ok(())
}
}
diff --git a/planetwars-cli/src/commands/run_match.rs b/planetwars-cli/src/commands/run_match.rs
index 039d89a..5b7a3ec 100644
--- a/planetwars-cli/src/commands/run_match.rs
+++ b/planetwars-cli/src/commands/run_match.rs
@@ -1,14 +1,10 @@
-use std::env;
use std::io;
use clap::Parser;
-use crate::match_runner;
-use crate::match_runner::MatchBot;
use crate::match_runner::MatchConfig;
-use crate::resolve_bot_config;
-use crate::WorkspaceConfig;
-
+use crate::match_runner::{self, MatchPlayer};
+use crate::workspace::Workspace;
#[derive(Parser)]
pub struct RunMatchCommand {
/// map name
@@ -19,30 +15,20 @@ pub struct RunMatchCommand {
impl RunMatchCommand {
pub async fn run(self) -> io::Result<()> {
- let workspace_root = env::current_dir().unwrap();
-
- let config_path = workspace_root.join("pw_workspace.toml");
-
- let map_path = workspace_root.join(format!("maps/{}.json", self.map));
+ let workspace = Workspace::open_current_dir()?;
+ let map_path = workspace.maps_dir().join(format!("{}.json", &self.map));
let timestamp = chrono::Local::now().format("%Y-%m-%d-%H-%M-%S");
- let log_path = workspace_root.join(format!("matches/{}.log", timestamp));
-
- let config_str = std::fs::read_to_string(config_path).unwrap();
- let workspace_config: WorkspaceConfig = toml::from_str(&config_str).unwrap();
-
- let players = self
- .bots
- .into_iter()
- .map(|bot_name| {
- let bot_config = workspace_config.bots.get(&bot_name).unwrap().clone();
- let resolved_config = resolve_bot_config(&workspace_root, bot_config);
- MatchBot {
- name: bot_name,
- bot_config: resolved_config,
- }
- })
- .collect();
+ let log_path = workspace.match_path(&format!("{}-{}", &self.map, &timestamp));
+
+ let mut players = Vec::new();
+ for bot_name in &self.bots {
+ let bot = workspace.get_bot(&bot_name)?;
+ players.push(MatchPlayer {
+ name: bot_name.clone(),
+ bot,
+ });
+ }
let match_config = MatchConfig {
map_name: self.map,
diff --git a/planetwars-cli/src/commands/serve.rs b/planetwars-cli/src/commands/serve.rs
index a078c83..aa8d149 100644
--- a/planetwars-cli/src/commands/serve.rs
+++ b/planetwars-cli/src/commands/serve.rs
@@ -1,18 +1,17 @@
-use std::env;
use std::io;
use clap::Parser;
use crate::web;
+use crate::workspace::Workspace;
#[derive(Parser)]
pub struct ServeCommand;
impl ServeCommand {
pub async fn run(self) -> io::Result<()> {
- let workspace_root = env::current_dir().unwrap();
-
- web::run(workspace_root).await;
+ let workspace = Workspace::open_current_dir()?;
+ web::run(workspace).await;
Ok(())
}
}