Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion Assets/Rivet/Editor/Task.cs
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,6 @@ private void OnOutputEvent(JObject eventObj)

private void OnLogEvent(string log)
{
RivetLogger.Log($"TaskLog is null: {TaskLog == null}");
TaskLog?.Invoke(log, LogType.STDOUT);
}

Expand Down
28 changes: 22 additions & 6 deletions Assets/Rivet/Editor/TaskManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -38,12 +38,14 @@ public LogEntry(string message, LogType type)
}

public delegate Task<TaskConfig?> GetStartConfigDelegate();
public delegate Task<TaskConfig?> GetHookConfigDelegate();
public delegate Task<TaskConfig?> GetStopConfigDelegate();
public delegate TaskPanelWindow? GetTaskPanelDelegate();
public delegate void StateChangeHandler(bool running);

// Config
private GetStartConfigDelegate _getStartConfig;
private GetHookConfigDelegate? _getHookConfig;
private GetStopConfigDelegate _getStopConfig;
private GetTaskPanelDelegate _getTaskPanel;
private bool _autoRestart = false;
Expand All @@ -57,17 +59,24 @@ public LogEntry(string message, LogType type)
private RivetTask? _stopTask;
public List<LogEntry> LogEntries = new();

public TaskManager(string initMessage, GetStartConfigDelegate getStartConfig, GetStopConfigDelegate getStopConfig, GetTaskPanelDelegate getTaskPanel, bool autoRestart = false)
public bool IsRunning {
get {
return _task != null || _stopTask != null;
}
}

public TaskManager(string initMessage, GetStartConfigDelegate getStartConfig, GetHookConfigDelegate? getHookConfig, GetStopConfigDelegate getStopConfig, GetTaskPanelDelegate getTaskPanel, bool autoRestart = false)
{
_getStartConfig = getStartConfig;
_getHookConfig = getHookConfig;
_getStopConfig = getStopConfig;
_getTaskPanel = getTaskPanel;
_autoRestart = autoRestart;

LogEntries.Add(new LogEntry(initMessage, LogType.META));
}

public async Task StartTask()
public async Task StartTask(bool hook = false)
{
lock (_taskLock)
{
Expand All @@ -77,10 +86,12 @@ public async Task StartTask()
}

// Kill old task
_ = StopTask();
if (!hook) {
_ = StopTask();
}

// Start new task
var config = await _getStartConfig();
var config = hook ? await _getHookConfig() : await _getStartConfig();
if (config == null)
{
RivetLogger.Log("No task config provided.");
Expand All @@ -90,14 +101,17 @@ public async Task StartTask()
{
_task = new RivetTask(config.Value.Name, config.Value.Input);
_task.TaskLog += OnTaskLog;
RivetLogger.Log($"Running {config.Value.Name}");
OnStateChange();
RivetLogger.Log($"After state change {config.Value.Name}");
}

AddLogLine("Start", LogType.META);
AddLogLine(hook ? "Hook" : "Start", LogType.META);

// Run task
var output = await _task.RunAsync();

RivetLogger.Log($"Finished {config.Value.Name}");
await OnTaskOutput(output, _task);
}

Expand Down Expand Up @@ -236,7 +250,9 @@ private void OnStateChange()
// event right after the task is started (where IsRunning is set to
// true). To fix this, we need to be able to hook in to state change
// events on RivetTask.
StateChange.Invoke(_task != null);
var isRunning = IsRunning;
EditorApplication.delayCall += () => StateChange.Invoke(isRunning);
RivetLogger.Log($"State change: {IsRunning} ({_task != null} {_stopTask != null})");
}
}
}
10 changes: 10 additions & 0 deletions Assets/Rivet/Editor/UI/Dock/Dock.cs
Original file line number Diff line number Diff line change
Expand Up @@ -145,6 +145,14 @@ public void OnEnable()
}
});
},
getHookConfig: () =>
{
return Task.FromResult<TaskConfig?>(new TaskConfig
{
Name = "game_server.hook",
Input = new JObject {}
});
},
getStopConfig: () =>
{
return Task.FromResult<TaskConfig?>(new TaskConfig
Expand All @@ -169,6 +177,7 @@ public void OnEnable()
}
});
},
getHookConfig: null,
getStopConfig: () =>
{
return Task.FromResult<TaskConfig?>(new TaskConfig
Expand Down Expand Up @@ -196,6 +205,7 @@ public void OnEnable()

// Auto-start backend
_ = BackendManager.StartTask();
_ = LocalGameServerManager.StartTask(hook: true);
}

public void OnDisable()
Expand Down
2 changes: 1 addition & 1 deletion Assets/Rivet/Editor/UI/Dock/Tabs/DevelopController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ void InitUI()

// Callbacks
_dock.LocalGameServerManager.StateChange += OnLocalGameServerStateChange;
OnLocalGameServerStateChange(false);
OnLocalGameServerStateChange(_dock.LocalGameServerManager.IsRunning);

_refreshButton.RegisterCallback<ClickEvent>(ev => { _ = plugin.Bootstrap(); });

Expand Down
2 changes: 1 addition & 1 deletion Assets/Rivet/Editor/UI/Dock/Tabs/SettingsController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ void InitUI()

// Callbacks
_dock.BackendManager.StateChange += OnBackendStateChange;
OnBackendStateChange(false);
OnBackendStateChange(_dock.BackendManager.IsRunning);

_signInButton.RegisterCallback<ClickEvent>(ev => { _ = _dock.StartSignIn(); });
_signOutButton.RegisterCallback<ClickEvent>(ev => { _ = _dock.SignOut(); });
Expand Down
5 changes: 4 additions & 1 deletion Assets/Rivet/Editor/UI/TaskPanel/TaskPanelWindow.cs
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,10 @@ public void CreateGUI()
public void UpdateLogs()
{
// In case the singleton doesn't exist yet
_logListView.itemsSource = TaskManager?.LogEntries;
if (TaskManager != null)
{
_logListView.itemsSource = TaskManager.LogEntries;
}

// Rebuild view
_logListView.Rebuild();
Expand Down