🐛 multiplayer fix

This commit is contained in:
anyreso 2024-05-12 17:18:09 -04:00
parent 7498d4206c
commit de902271df
26 changed files with 147 additions and 147 deletions

View file

@ -19,7 +19,7 @@ signal finished
@export var damage : float = .35
@export var impulse_force : int = 1000
var damage_dealer : MatchParticipantComponent
var damage_dealer : MatchParticipant
var _damaged_objects : Dictionary= {
"bodies": [],

View file

@ -19,7 +19,7 @@ class_name HealthComponent extends Area3D
set(value):
health = value
health_changed.emit(value)
@export var match_participant_component : MatchParticipantComponent
@export var match_participant : MatchParticipant
signal health_zeroed(killer_id : int)
signal health_changed(value : float)
@ -33,7 +33,7 @@ func _ready() -> void:
@rpc("call_local", "reliable")
func damage(amount : float, damage_dealer_player_id : int, damage_dealer_team_id : int) -> void:
if (damage_dealer_team_id == match_participant_component.team_id) and (damage_dealer_player_id != match_participant_component.player_id):
if (damage_dealer_team_id == match_participant.team_id) and (damage_dealer_player_id != match_participant.player_id):
return
health = clampf(health - amount, 0.0, max_health)

View file

@ -0,0 +1,20 @@
class_name MatchParticipant extends Node
signal player_id_changed(new_player_id : int)
signal username_changed(new_username : String)
signal team_id_changed(new_team_id : int)
@export var username : String = "Newblood":
set(value):
username = value
username_changed.emit(username)
@export var player_id : int:
set(value):
player_id = value
player_id_changed.emit(player_id)
@export var team_id : int = 1:
set(value):
team_id = value
team_id_changed.emit(team_id)

View file

@ -1,25 +0,0 @@
class_name MatchParticipantComponent extends MultiplayerSynchronizer
signal player_id_changed(new_player_id : int)
signal username_changed(new_username : String)
@export var username : String = "<Newblood>":
set(value):
username = value
username_changed.emit(username)
@export var player_id : int:
set(value):
player_id = value
player_id_changed.emit(player_id)
@export var team_id : int = 1
func _enter_tree() -> void:
root_path = "."
replication_config = SceneReplicationConfig.new()
for prop : String in ["player_id", "team_id", "username"]:
var prop_path : NodePath = NodePath(prop).get_as_property_path()
replication_config.add_property(prop_path)
replication_config.property_set_replication_mode(
prop_path, SceneReplicationConfig.REPLICATION_MODE_ON_CHANGE)

View file

@ -21,7 +21,7 @@ class_name ProjectileSpawner extends Node3D
func new_projectile(
projectile_type : Object,
owner_velocity : Vector3,
shooter : MatchParticipantComponent
shooter : MatchParticipant
) -> Node3D:
return projectile_type.new_projectile(
self,

View file

@ -12,7 +12,7 @@
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <https://www.gnu.org/licenses/>.
class_name PlayerInput extends MultiplayerSynchronizer
extends Node
@export var jetting : bool = false
@export var skiing : bool = false
@ -30,13 +30,13 @@ func update_multiplayer_authority(player_id : int) -> void:
set_multiplayer_authority(player_id)
func _unhandled_input(event: InputEvent) -> void:
var mouse_mode : Input.MouseMode = Input.get_mouse_mode()
# isolate mouse events
if event is InputEventMouseMotion:
if mouse_mode == Input.MOUSE_MODE_CAPTURED:
# retrieve mouse position relative to last frame
_update_camera(event.relative)
if is_multiplayer_authority():
var mouse_mode : Input.MouseMode = Input.get_mouse_mode()
# isolate mouse events
if event is InputEventMouseMotion:
if mouse_mode == Input.MOUSE_MODE_CAPTURED:
# update camera with mouse position relative to last frame
_update_camera(event.relative)
if event is InputEventMouseButton:
# @NOTE: there could be a control setting for direction
if event.button_index == MOUSE_BUTTON_WHEEL_UP and event.pressed:

View file

@ -23,6 +23,7 @@ signal energy_changed(energy : float)
@export var health_component : HealthComponent
@export var flag_carry_component : FlagCarryComponent
@export var walkable_surface_sensor : ShapeCast3D
@export var match_participant : MatchParticipant
## The inventory component can store up to [member Inventory.slots] objects. It
## also has specific slots to hold grenades, packs and a flag.
@ -47,14 +48,13 @@ signal energy_changed(energy : float)
@export_group("State")
@export var player_state : PlayerState = PlayerState.PLAYER_ALIVE
@export var input : Node
@onready var input : PlayerInput = $PlayerInput
@onready var camera : Camera3D = %Pivot/Camera3D
@onready var hud : CanvasLayer = $HUD
@onready var animation_player : AnimationPlayer = $AnimationPlayer
@onready var collision_shape : CollisionShape3D = $CollisionShape3D
@onready var jetpack_particles : Array = $ThirdPerson/Mesh/JetpackFX.get_children()
@onready var match_participant_component : MatchParticipantComponent = $MatchParticipantComponent
var g : float = ProjectSettings.get_setting("physics/3d/default_gravity") # in m/s²
var gravity : Vector3 = g * ProjectSettings.get_setting("physics/3d/default_gravity_vector")
@ -63,9 +63,9 @@ var _jumping : bool = false
static var pawn_player : Player
func _ready() -> void:
match_participant_component.player_id_changed.connect(_setup_pawn)
match_participant_component.username_changed.connect(iff._on_username_changed)
match_participant_component.player_id_changed.connect(input.update_multiplayer_authority)
match_participant.player_id_changed.connect(_setup_pawn)
match_participant.player_id_changed.connect(input.update_multiplayer_authority)
match_participant.username_changed.connect(iff._on_username_changed)
health_component.health_changed.connect(hud._on_health_changed)
health_component.health_changed.connect(iff._on_health_changed)
@ -82,8 +82,8 @@ func _process(_delta : float) -> void:
%Pivot.global_transform.basis = Basis.from_euler(Vector3(input.camera_rotation.y, input.camera_rotation.x, 0.0))
if not _is_pawn():
tp_mesh.global_transform.basis = Basis.from_euler(Vector3(.0, input.camera_rotation.x + PI, 0.0))
if match_participant_component and pawn_player:
if pawn_player.match_participant_component.team_id == match_participant_component.team_id:
if match_participant and pawn_player:
if pawn_player.match_participant.team_id == match_participant.team_id:
iff.fill = Color.GREEN
else:
iff.fill = Color.RED
@ -103,7 +103,7 @@ func _setup_pawn(_new_player_id : int) -> void:
hud.hide()
func _is_pawn() -> bool:
var peer_is_pawn : bool = multiplayer.get_unique_id() == match_participant_component.player_id
var peer_is_pawn : bool = multiplayer.get_unique_id() == match_participant.player_id
return Global.type is Singleplayer or peer_is_pawn
# @NOTE: this method works only because `tp_mesh` duplicates weapons meshes from the inventory

View file

@ -4,8 +4,7 @@
[ext_resource type="PackedScene" uid="uid://bbeecp3jusppn" path="res://interfaces/hud/iffs/IFF.tscn" id="2_s5wgp"]
[ext_resource type="PackedScene" uid="uid://bcv81ku26xo" path="res://interfaces/hud/hud.tscn" id="3_ccety"]
[ext_resource type="Shape3D" uid="uid://cb8esdlnottdn" path="res://entities/player/resources/collider.tres" id="4_8kvcy"]
[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="Script" path="res://entities/components/match_participant.gd" id="6_lrose"]
[ext_resource type="Script" path="res://entities/components/inventory.gd" id="8_768qh"]
[ext_resource type="PackedScene" uid="uid://drbefw6akui2v" path="res://entities/player/vanguard.tscn" id="8_eiy7q"]
[ext_resource type="Script" path="res://entities/components/flag_carry_component.gd" id="8_pdfbn"]
@ -18,6 +17,7 @@
[ext_resource type="PackedScene" uid="uid://b0xql5hi0b52y" path="res://entities/weapons/chaingun/chaingun.tscn" id="15_io0a3"]
[ext_resource type="PackedScene" uid="uid://cstl7yxc75572" path="res://entities/weapons/grenade_launcher/grenade_launcher.tscn" id="16_4xs2j"]
[ext_resource type="PackedScene" uid="uid://d3l7fvbdg6m5g" path="res://entities/flag/assets/flag.glb" id="18_7nkei"]
[ext_resource type="Script" path="res://entities/player/inputs_sync.gd" id="18_v4iu1"]
[sub_resource type="PhysicsMaterial" id="PhysicsMaterial_clur0"]
resource_local_to_scene = true
@ -59,45 +59,6 @@ _data = {
"death": SubResource("Animation_yqgrk")
}
[sub_resource type="SceneReplicationConfig" id="SceneReplicationConfig_rqdp6"]
properties/0/path = NodePath(".:linear_velocity")
properties/0/spawn = false
properties/0/replication_mode = 1
properties/1/path = NodePath(".:position")
properties/1/spawn = false
properties/1/replication_mode = 1
properties/2/path = NodePath("HealthComponent:health")
properties/2/spawn = false
properties/2/replication_mode = 2
properties/3/path = NodePath(".:player_state")
properties/3/spawn = false
properties/3/replication_mode = 2
[sub_resource type="SceneReplicationConfig" id="SceneReplicationConfig_5j4ew"]
properties/0/path = NodePath(".:direction")
properties/0/spawn = false
properties/0/replication_mode = 1
properties/1/path = NodePath(".:jetting")
properties/1/spawn = false
properties/1/replication_mode = 2
properties/2/path = NodePath(".:camera_rotation")
properties/2/spawn = false
properties/2/replication_mode = 1
properties/3/path = NodePath(".:skiing")
properties/3/spawn = false
properties/3/replication_mode = 2
[sub_resource type="SceneReplicationConfig" id="SceneReplicationConfig_7na0c"]
properties/0/path = NodePath("MatchParticipantComponent:player_id")
properties/0/spawn = false
properties/0/replication_mode = 2
properties/1/path = NodePath("MatchParticipantComponent:team_id")
properties/1/spawn = false
properties/1/replication_mode = 2
properties/2/path = NodePath("MatchParticipantComponent:nickname")
properties/2/spawn = false
properties/2/replication_mode = 2
[sub_resource type="Gradient" id="Gradient_3u0pn"]
offsets = PackedFloat32Array(0, 0.872727)
colors = PackedColorArray(1, 1, 1, 1, 1, 1, 1, 0)
@ -206,7 +167,46 @@ particles_anim_loop = false
[sub_resource type="QuadMesh" id="QuadMesh_uc7ts"]
material = SubResource("StandardMaterial3D_2jwv2")
[node name="Player" type="RigidBody3D" node_paths=PackedStringArray("iff", "health_component", "flag_carry_component", "walkable_surface_sensor", "inventory", "tp_mesh") groups=["Player"]]
[sub_resource type="SceneReplicationConfig" id="SceneReplicationConfig_rqdp6"]
properties/0/path = NodePath(".:linear_velocity")
properties/0/spawn = false
properties/0/replication_mode = 1
properties/1/path = NodePath(".:position")
properties/1/spawn = false
properties/1/replication_mode = 1
properties/2/path = NodePath("HealthComponent:health")
properties/2/spawn = false
properties/2/replication_mode = 2
properties/3/path = NodePath(".:player_state")
properties/3/spawn = false
properties/3/replication_mode = 2
[sub_resource type="SceneReplicationConfig" id="SceneReplicationConfig_5j4ew"]
properties/0/path = NodePath(".:direction")
properties/0/spawn = true
properties/0/replication_mode = 1
properties/1/path = NodePath(".:jetting")
properties/1/spawn = true
properties/1/replication_mode = 2
properties/2/path = NodePath(".:camera_rotation")
properties/2/spawn = true
properties/2/replication_mode = 1
properties/3/path = NodePath(".:skiing")
properties/3/spawn = true
properties/3/replication_mode = 2
[sub_resource type="SceneReplicationConfig" id="SceneReplicationConfig_7na0c"]
properties/0/path = NodePath(".:username")
properties/0/spawn = true
properties/0/replication_mode = 1
properties/1/path = NodePath(".:player_id")
properties/1/spawn = true
properties/1/replication_mode = 1
properties/2/path = NodePath(".:team_id")
properties/2/spawn = true
properties/2/replication_mode = 1
[node name="Player" type="RigidBody3D" node_paths=PackedStringArray("iff", "health_component", "flag_carry_component", "walkable_surface_sensor", "match_participant", "inventory", "tp_mesh", "input") groups=["Player"]]
collision_mask = 2147483649
collision_priority = 9.0
axis_lock_angular_x = true
@ -221,17 +221,19 @@ iff = NodePath("IFF")
health_component = NodePath("HealthComponent")
flag_carry_component = NodePath("Pivot/FlagCarryComponent")
walkable_surface_sensor = NodePath("WalkableSurfaceSensor")
match_participant = NodePath("MatchParticipant")
inventory = NodePath("Pivot/Inventory")
tp_mesh = NodePath("ThirdPerson/Mesh")
jump_height = 1.5
input = NodePath("Inputs")
[node name="IFF" parent="." instance=ExtResource("2_s5wgp")]
transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 1.1, 0)
fill = Color(0, 1, 0, 1)
[node name="HealthComponent" type="Area3D" parent="." node_paths=PackedStringArray("match_participant_component")]
[node name="HealthComponent" type="Area3D" parent="." node_paths=PackedStringArray("match_participant")]
script = ExtResource("14_ctgxn")
match_participant_component = NodePath("../MatchParticipantComponent")
match_participant = NodePath("../MatchParticipant")
[node name="CollisionShape3D" type="CollisionShape3D" parent="HealthComponent"]
shape = ExtResource("4_8kvcy")
@ -254,23 +256,6 @@ libraries = {
autoplay = "shoot"
playback_default_blend_time = 0.05
[node name="ServerSynchronizer" type="MultiplayerSynchronizer" parent="."]
replication_config = SubResource("SceneReplicationConfig_rqdp6")
[node name="PlayerInput" type="MultiplayerSynchronizer" parent="."]
root_path = NodePath(".")
replication_config = SubResource("SceneReplicationConfig_5j4ew")
script = ExtResource("6_ymcrr")
jetting = null
skiing = null
direction = null
camera_rotation = null
[node name="MatchParticipantComponent" type="MultiplayerSynchronizer" parent="."]
root_path = NodePath(".")
replication_config = SubResource("SceneReplicationConfig_7na0c")
script = ExtResource("6_lrose")
[node name="Pivot" type="Node3D" parent="."]
unique_name_in_owner = true
transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 0.5, 0)
@ -441,6 +426,21 @@ script = ExtResource("11_k330l")
target = NodePath("..")
flags = 3
[node name="MultiplayerSynchronizer" type="MultiplayerSynchronizer" parent="."]
replication_config = SubResource("SceneReplicationConfig_rqdp6")
[node name="Inputs" type="Node" parent="."]
script = ExtResource("18_v4iu1")
[node name="InputsSync" type="MultiplayerSynchronizer" parent="Inputs"]
replication_config = SubResource("SceneReplicationConfig_5j4ew")
[node name="MatchParticipant" type="Node" parent="."]
script = ExtResource("6_lrose")
[node name="MatchParticipantSync" type="MultiplayerSynchronizer" parent="MatchParticipant"]
replication_config = SubResource("SceneReplicationConfig_7na0c")
[connection signal="energy_changed" from="." to="HUD" method="_on_player_energy_changed"]
[editable path="ThirdPerson/Mesh"]

View file

@ -32,7 +32,7 @@ func trigger() -> void:
var projectile : Node3D = $ProjectileSpawner.new_projectile(
ChainGunProjectile,
owner.linear_velocity,
owner.match_participant_component
owner.match_participant
)
# add to owner of player for now
Global.type.add_child(projectile)

View file

@ -18,7 +18,7 @@ class_name ChainGunProjectile extends Node3D
@export var lifespan : float = .5 # in seconds
@export var build_up_time : float = .6 # seconds
var shooter : MatchParticipantComponent
var shooter : MatchParticipant
var velocity : Vector3 = Vector3.ZERO
@onready var shape_cast : ShapeCast3D = $ShapeCast3D
@ -45,7 +45,7 @@ func _physics_process(delta : float) -> void:
static func new_projectile(
origin : Marker3D,
inherited_velocity : Vector3,
_shooter : MatchParticipantComponent,
_shooter : MatchParticipant,
scene : PackedScene
) -> ChainGunProjectile:
var projectile : ChainGunProjectile = scene.instantiate()

View file

@ -4,7 +4,7 @@ class_name GrenadeLauncherProjectileExplosion extends Node3D
@export var explosive_damage : ExplosiveDamageComponent
## The component responsible for owner identification
var shooter : MatchParticipantComponent:
var shooter : MatchParticipant:
set(value):
shooter = value
explosive_damage.damage_dealer = value
@ -29,7 +29,7 @@ func _on_finished() -> void:
## [GrenadeLauncherProjectileExplosion] scene of the [GrenadeLauncherProjectile].
static func new_explosion(
origin : Vector3,
_shooter : MatchParticipantComponent,
_shooter : MatchParticipant,
scene : PackedScene
) -> GrenadeLauncherProjectileExplosion:
var explosion : GrenadeLauncherProjectileExplosion = scene.instantiate()

View file

@ -18,7 +18,7 @@ func trigger() -> void:
var projectile : Node3D = $ProjectileSpawner.new_projectile(
GrenadeLauncherProjectile,
owner.linear_velocity,
owner.match_participant_component
owner.match_participant
)
# add to owner of player for now
Global.type.add_child(projectile)

View file

@ -20,7 +20,7 @@ class_name GrenadeLauncherProjectile extends RigidBody3D
@export var speed : float = 44. # m/s
@export var lifespan : float = 1.6 # in seconds
var shooter : MatchParticipantComponent
var shooter : MatchParticipant
var pending_explosion : bool = false
## Called when the node enters the scene tree for the first time.
@ -47,7 +47,7 @@ func _on_body_entered(_body : Node) -> void:
static func new_projectile(
origin : Node3D,
inherited_velocity : Vector3,
_shooter : MatchParticipantComponent,
_shooter : MatchParticipant,
scene : PackedScene
) -> GrenadeLauncherProjectile:
var projectile : GrenadeLauncherProjectile = scene.instantiate()

View file

@ -25,7 +25,7 @@ class_name SpaceGunProjectile extends Node3D
@onready var projectile_trail : Trail3D = $Smoothing/ProjectileTrail
var velocity : Vector3 = Vector3.ZERO
var shooter : MatchParticipantComponent
var shooter : MatchParticipant
func _ready() -> void:
var lifespan_timer : Timer = Timer.new()
@ -61,7 +61,7 @@ func _physics_process(delta : float) -> void:
static func new_projectile(
origin : Marker3D,
inherited_velocity : Vector3,
_shooter : MatchParticipantComponent,
_shooter : MatchParticipant,
scene : PackedScene
) -> SpaceGunProjectile:
var projectile : SpaceGunProjectile = scene.instantiate()

View file

@ -20,7 +20,7 @@ class_name SpaceGunProjectileExplosion extends Node3D
var explosion_effect_pending : bool = false
var shooter : MatchParticipantComponent:
var shooter : MatchParticipant:
set(value):
shooter = value
assert(explosive_damage)
@ -31,7 +31,7 @@ func _ready() -> void:
fire.finished.connect(func() -> void: queue_free())
## This method is a parameterized constructor for the [SpaceGunProjectileExplosion] scene of the [SpaceGunProjectile]
static func new_explosion(spawn_position : Vector3, _shooter : MatchParticipantComponent, scene : PackedScene) -> SpaceGunProjectileExplosion:
static func new_explosion(spawn_position : Vector3, _shooter : MatchParticipant, scene : PackedScene) -> SpaceGunProjectileExplosion:
var explosion : SpaceGunProjectileExplosion = scene.instantiate()
explosion.shooter = _shooter
explosion.position = spawn_position

View file

@ -33,7 +33,7 @@ func trigger() -> void:
var projectile : Node3D = $ProjectileSpawner.new_projectile(
SpaceGunProjectile,
owner.linear_velocity,
owner.match_participant_component
owner.match_participant
)
# add to owner of player for now
Global.type.add_child(projectile)

View file

@ -30,16 +30,16 @@ func _unhandled_input(event : InputEvent) -> void:
elif event.is_action_released("scoreboard"):
hide()
func add_participant(participant : MatchParticipantComponent) -> void:
func add_participant(participant : MatchParticipant) -> void:
_add_scoreboard_entry.rpc(participant.player_id, participant.username)
func remove_participant(participant : MatchParticipantComponent) -> void:
func remove_participant(participant : MatchParticipant) -> void:
_remove_scoreboard_entry.rpc(participant.player_id)
func increment_kill_count(participant : MatchParticipantComponent) -> void:
func increment_kill_count(participant : MatchParticipant) -> void:
_entries[participant.player_id].kills += 1
func add_score_to_player(participant : MatchParticipantComponent, amount : int) -> void:
func add_score_to_player(participant : MatchParticipant, amount : int) -> void:
var player_id : int = participant.player_id
var entry : ScoreboardEntry = _entries[player_id]
_update_scoreboard_entry.rpc(player_id, entry.username, entry.kills, entry.score + amount)

View file

@ -9,6 +9,7 @@ anchor_right = 1.0
anchor_bottom = 1.0
grow_horizontal = 2
grow_vertical = 2
mouse_filter = 2
script = ExtResource("1_k2wav")
[node name="Panel" type="Panel" parent="."]
@ -18,6 +19,7 @@ anchor_right = 1.0
anchor_bottom = 1.0
grow_horizontal = 2
grow_vertical = 2
mouse_filter = 2
[node name="MarginContainer" type="MarginContainer" parent="Panel"]
layout_mode = 1
@ -26,11 +28,13 @@ anchor_right = 1.0
anchor_bottom = 1.0
grow_horizontal = 2
grow_vertical = 2
mouse_filter = 2
theme_override_constants/margin_left = 64
theme_override_constants/margin_top = 64
[node name="VBoxContainer" type="VBoxContainer" parent="Panel/MarginContainer"]
layout_mode = 2
mouse_filter = 2
[node name="Label" type="Label" parent="Panel/MarginContainer/VBoxContainer"]
layout_mode = 2
@ -42,6 +46,7 @@ text = "Scoreboard"
unique_name_in_owner = true
layout_mode = 2
size_flags_horizontal = 4
mouse_filter = 2
theme_override_constants/h_separation = 32
theme_override_constants/v_separation = 16
columns = 3

View file

@ -28,9 +28,9 @@ func unsubscribe_player(player : Player) -> void:
player.died.disconnect(_on_player_died)
func _on_player_died(player : Player, killer_id : int) -> void:
if player.match_participant_component.player_id != killer_id:
if player.match_participant.player_id != killer_id:
var node_name : String = str(killer_id)
if _players.has_node(node_name):
var killer : Player = _players.get_node(node_name)
_scoreboard.increment_kill_count(killer.match_participant_component)
_scoreboard.add_score_to_player(killer.match_participant_component, 10)
_scoreboard.increment_kill_count(killer.match_participant)
_scoreboard.add_score_to_player(killer.match_participant, 10)

View file

@ -38,16 +38,16 @@ func setup(flag : Flag) -> void:
flag.dropped.connect(_on_flag_dropped)
func _on_flag_grabbed(grabber : Player) -> void:
grabber.match_participant_component.team_id = _team_rabbit.team_id
_scoreboard.add_score_to_player(grabber.match_participant_component, ON_GRAB_SCORE)
grabber.match_participant.team_id = _team_rabbit.team_id
_scoreboard.add_score_to_player(grabber.match_participant, ON_GRAB_SCORE)
_flag_carrier_scoring_timer.start()
func _on_flag_regrabbed(grabber : Player) -> void:
grabber.match_participant_component.team_id = _team_rabbit.team_id
grabber.match_participant.team_id = _team_rabbit.team_id
func _on_flag_dropped(dropper : Player) -> void:
dropper.match_participant_component.team_id = _team_chasers.team_id
dropper.match_participant.team_id = _team_chasers.team_id
_flag_carrier_scoring_timer.stop()
func _on_flag_carrier_scoring_timer_timeout(flag : Flag) -> void:
_scoreboard.add_score_to_player(flag.last_carrier.match_participant_component, ON_HOLD_SCORE)
_scoreboard.add_score_to_player(flag.last_carrier.match_participant, ON_HOLD_SCORE)

View file

@ -68,19 +68,19 @@ func add_player(peer_id : int, username : String) -> void:
player.name = str(peer_id)
player.died.connect(_on_player_died)
players.add_child(player)
player.match_participant_component.player_id = peer_id
player.match_participant_component.team_id = ($RabbitScoringComponent as RabbitScoringComponent)._team_chasers.team_id
player.match_participant_component.username = username
player.match_participant.player_id = peer_id
player.match_participant.team_id = ($RabbitScoringComponent as RabbitScoringComponent)._team_chasers.team_id
player.match_participant.username = username
player.global_position = MapsManager.get_player_spawn().position
$DeathmatchScoringComponent.subscribe_player(player)
scoreboard.add_participant(player.match_participant_component)
scoreboard.add_participant(player.match_participant)
print("Peer `%s` connected" % player.name)
func remove_player(peer_id : int) -> void:
var node_name : String = str(peer_id)
if players.has_node(node_name):
var player : Player = players.get_node(node_name)
scoreboard.remove_participant(player.match_participant_component)
scoreboard.remove_participant(player.match_participant)
player.died.disconnect(_on_player_died)
$DeathmatchScoringComponent.unsubscribe_player(player)
player.queue_free()

View file

@ -20,7 +20,7 @@ class_name Singleplayer extends Node
func _ready() -> void:
player_node.died.connect(respawn_player)
player_node.match_participant_component.player_id = 1
player_node.match_participant.player_id = 1
MapsManager.current_map = $Desert
_add_flag()

View file

@ -26,8 +26,8 @@ func _setup_player(player_id : int) -> Player:
var player : Player = PLAYER.instantiate()
player.name = str(player_id)
add_child(player) # we can't autofree in this test setup
var participant : MatchParticipantComponent = player.match_participant_component
player.match_participant_component.player_id = player_id
var participant : MatchParticipant = player.match_participant
player.match_participant.player_id = player_id
_scoreboard.add_participant(participant)
_subject.subscribe_player(player)
_subject._players = self
@ -50,7 +50,7 @@ func after_each() -> void:
_subject.free()
func _kill_player(victim : Player, killer : Player) -> void:
victim.died.emit(victim, killer.match_participant_component.player_id)
victim.died.emit(victim, killer.match_participant.player_id)
func test_player_gets_no_score_for_self_kill() -> void:
_kill_player(_victim, _victim)
@ -59,8 +59,8 @@ func test_player_gets_no_score_for_self_kill() -> void:
func test_killer_gets_score_after_kill() -> void:
_kill_player(_victim, _killer)
assert_called(_scoreboard, 'add_score_to_player', [_killer.match_participant_component, _subject.ON_KILL_SCORE])
assert_called(_scoreboard, 'increment_kill_count', [_killer.match_participant_component])
assert_called(_scoreboard, 'add_score_to_player', [_killer.match_participant, _subject.ON_KILL_SCORE])
assert_called(_scoreboard, 'increment_kill_count', [_killer.match_participant])
func test_killer_leaves_before_kill() -> void:
remove_child(_killer)

View file

@ -23,14 +23,14 @@ func before_each() -> void:
_subject = HealthComponent.new()
watch_signals(_subject)
_subject.max_health = TEST_MAX_HEALTH
var participant : MatchParticipantComponent = MatchParticipantComponent.new()
var participant : MatchParticipant = MatchParticipant.new()
participant.player_id = TEST_PLAYER_ID
participant.team_id = TEST_TEAM_ID
_subject.match_participant_component = participant
_subject.match_participant = participant
add_child_autofree(_subject)
func after_each() -> void:
_subject.match_participant_component.free()
_subject.match_participant.free()
func test_that_it_has_max_health_when_ready() -> void:
assert_eq(_subject.health, _subject.max_health)

View file

@ -26,7 +26,7 @@ func test_that_new_scoreboard_is_empty() -> void:
assert_eq(_subject._entries, {})
func test_that_added_entry_is_added_correctly() -> void:
var participant : MatchParticipantComponent = MatchParticipantComponent.new()
var participant : MatchParticipant = MatchParticipant.new()
participant.username = "test_username"
_subject.add_participant(participant)
var entries : Array = _subject._entries.values()
@ -38,7 +38,7 @@ func test_that_added_entry_is_added_correctly() -> void:
participant.free()
func test_that_scores_are_added_correctly() -> void:
var participant : MatchParticipantComponent = MatchParticipantComponent.new()
var participant : MatchParticipant = MatchParticipant.new()
_subject.add_participant(participant)
_subject.add_score_to_player(participant, 10)
var tested_entry : Scoreboard.ScoreboardEntry = _subject._entries.values()[0]
@ -46,7 +46,7 @@ func test_that_scores_are_added_correctly() -> void:
participant.free()
func test_that_kill_counts_are_incremented_correctly() -> void:
var participant : MatchParticipantComponent = MatchParticipantComponent.new()
var participant : MatchParticipant = MatchParticipant.new()
_subject.add_participant(participant)
_subject.increment_kill_count(participant)
var tested_entry : Scoreboard.ScoreboardEntry = _subject._entries.values()[0]