feat: add two-handed flashlight interactions

This commit is contained in:
2026-08-24 00:48:07 +02:00
parent f4331f426c
commit bed12ad335
13 changed files with 524 additions and 1 deletions
@@ -0,0 +1,26 @@
[gd_scene load_steps=3 format=3 uid="uid://dy6p2w9m4c8kr"]
[sub_resource type="StandardMaterial3D" id="Material_flashlight"]
albedo_color = Color(0.08, 0.09, 0.1, 1)
metallic = 0.65
roughness = 0.3
[sub_resource type="CylinderMesh" id="Mesh_flashlight"]
material = SubResource("Material_flashlight")
top_radius = 0.055
bottom_radius = 0.07
height = 0.32
radial_segments = 12
[node name="FlashlightHeldView" type="Node3D"]
[node name="MeshInstance3D" type="MeshInstance3D" parent="."]
transform = Transform3D(1, 0, 0, 0, -4.371139e-08, -1, 0, 1, -4.371139e-08, 0, 0, -0.08)
mesh = SubResource("Mesh_flashlight")
[node name="SpotLight3D" type="SpotLight3D" parent="."]
visible = false
light_energy = 3.0
shadow_enabled = true
spot_range = 14.0
spot_angle = 24.0
@@ -0,0 +1,47 @@
[gd_scene load_steps=6 format=3 uid="uid://cv8m3q1y6r4nf"]
[ext_resource type="Script" uid="uid://a5q9y2d7m4v8p" path="res://src/Features/Items/Godot/Flashlight/FlashlightItemController.cs" id="1_script"]
[ext_resource type="PackedScene" uid="uid://dy6p2w9m4c8kr" path="res://src/Features/Items/Godot/Flashlight/FlashlightHeldView.tscn" id="2_held"]
[sub_resource type="StandardMaterial3D" id="Material_flashlight"]
albedo_color = Color(0.08, 0.09, 0.1, 1)
metallic = 0.65
roughness = 0.3
[sub_resource type="CylinderMesh" id="Mesh_flashlight"]
material = SubResource("Material_flashlight")
top_radius = 0.055
bottom_radius = 0.07
height = 0.32
radial_segments = 12
[sub_resource type="CapsuleShape3D" id="Shape_flashlight"]
radius = 0.07
height = 0.32
[node name="FlashlightItem" type="RigidBody3D" node_paths=PackedStringArray("Collision", "WorldVisual", "WorldLight")]
mass = 0.4
script = ExtResource("1_script")
DefinitionId = "flashlight"
DisplayName = "latarkę"
Collision = NodePath("CollisionShape3D")
WorldVisual = NodePath("WorldVisual")
HeldViewScene = ExtResource("2_held")
WorldLight = NodePath("WorldVisual/SpotLight3D")
[node name="CollisionShape3D" type="CollisionShape3D" parent="."]
transform = Transform3D(1, 0, 0, 0, -4.371139e-08, -1, 0, 1, -4.371139e-08, 0, 0, 0)
shape = SubResource("Shape_flashlight")
[node name="WorldVisual" type="Node3D" parent="."]
[node name="MeshInstance3D" type="MeshInstance3D" parent="WorldVisual"]
transform = Transform3D(1, 0, 0, 0, -4.371139e-08, -1, 0, 1, -4.371139e-08, 0, 0, 0)
mesh = SubResource("Mesh_flashlight")
[node name="SpotLight3D" type="SpotLight3D" parent="WorldVisual"]
visible = false
light_energy = 3.0
shadow_enabled = true
spot_range = 14.0
spot_angle = 24.0
@@ -0,0 +1,39 @@
using Game.Features.Items.Contracts;
using Game.Features.Items.Domain.Flashlight;
using Game.Features.Items.Godot;
using Godot;
namespace Game.Features.Items.Godot.Flashlight;
public partial class FlashlightItemController : WorldItemController
{
[Export] public SpotLight3D WorldLight;
private SpotLight3D _heldLight;
protected override IItemInstance CreateItemInstance(ItemInfo itemInfo) => new FlashlightItemInstance(itemInfo);
protected override void OnHeldViewCreated(Node3D heldView)
{
_heldLight = heldView.GetNodeOrNull<SpotLight3D>("SpotLight3D");
}
protected override void OnHeldViewRemoving(Node3D heldView)
{
_heldLight = null;
}
protected override void OnPresentationChanged(IItemInstance item)
{
bool isOn = item is FlashlightItemInstance flashlight && flashlight.IsOn;
if (WorldLight is not null)
{
WorldLight.Visible = isOn && !IsHeld;
}
if (_heldLight is not null)
{
_heldLight.Visible = isOn;
}
}
}
@@ -0,0 +1 @@
uid://a5q9y2d7m4v8p