Min max triggers

This commit is contained in:
Marco 2025-09-09 16:57:26 +02:00
commit 0492a008d0
6 changed files with 130 additions and 45 deletions

View file

@ -1,4 +1,4 @@
[gd_scene load_steps=243 format=4 uid="uid://d21ewu3hfa3us"]
[gd_scene load_steps=244 format=4 uid="uid://d21ewu3hfa3us"]
[ext_resource type="Script" uid="uid://kno58homctew" path="res://addons/func_godot/src/map/func_godot_map.gd" id="1_ifqpu"]
[ext_resource type="Resource" uid="uid://cx41lsryg5wpm" path="res://3D/TrenchBroom/map_settings.tres" id="2_dvbie"]
@ -981,7 +981,10 @@ _surfaces = [{
[sub_resource type="ConvexPolygonShape3D" id="ConvexPolygonShape3D_0gskd"]
points = PackedVector3Array(-1.375, 0.5, -0.125, -1.375, -0.5, -0.125, 1.375, -0.5, -0.125, 1.375, 0.5, -0.125, -1.375, 0.5, 0.125, -1.375, -0.5, 0.125, 1.375, -0.5, 0.125, 1.375, 0.5, 0.125)
[sub_resource type="ArrayMesh" id="ArrayMesh_t270j"]
[sub_resource type="ConvexPolygonShape3D" id="ConvexPolygonShape3D_t270j"]
points = PackedVector3Array(-0.5, 0.25, -0.75, -0.5, -0.25, -0.75, 0.5, -0.25, -0.75, 0.5, 0.25, -0.75, -0.5, 0.25, 0.75, -0.5, -0.25, 0.75, 0.5, -0.25, 0.75, 0.5, 0.25, 0.75)
[sub_resource type="ArrayMesh" id="ArrayMesh_li3o5"]
_surfaces = [{
"aabb": AABB(-1.25, -0.125, -2.5, 2.5, 0.25, 5),
"attribute_data": PackedByteArray("AAA+xAAAUMIAAD7EAABAwgAASMQAAEDCAABIxAAAUMIAAEBCAABQwgAAAEMAAFDCAAAAQwAAQMIAAEBCAABAwgAAQMIAAEjEAABAwgAAPsQAAADDAAA+xAAAAMMAAEjEAABAQgAASMQAAABDAABIxAAAAEMAAD7EAABAQgAAPsQAAEDCAABQwgAAQMIAAEDCAAAAwwAAQMIAAADDAABQwgAAPkQAAFDCAABIRAAAUMIAAEhEAABAwgAAPkQAAEDC"),
@ -996,7 +999,7 @@ _surfaces = [{
"vertex_data": PackedByteArray("AACgvwAAAD4AACDAAACgvwAAAL4AACDAAACgPwAAAL4AACDAAACgPwAAAD4AACDAAACgvwAAAD4AACDAAACgvwAAAD4AACBAAACgvwAAAL4AACBAAACgvwAAAL4AACDAAACgPwAAAL4AACDAAACgvwAAAL4AACDAAACgvwAAAL4AACBAAACgPwAAAL4AACBAAACgPwAAAD4AACDAAACgPwAAAD4AACBAAACgvwAAAD4AACBAAACgvwAAAD4AACDAAACgPwAAAD4AACDAAACgPwAAAL4AACDAAACgPwAAAL4AACBAAACgPwAAAD4AACBAAACgvwAAAD4AACBAAACgPwAAAD4AACBAAACgPwAAAL4AACBAAACgvwAAAL4AACBA/////wAA/7//////AAD/v/////8AAP+//////wAA/78AAP9//3//vwAA/3//f/+/AAD/f/9//78AAP9//3//v/9/AAD//////38AAP//////fwAA//////9/AAD//////3////9//7//f////3//v/9/////f/+//3////9//7////9//////////3//////////f/////////9///////9//3////+//3//f////7//f/9/////v/9//3////+/")
}]
[sub_resource type="ArrayOccluder3D" id="ArrayOccluder3D_li3o5"]
[sub_resource type="ArrayOccluder3D" id="ArrayOccluder3D_lolpd"]
vertices = PackedVector3Array(-1.25, 0.125, -2.5, -1.25, -0.125, -2.5, 1.25, -0.125, -2.5, 1.25, 0.125, -2.5, -1.25, 0.125, -2.5, -1.25, 0.125, 2.5, -1.25, -0.125, 2.5, -1.25, -0.125, -2.5, 1.25, -0.125, -2.5, -1.25, -0.125, -2.5, -1.25, -0.125, 2.5, 1.25, -0.125, 2.5, 1.25, 0.125, -2.5, 1.25, 0.125, 2.5, -1.25, 0.125, 2.5, -1.25, 0.125, -2.5, 1.25, 0.125, -2.5, 1.25, -0.125, -2.5, 1.25, -0.125, 2.5, 1.25, 0.125, 2.5, -1.25, 0.125, 2.5, 1.25, 0.125, 2.5, 1.25, -0.125, 2.5, -1.25, -0.125, 2.5)
indices = PackedInt32Array(0, 1, 2, 0, 2, 3, 4, 5, 6, 4, 6, 7, 8, 9, 10, 8, 10, 11, 12, 13, 14, 12, 14, 15, 16, 17, 18, 16, 18, 19, 20, 21, 22, 20, 22, 23)
@ -2318,10 +2321,26 @@ transform = Transform3D(-4.371139e-08, 0, 1, 0, 1, 0, -1, 0, -4.371139e-08, 63.7
[node name="entity_191_actor_teleporter" parent="FuncGodotMap" instance=ExtResource("92_f8yqq")]
transform = Transform3D(-1, 0, -8.742278e-08, 0, 1, 0, 8.742278e-08, 0, -1, 6.75, 1.0625, -3.25)
[node name="entity_192_actor_alarmbox" parent="FuncGodotMap" instance=ExtResource("94_e180r")]
transform = Transform3D(1.1924881e-08, 0, -1, 0, 1, 0, 1, 0, 1.1924881e-08, 26, 2.25, -3.75)
[node name="entity_193_trigger_area" type="Area3D" parent="FuncGodotMap"]
transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, -1.5, 1.25, -1.75)
collision_layer = 4
collision_mask = 2
monitorable = false
script = ExtResource("36_bevgl")
Target = "tube_emitter_intro"
MinActivations = 1
MaxActivations = 2
[node name="entity_193_brush_0_collision_shape" type="CollisionShape3D" parent="FuncGodotMap/entity_193_trigger_area"]
shape = SubResource("ConvexPolygonShape3D_t270j")
[node name="layer_0_Shrouds" type="Node3D" parent="FuncGodotMap"]
metadata/_tb_type = "_tb_layer"
[node name="entity_193_func_shroud" type="StaticBody3D" parent="FuncGodotMap/layer_0_Shrouds"]
[node name="entity_195_func_shroud" type="StaticBody3D" parent="FuncGodotMap/layer_0_Shrouds"]
transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 48.75, 2.875, 5.5)
visible = false
script = ExtResource("57_pmuwb")
@ -2329,13 +2348,13 @@ TargetName = "secret_001"
OneTime = true
metadata/func_godot_mesh_data = {}
[node name="entity_193_mesh_instance" type="MeshInstance3D" parent="FuncGodotMap/layer_0_Shrouds/entity_193_func_shroud"]
[node name="entity_195_mesh_instance" type="MeshInstance3D" parent="FuncGodotMap/layer_0_Shrouds/entity_195_func_shroud"]
cast_shadow = 0
gi_mode = 0
mesh = SubResource("ArrayMesh_t270j")
mesh = SubResource("ArrayMesh_li3o5")
[node name="entity_193_occluder_instance" type="OccluderInstance3D" parent="FuncGodotMap/layer_0_Shrouds/entity_193_func_shroud"]
occluder = SubResource("ArrayOccluder3D_li3o5")
[node name="entity_195_occluder_instance" type="OccluderInstance3D" parent="FuncGodotMap/layer_0_Shrouds/entity_195_func_shroud"]
occluder = SubResource("ArrayOccluder3D_lolpd")
[node name="Props" type="Node3D" parent="."]

View file

@ -1503,6 +1503,7 @@
"targetname" ""
"target" "door_intro"
"activationtype" "Open"
"minactivations" "0"
// brush 0
{
( 0 -100 16 ) ( 0 -99 16 ) ( 0 -100 17 ) special/trigger [ 0 -1 0 16 ] [ 0 0 -1 0 ] 0 1 1
@ -2451,6 +2452,24 @@
}
// entity 193
{
"classname" "trigger_area"
"targetname" ""
"target" "tube_emitter_intro"
"activationtype" "Toggle"
"minactivations" "1"
"maxactivations" "2"
// brush 0
{
( -40 -60 16 ) ( -40 -59 16 ) ( -40 -60 17 ) special/trigger [ 0 -1 0 24 ] [ 0 0 -1 0 ] 270 1 1
( -40 -32 16 ) ( -40 -32 17 ) ( -39 -32 16 ) special/trigger [ 1 0 0 8 ] [ 0 0 -1 0 ] 90 1 1
( -40 -60 16 ) ( -39 -60 16 ) ( -40 -59 16 ) special/trigger [ -1 0 0 -8 ] [ 0 -1 0 24 ] 270 1 1
( 12 -32 24 ) ( 12 -31 24 ) ( 13 -32 24 ) special/trigger [ 1 0 0 8 ] [ 0 -1 0 24 ] 180 1 1
( 12 -16 20 ) ( 13 -16 20 ) ( 12 -16 21 ) special/trigger [ -1 0 0 -8 ] [ 0 0 -1 0 ] 180 1 1
( -16 -32 20 ) ( -16 -32 21 ) ( -16 -31 20 ) special/trigger [ 0 1 0 -24 ] [ 0 0 -1 0 ] 180 1 1
}
}
// entity 194
{
"classname" "func_group"
"_tb_type" "_tb_layer"
"_tb_name" "Shrouds"
@ -2458,7 +2477,7 @@
"_tb_layer_sort_index" "0"
"_tb_layer_hidden" "1"
}
// entity 194
// entity 195
{
"classname" "func_shroud"
"targetname" "secret_001"

View file

@ -0,0 +1,17 @@
[gd_resource type="Resource" script_class="FuncGodotFGDBaseClass" load_steps=2 format=3 uid="uid://bpdbncl6tswbj"]
[ext_resource type="Script" uid="uid://6o4wbl0iau0v" path="res://addons/func_godot/src/fgd/func_godot_fgd_base_class.gd" id="1_2os3e"]
[resource]
script = ExtResource("1_2os3e")
classname = "ActivationCounts"
description = "Activation min and max"
class_properties = {
"maxactivations": 1,
"minactivations": 0
}
class_property_descriptions = {
"maxactivations": "Max amount of times it needs to be activated to trigger an efffect (-1 means no limit)",
"minactivations": "Minimum amount of times it needs to be activated to trigger an effect"
}
metadata/_custom_type_script = "uid://6o4wbl0iau0v"

View file

@ -1,23 +1,14 @@
[gd_resource type="Resource" script_class="FuncGodotFGDBaseClass" load_steps=6 format=3 uid="uid://ermxog0n4mvn"]
[gd_resource type="Resource" script_class="FuncGodotFGDBaseClass" load_steps=7 format=3 uid="uid://ermxog0n4mvn"]
[ext_resource type="Script" uid="uid://6o4wbl0iau0v" path="res://addons/func_godot/src/fgd/func_godot_fgd_base_class.gd" id="1_0kba8"]
[ext_resource type="Resource" uid="uid://kerywjgft7vh" path="res://3D/TrenchBroom/EntityDefinitions/base/target_base.tres" id="1_73jh0"]
[ext_resource type="Resource" uid="uid://c1utxplehq2jl" path="res://3D/TrenchBroom/EntityDefinitions/base/targetname_base.tres" id="2_f4xyy"]
[ext_resource type="Resource" uid="uid://x4g06004i574" path="res://3D/TrenchBroom/EntityDefinitions/base/globalname_base.tres" id="3_mslp0"]
[ext_resource type="Resource" uid="uid://bd4h6ha84s74b" path="res://3D/TrenchBroom/EntityDefinitions/base/activation_type_base.tres" id="4_mslp0"]
[ext_resource type="Resource" uid="uid://bpdbncl6tswbj" path="res://3D/TrenchBroom/EntityDefinitions/base/activation_counts_base.tres" id="5_akop0"]
[resource]
script = ExtResource("1_0kba8")
classname = "Trigger"
description = "Base Trigger"
func_godot_internal = false
base_classes = Array[Resource]([ExtResource("1_73jh0"), ExtResource("2_f4xyy"), ExtResource("3_mslp0"), ExtResource("4_mslp0")])
class_properties = {}
class_property_descriptions = {}
auto_apply_to_matching_node_properties = false
meta_properties = {
"color": Color(0.8, 0.8, 0.8, 1),
"size": AABB(-8, -8, -8, 8, 8, 8)
}
node_class = ""
name_property = ""
base_classes = Array[Resource]([ExtResource("1_73jh0"), ExtResource("2_f4xyy"), ExtResource("3_mslp0"), ExtResource("4_mslp0"), ExtResource("5_akop0")])

View file

@ -12,12 +12,16 @@ public partial class TriggerArea : Area3D
[Export] public string TargetFunc { get; private set; }
[Export] public string TargetName { get; private set; }
[Export] public int MinActivations { get; private set; } = 0;
[Export] public int MaxActivations { get; private set; } = 1;
[Export] public ActivationType ActivationType { get; private set; } = ActivationType.Toggle;
public enum TriggerStates
{
READY,
USED
USED,
WAITING
}
private TriggerStates _triggerState = TriggerStates.READY;
@ -25,6 +29,8 @@ public partial class TriggerArea : Area3D
private float _timeout = 0f;
private Node _lastActivator;
private int _activations = 0;
public void _func_godot_apply_properties(Dictionary<string, string> props)
{
Target = props["target"];
@ -38,45 +44,77 @@ public partial class TriggerArea : Area3D
ActivationType = activationType;
}
}
// TODO: Oneshot
if (int.TryParse(props["minactivations"], out var minActivations))
{
MinActivations = minActivations;
}
if (int.TryParse(props["maxactivations"], out var maxActivations))
{
MaxActivations = maxActivations;
}
}
public void _on_ent_entered(Node ent)
{
GD.Print($"Trigger entered by {ent.Name}");
if (_triggerState is TriggerStates.READY)
//GD.Print($"Trigger entered by {ent.Name}");
switch (_triggerState)
{
if (ent is IsoPlayerFSMProxy)
{
GD.Print($"Entity {ent} is player, trying to use");
Use();
}
else
{
GD.Print($"{ent.Name} was not interaction controller");
}
}
else
{
GD.Print("Trigger was not ready");
case TriggerStates.READY:
if (ent is IsoPlayerFSMProxy)
{
if (_activations >= MinActivations && _activations < MaxActivations )
{
Use();
}
else
{
_activations++;
}
}
break;
case TriggerStates.USED:
break;
}
// if (_triggerState is TriggerStates.READY)
// {
// if (ent is IsoPlayerFSMProxy)
// {
// //GD.Print($"Entity {ent} is player, trying to use");
// Use();
// }
// else
// {
// //GD.Print($"{ent.Name} was not interaction controller");
// }
// }
// else
// {
// //GD.Print("Trigger was not ready");
// }
}
public void Use()
{
if (_triggerState is TriggerStates.READY)
if (_triggerState is not TriggerStates.READY) return;
ActivationHelper.UseTargets(this, Target, ActivationType);
_activations++;
if (_activations >= MaxActivations)
{
_triggerState = TriggerStates.USED;
ToggleCollision(false);
ActivationHelper.UseTargets(this, Target, ActivationType);
}
}
private void ToggleCollision(bool toggle)
{
Monitoring = toggle;
}
// Called when the node enters the scene tree for the first time.

View file

@ -1,4 +1,4 @@
[gd_resource type="Resource" script_class="FuncGodotFGDFile" load_steps=15 format=3 uid="uid://onsfttdpojex"]
[gd_resource type="Resource" script_class="FuncGodotFGDFile" load_steps=16 format=3 uid="uid://onsfttdpojex"]
[ext_resource type="Resource" uid="uid://kerywjgft7vh" path="res://3D/TrenchBroom/EntityDefinitions/base/target_base.tres" id="1_abw2p"]
[ext_resource type="Script" uid="uid://cknmd0lgmorx2" path="res://addons/func_godot/src/fgd/func_godot_fgd_file.gd" id="1_p3xok"]
@ -14,8 +14,9 @@
[ext_resource type="Resource" uid="uid://dl5gtmotc4g6a" path="res://3D/TrenchBroom/EntityDefinitions/base/destroyable_base.tres" id="11_pydck"]
[ext_resource type="Resource" uid="uid://cy0telb0x1l4k" path="res://3D/TrenchBroom/EntityDefinitions/base/Script_path.tres" id="12_ueg06"]
[ext_resource type="Resource" uid="uid://0u5qbphjq045" path="res://3D/TrenchBroom/EntityDefinitions/base/emitter_base.tres" id="13_hm8wc"]
[ext_resource type="Resource" uid="uid://bpdbncl6tswbj" path="res://3D/TrenchBroom/EntityDefinitions/base/activation_counts_base.tres" id="14_hblj5"]
[resource]
script = ExtResource("1_p3xok")
entity_definitions = Array[Resource]([ExtResource("1_abw2p"), ExtResource("2_entxp"), ExtResource("1_wfoxw"), ExtResource("5_mkw5g"), ExtResource("2_abw2p"), ExtResource("6_1xsdl"), ExtResource("7_2isdf"), ExtResource("8_2isdf"), ExtResource("9_htav4"), ExtResource("10_vqlk3"), ExtResource("11_pydck"), ExtResource("12_ueg06"), ExtResource("13_hm8wc")])
entity_definitions = Array[Resource]([ExtResource("1_abw2p"), ExtResource("2_entxp"), ExtResource("1_wfoxw"), ExtResource("5_mkw5g"), ExtResource("2_abw2p"), ExtResource("6_1xsdl"), ExtResource("7_2isdf"), ExtResource("8_2isdf"), ExtResource("9_htav4"), ExtResource("10_vqlk3"), ExtResource("11_pydck"), ExtResource("12_ueg06"), ExtResource("13_hm8wc"), ExtResource("14_hblj5")])
metadata/_custom_type_script = "uid://cknmd0lgmorx2"