Skip to content

Commit

Permalink
slightly simplify GTimer further
Browse files Browse the repository at this point in the history
  • Loading branch information
valkyrienyanko committed Feb 1, 2023
1 parent 30b0f9c commit 3b2147d
Show file tree
Hide file tree
Showing 11 changed files with 17 additions and 17 deletions.
2 changes: 1 addition & 1 deletion Scripts/Entities/Enemy/Bird.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ public partial class Bird : MovingEntity<Bird>
public override void Init()
{
TimerChangeDirection = new GTimer(this, 1000, false);
TimerFlap = new GTimer(this, nameof(OnTimerFlap), 1000, true) { Loop = true };
TimerFlap = new GTimer(this, OnTimerFlap, 1000, true) { Loop = true };
AnimatedSprite.Play("fly");
MoveDir = Vector2.Left;
}
Expand Down
2 changes: 1 addition & 1 deletion Scripts/Entities/Enemy/Slime/Slime.cs
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ public override void Init()
CurrentAnimation = EntityAnimationType.Idle;

IdleTimer = new GTimer(this, 1000);
PreJumpTimer = new GTimer(this, nameof(OnPreJumpTimer), 400, false);
PreJumpTimer = new GTimer(this, OnPreJumpTimer, 400, false);

Label.Visible = true;
}
Expand Down
2 changes: 1 addition & 1 deletion Scripts/Entities/Enemy/Spawner.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ public partial class Spawner : Marker2D, IEntity

public override void _Ready()
{
Timer = new GTimer(this, nameof(OnTimer), RespawnInterval, false)
Timer = new GTimer(this, OnTimer, RespawnInterval, false)
{
Loop = true
};
Expand Down
2 changes: 1 addition & 1 deletion Scripts/Entities/Enemy/Trapper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ public partial class Trapper : Entity
public override void Init()
{
AreaDamage = GetNode<Area2D>("Damage");
TimerReveal = new GTimer(this, nameof(OnTimerReveal), 1500, false);
TimerReveal = new GTimer(this, OnTimerReveal, 1500, false);
TimerRevealCooldown = new GTimer(this, 2000, false);
AnimatedSprite.Play("idle");

Expand Down
2 changes: 1 addition & 1 deletion Scripts/Entities/Level/APlatform.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ public abstract partial class APlatform : CharacterBody2D

public void Init()
{
Timer = new GTimer(this, nameof(OnTimerUp), 400, false);
Timer = new GTimer(this, OnTimerUp, 400, false);

Collision = GetNode<CollisionShape2D>("CollisionShape2D");
}
Expand Down
6 changes: 3 additions & 3 deletions Scripts/Entities/Level/PlatformDisappear.cs
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,9 @@ public override void _Ready()
Sprite = GetNode<Sprite2D>("Sprite2D");
ShaderMaterial = (Sprite.Material as ShaderMaterial);

TimerFlash1 = new GTimer(this, nameof(OnTimerFlash1Up), DurationFlash1, false);
TimerFlash2 = new GTimer(this, nameof(OnTimerFlash2Up), DurationFlash2, false);
TimerReappear = new GTimer(this, nameof(OnTimerReappear), DurationReappear, false);
TimerFlash1 = new GTimer(this, OnTimerFlash1Up, DurationFlash1, false);
TimerFlash2 = new GTimer(this, OnTimerFlash2Up, DurationFlash2, false);
TimerReappear = new GTimer(this, OnTimerReappear, DurationReappear, false);
}

public override void _PhysicsProcess(double d)
Expand Down
2 changes: 1 addition & 1 deletion Scripts/Entities/MovingEntity.cs
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ public sealed override void _Ready()
// Does not seem to have any effect if this is either true or false
SlideOnCeiling = true;

ImmunityTimer = new GTimer(this, nameof(OnImmunityTimerFinished), ImmunityMs, false);
ImmunityTimer = new GTimer(this, OnImmunityTimerFinished, ImmunityMs, false);

if (Label != null)
{
Expand Down
4 changes: 2 additions & 2 deletions Scripts/Entities/Player/Commands/PlayerCommandDash.cs
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,8 @@ public PlayerCommandDash(Player player) : base(player) { }

public override void Initialize()
{
TimerDashCooldown = Entity.Timers.CreateTimer(nameof(Entity.OnDashReady), DashCooldown, false);
TimerDashDuration = Entity.Timers.CreateTimer(nameof(Entity.OnDashDurationDone), DashDuration, false);
TimerDashCooldown = Entity.Timers.CreateTimer(Entity.OnDashReady, DashCooldown, false);
TimerDashDuration = Entity.Timers.CreateTimer(Entity.OnDashDurationDone, DashDuration, false);
}

public override void Start()
Expand Down
4 changes: 2 additions & 2 deletions Scripts/Entities/Player/Player.cs
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ public override void Init()
if (GameManager.PlayerManager.ActiveCheckpoint)
Position = GameManager.PlayerManager.RespawnPosition;

TimerNetSend = new GTimer(this, nameof(NetUpdate), NetIntervals.HEARTBEAT, Net.IsMultiplayer())
TimerNetSend = new GTimer(this, NetUpdate, NetIntervals.HEARTBEAT, Net.IsMultiplayer())
{
Loop = true
};
Expand All @@ -82,7 +82,7 @@ public override void Init()
GetCommandClass<PlayerCommandWallJump>(PlayerCommandType.WallJump).WallJump += OnWallJump;

DontCheckPlatformAfterDashDuration = new GTimer(this, 500, false);
PreventMovementTimer = new GTimer(this, nameof(PreventMovementFinished), 50, false);
PreventMovementTimer = new GTimer(this, PreventMovementFinished, 50, false);
}

public override void UpdatePhysics()
Expand Down
4 changes: 2 additions & 2 deletions Scripts/Utils/Godot Helpers/GTimer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,10 @@ public bool Loop
public GTimer(Node node, int delayMs = 1000, bool autoStart = true) =>
Init(node, delayMs, autoStart);

public GTimer(Node node, string methodName, int delayMs = 1000, bool autoStart = true)
public GTimer(Node node, Action action, int delayMs = 1000, bool autoStart = true)
{
Init(node, delayMs, autoStart);
Callable = new Callable(node, methodName);
Callable = Callable.From(action);
Timer.Connect("timeout", Callable);
}

Expand Down
4 changes: 2 additions & 2 deletions Scripts/Utils/Godot Helpers/GTimers.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ public class GTimers
public GTimer CreateTimer(int delayMS, bool autoStart = true) =>
new GTimer(Node, delayMS, autoStart);

public GTimer CreateTimer(string methodName, int delayMS, bool autoStart = true) =>
new GTimer(Node, methodName, delayMS, autoStart);
public GTimer CreateTimer(Action action, int delayMS, bool autoStart = true) =>
new GTimer(Node, action, delayMS, autoStart);
}

0 comments on commit 3b2147d

Please sign in to comment.