From 67b512222fa0d8d6bc2e6574b299dc93f608d93b Mon Sep 17 00:00:00 2001 From: Sofia Date: Sun, 9 Aug 2026 23:05:08 +0300 Subject: [PATCH] Add tint to gun color --- godot/mesh/materials/gear.tres | 1 + godot/mesh/raygun.tscn | 5 +++- godot/mesh/shotgun.tscn | 6 ++++- godot/scenes/weapons/raygun.tscn | 14 ++++++++++- godot/scenes/weapons/shotgun.tscn | 14 ++++++++++- rust/src/player/local_player.rs | 10 ++++++++ rust/src/player/weapon.rs | 40 ++++++++++++++++++++++++++++++- 7 files changed, 85 insertions(+), 5 deletions(-) diff --git a/godot/mesh/materials/gear.tres b/godot/mesh/materials/gear.tres index 9d52e19..a2db60d 100644 --- a/godot/mesh/materials/gear.tres +++ b/godot/mesh/materials/gear.tres @@ -3,5 +3,6 @@ [ext_resource type="Texture2D" uid="uid://c7epv5p0qau02" path="res://assets/Gear.png" id="1_qr2ym"] [resource] +resource_local_to_scene = true albedo_texture = ExtResource("1_qr2ym") texture_filter = 0 diff --git a/godot/mesh/raygun.tscn b/godot/mesh/raygun.tscn index fe5ddfe..cd81731 100644 --- a/godot/mesh/raygun.tscn +++ b/godot/mesh/raygun.tscn @@ -5,6 +5,9 @@ [node name="Raygun" unique_id=1928455392 instance=ExtResource("1_njit6")] -[node name="Sniper_Rifle" parent="." index="0" unique_id=1650136097] +[node name="weapon_mesh" type="WeaponMesh" parent="." index="0" unique_id=612110357 node_paths=PackedStringArray("mesh")] +mesh = NodePath("../Sniper_Rifle") + +[node name="Sniper_Rifle" parent="." index="1" unique_id=1650136097] layers = 2 surface_material_override/0 = ExtResource("2_81k8r") diff --git a/godot/mesh/shotgun.tscn b/godot/mesh/shotgun.tscn index 23f995c..2132de7 100644 --- a/godot/mesh/shotgun.tscn +++ b/godot/mesh/shotgun.tscn @@ -4,11 +4,15 @@ [ext_resource type="Texture2D" uid="uid://bis6yrsc7uo1p" path="res://raw_assets/Soldier/Shotgun.png" id="2_cseg6"] [sub_resource type="StandardMaterial3D" id="StandardMaterial3D_cseg6"] +resource_local_to_scene = true albedo_texture = ExtResource("2_cseg6") texture_filter = 0 [node name="Shotgun" unique_id=1412770732 instance=ExtResource("1_wwlim")] -[node name="Shotgun" parent="." index="0" unique_id=508004006] +[node name="weapon_mesh" type="WeaponMesh" parent="." index="0" unique_id=669806124 node_paths=PackedStringArray("mesh")] +mesh = NodePath("../Shotgun") + +[node name="Shotgun" parent="." index="1" unique_id=508004006] layers = 2 surface_material_override/0 = SubResource("StandardMaterial3D_cseg6") diff --git a/godot/scenes/weapons/raygun.tscn b/godot/scenes/weapons/raygun.tscn index b819601..fd47721 100644 --- a/godot/scenes/weapons/raygun.tscn +++ b/godot/scenes/weapons/raygun.tscn @@ -4,16 +4,26 @@ [ext_resource type="PackedScene" uid="uid://ctslratcr8h6v" path="res://scenes/weapons/raygun_beam.tscn" id="1_m84jv"] [ext_resource type="PackedScene" uid="uid://b32uxedvawp73" path="res://scenes/weapons/bullet_hole_decal.tscn" id="2_vhn31"] [ext_resource type="AudioStream" uid="uid://bq553wxrelpdr" path="res://raw_assets/sfx/LaserWithRecoveryEditedCompressed.mp3" id="3_m84jv"] +[ext_resource type="Texture2D" uid="uid://c7epv5p0qau02" path="res://assets/Gear.png" id="4_6y348"] -[node name="raygun" type="Raygun" unique_id=573018429 node_paths=PackedStringArray("sound_emitter", "bullet_source")] +[sub_resource type="StandardMaterial3D" id="StandardMaterial3D_j7oj0"] +resource_local_to_scene = true +albedo_texture = ExtResource("4_6y348") +texture_filter = 0 + +[node name="raygun" type="Raygun" unique_id=573018429 node_paths=PackedStringArray("sound_emitter", "bullet_source", "mesh")] sound_emitter = NodePath("sound_emitter") bullet_prefab = ExtResource("1_m84jv") bullet_source = NodePath("bullet_source") decal = ExtResource("2_vhn31") +mesh = NodePath("Raygun/weapon_mesh") cooldown = 1.5 [node name="Raygun" parent="." unique_id=1928455392 instance=ExtResource("1_ckadf")] +[node name="Sniper_Rifle" parent="Raygun" index="1" unique_id=1650136097] +surface_material_override/0 = SubResource("StandardMaterial3D_j7oj0") + [node name="sound_emitter" type="AudioStreamPlayer3D" parent="." unique_id=1572422640] transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 1.8420726, 0) stream = ExtResource("3_m84jv") @@ -21,3 +31,5 @@ bus = &"SFX" [node name="bullet_source" type="Node3D" parent="." unique_id=211401237] transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 0.36108458, -1.490972) + +[editable path="Raygun"] diff --git a/godot/scenes/weapons/shotgun.tscn b/godot/scenes/weapons/shotgun.tscn index aac8e37..48e2d5b 100644 --- a/godot/scenes/weapons/shotgun.tscn +++ b/godot/scenes/weapons/shotgun.tscn @@ -3,6 +3,12 @@ [ext_resource type="PackedScene" uid="uid://b32uxedvawp73" path="res://scenes/weapons/bullet_hole_decal.tscn" id="1_278ir"] [ext_resource type="AudioStream" uid="uid://bcclq2sv7k0x3" path="res://raw_assets/sfx/gun_sounds/shotgun_compressed.mp3" id="1_pyt38"] [ext_resource type="PackedScene" uid="uid://b8nwd3323kwlc" path="res://mesh/shotgun.tscn" id="3_0xpw2"] +[ext_resource type="Texture2D" uid="uid://bis6yrsc7uo1p" path="res://raw_assets/Soldier/Shotgun.png" id="4_uukpr"] + +[sub_resource type="StandardMaterial3D" id="StandardMaterial3D_qn8fy"] +resource_local_to_scene = true +albedo_texture = ExtResource("4_uukpr") +texture_filter = 0 [sub_resource type="Gradient" id="Gradient_0xpw2"] @@ -50,11 +56,12 @@ material = SubResource("StandardMaterial3D_ybahf") radius = 0.1 curve = SubResource("Curve_yli5f") -[node name="shotgun" type="Shotgun" unique_id=786130999 node_paths=PackedStringArray("sound_emitter", "vfx")] +[node name="shotgun" type="Shotgun" unique_id=786130999 node_paths=PackedStringArray("sound_emitter", "vfx", "mesh")] sound_emitter = NodePath("sound_emitter") vfx = NodePath("gpu_particles_3d") cooldown = 1.0 decal = ExtResource("1_278ir") +mesh = NodePath("Shotgun/weapon_mesh") [node name="sound_emitter" type="AudioStreamPlayer3D" parent="." unique_id=1572422640] transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 1.8420726, 0) @@ -66,6 +73,9 @@ transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 0.36108458, -1.2375934) [node name="Shotgun" parent="." unique_id=1412770732 instance=ExtResource("3_0xpw2")] +[node name="Shotgun" parent="Shotgun" index="1" unique_id=508004006] +surface_material_override/0 = SubResource("StandardMaterial3D_qn8fy") + [node name="gpu_particles_3d" type="GPUParticles3D" parent="." unique_id=898123062] transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 0.2958451, -1.2305822) emitting = false @@ -78,3 +88,5 @@ trail_enabled = true trail_lifetime = 0.1 process_material = SubResource("ParticleProcessMaterial_1cgct") draw_pass_1 = SubResource("TubeTrailMesh_wwb7k") + +[editable path="Shotgun"] diff --git a/rust/src/player/local_player.rs b/rust/src/player/local_player.rs index b09da4a..b39fe8e 100644 --- a/rust/src/player/local_player.rs +++ b/rust/src/player/local_player.rs @@ -333,6 +333,16 @@ impl IPlayer for LocalPlayer { } }; } + self.run_deferred(|s| { + if let Some(game) = Game::singleton() + && let Some(player) = game.bind().find_player(s.player_id.unwrap_or(0)) + && let Some(team) = game.bind().get_team(player.data.team) + { + if let Some(weapon) = &mut s.weapon { + weapon.dyn_bind_mut().set_color(team.bind().color()); + } + } + }); } fn get_weapon(&self) -> Option> { diff --git a/rust/src/player/weapon.rs b/rust/src/player/weapon.rs index 7d301a6..0cb979c 100644 --- a/rust/src/player/weapon.rs +++ b/rust/src/player/weapon.rs @@ -1,7 +1,7 @@ use std::{collections::HashMap, f32::consts::PI}; use godot::{ - classes::{AudioStreamPlayer3D, GpuParticles3D, RandomNumberGenerator}, + classes::{AudioStreamPlayer3D, GpuParticles3D, MeshInstance3D, RandomNumberGenerator}, prelude::*, }; use serde::{Deserialize, Serialize}; @@ -13,6 +13,25 @@ use crate::{ util::{RaycastResult, cast_ray, shotgun_ray}, }; +#[derive(GodotClass)] +#[class(base=Node3D, init)] +pub struct WeaponMesh { + #[export] + mesh: Option>, + + base: Base, +} + +impl WeaponMesh { + fn set_color(&mut self, color: Color) { + if let Some(mesh) = &mut self.mesh + && let Some(mut mat) = mesh.get_active_material(0) + { + mat.set("albedo_color", &color.to_variant()); + } + } +} + pub trait Weapon { fn shoot( &mut self, @@ -28,6 +47,7 @@ pub trait Weapon { fn get_max_cd(&self) -> f64; fn get_remaining_cd(&self) -> f64; fn set_remaining_cd(&mut self, cd: f64); + fn set_color(&mut self, color: Color); } #[derive(Debug, Clone, Copy, Deserialize, Serialize, PartialEq, PartialOrd)] @@ -48,6 +68,8 @@ pub struct Raygun { bullet_source: Option>, #[export] decal: Option>, + #[export] + mesh: Option>, #[export] cooldown: f64, @@ -167,6 +189,12 @@ impl Weapon for Raygun { fn set_remaining_cd(&mut self, cd: f64) { self.cooldown_remaining = cd; } + + fn set_color(&mut self, color: Color) { + if let Some(mesh) = &mut self.mesh { + mesh.bind_mut().set_color(color); + } + } } #[derive(GodotClass)] @@ -182,6 +210,8 @@ pub struct Shotgun { #[export] decal: Option>, + #[export] + mesh: Option>, cooldown_remaining: f64, @@ -299,6 +329,12 @@ impl Weapon for Shotgun { fn set_remaining_cd(&mut self, cd: f64) { self.cooldown_remaining = cd; } + + fn set_color(&mut self, color: Color) { + if let Some(mesh) = &mut self.mesh { + mesh.bind_mut().set_color(color); + } + } } #[derive(GodotClass)] @@ -379,6 +415,8 @@ impl Weapon for BallWeapon { } fn set_remaining_cd(&mut self, _: f64) {} + + fn set_color(&mut self, _: Color) {} } fn add_decal(result: &RaycastResult, prefab: Option>) {