From 6ba368c76efcf52467ea78b96d7b26abf4f9fe58 Mon Sep 17 00:00:00 2001 From: anyreso Date: Thu, 9 May 2024 01:17:10 -0400 Subject: [PATCH] =?UTF-8?q?=E2=9C=A8=20flag=20refactoring?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- entities/components/flag_carry_component.gd | 52 +++---- entities/dummy_target/dummy_target.tscn | 2 +- entities/flag/assets/flag.glb | Bin 21300 -> 15064 bytes entities/flag/flag.gd | 41 +++--- entities/flag/flag.tscn | 41 +++--- entities/flag/resources/collider.tres | 4 + entities/flag/resources/grip_area.tres | 4 + entities/flag/waypoint.gd | 52 ------- entities/flag/waypoint.tscn | 27 ---- entities/player/player.gd | 3 +- entities/player/player.tscn | 62 ++++----- .../collider.tres} | 0 interfaces/waypoint/assets/waypoint.svg | 1 + .../waypoint/assets/waypoint.svg.import | 38 ++++++ interfaces/waypoint/waypoint.gd | 129 ++++++++++++++++++ interfaces/waypoint/waypoint.tscn | 30 ++++ interfaces/waypoint/waypoint3d.gd | 45 ++++++ interfaces/waypoint/waypoint3d.tscn | 23 ++++ project.godot | 1 + systems/global.gd | 2 +- tests/test_flag.gd | 30 ++-- 21 files changed, 389 insertions(+), 198 deletions(-) create mode 100644 entities/flag/resources/collider.tres create mode 100644 entities/flag/resources/grip_area.tres delete mode 100644 entities/flag/waypoint.gd delete mode 100644 entities/flag/waypoint.tscn rename entities/player/{collision_shape.tres => resources/collider.tres} (100%) create mode 100644 interfaces/waypoint/assets/waypoint.svg create mode 100644 interfaces/waypoint/assets/waypoint.svg.import create mode 100644 interfaces/waypoint/waypoint.gd create mode 100644 interfaces/waypoint/waypoint.tscn create mode 100644 interfaces/waypoint/waypoint3d.gd create mode 100644 interfaces/waypoint/waypoint3d.tscn diff --git a/entities/components/flag_carry_component.gd b/entities/components/flag_carry_component.gd index d9f6e49..d33fcdc 100644 --- a/entities/components/flag_carry_component.gd +++ b/entities/components/flag_carry_component.gd @@ -12,51 +12,43 @@ # # You should have received a copy of the GNU General Public License # along with this program. If not, see . +## This component allows its entity to interact with flags class_name FlagCarryComponent extends Node3D -## This component allows its entity to grab, carry and throw flags -## -## To work correctly the owner MUST set an attachment point for carried flags -## and a sensor to detect when flags are within grab range @export var max_throw_speed : float = 10.0 -@export var sensor : Area3D -@export var carrier : Player +@export var mesh : Node3D var _carried_flag : Flag -func _ready() -> void: - sensor.body_entered.connect(_sensor_on_body_entered) - -func _physics_process(_delta : float) -> void: +func _process(_delta : float) -> void: if _is_carrying(): _carried_flag.global_position = global_position - _carried_flag.global_rotation = global_rotation - -func _grab(flag : Flag) -> void: - if not _is_carrying(): - flag.grab(carrier) - _carried_flag = flag - show() - -func _release(inherited_velocity : Vector3, throw_speed : float, dropper : Player) -> void: - if _is_carrying(): - _carried_flag.drop(dropper) - _carried_flag.rotation_degrees.x = 0.0 - _carried_flag.linear_velocity = inherited_velocity + (global_basis.z * throw_speed) - # Throw the flag from some distance in front of the player to avoid regrabbing mid-air - _carried_flag.global_position = carrier.global_position + (global_basis.z * 1.7) - _carried_flag = null - hide() + _carried_flag.global_rotation = Vector3(.0, global_rotation.y, .0) func _is_carrying() -> bool: return _carried_flag != null -func _sensor_on_body_entered(collider : Flag) -> void: - if collider is Flag: - _grab(collider) +func grab(flag : Flag) -> void: + if not _is_carrying(): + flag.grabbed.emit(owner) + _carried_flag = flag + show() func drop(dropper : Player) -> void: _release(Vector3.ZERO, 0.0, dropper) func throw(inherited_velocity : Vector3, dropper : Player) -> void: _release(inherited_velocity, max_throw_speed, dropper) + +func _release(inherited_velocity : Vector3, throw_speed : float, dropper : Player) -> void: + if not _is_carrying(): + return + # update carried flag global rotation based on component global rotation + _carried_flag.global_rotation = Vector3(.0, global_rotation.y, .0) + _carried_flag.linear_velocity = inherited_velocity + (global_basis.z * throw_speed) + # Throw the flag from some distance in front of the player to avoid regrabbing mid-air + _carried_flag.global_position = owner.global_position + (global_basis.z * 1.7) + _carried_flag.dropped.emit(dropper) + _carried_flag = null + hide() + diff --git a/entities/dummy_target/dummy_target.tscn b/entities/dummy_target/dummy_target.tscn index 62806d3..54dc3f3 100644 --- a/entities/dummy_target/dummy_target.tscn +++ b/entities/dummy_target/dummy_target.tscn @@ -1,7 +1,7 @@ [gd_scene load_steps=5 format=3 uid="uid://dpnu1lvfncx6q"] [ext_resource type="Script" path="res://entities/dummy_target/dummy_target.gd" id="1_iup5v"] -[ext_resource type="Shape3D" uid="uid://cb8esdlnottdn" path="res://entities/player/collision_shape.tres" id="2_i5k5j"] +[ext_resource type="Shape3D" uid="uid://cb8esdlnottdn" path="res://entities/player/resources/collider.tres" id="2_i5k5j"] [ext_resource type="PackedScene" uid="uid://chuein4frnvwt" path="res://entities/dummy_target/assets/player_mesh.glb" id="4_fuync"] [sub_resource type="PhysicsMaterial" id="PhysicsMaterial_b0142"] diff --git a/entities/flag/assets/flag.glb b/entities/flag/assets/flag.glb index 391e0acccaa21839302331a2adbb8adce8036991..9fe08cc1cf159ba161f5eafe1721d2c5a631a18f 100644 GIT binary patch literal 15064 zcmeI0dvw&*wZ{*jh*~gWMMcywYC#Qg-VfTDgr}lFA|PTBAwY zZLMgjAH=8*x$oH4y->he%sdwYFHX!P<>Lw$37TU|#>TWECX z%nRCDnp@h-8(304wyC~(VSQWqq*H6km&Ge1mC0DBBDAc&t-Z0Onc!$;IJBZ7)V=_K z(CDz!+C!sfFAp`>Ex{L>Zm(5@np+mu>q2zaak7Pc&%-&8-n zabf+!(CCh~rS()1lsLu3RffY+Qn$`;n^NCV*VNRwU|P%4h6|eO+d)_!nqSvmKdz;z zrEOx}0^2K!OC(b9R3w^8#G;u*I+Lc9y>Ufo!4j9lqtU%KpRVAmOsCWFXeN~mXUGtZ z##gMUSRUG|twg@yR-(~JG?S#Gk!U)aPDj<&NG6<4MbhDTCJ{|WIRN>R$xJ*NBM3X5 zh-E5vxf}WrV`(NGr#<0#JhjX1MU&xJEKJMN(O4uMi6mBNIy4h@SPE0*rlPg2aY>PSezyX;a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lw>XYd|^T|R?#9`B*p{qtBC@lL~3 zT*S(R*NYNn;{Lq=j$jt<+Y=_iqU?TTPEeWI!QQpFV$Lxe(|M$FjAZh=J{e1B99}*gnTwl_b zXh!mXZLYKtkI0`l<<-h-$TobL4c{S4?MW9euf9s{N$77+&(mHT^?zmWb;jIgPd;yz uOp|pH9bn`N8owKvX8+zV|HjK~+e2Gdz0Dr_`6YL;CwWi<7=No_m; diff --git a/entities/flag/flag.gd b/entities/flag/flag.gd index 79c3a67..e1b0013 100644 --- a/entities/flag/flag.gd +++ b/entities/flag/flag.gd @@ -12,34 +12,39 @@ # # You should have received a copy of the GNU General Public License # along with this program. If not, see . -class_name Flag extends Node3D - -enum FlagState { FLAG_STATE_ON_STAND, FLAG_STATE_DROPPED, FLAG_STATE_TAKEN } - -@export var flag_state : FlagState = FlagState.FLAG_STATE_ON_STAND +class_name Flag extends RigidBody3D signal grabbed(grabber : Player) signal regrabbed(grabber : Player) signal dropped(dropper : Player) +enum FlagState { ON_STAND, DROPPED, TAKEN } + +@export var state : FlagState = FlagState.ON_STAND + +@onready var area : Area3D = $GripArea3D +@onready var mesh : Node3D = $Mesh + var last_carrier : Player = null -@onready var _mesh : Node = $Smoothing/Mesh -func can_be_grabbed() -> bool: - return flag_state != FlagState.FLAG_STATE_TAKEN +func _ready() -> void: + area.body_entered.connect(_on_body_entered) -func grab(grabber : Player) -> void: - if flag_state != FlagState.FLAG_STATE_TAKEN: - _mesh.hide() - flag_state = FlagState.FLAG_STATE_TAKEN +func _on_grabbed(grabber : Player) -> void: + if state != FlagState.TAKEN: + hide() + state = FlagState.TAKEN if (last_carrier == null) or (grabber != last_carrier): - grabbed.emit(grabber) last_carrier = grabber else: regrabbed.emit(grabber) -func drop(dropper : Player) -> void: - if flag_state == FlagState.FLAG_STATE_TAKEN: - _mesh.show() - flag_state = FlagState.FLAG_STATE_DROPPED - dropped.emit(dropper) +func _on_dropped(_dropper : Player) -> void: + if state == FlagState.TAKEN: + show() + state = FlagState.DROPPED + +func _on_body_entered(body: Node) -> void: + if body is Player: + assert(body.flag_carry_component) + body.flag_carry_component.grab(self) diff --git a/entities/flag/flag.tscn b/entities/flag/flag.tscn index c1a5337..1b1a89a 100644 --- a/entities/flag/flag.tscn +++ b/entities/flag/flag.tscn @@ -1,17 +1,15 @@ [gd_scene load_steps=8 format=3 uid="uid://c88l3h0ph00c7"] [ext_resource type="Script" path="res://entities/flag/flag.gd" id="1_y7d3d"] -[ext_resource type="Script" path="res://addons/smoothing/smoothing.gd" id="2_es4ce"] [ext_resource type="PackedScene" uid="uid://d3l7fvbdg6m5g" path="res://entities/flag/assets/flag.glb" id="2_i78em"] -[ext_resource type="PackedScene" uid="uid://bcgkc5fhhyauv" path="res://entities/flag/waypoint.tscn" id="3_tu6jg"] +[ext_resource type="Shape3D" uid="uid://dfko4x6uq27q" path="res://entities/flag/resources/collider.tres" id="2_kx0v0"] +[ext_resource type="Shape3D" uid="uid://b5a6oybteqj6n" path="res://entities/flag/resources/grip_area.tres" id="3_uhsc8"] +[ext_resource type="PackedScene" uid="uid://2350a3ce4xs8" path="res://interfaces/waypoint/waypoint3d.tscn" id="4_y8nj0"] [sub_resource type="PhysicsMaterial" id="PhysicsMaterial_4ymrw"] friction = 0.5 bounce = 0.5 -[sub_resource type="BoxShape3D" id="BoxShape3D_fkf1k"] -size = Vector3(0.5, 2.33994, 0.5) - [sub_resource type="SceneReplicationConfig" id="SceneReplicationConfig_lpijf"] properties/0/path = NodePath(".:position") properties/0/spawn = true @@ -19,10 +17,10 @@ properties/0/replication_mode = 1 properties/1/path = NodePath(".:linear_velocity") properties/1/spawn = true properties/1/replication_mode = 1 -properties/2/path = NodePath(".:flag_state") +properties/2/path = NodePath("Smoothing/Mesh:visible") properties/2/spawn = true properties/2/replication_mode = 2 -properties/3/path = NodePath("Smoothing/Mesh:visible") +properties/3/path = NodePath("Flag:state") properties/3/spawn = true properties/3/replication_mode = 2 @@ -40,20 +38,23 @@ continuous_cd = true script = ExtResource("1_y7d3d") [node name="CollisionShape3D" type="CollisionShape3D" parent="."] -transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 1.175, 0) -shape = SubResource("BoxShape3D_fkf1k") +transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 1, 0.00601196) +shape = ExtResource("2_kx0v0") + +[node name="GripArea3D" type="Area3D" parent="."] + +[node name="CollisionShape3D" type="CollisionShape3D" parent="GripArea3D"] +transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 1, 0) +shape = ExtResource("3_uhsc8") + +[node name="Mesh" parent="." instance=ExtResource("2_i78em")] + +[node name="Waypoint" parent="." instance=ExtResource("4_y8nj0")] +transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 2.25, 0) +foreground_color = Color(0, 0.75, 0.75, 1) [node name="MultiplayerSynchronizer" type="MultiplayerSynchronizer" parent="."] replication_config = SubResource("SceneReplicationConfig_lpijf") -[node name="Smoothing" type="Node3D" parent="."] -script = ExtResource("2_es4ce") - -[node name="WaypointAttachment" type="Marker3D" parent="Smoothing"] - -[node name="Waypoint" parent="Smoothing/WaypointAttachment" node_paths=PackedStringArray("attach_point", "flag") instance=ExtResource("3_tu6jg")] -attach_point = NodePath("..") -flag = NodePath("../../..") - -[node name="Mesh" parent="Smoothing" instance=ExtResource("2_i78em")] -transform = Transform3D(0.5, 0, 0, 0, 0.5, 0, 0, 0, 0.5, 0, 0.0744106, 0) +[connection signal="dropped" from="." to="." method="_on_dropped"] +[connection signal="grabbed" from="." to="." method="_on_grabbed"] diff --git a/entities/flag/resources/collider.tres b/entities/flag/resources/collider.tres new file mode 100644 index 0000000..d2f56f4 --- /dev/null +++ b/entities/flag/resources/collider.tres @@ -0,0 +1,4 @@ +[gd_resource type="BoxShape3D" format=3 uid="uid://dfko4x6uq27q"] + +[resource] +size = Vector3(0.5, 2, 0.164246) diff --git a/entities/flag/resources/grip_area.tres b/entities/flag/resources/grip_area.tres new file mode 100644 index 0000000..cb56f58 --- /dev/null +++ b/entities/flag/resources/grip_area.tres @@ -0,0 +1,4 @@ +[gd_resource type="BoxShape3D" format=3 uid="uid://b5a6oybteqj6n"] + +[resource] +size = Vector3(0.5, 2, 0.5) diff --git a/entities/flag/waypoint.gd b/entities/flag/waypoint.gd deleted file mode 100644 index 12d6741..0000000 --- a/entities/flag/waypoint.gd +++ /dev/null @@ -1,52 +0,0 @@ -# This file is part of open-fpsz. -# -# This program is free software: you can redistribute it and/or modify -# it under the terms of the GNU General Public License as published by -# the Free Software Foundation, either version 3 of the License, or -# (at your option) any later version. -# -# This program is distributed in the hope that it will be useful, -# but WITHOUT ANY WARRANTY; without even the implied warranty of -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -# GNU General Public License for more details. -# -# You should have received a copy of the GNU General Public License -# along with this program. If not, see . -extends Control - -@export var attach_point : Node3D -@export var flag : Flag - -@onready var _iff_container : Control = $IFFContainer - -func _ready() -> void: - attach_point.transform = attach_point.transform.translated( - Vector3(0, flag.get_node("CollisionShape3D").shape.size.y, 0)) - -func _process(_delta : float) -> void: - # disable waypoint repositioning when running headless - if DisplayServer.get_name() == "headless": - set_process(false) - return - - # repositon iff on viewport - var camera : Camera3D = get_viewport().get_camera_3d() - var viewport_rect : Rect2 = get_viewport_rect() - # if the player is NOT infront of the camera or camera does NOT have LOS to player - if camera.is_position_behind(attach_point.global_position): - _iff_container.hide() # hide the IFF and exit function - return - else: - _iff_container.show() # display the IFF - # get the screen location of the players head - var new_iff_position : Vector2 = camera.unproject_position(attach_point.global_position) - # check if the unprojected point lies inside the viewport - if !Rect2(Vector2(0, 0), viewport_rect.size).has_point(new_iff_position): - _iff_container.hide() # hide the IFF and exit function - return - # move the IFF up so the bottom of it is at the players head - new_iff_position.y -= _iff_container.size.y - # move the IFF left so it's centered horizontally above players head - new_iff_position.x -= _iff_container.size.x / 2 - # set the position of the IFF - position = new_iff_position diff --git a/entities/flag/waypoint.tscn b/entities/flag/waypoint.tscn deleted file mode 100644 index a3f5cc5..0000000 --- a/entities/flag/waypoint.tscn +++ /dev/null @@ -1,27 +0,0 @@ -[gd_scene load_steps=2 format=3 uid="uid://bcgkc5fhhyauv"] - -[ext_resource type="Script" path="res://entities/flag/waypoint.gd" id="1_gmnl6"] - -[node name="IFF" type="Control"] -layout_mode = 3 -anchors_preset = 0 -script = ExtResource("1_gmnl6") - -[node name="IFFContainer" type="MarginContainer" parent="."] -layout_mode = 0 -offset_right = 11.0 -offset_bottom = 20.0 -mouse_filter = 2 - -[node name="Chevron" type="Label" parent="IFFContainer"] -layout_direction = 2 -layout_mode = 2 -size_flags_vertical = 1 -theme_override_colors/font_color = Color(0, 1, 1, 0.784314) -theme_override_colors/font_outline_color = Color(0, 0, 0, 1) -theme_override_constants/outline_size = 3 -theme_override_constants/line_spacing = -20 -theme_override_font_sizes/font_size = 14 -text = "▼" -horizontal_alignment = 1 -vertical_alignment = 2 diff --git a/entities/player/player.gd b/entities/player/player.gd index c4ddee0..96d807b 100644 --- a/entities/player/player.gd +++ b/entities/player/player.gd @@ -18,6 +18,7 @@ enum PlayerState { PLAYER_ALIVE, PLAYER_DEAD } @export var iff : Control @export var health_component : HealthComponent +@export var flag_carry_component : FlagCarryComponent @export var walkable_surface_sensor : ShapeCast3D ## The inventory component can store up to [member Inventory.slots] objects. It @@ -49,7 +50,6 @@ enum PlayerState { PLAYER_ALIVE, PLAYER_DEAD } @onready var hud : CanvasLayer = $HUD @onready var animation_player : AnimationPlayer = $AnimationPlayer @onready var collision_shape : CollisionShape3D = $CollisionShape3D -@onready var flag_carry_component : FlagCarryComponent = %Pivot/FlagCarryComponent @onready var jetpack_particles : Array = $Smoothing/ThirdPerson/Mesh/JetpackFX.get_children() @onready var match_participant_component : MatchParticipantComponent = $MatchParticipantComponent @@ -65,7 +65,6 @@ static var pawn_player : Player func _ready() -> void: 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) diff --git a/entities/player/player.tscn b/entities/player/player.tscn index dfaaac4..5ecea45 100644 --- a/entities/player/player.tscn +++ b/entities/player/player.tscn @@ -1,8 +1,8 @@ [gd_scene load_steps=45 format=3 uid="uid://cbhx1xme0sb7k"] [ext_resource type="Script" path="res://entities/player/player.gd" id="1_mk68k"] -[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="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="PackedScene" uid="uid://dsysi2rd3bu76" path="res://interfaces/hud/iffs/iff.tscn" id="7_8hc80"] @@ -206,8 +206,9 @@ 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", "walkable_surface_sensor", "inventory", "tp_mesh") groups=["Player"]] +[node name="Player" type="RigidBody3D" node_paths=PackedStringArray("iff", "health_component", "flag_carry_component", "walkable_surface_sensor", "inventory", "tp_mesh") groups=["Player"]] collision_mask = 2147483649 +collision_priority = 9.0 axis_lock_angular_x = true axis_lock_angular_y = true axis_lock_angular_z = true @@ -216,27 +217,20 @@ physics_material_override = SubResource("PhysicsMaterial_clur0") can_sleep = false continuous_cd = true script = ExtResource("1_mk68k") -iff = NodePath("Smoothing/ThirdPerson/IFF") +iff = NodePath("Smoothing/ThirdPerson/IFFAttachment/IFF") health_component = NodePath("HealthComponent") +flag_carry_component = NodePath("Pivot/FlagCarryComponent") walkable_surface_sensor = NodePath("WalkableSurfaceSensor") inventory = NodePath("Pivot/Inventory") tp_mesh = NodePath("Smoothing/ThirdPerson/Mesh") jump_height = 1.5 -[node name="Sensor" type="Area3D" parent="."] -collision_layer = 0 -collision_mask = 8 -monitorable = false - -[node name="CollisionShape3D" type="CollisionShape3D" parent="Sensor"] -shape = ExtResource("2_vjqny") - [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") +shape = ExtResource("4_8kvcy") [node name="WalkableSurfaceSensor" type="ShapeCast3D" parent="."] transform = Transform3D(1.05, 0, 0, 0, 1.05, 0, 0, 0, 1.05, 0, -0.85, 0) @@ -245,7 +239,7 @@ target_position = Vector3(0, 0, 0) collision_mask = 2147483648 [node name="CollisionShape3D" type="CollisionShape3D" parent="."] -shape = ExtResource("2_vjqny") +shape = ExtResource("4_8kvcy") [node name="HUD" parent="." instance=ExtResource("3_ccety")] @@ -295,19 +289,17 @@ visible = false [node name="GrenadeLauncher" parent="Pivot/Inventory" instance=ExtResource("16_4xs2j")] visible = false -[node name="FlagCarryComponent" type="Node3D" parent="Pivot" 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="Pivot/FlagCarryComponent" instance=ExtResource("18_7nkei")] -transform = Transform3D(0.5, 0, 0, 0, 0.5, 0, 0, 0, 0.5, 1.559e-08, -0.462981, -0.178329) - [node name="SpineIKTarget" type="Marker3D" parent="Pivot"] transform = Transform3D(-1, 0, -8.74228e-08, 0, 1, 0, 8.74228e-08, 0, -1, 0, 0, 0) +[node name="FlagCarryComponent" type="Node3D" parent="Pivot" node_paths=PackedStringArray("mesh")] +transform = Transform3D(-1, 0, -8.74228e-08, 0, 1, 0, 8.74228e-08, 0, -1, 0, -0.25, 0.377972) +visible = false +script = ExtResource("8_pdfbn") +mesh = NodePath("FlagMesh") + +[node name="FlagMesh" parent="Pivot/FlagCarryComponent" instance=ExtResource("18_7nkei")] + [node name="Smoothing" type="Node3D" parent="."] script = ExtResource("11_k330l") target = NodePath("..") @@ -329,7 +321,6 @@ bones/6/rotation = Quaternion(0.160951, 0.00623474, 0.0096637, 0.986895) bones/8/rotation = Quaternion(0.675761, -0.399581, 0.409695, 0.464577) bones/10/rotation = Quaternion(0.212344, -0.0870591, -0.287653, 0.929831) bones/12/rotation = Quaternion(0.0811501, 0.206806, -0.754068, 0.618084) -bones/14/position = Vector3(-0.074525, 0.220475, 0.075475) bones/14/rotation = Quaternion(0.00943715, 0.0971687, -0.145046, 0.984597) bones/20/rotation = Quaternion(-0.123455, 0.0248346, 0.23344, 0.964183) bones/24/rotation = Quaternion(0.0450683, -0.000817796, 0.0508488, 0.997689) @@ -347,9 +338,8 @@ bones/56/rotation = Quaternion(-0.0254885, 0.0439755, -0.00910637, 0.998666) bones/58/rotation = Quaternion(-0.0119802, 0.289956, -0.0527053, 0.955513) bones/62/rotation = Quaternion(0.689943, 0.375565, -0.410267, 0.463261) bones/64/rotation = Quaternion(0.337746, -0.290519, 0.159479, 0.880961) -bones/66/position = Vector3(0.055475, 0.231475, 0.000474975) bones/66/rotation = Quaternion(0.540371, -0.580679, 0.406779, 0.453147) -bones/68/position = Vector3(-0.014525, 0.270475, -0.054525) +bones/68/position = Vector3(-1.77636e-17, 0.240718, 0) bones/68/rotation = Quaternion(0.0150529, -0.289001, 0.0720108, 0.954498) bones/70/rotation = Quaternion(0.155965, 0.0109114, -0.00107202, 0.987702) bones/72/rotation = Quaternion(0.563923, 4.19095e-08, -0.0577906, 0.823803) @@ -376,7 +366,7 @@ bones/124/rotation = Quaternion(0.417677, -0.0431149, 0.00625689, 0.90755) bones/126/rotation = Quaternion(0.397818, -0.0427722, -0.00601182, 0.916447) [node name="HandAttachment" parent="Smoothing/ThirdPerson/Mesh/Node/Skeleton3D" index="0"] -transform = Transform3D(-0.152214, 0.0548832, 0.986823, 0.933991, 0.334546, 0.125459, -0.323252, 0.94078, -0.102183, -0.191759, 1.06335, 0.0698007) +transform = Transform3D(-0.152214, 0.0548832, 0.986823, 0.933991, 0.334546, 0.125459, -0.323252, 0.94078, -0.102183, -0.261612, 1.14328, 0.0896011) [node name="grip" parent="Smoothing/ThirdPerson/Mesh/Node/Skeleton3D/HandAttachment/SpaceGun/Mesh/Armature/Skeleton3D" index="0"] transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 2.84217e-14, 1.19209e-07, 2.38419e-07) @@ -400,7 +390,13 @@ transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 0.692504, 1.30946) transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 0.692504, 1.30946) [node name="Barrels" parent="Smoothing/ThirdPerson/Mesh/Node/Skeleton3D/HandAttachment/ChainGun" index="3"] -transform = Transform3D(-1, 0, 8.9407e-08, 8.47504e-08, 0, 1, 0, 1, -3.72529e-09, 0, -2.38419e-07, -0.55315) +transform = Transform3D(-1, -1.49012e-08, 8.801e-08, 8.19564e-08, -3.72529e-09, 1, 0, 1, -7.45058e-09, 5.96046e-08, 0, -0.55315) + +[node name="Skeleton3D" parent="Smoothing/ThirdPerson/Mesh/Node/Skeleton3D/HandAttachment/GrenadeLauncher/Armature" index="0"] +bones/0/rotation = Quaternion(0, 0.707107, 0.707107, 0) +bones/1/rotation = Quaternion(0, 0.707107, 0.707107, 0) +bones/2/rotation = Quaternion(0, 0.707107, 0.707107, 0) +bones/3/rotation = Quaternion(0, 0.707107, 0.707107, 0) [node name="barrel" parent="Smoothing/ThirdPerson/Mesh/Node/Skeleton3D/HandAttachment/GrenadeLauncher/Armature/Skeleton3D" index="0"] transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 1.19209e-07, 0) @@ -443,11 +439,13 @@ 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) +visible = false -[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") +[node name="IFF" parent="Smoothing/ThirdPerson/IFFAttachment" node_paths=PackedStringArray("player", "match_participant_component", "attach_point") instance=ExtResource("7_8hc80")] +visible = false +player = NodePath("../../../..") +match_participant_component = NodePath("../../../../MatchParticipantComponent") +attach_point = NodePath("..") [connection signal="energy_changed" from="." to="HUD" method="_on_player_energy_changed"] diff --git a/entities/player/collision_shape.tres b/entities/player/resources/collider.tres similarity index 100% rename from entities/player/collision_shape.tres rename to entities/player/resources/collider.tres diff --git a/interfaces/waypoint/assets/waypoint.svg b/interfaces/waypoint/assets/waypoint.svg new file mode 100644 index 0000000..6a5a1b0 --- /dev/null +++ b/interfaces/waypoint/assets/waypoint.svg @@ -0,0 +1 @@ + diff --git a/interfaces/waypoint/assets/waypoint.svg.import b/interfaces/waypoint/assets/waypoint.svg.import new file mode 100644 index 0000000..600e8c8 --- /dev/null +++ b/interfaces/waypoint/assets/waypoint.svg.import @@ -0,0 +1,38 @@ +[remap] + +importer="texture" +type="CompressedTexture2D" +uid="uid://cpb6vpa0c74rl" +path.s3tc="res://.godot/imported/waypoint.svg-e7e029f470e2f863636e9426f3893ced.s3tc.ctex" +metadata={ +"imported_formats": ["s3tc_bptc"], +"vram_texture": true +} + +[deps] + +source_file="res://interfaces/waypoint/assets/waypoint.svg" +dest_files=["res://.godot/imported/waypoint.svg-e7e029f470e2f863636e9426f3893ced.s3tc.ctex"] + +[params] + +compress/mode=2 +compress/high_quality=false +compress/lossy_quality=0.7 +compress/hdr_compression=1 +compress/normal_map=0 +compress/channel_pack=0 +mipmaps/generate=true +mipmaps/limit=-1 +roughness/mode=0 +roughness/src_normal="" +process/fix_alpha_border=true +process/premult_alpha=false +process/normal_map_invert_y=false +process/hdr_as_srgb=false +process/hdr_clamp_exposure=false +process/size_limit=0 +detect_3d/compress_to=0 +svg/scale=1.0 +editor/scale_with_editor_scale=false +editor/convert_colors_with_editor_theme=false diff --git a/interfaces/waypoint/waypoint.gd b/interfaces/waypoint/waypoint.gd new file mode 100644 index 0000000..a3113dc --- /dev/null +++ b/interfaces/waypoint/waypoint.gd @@ -0,0 +1,129 @@ +# This file is part of open-fpsz. +# +# This program is free software: you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation, either version 3 of the License, or +# (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program. If not, see . +extends Control + +# Some margin to keep the marker away from the screen's corners. +const MARGIN : float = 8. + +# If `true`, the waypoint sticks to the viewport's edges when moving off-screen. +@export var sticky : bool = true + +# If `true`, the waypoint fades as the camera get closer. +@export var fade : bool = true + +# The waypoint's text. +@export var text : String = "Waypoint": + set(value): + text = value + # The label's text can only be set once the node is ready. + if is_inside_tree(): + label.text = value + +@onready var camera : Camera3D = get_viewport().get_camera_3d() +@onready var label : Label = $Label +@onready var parent : Node = get_parent() + +func _ready() -> void: + self.text = text + if not parent is Node3D: + push_error("The waypoint's parent node must inherit from Node3D.") + if DisplayServer.get_name() == "headless": + parent.queue_free() + +func _process(_delta : float) -> void: + if not camera.current: + # If the camera we have isn't the current one, get the current camera. + camera = get_viewport().get_camera_3d() + + var parent_position : Vector3 = parent.global_transform.origin + var camera_transform : Transform3D = camera.global_transform + var camera_position : Vector3 = camera_transform.origin + + # We would use "camera.is_position_behind(parent_position)", except + # that it also accounts for the near clip plane, which we don't want. + var is_behind : bool = camera_transform.basis.z.dot(parent_position - camera_position) > 0 + + # Fade the waypoint when the camera gets close. + if fade: + var distance : float = camera_position.distance_to(parent_position) + modulate.a = remap(distance, 0., 256., 0., 1.) + + var unprojected_position : Vector2 = camera.unproject_position(parent_position) + var viewport_size : Vector2 = get_viewport_rect().size + + if not sticky: + # For non-sticky waypoints, we don't need to clamp and calculate + # the position if the waypoint goes off screen. + position = unprojected_position + visible = not is_behind + return + + # We need to handle the axes differently. + # For the screen's X axis, the projected position is useful to us, + # but we need to force it to the side if it's also behind. + if is_behind: + if unprojected_position.x < viewport_size.x / 2.: + unprojected_position.x = viewport_size.x - MARGIN + else: + unprojected_position.x = MARGIN + + # For the screen's Y axis, the projected position is NOT useful to us + # because we don't want to indicate to the user that they need to look + # up or down to see something behind them. Instead, here we approximate + # the correct position using difference of the X axis Euler angles + # (up/down rotation) and the ratio of that with the camera's FOV. + # This will be slightly off from the theoretical "ideal" position. + if is_behind or unprojected_position.x < MARGIN or \ + unprojected_position.x > viewport_size.x - MARGIN: + var look : Transform3D = camera_transform.looking_at(parent_position, Vector3.UP) + var diff : float = angle_diff( + look.basis.get_euler().x, camera_transform.basis.get_euler().x) + unprojected_position.y = viewport_size.y * (0.5 + (diff / deg_to_rad(camera.fov))) + + position = Vector2( + clamp(unprojected_position.x, MARGIN, viewport_size.x - MARGIN), + clamp(unprojected_position.y, MARGIN, viewport_size.y - MARGIN) + ) + + label.visible = true + rotation = 0 + # Used to display a diagonal arrow when the waypoint is displayed in + # one of the screen corners. + var overflow : float = .0 + + if position.x <= MARGIN: + # Left overflow. + overflow = -TAU / 8.0 + label.visible = false + rotation = TAU / 4.0 + elif position.x >= viewport_size.x - MARGIN: + # Right overflow. + overflow = TAU / 8.0 + label.visible = false + rotation = TAU * 3.0 / 4.0 + + if position.y <= MARGIN: + # Top overflow. + label.visible = false + rotation = TAU / 2.0 + overflow + elif position.y >= viewport_size.y - MARGIN: + # Bottom overflow. + label.visible = false + rotation = -overflow + + +static func angle_diff(from : float, to : float) -> float: + var diff : float = fmod(to - from, TAU) + return fmod(2.0 * diff, TAU) - diff diff --git a/interfaces/waypoint/waypoint.tscn b/interfaces/waypoint/waypoint.tscn new file mode 100644 index 0000000..6a0f401 --- /dev/null +++ b/interfaces/waypoint/waypoint.tscn @@ -0,0 +1,30 @@ +[gd_scene load_steps=3 format=3 uid="uid://bcgkc5fhhyauv"] + +[ext_resource type="Script" path="res://interfaces/waypoint/waypoint.gd" id="1_gmnl6"] +[ext_resource type="Texture2D" uid="uid://cpb6vpa0c74rl" path="res://interfaces/waypoint/assets/waypoint.svg" id="2_xby6k"] + +[node name="Waypoint" type="Control"] +layout_mode = 3 +anchors_preset = 0 +size_flags_horizontal = 3 +script = ExtResource("1_gmnl6") +fade = false + +[node name="Marker" type="TextureRect" parent="."] +visible = false +layout_mode = 0 +offset_left = -8.0 +offset_top = -16.0 +offset_right = 8.0 +texture = ExtResource("2_xby6k") +expand_mode = 1 + +[node name="Label" type="Label" parent="."] +layout_mode = 0 +offset_left = -128.0 +offset_top = -42.0 +offset_right = 128.0 +offset_bottom = -19.0 +theme_override_font_sizes/font_size = 14 +horizontal_alignment = 1 +vertical_alignment = 2 diff --git a/interfaces/waypoint/waypoint3d.gd b/interfaces/waypoint/waypoint3d.gd new file mode 100644 index 0000000..d4311a9 --- /dev/null +++ b/interfaces/waypoint/waypoint3d.gd @@ -0,0 +1,45 @@ +# This file is part of open-fpsz. +# +# This program is free software: you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation, either version 3 of the License, or +# (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program. If not, see . +@tool +class_name Waypoint3D extends Node3D + +# If `true`, the waypoint sticks to the viewport's edges when moving off-screen. +@export var sticky : bool = true + +# If `true`, the waypoint fades as the camera get closer. +@export var fade : bool = true + +# The waypoint's text. +@export var text : String: + set(value): + text = value + # The label's text can only be set once the node is ready. + if is_inside_tree(): + label.text = value + +## The foreground color to modulate the waypoint color +@export var foreground_color : Color = Color.WHITE + +@onready var label : Label3D = $Label3D +@onready var sprite : Sprite3D = $Sprite3D + +# Called when the node enters the scene tree for the first time. +func _ready() -> void: + pass + +func _process(_delta : float) -> void: + sprite.modulate = foreground_color + label.modulate = foreground_color + label.outline_modulate.a = foreground_color.a diff --git a/interfaces/waypoint/waypoint3d.tscn b/interfaces/waypoint/waypoint3d.tscn new file mode 100644 index 0000000..ed8c190 --- /dev/null +++ b/interfaces/waypoint/waypoint3d.tscn @@ -0,0 +1,23 @@ +[gd_scene load_steps=3 format=3 uid="uid://2350a3ce4xs8"] + +[ext_resource type="Texture2D" uid="uid://cpb6vpa0c74rl" path="res://interfaces/waypoint/assets/waypoint.svg" id="1_502g6"] +[ext_resource type="Script" path="res://interfaces/waypoint/waypoint3d.gd" id="1_kq7bj"] + +[node name="Waypoint" type="Node3D"] +script = ExtResource("1_kq7bj") + +[node name="Label3D" type="Label3D" parent="."] +transform = Transform3D(0.5, 0, 0, 0, 0.5, 0, 0, 0, 0.5, 0, 0, 0) +offset = Vector2(0, 48) +billboard = 2 +no_depth_test = true +fixed_size = true +line_spacing = 32.025 + +[node name="Sprite3D" type="Sprite3D" parent="."] +transform = Transform3D(0.05, 0, 0, 0, 0.05, 0, 0, 0, 0.05, 0, 0, 0) +offset = Vector2(0, 64) +billboard = 2 +no_depth_test = true +fixed_size = true +texture = ExtResource("1_502g6") diff --git a/project.godot b/project.godot index d5fa618..9f5432c 100644 --- a/project.godot +++ b/project.godot @@ -42,6 +42,7 @@ gdscript/warnings/property_used_as_function=2 gdscript/warnings/constant_used_as_function=2 gdscript/warnings/function_used_as_property=2 gdscript/warnings/untyped_declaration=1 +gdscript/warnings/static_called_on_instance=0 [editor] diff --git a/systems/global.gd b/systems/global.gd index 1b374a0..740b524 100644 --- a/systems/global.gd +++ b/systems/global.gd @@ -27,7 +27,7 @@ var type : Node: # keep reference to new type type = new_type if type != null: - add_child(type) + get_tree().get_root().add_child(type) type_changed.emit(type) func _unhandled_input(event : InputEvent) -> void: diff --git a/tests/test_flag.gd b/tests/test_flag.gd index 78a87e7..b0a8055 100644 --- a/tests/test_flag.gd +++ b/tests/test_flag.gd @@ -29,46 +29,46 @@ func _is_mesh_visible() -> bool: return mesh.is_visible() func test_that_flag_is_on_stand_by_default() -> void: - assert_eq(_subject.flag_state, Flag.FlagState.FLAG_STATE_ON_STAND) + assert_eq(_subject.flag_state, Flag.FlagState.ON_STAND) func test_that_mesh_is_visible_by_default() -> void: assert_true(_is_mesh_visible()) func test_that_flag_on_stand_can_be_grabbed() -> void: - _subject.flag_state = Flag.FlagState.FLAG_STATE_ON_STAND - assert_true(_subject.can_be_grabbed()) + _subject.flag_state = Flag.FlagState.ON_STAND + assert_true(_subject.state != _subject.FlagState.TAKEN) func test_that_dropped_flag_can_be_grabbed() -> void: - _subject.flag_state = Flag.FlagState.FLAG_STATE_DROPPED - assert_true(_subject.can_be_grabbed()) + _subject.flag_state = Flag.FlagState.DROPPED + assert_true(_subject.state != _subject.FlagState.TAKEN) func test_that_taken_flag_cannot_be_grabbed() -> void: - _subject.flag_state = Flag.FlagState.FLAG_STATE_TAKEN - assert_false(_subject.can_be_grabbed()) + _subject.flag_state = Flag.FlagState.TAKEN + assert_false(_subject.state != _subject.FlagState.TAKEN) func test_that_on_stand_flag_grab_emits_grab_signal_and_changes_state() -> void: - _subject.flag_state = Flag.FlagState.FLAG_STATE_ON_STAND + _subject.flag_state = Flag.FlagState.ON_STAND var player : Player = PLAYER.instantiate() _subject.grab(player) assert_signal_emitted_with_parameters(_subject, 'grabbed', [player]) - assert_eq(_subject.flag_state, Flag.FlagState.FLAG_STATE_TAKEN) + assert_eq(_subject.flag_state, Flag.FlagState.TAKEN) assert_eq(_subject.last_carrier, player) player.free() func test_that_dropped_flag_grab_emits_grab_signal_and_changes_state() -> void: - _subject.flag_state = Flag.FlagState.FLAG_STATE_DROPPED + _subject.flag_state = Flag.FlagState.DROPPED var player : Player = PLAYER.instantiate() _subject.grab(player) assert_signal_emitted_with_parameters(_subject, 'grabbed', [player]) - assert_eq(_subject.flag_state, Flag.FlagState.FLAG_STATE_TAKEN) + assert_eq(_subject.flag_state, Flag.FlagState.TAKEN) assert_eq(_subject.last_carrier, player) player.free() func test_that_taken_flag_grab_does_not_emit_grab_signal_and_keeps_state() -> void: - _subject.flag_state = Flag.FlagState.FLAG_STATE_TAKEN + _subject.flag_state = Flag.FlagState.TAKEN _subject.grab(null) # doesn't matter that it's null in this case assert_signal_not_emitted(_subject, 'grabbed') - assert_eq(_subject.flag_state, Flag.FlagState.FLAG_STATE_TAKEN) + assert_eq(_subject.flag_state, Flag.FlagState.TAKEN) assert_null(_subject.last_carrier) func test_that_flag_grab_hides_mesh() -> void: @@ -82,14 +82,14 @@ func test_that_taken_flag_drop_emits_signal_and_changes_state() -> void: _subject.grab(player) _subject.drop(player) assert_signal_emitted_with_parameters(_subject, 'dropped', [player]) - assert_eq(_subject.flag_state, Flag.FlagState.FLAG_STATE_DROPPED) + assert_eq(_subject.flag_state, Flag.FlagState.DROPPED) player.free() func test_that_on_stand_flag_drop_does_not_emit_signals_and_keeps_state() -> void: var player : Player = PLAYER.instantiate() _subject.drop(player) assert_signal_not_emitted(_subject, 'dropped') - assert_eq(_subject.flag_state, Flag.FlagState.FLAG_STATE_ON_STAND) + assert_eq(_subject.flag_state, Flag.FlagState.ON_STAND) player.free() func test_that_flag_drop_shows_mesh() -> void: