2019-07-03 09:44:53 +02:00
|
|
|
using Godot;
|
|
|
|
using GodotTools.Internals;
|
2021-09-12 20:23:05 +02:00
|
|
|
using JetBrains.Annotations;
|
2019-07-11 13:59:06 +02:00
|
|
|
using static GodotTools.Internals.Globals;
|
2019-07-03 09:44:53 +02:00
|
|
|
|
|
|
|
namespace GodotTools
|
|
|
|
{
|
|
|
|
public class HotReloadAssemblyWatcher : Node
|
|
|
|
{
|
|
|
|
private Timer watchTimer;
|
|
|
|
|
|
|
|
public override void _Notification(int what)
|
|
|
|
{
|
2020-06-30 23:41:38 +02:00
|
|
|
if (what == Node.NotificationWmWindowFocusIn)
|
2019-07-03 09:44:53 +02:00
|
|
|
{
|
|
|
|
RestartTimer();
|
|
|
|
|
|
|
|
if (Internal.IsAssembliesReloadingNeeded())
|
|
|
|
Internal.ReloadAssemblies(softReload: false);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
private void TimerTimeout()
|
|
|
|
{
|
|
|
|
if (Internal.IsAssembliesReloadingNeeded())
|
|
|
|
Internal.ReloadAssemblies(softReload: false);
|
|
|
|
}
|
|
|
|
|
2021-09-12 20:23:05 +02:00
|
|
|
[UsedImplicitly]
|
2019-07-03 09:44:53 +02:00
|
|
|
public void RestartTimer()
|
|
|
|
{
|
|
|
|
watchTimer.Stop();
|
|
|
|
watchTimer.Start();
|
|
|
|
}
|
|
|
|
|
|
|
|
public override void _Ready()
|
|
|
|
{
|
|
|
|
base._Ready();
|
|
|
|
|
|
|
|
watchTimer = new Timer
|
|
|
|
{
|
|
|
|
OneShot = false,
|
2019-12-11 14:46:28 +01:00
|
|
|
WaitTime = (float)EditorDef("mono/assembly_watch_interval_sec", 0.5)
|
2019-07-03 09:44:53 +02:00
|
|
|
};
|
2020-03-14 19:20:17 +01:00
|
|
|
watchTimer.Timeout += TimerTimeout;
|
2019-07-03 09:44:53 +02:00
|
|
|
AddChild(watchTimer);
|
|
|
|
watchTimer.Start();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|