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

@ -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"