Timescalable components

This commit is contained in:
Rendo 2025-07-08 00:05:23 +05:00
commit e527d1da44
11 changed files with 83 additions and 24 deletions

View file

@ -1,4 +1,4 @@
[gd_scene load_steps=29 format=3 uid="uid://co11v3w8hbwgf"]
[gd_scene load_steps=30 format=3 uid="uid://co11v3w8hbwgf"]
[ext_resource type="Script" uid="uid://dildme6epx8l4" path="res://scripts/components/zombies/RuntimeZombieData.cs" id="1_qq3f1"]
[ext_resource type="Texture2D" uid="uid://bwdqbrnn7ygtr" path="res://assets/sprites/atlases/zombies/Зондби.png" id="2_4pdxh"]
@ -12,6 +12,7 @@
[ext_resource type="Script" uid="uid://c3cfnrmnnuqms" path="res://addons/floatmodifiers/FloatModifiers.cs" id="7_b3p4o"]
[ext_resource type="AnimationNodeStateMachine" uid="uid://dj0blope85bg7" path="res://resources/animations/zombies/basic_zombie_tree.tres" id="8_ckb7n"]
[ext_resource type="Script" uid="uid://c36bj8u7jghc7" path="res://scripts/audio/ChannelPlayer.cs" id="10_ruqsf"]
[ext_resource type="Script" uid="uid://dwlwi42smgxkb" path="res://scripts/components/TimeScalableAnimationTree.cs" id="11_ccrjo"]
[ext_resource type="AudioStream" uid="uid://dyid55nhflwyn" path="res://assets/audio/sfx/chomp_generic.tres" id="11_vjrlo"]
[ext_resource type="AudioStream" uid="uid://bg76miyscfvhu" path="res://assets/audio/sfx/groan.tres" id="12_ad42i"]
[ext_resource type="Script" uid="uid://cnn0ymuhypdff" path="res://scripts/audio/ChannelPlaylist.cs" id="12_he8da"]
@ -62,7 +63,6 @@ _data = {
[sub_resource type="AnimationNodeTimeScale" id="AnimationNodeTimeScale_2q05d"]
[sub_resource type="AnimationNodeBlendTree" id="AnimationNodeBlendTree_ccrjo"]
graph_offset = Vector2(-447, 53)
nodes/TimeScale/node = SubResource("AnimationNodeTimeScale_2q05d")
nodes/TimeScale/position = Vector2(60, 120)
nodes/Tree/node = ExtResource("8_ckb7n")
@ -115,11 +115,13 @@ libraries = {
&"basic_zombie": ExtResource("6_ckb7n")
}
[node name="AnimationTree" type="AnimationTree" parent="."]
[node name="AnimationTree" type="AnimationTree" parent="." node_paths=PackedStringArray("entity")]
tree_root = SubResource("AnimationNodeBlendTree_ccrjo")
advance_expression_base_node = NodePath("../Eatbox")
anim_player = NodePath("../AnimationPlayer")
parameters/TimeScale/scale = 1.0
script = ExtResource("11_ccrjo")
entity = NodePath("..")
[node name="Mover" type="Node" parent="."]
script = ExtResource("4_u5syx")

View file

@ -1,9 +1,10 @@
[gd_scene load_steps=20 format=3 uid="uid://bw1w8jp0yeypy"]
[gd_scene load_steps=21 format=3 uid="uid://bw1w8jp0yeypy"]
[ext_resource type="PackedScene" uid="uid://b1hjjbdwf1rtc" path="res://scenes/templates/plant_template.tscn" id="1_n25yi"]
[ext_resource type="Texture2D" uid="uid://b6tyoa5htapir" path="res://assets/sprites/atlases/plants/aloe.png" id="2_iup5p"]
[ext_resource type="AnimationLibrary" uid="uid://bgutjc3ruq27s" path="res://resources/animations/plants/aloe.res" id="3_3sp3b"]
[ext_resource type="Script" uid="uid://cljytsmqac0w7" path="res://scripts/components/plants/behaviours/AloeBehaviour.cs" id="4_55asm"]
[ext_resource type="Script" uid="uid://c4jy0cnbnx33h" path="res://scripts/components/TimeScalableTimer.cs" id="5_gfy6j"]
[sub_resource type="Animation" id="Animation_vknky"]
length = 0.001
@ -118,9 +119,11 @@ parameters/Tree/conditions/heal = false
script = ExtResource("4_55asm")
_hpTreshold = 0.33
[node name="Timer" type="Timer" parent="Behaviour" index="0"]
[node name="Timer" type="Timer" parent="Behaviour" index="0" node_paths=PackedStringArray("entity")]
wait_time = 20.0
one_shot = true
script = ExtResource("5_gfy6j")
entity = NodePath("../..")
[node name="CollisionShape2D" type="CollisionShape2D" parent="Hitbox" index="0"]
shape = SubResource("RectangleShape2D_oe0dc")

View file

@ -1,4 +1,4 @@
[gd_scene load_steps=23 format=3 uid="uid://dy41q1kxray5t"]
[gd_scene load_steps=24 format=3 uid="uid://dy41q1kxray5t"]
[ext_resource type="PackedScene" uid="uid://b1hjjbdwf1rtc" path="res://scenes/templates/plant_template.tscn" id="1_pyk3o"]
[ext_resource type="Texture2D" uid="uid://cksryh4w5dbbx" path="res://assets/sprites/atlases/plants/peashooter.png" id="2_14qlx"]
@ -6,6 +6,7 @@
[ext_resource type="Script" uid="uid://ceprqkraw3v6m" path="res://scripts/components/plants/Shooter.cs" id="3_a4ew1"]
[ext_resource type="PackedScene" uid="uid://b2hrv0aqbui7u" path="res://scenes/projectiles/pea.tscn" id="4_saxds"]
[ext_resource type="Script" uid="uid://bdk5iqtw4xbkl" path="res://scripts/components/plants/behaviours/PeashooterBehaviour.cs" id="5_7qiua"]
[ext_resource type="Script" uid="uid://c4jy0cnbnx33h" path="res://scripts/components/TimeScalableTimer.cs" id="6_q58jr"]
[ext_resource type="Script" uid="uid://dn53jvpjyg63l" path="res://scripts/components/plants/Eyesight.cs" id="7_2bki8"]
[ext_resource type="Script" uid="uid://hccb0aee0x0o" path="res://scripts/components/plants/PlantEyesightLimiter.cs" id="8_nl4jc"]
[ext_resource type="Script" uid="uid://c36bj8u7jghc7" path="res://scripts/audio/ChannelPlayer.cs" id="9_mbbd7"]
@ -97,9 +98,11 @@ script = ExtResource("3_a4ew1")
_projectile = ExtResource("4_saxds")
_timer = NodePath("Timer")
[node name="Timer" type="Timer" parent="Shooter" index="0"]
[node name="Timer" type="Timer" parent="Shooter" index="0" node_paths=PackedStringArray("entity")]
wait_time = 1.5
one_shot = true
script = ExtResource("6_q58jr")
entity = NodePath("../..")
[node name="Behaviour" type="Node" parent="." index="4" node_paths=PackedStringArray("_shootTimer", "_sight")]
script = ExtResource("5_7qiua")

View file

@ -1,4 +1,4 @@
[gd_scene load_steps=26 format=3 uid="uid://b5x35v3w2u8dx"]
[gd_scene load_steps=27 format=3 uid="uid://b5x35v3w2u8dx"]
[ext_resource type="PackedScene" uid="uid://b1hjjbdwf1rtc" path="res://scenes/templates/plant_template.tscn" id="1_dj7ul"]
[ext_resource type="Texture2D" uid="uid://c77o6ba0mw7a3" path="res://assets/sprites/atlases/plants/potato_mine.png" id="2_sneas"]
@ -8,6 +8,7 @@
[ext_resource type="PackedScene" uid="uid://ckanq33rao1ur" path="res://scenes/particles/potato_explosion.tscn" id="5_px4r0"]
[ext_resource type="Script" uid="uid://c36bj8u7jghc7" path="res://scripts/audio/ChannelPlayer.cs" id="7_b1j2f"]
[ext_resource type="AudioStream" uid="uid://dltjtpyfr1so0" path="res://assets/audio/sfx/potato_mine.mp3" id="8_3vqdc"]
[ext_resource type="Script" uid="uid://c4jy0cnbnx33h" path="res://scripts/components/TimeScalableTimer.cs" id="8_824aq"]
[ext_resource type="AudioStream" uid="uid://b27om1bw1x04e" path="res://assets/audio/sfx/dirt_rise.mp3" id="9_3vqdc"]
[sub_resource type="AnimationNodeTimeScale" id="AnimationNodeTimeScale_3vqdc"]
@ -58,7 +59,6 @@ transitions = ["Start", "potato_mine_idle_unprimed", SubResource("AnimationNodeS
graph_offset = Vector2(-16.3438, -67.832)
[sub_resource type="AnimationNodeBlendTree" id="AnimationNodeBlendTree_824aq"]
graph_offset = Vector2(-427, 79)
nodes/TimeScale/node = SubResource("AnimationNodeTimeScale_3vqdc")
nodes/TimeScale/position = Vector2(100, 120)
nodes/Tree/node = SubResource("AnimationNodeStateMachine_nfn7b")
@ -84,7 +84,7 @@ MaxHP = 20.0
texture = ExtResource("2_sneas")
hframes = 7
vframes = 4
frame = 14
frame = 7
[node name="AnimationPlayer" parent="." index="1"]
libraries = {
@ -123,10 +123,12 @@ audioStream = ExtResource("8_3vqdc")
channel = "explosion"
metadata/_custom_type_script = "uid://c36bj8u7jghc7"
[node name="PrimeTimer" type="Timer" parent="." index="5"]
[node name="PrimeTimer" type="Timer" parent="." index="5" node_paths=PackedStringArray("entity")]
wait_time = 15.0
one_shot = true
autostart = true
script = ExtResource("8_824aq")
entity = NodePath("..")
[node name="Behaviour" type="Node" parent="." index="6" node_paths=PackedStringArray("_hitbox", "_unprimedShape", "_primedShape")]
script = ExtResource("4_twx65")

View file

@ -1,4 +1,4 @@
[gd_scene load_steps=18 format=3 uid="uid://bg7lomiorxo2c"]
[gd_scene load_steps=19 format=3 uid="uid://bg7lomiorxo2c"]
[ext_resource type="PackedScene" uid="uid://b1hjjbdwf1rtc" path="res://scenes/templates/plant_template.tscn" id="1_bikjn"]
[ext_resource type="Texture2D" uid="uid://b3tuidu8dag8u" path="res://assets/sprites/atlases/plants/sunflower.png" id="2_fwcda"]
@ -6,6 +6,7 @@
[ext_resource type="Script" uid="uid://b71gebny84s81" path="res://scripts/components/plants/PlantSunSpawner.cs" id="3_te0pl"]
[ext_resource type="PackedScene" uid="uid://bpekho7leatr5" path="res://scenes/sun.tscn" id="4_b8hls"]
[ext_resource type="Script" uid="uid://bth7gah4tn7uj" path="res://scripts/components/plants/behaviours/SunflowerBehaviour.cs" id="5_26je0"]
[ext_resource type="Script" uid="uid://c4jy0cnbnx33h" path="res://scripts/components/TimeScalableTimer.cs" id="7_rlkb7"]
[sub_resource type="Animation" id="Animation_bfx6v"]
length = 0.001
@ -92,13 +93,17 @@ _amountPerSun = 25
[node name="Behaviour" type="Node" parent="." index="4"]
script = ExtResource("5_26je0")
[node name="Timer" type="Timer" parent="Behaviour" index="0"]
[node name="Timer" type="Timer" parent="Behaviour" index="0" node_paths=PackedStringArray("entity")]
wait_time = 24.25
script = ExtResource("7_rlkb7")
entity = NodePath("../..")
[node name="StartTimer" type="Timer" parent="Behaviour" index="1"]
[node name="StartTimer" type="Timer" parent="Behaviour" index="1" node_paths=PackedStringArray("entity")]
wait_time = 12.0
one_shot = true
autostart = true
script = ExtResource("7_rlkb7")
entity = NodePath("../..")
[node name="CollisionShape2D" type="CollisionShape2D" parent="Hitbox" index="0"]
position = Vector2(0, 4)

View file

@ -1,6 +1,7 @@
[gd_scene load_steps=2 format=3 uid="uid://b1hjjbdwf1rtc"]
[gd_scene load_steps=3 format=3 uid="uid://b1hjjbdwf1rtc"]
[ext_resource type="Script" uid="uid://dli2i6albvugt" path="res://scripts/components/plants/RuntimePlantData.cs" id="1_324sd"]
[ext_resource type="Script" uid="uid://dwlwi42smgxkb" path="res://scripts/components/TimeScalableAnimationTree.cs" id="2_e75pf"]
[node name="PlantTemplate" type="Node2D"]
script = ExtResource("1_324sd")
@ -10,8 +11,10 @@ use_parent_material = true
[node name="AnimationPlayer" type="AnimationPlayer" parent="."]
[node name="AnimationTree" type="AnimationTree" parent="."]
[node name="AnimationTree" type="AnimationTree" parent="." node_paths=PackedStringArray("entity")]
anim_player = NodePath("../AnimationPlayer")
script = ExtResource("2_e75pf")
entity = NodePath("..")
[node name="Hitbox" type="Area2D" parent="."]
collision_layer = 2

View file

@ -4,6 +4,7 @@ using Newlon.Systems.Effects;
namespace Newlon.Components;
[GlobalClass]
public partial class Entity : Node2D
{
#region Health points
@ -58,13 +59,13 @@ public partial class Entity : Node2D
#endregion
#region Effects
[Export] private Array<Effect> _effectImmunities = new();
private readonly Dictionary<string,Effect> _activeEffectSlots = new();
private readonly Dictionary<string,Timer> _effectSlotTimers = new();
private readonly Dictionary<string, Effect> _activeEffectSlots = new();
private readonly Dictionary<string, Timer> _effectSlotTimers = new();
[Signal] public delegate void EffectStartedEventHandler(Effect what);
[Signal] public delegate void EffectEndedEventHandler(Effect what);
[Signal] public delegate void EffectContinuedEventHandler(Effect what);
public virtual void GiveEffect(Effect what)
{
@ -108,7 +109,7 @@ public partial class Entity : Node2D
var timer = new Timer() { Autostart = false, OneShot = true };
AddChild(timer);
timer.Timeout += () => { EndEffectAtSlot(key); };
_effectSlotTimers.Add(key, timer);
}
@ -120,7 +121,7 @@ public partial class Entity : Node2D
public void ProcessEffects()
{
foreach(string key in _activeEffectSlots.Keys)
foreach (string key in _activeEffectSlots.Keys)
_activeEffectSlots[key]?.Process(this);
}
@ -148,8 +149,8 @@ public partial class Entity : Node2D
#endregion
#region Godot overrides
public override void _Ready()
{
HP = MaxHP;
}
{
HP = MaxHP;
}
#endregion
}

View file

@ -0,0 +1,17 @@
using Godot;
namespace Newlon.Components;
public partial class TimeScalableAnimationTree : AnimationTree
{
[Export] private Entity entity;
public override void _Ready()
{
entity.OnLocalTimescaleChanged += OnTimescaleChanged;
}
private void OnTimescaleChanged(float timescale)
{
Set("parameters/TimeScale/scale", timescale);
}
}

View file

@ -0,0 +1 @@
uid://dwlwi42smgxkb

View file

@ -0,0 +1,21 @@
using Godot;
namespace Newlon.Components;
public partial class TimeScalableTimer : Timer
{
[Export] private Entity entity;
private float internal_timescale;
public override void _Ready()
{
internal_timescale = entity.LocalTimescale;
entity.OnLocalTimescaleChanged += OnTimescaleChanged;
}
private void OnTimescaleChanged(float timescale)
{
WaitTime *= internal_timescale / timescale;
internal_timescale = timescale;
}
}

View file

@ -0,0 +1 @@
uid://c4jy0cnbnx33h