Extract MatchParticipantComponent from Player entity and fix HealthComponent tests

This commit is contained in:
Squinty 2024-04-27 13:32:03 +00:00
parent d238c29f76
commit b339bf34f0
23 changed files with 149 additions and 124 deletions

View file

@ -35,12 +35,6 @@ enum PlayerState { PLAYER_ALIVE, PLAYER_DEAD }
@export_group("State")
@export var player_state : PlayerState = PlayerState.PLAYER_ALIVE
@export var player_id : int = 1:
set(id):
player_id = id
$PlayerInput.set_multiplayer_authority(id)
@export var team_id : int = 1
@export var nickname : String
@onready var input : PlayerInput = $PlayerInput
@onready var camera : Camera3D = $Smoothing/SpringArm3D/Camera3D
@ -56,6 +50,7 @@ enum PlayerState { PLAYER_ALIVE, PLAYER_DEAD }
@onready var tp_player : Vanguard = $Smoothing/ThirdPerson/PlayerMesh
@onready var _game_settings : Settings = get_node("/root/GlobalSettings")
@onready var jetpack_particles : Array = $Smoothing/ThirdPerson/PlayerMesh/JetpackFX.get_children()
@onready var match_participant_component : MatchParticipantComponent = $MatchParticipantComponent
signal died(player : Player, killer_id : int)
signal energy_changed(energy : float)
@ -65,17 +60,16 @@ var g : float = ProjectSettings.get_setting("physics/3d/default_gravity") # in m
var gravity : Vector3 = g * ProjectSettings.get_setting("physics/3d/default_gravity_vector")
var _jumping : bool = false
@rpc("call_local", "reliable")
func set_nickname(value : String) -> void:
nickname = value
func _ready() -> void:
energy_changed.connect(hud._on_energy_changed)
match_participant_component.player_id_changed.connect(_setup_pawn)
match_participant_component.player_id_changed.connect(input.update_multiplayer_authority)
match_participant_component.nickname_changed.connect(iff.set_nickname)
health_component.health_changed.connect(hud._on_health_changed)
health_component.health_changed.connect(iff._on_health_changed)
health_component.health_changed.emit(health_component.health)
health_component.health_zeroed.connect(die)
energy_changed.connect(hud._on_energy_changed)
input.fired_primary.connect(_fire_primary)
input.jumped.connect(_jump)
input.throwed_flag.connect(_throw_flag)
@ -83,22 +77,22 @@ func _ready() -> void:
input.MOUSE_SENSITIVITY = _game_settings.mouse_sensitivity
input.inverted_y_axis = _game_settings.inverted_y_axis
func _setup_pawn(_new_player_id : int) -> void:
if _is_pawn():
camera.current = true
camera.fov = _game_settings.fov
pawn_player = self
# set the spring arm translation to be about head height level
$Smoothing/SpringArm3D.transform = Transform3D().translated(Vector3(0, collision_shape.shape.height / 2, 0) * 0.9)
$Smoothing.remove_child($Smoothing/ThirdPerson)
$Smoothing/ThirdPerson.hide()
else:
# set the iff attachment translation to be about head height level
$Smoothing/ThirdPerson/IFFAttachment.transform = Transform3D().translated(Vector3(0, collision_shape.shape.height / 2, 0) * 0.9)
remove_child(hud)
hud.hide()
weapon.hide()
func _is_pawn() -> bool:
return player_id == multiplayer.get_unique_id()
return multiplayer.get_unique_id() == match_participant_component.player_id
func _fire_primary() -> void:
if _is_player_dead():

View file

@ -1,18 +1,19 @@
[gd_scene load_steps=41 format=3 uid="uid://cbhx1xme0sb7k"]
[gd_scene load_steps=42 format=3 uid="uid://cbhx1xme0sb7k"]
[ext_resource type="Script" path="res://entities/player/player.gd" id="1_mk68k"]
[ext_resource type="PackedScene" uid="uid://drbefw6akui2v" path="res://entities/player/assets/vanguard.tscn" id="2_beyex"]
[ext_resource type="Shape3D" uid="uid://cb8esdlnottdn" path="res://entities/player/collision_shape.tres" id="2_vjqny"]
[ext_resource type="PackedScene" uid="uid://bcv81ku26xo" path="res://interfaces/hud/hud.tscn" id="3_ccety"]
[ext_resource type="PackedScene" uid="uid://c8co0qa2omjmh" path="res://entities/weapons/space_gun/space_gun.tscn" id="4_6jh57"]
[ext_resource type="PackedScene" uid="uid://bof3mg7wgxrmn" path="res://entities/components/health_component.tscn" id="4_jxn63"]
[ext_resource type="Script" path="res://entities/components/match_participant_component.gd" id="6_lrose"]
[ext_resource type="Script" path="res://entities/player/player_input.gd" id="6_ymcrr"]
[ext_resource type="PackedScene" uid="uid://dsysi2rd3bu76" path="res://interfaces/hud/iffs/iff.tscn" id="7_8hc80"]
[ext_resource type="PackedScene" uid="uid://2t8ql8pkxv6c" path="res://entities/components/flag_carry_component.tscn" id="8_ej011"]
[ext_resource type="Script" path="res://entities/components/flag_carry_component.gd" id="8_pdfbn"]
[ext_resource type="PackedScene" uid="uid://d3l7fvbdg6m5g" path="res://entities/flag/assets/flag.glb" id="9_fce2y"]
[ext_resource type="Script" path="res://addons/smoothing/smoothing.gd" id="11_k330l"]
[ext_resource type="Texture2D" uid="uid://ct1v5iadtpadm" path="res://entities/player/assets/jetpackfx/smoke_01.png" id="12_ypuho"]
[ext_resource type="Texture2D" uid="uid://doxo4vfn0bjlp" path="res://entities/player/assets/jetpackfx/smoke_02.png" id="13_wvbf0"]
[ext_resource type="Script" path="res://entities/components/health_component.gd" id="14_ctgxn"]
[ext_resource type="Texture2D" uid="uid://dmf12llra7aq5" path="res://entities/player/assets/jetpackfx/Particle01.png" id="14_vughy"]
[sub_resource type="PhysicsMaterial" id="PhysicsMaterial_clur0"]
@ -65,21 +66,12 @@ properties/0/replication_mode = 1
properties/1/path = NodePath(".:position")
properties/1/spawn = true
properties/1/replication_mode = 1
properties/2/path = NodePath(".:player_id")
properties/2/path = NodePath("HealthComponent:health")
properties/2/spawn = true
properties/2/replication_mode = 2
properties/3/path = NodePath("HealthComponent:health")
properties/3/path = NodePath(".:player_state")
properties/3/spawn = true
properties/3/replication_mode = 2
properties/4/path = NodePath(".:player_state")
properties/4/spawn = true
properties/4/replication_mode = 2
properties/5/path = NodePath(".:nickname")
properties/5/spawn = true
properties/5/replication_mode = 2
properties/6/path = NodePath(".:team_id")
properties/6/spawn = true
properties/6/replication_mode = 2
[sub_resource type="SceneReplicationConfig" id="SceneReplicationConfig_5j4ew"]
properties/0/path = NodePath(".:direction")
@ -238,14 +230,15 @@ monitorable = false
[node name="CollisionShape3D" type="CollisionShape3D" parent="Sensor"]
shape = ExtResource("2_vjqny")
[node name="HUD" parent="." instance=ExtResource("3_ccety")]
[node name="HealthComponent" parent="." node_paths=PackedStringArray("_player") instance=ExtResource("4_jxn63")]
_player = NodePath("..")
[node name="HealthComponent" type="Area3D" parent="." node_paths=PackedStringArray("match_participant_component")]
script = ExtResource("14_ctgxn")
match_participant_component = NodePath("../MatchParticipantComponent")
[node name="CollisionShape3D" type="CollisionShape3D" parent="HealthComponent"]
shape = ExtResource("2_vjqny")
[node name="HUD" parent="." instance=ExtResource("3_ccety")]
[node name="AnimationPlayer" type="AnimationPlayer" parent="."]
libraries = {
"": SubResource("AnimationLibrary_hg307")
@ -261,6 +254,9 @@ root_path = NodePath(".")
replication_config = SubResource("SceneReplicationConfig_5j4ew")
script = ExtResource("6_ymcrr")
[node name="MatchParticipantComponent" type="MultiplayerSynchronizer" parent="."]
script = ExtResource("6_lrose")
[node name="Smoothing" type="Node3D" parent="."]
script = ExtResource("11_k330l")
target = NodePath("..")
@ -280,19 +276,20 @@ unique_name_in_owner = true
[node name="SpaceGun" parent="Smoothing/SpringArm3D/Inventory" node_paths=PackedStringArray("holder") instance=ExtResource("4_6jh57")]
transform = Transform3D(-1, 0, 2.53518e-06, 0, 1, 0, -2.53518e-06, 0, -1, 0.15, -0.3, -0.55)
holder = NodePath("../../../..")
holder = NodePath("../../../../MatchParticipantComponent")
[node name="SpineIKTarget" type="Node3D" parent="Smoothing/SpringArm3D"]
transform = Transform3D(-1, 0, -8.74228e-08, 0, 1, 0, 8.74228e-08, 0, -1, 0, 0, 0)
[node name="FlagCarryComponent" parent="Smoothing/SpringArm3D" node_paths=PackedStringArray("sensor", "carrier") instance=ExtResource("8_ej011")]
transform = Transform3D(-1, 0, -8.74228e-08, 0, 1, 0, 8.74228e-08, 0, -1, 0, 0, 0.150603)
[node name="FlagCarryComponent" type="Node3D" parent="Smoothing/SpringArm3D" node_paths=PackedStringArray("sensor", "carrier")]
transform = Transform3D(-1, 0, -8.74228e-08, 0, 1, 0, 8.74228e-08, 0, -1, 0, 0, 0)
visible = false
script = ExtResource("8_pdfbn")
sensor = NodePath("../../../Sensor")
carrier = NodePath("../../..")
[node name="FlagMesh" parent="Smoothing/SpringArm3D/FlagCarryComponent" instance=ExtResource("9_fce2y")]
transform = Transform3D(0.5, 0, 0, 0, 0.5, 0, 0, 0, 0.5, 0, -0.602515, 0)
transform = Transform3D(0.5, 0, 0, 0, 0.5, 0, 0, 0, 0.5, 1.559e-08, -0.462981, -0.178329)
[node name="ThirdPerson" type="Node3D" parent="Smoothing"]
@ -330,6 +327,7 @@ draw_pass_1 = SubResource("QuadMesh_uc7ts")
[node name="IFFAttachment" type="Marker3D" parent="Smoothing/ThirdPerson"]
transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 1.27457, 0)
[node name="IFF" parent="Smoothing/ThirdPerson" node_paths=PackedStringArray("player", "attach_point") instance=ExtResource("7_8hc80")]
[node name="IFF" parent="Smoothing/ThirdPerson" node_paths=PackedStringArray("player", "match_participant_component", "attach_point") instance=ExtResource("7_8hc80")]
player = NodePath("../../..")
match_participant_component = NodePath("../../../MatchParticipantComponent")
attach_point = NodePath("../IFFAttachment")

View file

@ -26,6 +26,10 @@ signal fired_primary
signal throwed_flag
func _ready() -> void:
update_multiplayer_authority(0)
func update_multiplayer_authority(player_id : int) -> void:
set_multiplayer_authority(player_id)
var has_authority : bool = is_multiplayer_authority()
set_process(has_authority)
set_process_unhandled_input(has_authority)