From 2879337ad271112043dcea642e92e14c587d177a Mon Sep 17 00:00:00 2001 From: Zakarya Date: Tue, 28 May 2024 20:28:37 -0700 Subject: [PATCH] In-editor tools module --- README.md | 23 +++++++++++------- addons/fpc/EditorModule.gd | 48 ++++++++++++++++++++++++++++++++++++++ addons/fpc/character.tscn | 6 ++++- test_world.tscn | 5 ++++ 4 files changed, 73 insertions(+), 9 deletions(-) create mode 100644 addons/fpc/EditorModule.gd diff --git a/README.md b/README.md index 298b843..126a54e 100644 --- a/README.md +++ b/README.md @@ -11,14 +11,16 @@ Some parts came from StayAtHomeDev's FPS tutorial. You can find that [here](http Move with WASD, space to jump, shift to sprint, C to crouch. **FEATURES:** - - In-air momentum - - Motion smoothing - - FOV smoothing - - Movement animations - - Crouching - - Sprinting - - 2 crosshairs/reticles, one is animated (more to come?) - - Controller/GamePad support (enabled through code, see wiki) +- Extremely configurable +- In-air momentum +- Motion smoothing +- FOV smoothing +- Movement animations +- Crouching +- Sprinting +- 2 crosshairs/reticles, one is animated (more to come?) +- Controller/GamePad support (enabled through code, see wiki) +- In-editor tools (enable editable children to use) If you make a cool game with this addon, I would love to hear about it! @@ -54,3 +56,8 @@ Use the `change_reticle` function on the character. - Remove the script from the reticle and create a new one. (for some reason you have to do this) - Edit the reticle to your needs. - Follow the "how to change reticles" directions to use it. + +**How to use the editor tools:** +- Enable editable children on the `CharacterBody` node +- Use the options in the Properties tab to change things +- These changes apply in runtime as well diff --git a/addons/fpc/EditorModule.gd b/addons/fpc/EditorModule.gd new file mode 100644 index 0000000..28297ce --- /dev/null +++ b/addons/fpc/EditorModule.gd @@ -0,0 +1,48 @@ +@tool +extends Node + +# This module affects runtime nad + + +#TODO: Add descriptions +@export_category("Controller Editor Module") +@export var head_y_rotation : float = 0: + set(new_rotation): + head_y_rotation = new_rotation + HEAD.rotation.y = head_y_rotation + update_configuration_warnings() + +@export_group("Nodes") +@export var CHARACTER : CharacterBody3D +@export var head_path : String = "Head" # From this nodes parent node +#@export var CAMERA : Camera3D +#@export var HEADBOB_ANIMATION : AnimationPlayer +#@export var JUMP_ANIMATION : AnimationPlayer +#@export var CROUCH_ANIMATION : AnimationPlayer +#@export var COLLISION_MESH : CollisionShape3D + +var HEAD + + +func _ready(): + HEAD = get_node("../" + head_path) + if Engine.is_editor_hint(): + pass + else: + HEAD.rotation.y = head_y_rotation + +func _process(delta): + if Engine.is_editor_hint(): + pass + +func _get_configuration_warnings(): + var warnings = [] + + if head_y_rotation > 360: + warnings.append("The head rotation is greater than 360") + + if head_y_rotation < 0: + warnings.append("The head rotation is less than 0") + + # Returning an empty array gives no warnings + return warnings diff --git a/addons/fpc/character.tscn b/addons/fpc/character.tscn index b2a0fdc..34159db 100644 --- a/addons/fpc/character.tscn +++ b/addons/fpc/character.tscn @@ -1,6 +1,7 @@ -[gd_scene load_steps=20 format=3 uid="uid://cc1m2a1obsyn4"] +[gd_scene load_steps=21 format=3 uid="uid://cc1m2a1obsyn4"] [ext_resource type="Script" path="res://addons/fpc/character.gd" id="1_0t4e8"] +[ext_resource type="Script" path="res://addons/fpc/EditorModule.gd" id="3_v3ckk"] [ext_resource type="Script" path="res://addons/fpc/debug.gd" id="3_x1wcc"] [sub_resource type="StandardMaterial3D" id="StandardMaterial3D_kp17n"] @@ -455,3 +456,6 @@ layout_mode = 2 transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 1, 0) shape = SubResource("SphereShape3D_k4wwl") target_position = Vector3(0, 0.5, 0) + +[node name="EditorModule" type="Node" parent="."] +script = ExtResource("3_v3ckk") diff --git a/test_world.tscn b/test_world.tscn index b6901b9..e902043 100644 --- a/test_world.tscn +++ b/test_world.tscn @@ -65,6 +65,9 @@ uv1_triplanar_sharpness = 0.000850145 [node name="Character" parent="." instance=ExtResource("1_e18vq")] transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 1, 0) +[node name="Camera" parent="Character/Head" index="0"] +transform = Transform3D(1, 0, 0, 0, 0.999391, -0.0348995, 0, 0.0348995, 0.999391, 0, 0, 0) + [node name="WorldEnvironment" type="WorldEnvironment" parent="."] environment = SubResource("Environment_20rw3") @@ -104,3 +107,5 @@ transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, -4.5, 3, -15.5) use_collision = true size = Vector3(19, 8, 1) material = SubResource("StandardMaterial3D_7j4uu") + +[editable path="Character"]