Clear replay players when replay ends

This commit is contained in:
Sofia 2026-07-26 19:50:37 +03:00
parent 5748a0af7b
commit f67843cc59
3 changed files with 21 additions and 2 deletions

View File

@ -346,7 +346,7 @@ impl Game {
.map(|g| g.cast::<Game>()) .map(|g| g.cast::<Game>())
} }
pub fn start_playback(&mut self, time_delta: f64) { pub fn start_playback(&mut self, time_delta: f64, spectated_id: u16) {
if let Some(recorder) = &self.replay_recorder { if let Some(recorder) = &self.replay_recorder {
let mut playback = ReplayPlayback::new_alloc(); let mut playback = ReplayPlayback::new_alloc();
playback.bind_mut().replay = recorder.bind().replay.clone(); playback.bind_mut().replay = recorder.bind().replay.clone();

View File

@ -364,7 +364,7 @@ impl ICharacterBody3D for LocalPlayer {
camera.set_current(true); camera.set_current(true);
} }
game.start_playback(-5.); game.start_playback(-5., killer_id);
} }
} }
} }

View File

@ -21,6 +21,8 @@ pub struct ReplayPlayback {
pub current_time: f64, pub current_time: f64,
pub spectated_player_id: u16,
base: Base<Node>, base: Base<Node>,
} }
@ -28,6 +30,16 @@ pub struct ReplayPlayback {
impl INode for ReplayPlayback { impl INode for ReplayPlayback {
fn ready(&mut self) {} fn ready(&mut self) {}
fn process(&mut self, _: f64) {
if let Some(character) = self.player_characters.get_mut(&self.spectated_player_id) {
if let Some(camera) = &mut character.bind_mut().spectator_camera {
if !camera.is_current() {
camera.make_current();
}
}
}
}
fn physics_process(&mut self, delta: f64) { fn physics_process(&mut self, delta: f64) {
self.current_time += delta; self.current_time += delta;
@ -77,6 +89,13 @@ impl INode for ReplayPlayback {
} }
self.current_frame_idx += 1; self.current_frame_idx += 1;
} }
if self.current_frame_idx >= self.replay.frames.len() {
for (id, mut character) in self.player_characters.clone() {
character.queue_free();
self.player_characters.remove(&id);
}
}
} }
fn exit_tree(&mut self) { fn exit_tree(&mut self) {