2024-12-19 22:25:39 -05:00
|
|
|
using Microsoft.CodeAnalysis.Scripting;
|
|
|
|
|
using System.Collections.Generic;
|
|
|
|
|
using System.IO;
|
|
|
|
|
|
|
|
|
|
namespace Arrowgene.Ddon.GameServer.Scripting
|
|
|
|
|
{
|
|
|
|
|
public abstract class ScriptModule
|
|
|
|
|
{
|
|
|
|
|
public abstract string ModuleRoot { get; }
|
|
|
|
|
public abstract string Filter { get; }
|
|
|
|
|
public abstract bool ScanSubdirectories { get; }
|
2025-02-24 10:40:48 -05:00
|
|
|
public List<FileSystemWatcher> Watchers { get; set; }
|
2024-12-19 22:25:39 -05:00
|
|
|
|
2024-12-23 14:40:57 -05:00
|
|
|
/// <summary>
|
|
|
|
|
/// Determines if this module is able to be hot-loadable or not.
|
|
|
|
|
/// If a module is not hot-loadable, it will only be evaluated once
|
|
|
|
|
/// when the server first loads.
|
|
|
|
|
/// </summary>
|
|
|
|
|
public abstract bool EnableHotLoad { get; }
|
|
|
|
|
|
2024-12-26 22:26:23 -05:00
|
|
|
/// <summary>
|
|
|
|
|
/// Determines if this module is enabled or not. Intended for development;
|
|
|
|
|
/// should be used such that an in-development module can be checked in but
|
|
|
|
|
/// disabled until the feature is ready.
|
|
|
|
|
/// </summary>
|
|
|
|
|
public virtual bool IsEnabled { get; } = true;
|
|
|
|
|
|
2024-12-19 22:25:39 -05:00
|
|
|
public HashSet<string> Scripts { get; set; }
|
|
|
|
|
|
2025-07-03 09:28:21 -04:00
|
|
|
/// <summary>
|
|
|
|
|
/// A list of scripts in the module directory which should be ignored
|
|
|
|
|
/// and not compiled directly. These files may be interfaces or abstract classes
|
|
|
|
|
/// which can't be instantiated directly.
|
|
|
|
|
/// </summary>
|
|
|
|
|
public HashSet<string> IgnoredScripts { get; set; }
|
|
|
|
|
|
2024-12-19 22:25:39 -05:00
|
|
|
public ScriptModule()
|
|
|
|
|
{
|
2025-07-03 09:28:21 -04:00
|
|
|
IgnoredScripts = new HashSet<string>();
|
2024-12-19 22:25:39 -05:00
|
|
|
Scripts = new HashSet<string>();
|
2025-02-24 10:40:48 -05:00
|
|
|
Watchers = new List<FileSystemWatcher>();
|
2024-12-19 22:25:39 -05:00
|
|
|
}
|
|
|
|
|
|
2025-02-25 00:52:52 -05:00
|
|
|
/// <summary>
|
|
|
|
|
/// Code that a module can execute before EvaluateResult is called for each script.
|
|
|
|
|
/// </summary>
|
|
|
|
|
public virtual void Initialize()
|
|
|
|
|
{
|
|
|
|
|
}
|
|
|
|
|
|
2024-12-19 22:25:39 -05:00
|
|
|
/// <summary>
|
|
|
|
|
/// Options passed into the compilation unit.
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <returns></returns>
|
|
|
|
|
public abstract ScriptOptions Options();
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Evaluates the result returned by the script.
|
|
|
|
|
/// </summary>
|
2024-12-23 14:40:57 -05:00
|
|
|
/// <param name="path">Path to the script that was executed</param>
|
|
|
|
|
/// <param name="result">The result object of the script that executed</param>
|
2025-06-29 02:07:13 -07:00
|
|
|
/// <param name="variables">The local variables of the script that executed</param>
|
2024-12-19 22:25:39 -05:00
|
|
|
/// <returns></returns>
|
2025-06-29 02:07:13 -07:00
|
|
|
public abstract bool EvaluateResult(string path, object result, IDictionary<string, object> variables);
|
2024-12-19 22:25:39 -05:00
|
|
|
}
|
|
|
|
|
}
|