Use team colors for goals even in replay
This commit is contained in:
parent
efa44cb32e
commit
e76d131580
@ -3,7 +3,10 @@ use godot::{
|
|||||||
prelude::*,
|
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)]
|
#[derive(GodotClass)]
|
||||||
#[class(base=Area3D, init)]
|
#[class(base=Area3D, init)]
|
||||||
@ -19,24 +22,38 @@ pub struct Goal {
|
|||||||
#[godot_api]
|
#[godot_api]
|
||||||
impl IArea3D for Goal {
|
impl IArea3D for Goal {
|
||||||
fn ready(&mut self) {
|
fn ready(&mut self) {
|
||||||
if let Some(game) = Game::singleton() {
|
self.update_color();
|
||||||
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.base()
|
self.base()
|
||||||
.signals()
|
.signals()
|
||||||
.body_entered()
|
.body_entered()
|
||||||
.connect_other(self, |s, other| s.on_enter(other));
|
.connect_other(self, |s, other| s.on_enter(other));
|
||||||
|
|
||||||
|
StandaloneReplayManager::singleton()
|
||||||
|
.signals()
|
||||||
|
.on_map_loaded()
|
||||||
|
.connect_other(self, |s, _| s.update_color());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Goal {
|
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>) {
|
fn on_enter(&self, node: Gd<Node3D>) {
|
||||||
if let Ok(mut ball) = node.try_cast::<Ball>()
|
if let Ok(mut ball) = node.try_cast::<Ball>()
|
||||||
&& !ball.bind().entered_goal
|
&& !ball.bind().entered_goal
|
||||||
|
|||||||
@ -4,9 +4,7 @@ use godot::{
|
|||||||
};
|
};
|
||||||
|
|
||||||
use crate::{
|
use crate::{
|
||||||
game::{Game, GameManager},
|
game::GameManager, replay::StandaloneReplayManager, ui::player_listings::PlayerListings,
|
||||||
replay::StandaloneReplayManager,
|
|
||||||
ui::player_listings::PlayerListings,
|
|
||||||
};
|
};
|
||||||
|
|
||||||
#[derive(GodotClass)]
|
#[derive(GodotClass)]
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user