aboutsummaryrefslogtreecommitdiff
path: root/planetwars-localdev/src
diff options
context:
space:
mode:
Diffstat (limited to 'planetwars-localdev/src')
-rw-r--r--planetwars-localdev/src/lib.rs40
1 files changed, 39 insertions, 1 deletions
diff --git a/planetwars-localdev/src/lib.rs b/planetwars-localdev/src/lib.rs
index 3b77efb..562e9a6 100644
--- a/planetwars-localdev/src/lib.rs
+++ b/planetwars-localdev/src/lib.rs
@@ -22,6 +22,8 @@ struct Cli {
#[derive(Subcommand)]
enum Commands {
+ /// Initialize a new project
+ InitProject(InitProjectCommand),
/// Run a match
RunMatch(RunMatchCommand),
}
@@ -34,6 +36,12 @@ struct RunMatchCommand {
bots: Vec<String>,
}
+#[derive(Parser)]
+struct InitProjectCommand {
+ /// project root directory
+ path: String,
+}
+
#[derive(Serialize, Deserialize, Debug)]
struct ProjectConfig {
bots: HashMap<String, BotConfig>,
@@ -49,6 +57,7 @@ pub async fn run() {
let matches = Cli::parse();
let res = match matches.command {
Commands::RunMatch(command) => run_match(command).await,
+ Commands::InitProject(command) => init_project(command),
};
if let Err(err) = res {
eprintln!("{}", err);
@@ -89,7 +98,10 @@ async fn run_match(command: RunMatchCommand) -> io::Result<()> {
};
match_runner::run_match(match_config).await;
-
+ println!("match completed successfully");
+ // TODO: don't hardcode match path.
+ // maybe print the match result as well?
+ println!("wrote match log to matches/{}.log", timestamp);
Ok(())
}
@@ -101,3 +113,29 @@ fn resolve_bot_config(project_dir: &Path, config: BotConfig) -> BotConfig {
argv: config.argv,
}
}
+
+macro_rules! copy_asset {
+ ($path:expr, $file_name:literal) => {
+ ::std::fs::write(
+ $path.join($file_name),
+ include_bytes!(concat!("../assets/", $file_name)),
+ )?;
+ };
+}
+
+fn init_project(command: InitProjectCommand) -> io::Result<()> {
+ let path = PathBuf::from(&command.path);
+
+ // create directories
+ std::fs::create_dir_all(&path)?;
+ std::fs::create_dir(path.join("maps"))?;
+ std::fs::create_dir(path.join("matches"))?;
+ std::fs::create_dir_all(path.join("bots/simplebot"))?;
+
+ // create files
+ copy_asset!(path, "pw_project.toml");
+ copy_asset!(path.join("maps"), "hex.json");
+ copy_asset!(path.join("bots/simplebot"), "simplebot.py");
+
+ Ok(())
+}