Make goals work correctly in replay
This commit is contained in:
parent
ba1b1bf6f1
commit
e64bcc0427
@ -153,6 +153,8 @@ pub struct ReplayPlayback {
|
|||||||
|
|
||||||
pub finished: bool,
|
pub finished: bool,
|
||||||
|
|
||||||
|
pub running_goals: HashMap<u8, u16>,
|
||||||
|
|
||||||
base: Base<Node>,
|
base: Base<Node>,
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -187,6 +189,7 @@ impl INode for ReplayPlayback {
|
|||||||
&& frame.time <= self.current_time
|
&& frame.time <= self.current_time
|
||||||
{
|
{
|
||||||
self.player_data = frame.player_data.clone();
|
self.player_data = frame.player_data.clone();
|
||||||
|
self.running_goals = frame.goals.clone();
|
||||||
|
|
||||||
if let ReplayBall::World(ball_state) = &frame.ball_data {
|
if let ReplayBall::World(ball_state) = &frame.ball_data {
|
||||||
if let Some(ball) = &mut self.ball {
|
if let Some(ball) = &mut self.ball {
|
||||||
|
|||||||
@ -5,7 +5,7 @@ use godot::{
|
|||||||
prelude::*,
|
prelude::*,
|
||||||
};
|
};
|
||||||
|
|
||||||
use crate::game_manager::Game;
|
use crate::{game_manager::Game, replay::StandaloneReplayManager};
|
||||||
|
|
||||||
#[derive(GodotClass)]
|
#[derive(GodotClass)]
|
||||||
#[class(base=HBoxContainer, init)]
|
#[class(base=HBoxContainer, init)]
|
||||||
@ -35,6 +35,23 @@ impl IHBoxContainer for SimpleScoreView {
|
|||||||
game.signals()
|
game.signals()
|
||||||
.on_goal()
|
.on_goal()
|
||||||
.connect_other(s, |s| s.update_goals());
|
.connect_other(s, |s| s.update_goals());
|
||||||
|
} else if let Some(playback) = &StandaloneReplayManager::singleton().bind().playback {
|
||||||
|
for (id, team) in playback.bind().replay.teams.iter().enumerate() {
|
||||||
|
let mut goals_label = Label::new_alloc();
|
||||||
|
goals_label.set_modulate(team.color.clone().into());
|
||||||
|
goals_label.set_text("0");
|
||||||
|
if !s.team_goals.is_empty() {
|
||||||
|
let mut dash = Label::new_alloc();
|
||||||
|
dash.set_text(" - ");
|
||||||
|
s.base_mut().add_child(&dash);
|
||||||
|
}
|
||||||
|
s.base_mut().add_child(&goals_label);
|
||||||
|
s.team_goals.insert(id as u8, goals_label);
|
||||||
|
}
|
||||||
|
playback
|
||||||
|
.signals()
|
||||||
|
.on_data_changed()
|
||||||
|
.connect_other(s, |s| s.update_goals());
|
||||||
}
|
}
|
||||||
s.update_goals();
|
s.update_goals();
|
||||||
});
|
});
|
||||||
@ -51,6 +68,14 @@ impl SimpleScoreView {
|
|||||||
label.set_text(&goals.to_string());
|
label.set_text(&goals.to_string());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
} else if let Some(playback) = &StandaloneReplayManager::singleton().bind().playback {
|
||||||
|
for (id, _) in playback.bind().replay.teams.iter().enumerate() {
|
||||||
|
if let Some(goals) = playback.bind().running_goals.get(&(id as u8))
|
||||||
|
&& let Some(label) = self.team_goals.get_mut(&(id as u8))
|
||||||
|
{
|
||||||
|
label.set_text(&goals.to_string());
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user