Class ScriptManager
Manages scripts within the application, allowing for dynamic loading, reloading, and management of script files.
public class ScriptManager : TypeMapManager<IScript, ScriptManager>, IManager<IScript, ScriptManager>, IManager, IPluginComponent, IManageable<PluginComponentsManager>, IManageable
- Inheritance
-
ScriptManager
- Implements
- Inherited Members
- Extension Methods
Fields
PluginScriptPathMap
protected readonly Map<string, (string, string)> PluginScriptPathMap
Field Value
ScriptRootPaths
public readonly HashSet<string> ScriptRootPaths
Field Value
StoredReloadMap
protected readonly Map<string, (IPlugin, FileChange)> StoredReloadMap
Field Value
- Map<string, (IPlugin, FileChange)>
Properties
Log
protected override Logger Log { get; }
Property Value
ReloadChangedOnly
Indicates whether to reload only scripts that have changed.
public bool ReloadChangedOnly { get; set; }
Property Value
ReloadTrigger
Specifies the trigger for reloading scripts.
public ReloadTrigger ReloadTrigger { get; set; }
Property Value
ScriptLoader
public ScriptLoader ScriptLoader { get; }
Property Value
Methods
AutoReload()
Automatically reloads scripts based on the current reload trigger and stored file changes.
public virtual void AutoReload()
AutoReload(IReadOnlyList<FileChange>, IPlugin, bool)
Automatically reloads scripts based on file changes detected for a specific plugin.
protected override void AutoReload(IReadOnlyList<FileChange> fileChanges, IPlugin plugin, bool force = false)
Parameters
fileChanges
IReadOnlyList<FileChange>The list of file changes to process.
plugin
IPluginThe plugin context in which the scripts are being reloaded.
force
boolIndicates whether to force the reload regardless of the current reload trigger.
CanAutoReloadAll(IReadOnlyList<FileChange>)
Determines if all file changes can be auto-reloaded based on the current settings.
protected override bool CanAutoReloadAll(IReadOnlyList<FileChange> fileChanges)
Parameters
fileChanges
IReadOnlyList<FileChange>The list of file changes to evaluate.
Returns
- bool
True if all file changes can be auto-reloaded, false otherwise.
GetPluginScriptPath(IPlugin)
Gets the script path for a plugin, creating it if it does not exist.
public (string, string) GetPluginScriptPath(IPlugin plugin)
Parameters
plugin
IPluginThe plugin for which to get the script path.
Returns
- (string, string)
A tuple containing the absolute script path and the relative path within the plugin.
GetScriptByFilePath(string)
Retrieves a script by its file path.
public IScript? GetScriptByFilePath(string filePath)
Parameters
filePath
stringThe file path of the script to retrieve.
Returns
Initialize(IPlugin)
Initialize the manager with the given plugin including its manageable objects.
public override void Initialize(IPlugin plugin)
Parameters
plugin
IPlugin
LoadScript(string, IPlugin)
Loads a script from the specified file path within the context of a plugin.
protected IScript<IScriptContext<ScriptData>> LoadScript(string scriptFile, IPlugin plugin)
Parameters
scriptFile
stringThe file path of the script to load, relative to the plugin's script path.
plugin
IPluginThe plugin context in which the script is being loaded.
Returns
- IScript<IScriptContext<ScriptData>>
An instance of IScript representing the loaded script.
Exceptions
- ScriptLoaderException
Thrown if the script file is not within the required script path for the plugin.
ProcessFileChange(FileChange, string, ref HashSet<IScript>, ref HashSet<string>, ref List<IReloadableScript>)
Processes a file change event for a script, determining if it should be added as a new script, marked for reload, or removed.
protected virtual bool ProcessFileChange(FileChange fileChange, string pluginScriptPath, ref HashSet<IScript> missingScripts, ref HashSet<string> newScriptFiles, ref List<IReloadableScript> scriptsToReload)
Parameters
fileChange
FileChangeThe file change event to process.
pluginScriptPath
stringThe path to the plugin's script directory.
missingScripts
HashSet<IScript>A reference to a set of scripts that are missing and need to be removed.
newScriptFiles
HashSet<string>A reference to a set of new script files that have been detected.
scriptsToReload
List<IReloadableScript>A reference to a list of scripts that need to be reloaded.