Skip to content

Commit

Permalink
Add Additional Checkers to tell user not to call GDTask APIs under ed…
Browse files Browse the repository at this point in the history
…itor.
  • Loading branch information
Delsin-Yu committed Mar 29, 2024
1 parent 33f33a4 commit 958f36d
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 0 deletions.
1 change: 1 addition & 0 deletions GDTask/src/PlayerLoopRunner/GDTaskPlayerLoopRunner.cs
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,7 @@ public static GDTaskPlayerLoopRunner Global
{
get
{
RuntimeChecker.ThrowIfEditor();
if (s_Global != null) return s_Global;

var newInstance = new GDTaskPlayerLoopRunner();
Expand Down
13 changes: 13 additions & 0 deletions GDTask/src/RuntimeGuard/RuntimeChecker.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
using System;
using Godot;

namespace GodotTask.Internal;

internal static class RuntimeChecker
{
internal static void ThrowIfEditor()
{
if(!Engine.IsEditorHint()) return;
throw new InvalidOperationException("Calling any GDTask API under editor is not supported.");
}
}
2 changes: 2 additions & 0 deletions GDTask/src/Triggers/AsyncTriggerExtensions.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
using System;
using Godot;
using GodotTask.Internal;

namespace GodotTask.Triggers
{
Expand Down Expand Up @@ -27,6 +28,7 @@ internal static T GetChild<T>(this Node node, bool includeRoot = true)

internal static T GetOrCreateChild<T>(this Node node) where T : Node, new()
{
RuntimeChecker.ThrowIfEditor();
T child = GetChild<T>(node);
if (child == null)
child = CreateChild<T>(node);
Expand Down

0 comments on commit 958f36d

Please sign in to comment.