From 2eaddd493db71a4cb5de668473ce39f9051d0d75 Mon Sep 17 00:00:00 2001
From: Quaternions <krakow20@gmail.com>
Date: Wed, 22 Jan 2025 08:54:39 -0800
Subject: [PATCH] session: use replay directory

---
 engine/session/src/session.rs       | 18 ++++++++++++++----
 strafe-client/src/physics_worker.rs |  4 +++-
 strafe-client/src/window.rs         |  1 +
 3 files changed, 18 insertions(+), 5 deletions(-)

diff --git a/engine/session/src/session.rs b/engine/session/src/session.rs
index 7749f2ba..c5f63293 100644
--- a/engine/session/src/session.rs
+++ b/engine/session/src/session.rs
@@ -12,6 +12,7 @@ use strafesnet_common::physics::{
 };
 use strafesnet_common::timer::{Scaled,Timer};
 use strafesnet_common::session::{TimeInner as SessionTimeInner,Time as SessionTime};
+use strafesnet_settings::directories::Directories;
 
 use crate::mouse_interpolator::{MouseInterpolator,StepInstruction,Instruction as MouseInterpolatorInstruction};
 use strafesnet_physics::physics::{self,PhysicsContext,PhysicsData};
@@ -149,6 +150,7 @@ enum ViewState{
 }
 
 pub struct Session{
+	directories:Directories,
 	user_settings:UserSettings,
 	mouse_interpolator:crate::mouse_interpolator::MouseInterpolator,
 	view_state:ViewState,
@@ -163,10 +165,12 @@ pub struct Session{
 impl Session{
 	pub fn new(
 		user_settings:UserSettings,
+		directories:Directories,
 		simulation:Simulation,
 	)->Self{
 		Self{
 			user_settings,
+			directories,
 			mouse_interpolator:MouseInterpolator::new(),
 			geometry_shared:Default::default(),
 			simulation,
@@ -295,11 +299,17 @@ impl InstructionConsumer<Instruction<'_>> for Session{
 				match view_state{
 					ViewState::Play=>(),
 					ViewState::Replay(bot_id)=>if let Some(replay)=self.replays.remove(&bot_id){
-						let file_name=format!("replays/{}.snfb",ins.time);
+						let mut replays_path=self.directories.replays.clone();
+						let file_name=format!("{}.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),strafesnet_physics::VERSION.get(),replay.recording.instructions).unwrap();
+							std::fs::create_dir_all(replays_path.as_path()).unwrap();
+							replays_path.push(file_name);
+							let file=std::fs::File::create(replays_path).unwrap();
+							strafesnet_snf::bot::write_bot(
+								std::io::BufWriter::new(file),
+								strafesnet_physics::VERSION.get(),
+								replay.recording.instructions
+							).unwrap();
 							println!("Finished writing bot file!");
 						});
 					},
diff --git a/strafe-client/src/physics_worker.rs b/strafe-client/src/physics_worker.rs
index a597c03a..4b18740f 100644
--- a/strafe-client/src/physics_worker.rs
+++ b/strafe-client/src/physics_worker.rs
@@ -1,5 +1,5 @@
 use crate::graphics_worker::Instruction as GraphicsInstruction;
-use strafesnet_settings::settings;
+use strafesnet_settings::{directories::Directories,settings};
 use strafesnet_session::session::{
 	Session,Simulation,SessionInputInstruction,SessionControlInstruction,SessionPlaybackInstruction,ImplicitModeInstruction,
 	Instruction as SessionInstruction,
@@ -21,6 +21,7 @@ pub enum Instruction{
 
 pub fn new<'a>(
 	mut graphics_worker:crate::compat_worker::INWorker<'a,crate::graphics_worker::Instruction>,
+	directories:Directories,
 	user_settings:settings::UserSettings,
 )->crate::compat_worker::QNWorker<'a,TimedInstruction<Instruction,SessionTimeInner>>{
 	let physics=strafesnet_physics::physics::PhysicsState::default();
@@ -28,6 +29,7 @@ pub fn new<'a>(
 	let simulation=Simulation::new(timer,physics);
 	let mut session=Session::new(
 		user_settings,
+		directories,
 		simulation,
 	);
 	crate::compat_worker::QNWorker::new(move |ins:TimedInstruction<Instruction,SessionTimeInner>|{
diff --git a/strafe-client/src/window.rs b/strafe-client/src/window.rs
index 985291c9..b2139cde 100644
--- a/strafe-client/src/window.rs
+++ b/strafe-client/src/window.rs
@@ -232,6 +232,7 @@ pub fn worker<'a>(
 		window,
 		physics_thread:crate::physics_worker::new(
 			graphics_thread,
+			directories,
 			user_settings,
 		),
 	};