From 35f9476c3d190044bdbd8a8297ff1ac6c6dd107c Mon Sep 17 00:00:00 2001 From: alex-kumpula Date: Sat, 11 Nov 2023 19:58:56 -0700 Subject: [PATCH] Added Timescale System --- godot/TAS_system/TASable.cs | 8 ++-- godot/Timescale_System/TimescaleSystem.cs | 52 +++++++++++++++++++++ godot/Timescale_System/TimescaleSystem.tscn | 6 +++ godot/physics/grape.tscn | 1 + godot/project.godot | 1 + godot/tests/TAS_system/TAS_test_003.tscn | 1 - 6 files changed, 65 insertions(+), 4 deletions(-) create mode 100644 godot/Timescale_System/TimescaleSystem.cs create mode 100644 godot/Timescale_System/TimescaleSystem.tscn diff --git a/godot/TAS_system/TASable.cs b/godot/TAS_system/TASable.cs index 435336b..ab4d6ef 100644 --- a/godot/TAS_system/TASable.cs +++ b/godot/TAS_system/TASable.cs @@ -50,29 +50,31 @@ public partial class TASable : Node public virtual void OnFrameIncremented(int newFrame) { this.SaveState(newFrame); - GD.Print($"Frame advanced to {newFrame}, called from node {this.AssignedRigidBody3D.Name}"); + // GD.Print($"Frame advanced to {newFrame}, called from node {this.AssignedRigidBody3D.Name}"); } public virtual void OnFramesAdvanced(int startFrame, int endFrame) { this.LoadState(endFrame); - GD.Print($"Frames advanced from {startFrame} to {endFrame}, called from node {this.AssignedRigidBody3D.Name}"); + // GD.Print($"Frames advanced from {startFrame} to {endFrame}, called from node {this.AssignedRigidBody3D.Name}"); } public virtual void OnFramesRegressed(int startFrame, int endFrame) { this.LoadState(endFrame); - GD.Print($"Frames regressed from {startFrame} to {endFrame}, called from node {this.AssignedRigidBody3D.Name}"); + // GD.Print($"Frames regressed from {startFrame} to {endFrame}, called from node {this.AssignedRigidBody3D.Name}"); } public virtual void OnStartedIncrementing() { this.AssignedRigidBody3D.Freeze = false; + this.AssignedRigidBody3D.LockRotation = false; } public virtual void OnStoppedIncrementing() { this.AssignedRigidBody3D.Freeze = true; + this.AssignedRigidBody3D.LockRotation = true; } public virtual void OnFramesReset() diff --git a/godot/Timescale_System/TimescaleSystem.cs b/godot/Timescale_System/TimescaleSystem.cs new file mode 100644 index 0000000..f75779b --- /dev/null +++ b/godot/Timescale_System/TimescaleSystem.cs @@ -0,0 +1,52 @@ +using Godot; +using System; + +public partial class TimescaleSystem : Node +{ + [Export] public double SlowLength = 1.0; + [Export] public double SlowMagnitude = 0.2; + + Node controller; + + public override void _Ready() + { + controller = GetNode("/root/ControllerEventBus"); + + Callable callable = new Callable(this, MethodName.OnControllerContact); + + controller.Connect("new_target", callable); + + this.OnControllerContact(this); + } + + + public void OnControllerContact(Node node) + { + GD.Print("toUCHED!"); + + Engine.TimeScale = this.SlowMagnitude; + + Timer timer = new Timer(); + timer.Name = "SlowTimer"; + + this.AddChild(timer); + + timer.WaitTime = this.SlowLength * this.SlowMagnitude; + timer.OneShot = true; + + timer.Timeout += () => { + GD.Print("TimE!"); + Engine.TimeScale = 1.0; + timer.QueueFree(); + }; + + + + + timer.Start(); + + + + } + +} diff --git a/godot/Timescale_System/TimescaleSystem.tscn b/godot/Timescale_System/TimescaleSystem.tscn new file mode 100644 index 0000000..f5c4bbe --- /dev/null +++ b/godot/Timescale_System/TimescaleSystem.tscn @@ -0,0 +1,6 @@ +[gd_scene load_steps=2 format=3 uid="uid://bs3yqnctxfwaa"] + +[ext_resource type="Script" path="res://Timescale_System/TimescaleSystem.cs" id="1_6tt5j"] + +[node name="TimescaleSystem" type="Node"] +script = ExtResource("1_6tt5j") diff --git a/godot/physics/grape.tscn b/godot/physics/grape.tscn index cfabd01..74cb567 100644 --- a/godot/physics/grape.tscn +++ b/godot/physics/grape.tscn @@ -3,3 +3,4 @@ [ext_resource type="PackedScene" uid="uid://bsge8trc5uwb0" path="res://grape.glb" id="1_jlfas"] [node name="grape" instance=ExtResource("1_jlfas")] +continuous_cd = true diff --git a/godot/project.godot b/godot/project.godot index b3a9b54..d35607e 100644 --- a/godot/project.godot +++ b/godot/project.godot @@ -20,6 +20,7 @@ config/icon="res://icon.svg" ControllerEventBus="*res://controller_event_bus.gd" TAS_System="*res://TAS_system/TAS_System.tscn" MouseControl="*res://mouse_control.gd" +TimescaleSystem="*res://Timescale_System/TimescaleSystem.tscn" [dotnet] diff --git a/godot/tests/TAS_system/TAS_test_003.tscn b/godot/tests/TAS_system/TAS_test_003.tscn index e80a146..14ee79e 100644 --- a/godot/tests/TAS_system/TAS_test_003.tscn +++ b/godot/tests/TAS_system/TAS_test_003.tscn @@ -31,6 +31,5 @@ transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 1.98064, 0.385236) [node name="grape2" parent="." index="6" instance=ExtResource("3_kg8e8")] transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 2.94627, 0) -continuous_cd = true [node name="TAS UI" parent="." index="7" instance=ExtResource("4_jskxr")]