Clear replay players when replay ends
This commit is contained in:
parent
5748a0af7b
commit
f67843cc59
@ -346,7 +346,7 @@ impl 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 {
|
||||
let mut playback = ReplayPlayback::new_alloc();
|
||||
playback.bind_mut().replay = recorder.bind().replay.clone();
|
||||
|
||||
@ -364,7 +364,7 @@ impl ICharacterBody3D for LocalPlayer {
|
||||
camera.set_current(true);
|
||||
}
|
||||
|
||||
game.start_playback(-5.);
|
||||
game.start_playback(-5., killer_id);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -21,6 +21,8 @@ pub struct ReplayPlayback {
|
||||
|
||||
pub current_time: f64,
|
||||
|
||||
pub spectated_player_id: u16,
|
||||
|
||||
base: Base<Node>,
|
||||
}
|
||||
|
||||
@ -28,6 +30,16 @@ pub struct ReplayPlayback {
|
||||
impl INode for ReplayPlayback {
|
||||
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) {
|
||||
self.current_time += delta;
|
||||
|
||||
@ -77,6 +89,13 @@ impl INode for ReplayPlayback {
|
||||
}
|
||||
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) {
|
||||
|
||||
Loading…
Reference in New Issue
Block a user