Use team colors for goals even in replay
This commit is contained in:
parent
efa44cb32e
commit
e76d131580
@ -3,7 +3,10 @@ use godot::{
|
||||
prelude::*,
|
||||
};
|
||||
|
||||
use crate::{game::Game, net::network_manager::NetworkManager, player::ball::Ball};
|
||||
use crate::{
|
||||
game::Game, map::Map, net::network_manager::NetworkManager, player::ball::Ball,
|
||||
replay::StandaloneReplayManager,
|
||||
};
|
||||
|
||||
#[derive(GodotClass)]
|
||||
#[class(base=Area3D, init)]
|
||||
@ -19,24 +22,38 @@ pub struct Goal {
|
||||
#[godot_api]
|
||||
impl IArea3D for Goal {
|
||||
fn ready(&mut self) {
|
||||
if let Some(game) = Game::singleton() {
|
||||
if let Some(team) = game.bind().get_team(self.team)
|
||||
&& let Some(mesh) = &mut self.mesh
|
||||
&& let Some(mat) = mesh.get_active_material(0)
|
||||
&& let Ok(mut mat) = mat.try_cast::<ShaderMaterial>()
|
||||
{
|
||||
mat.set_shader_parameter("goal_color", &team.bind().color.to_variant());
|
||||
}
|
||||
}
|
||||
|
||||
self.update_color();
|
||||
self.base()
|
||||
.signals()
|
||||
.body_entered()
|
||||
.connect_other(self, |s, other| s.on_enter(other));
|
||||
|
||||
StandaloneReplayManager::singleton()
|
||||
.signals()
|
||||
.on_map_loaded()
|
||||
.connect_other(self, |s, _| s.update_color());
|
||||
}
|
||||
}
|
||||
|
||||
impl Goal {
|
||||
fn update_color(&mut self) {
|
||||
if let Some(mesh) = &mut self.mesh
|
||||
&& let Some(mat) = mesh.get_active_material(0)
|
||||
&& let Ok(mut mat) = mat.try_cast::<ShaderMaterial>()
|
||||
{
|
||||
if let Some(game) = Game::singleton()
|
||||
&& let Some(team) = game.bind().get_team(self.team)
|
||||
{
|
||||
mat.set_shader_parameter("goal_color", &team.bind().color.to_variant());
|
||||
} else if let Some(playback) = &StandaloneReplayManager::singleton().bind().playback
|
||||
&& let Some(team) = playback.bind().replay.teams.get(self.team as usize)
|
||||
{
|
||||
let color: Color = team.color.clone().into();
|
||||
mat.set_shader_parameter("goal_color", &color.to_variant());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
fn on_enter(&self, node: Gd<Node3D>) {
|
||||
if let Ok(mut ball) = node.try_cast::<Ball>()
|
||||
&& !ball.bind().entered_goal
|
||||
|
||||
@ -4,9 +4,7 @@ use godot::{
|
||||
};
|
||||
|
||||
use crate::{
|
||||
game::{Game, GameManager},
|
||||
replay::StandaloneReplayManager,
|
||||
ui::player_listings::PlayerListings,
|
||||
game::GameManager, replay::StandaloneReplayManager, ui::player_listings::PlayerListings,
|
||||
};
|
||||
|
||||
#[derive(GodotClass)]
|
||||
|
||||
Loading…
Reference in New Issue
Block a user