From 9ba3484e25c0f2198e5a96208ec3d89ed2f35725 Mon Sep 17 00:00:00 2001
From: Quaternions <krakow20@gmail.com>
Date: Mon, 20 Jan 2025 05:40:11 -0800
Subject: [PATCH] create replays folder + write replay using spawned thread :)

---
 strafe-client/src/session.rs | 8 ++++++--
 tools/replays                | 1 +
 2 files changed, 7 insertions(+), 2 deletions(-)
 create mode 120000 tools/replays

diff --git a/strafe-client/src/session.rs b/strafe-client/src/session.rs
index 14843292..d6518e65 100644
--- a/strafe-client/src/session.rs
+++ b/strafe-client/src/session.rs
@@ -292,11 +292,15 @@ impl InstructionConsumer<Instruction<'_>> for Session{
 			Instruction::Control(SessionControlInstruction::SaveReplay)=>{
 				// Bind: N
 				let view_state=core::mem::replace(&mut self.view_state,ViewState::Play);
-				let file=std::fs::File::create(format!("{}.snfb",ins.time)).unwrap();
 				match view_state{
 					ViewState::Play=>(),
 					ViewState::Replay(bot_id)=>if let Some(replay)=self.replays.remove(&bot_id){
-						strafesnet_snf::bot::write_bot(std::io::BufWriter::new(file),replay.recording.instructions).unwrap();
+						let file_name=format!("replays/{}.snfb",ins.time);
+						std::thread::spawn(move ||{
+							std::fs::create_dir_all("replays").unwrap();
+							let file=std::fs::File::create(file_name).unwrap();
+							strafesnet_snf::bot::write_bot(std::io::BufWriter::new(file),replay.recording.instructions).unwrap();
+						});
 					},
 				}
 				_=self.simulation.timer.set_paused(ins.time,false);
diff --git a/tools/replays b/tools/replays
new file mode 120000
index 00000000..5b3db67c
--- /dev/null
+++ b/tools/replays
@@ -0,0 +1 @@
+/run/media/quat/Files/Documents/map-files/verify-scripts/replays
\ No newline at end of file