Skip to content

Commit 236616d

Browse files
committed
Add Load(Action<IPlugin> onLoading) and update README
1 parent f3142f6 commit 236616d

File tree

3 files changed

+81
-58
lines changed

3 files changed

+81
-58
lines changed

README.md

Lines changed: 78 additions & 55 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,8 @@
55

66
Hot-reloadable C# scripting for live mod prototyping for [RisingV](https://risingv.dev).
77

8-
> *[RisingV.Scripting](https://github.com/RisingV-Mods/RisingV.Scripting) is a core mod for V Rising that allows you to use RisingV mods.
9-
> It provides a set of APIs and utilities that make it easier to create and manage mods for V Rising.”*
8+
> *[RisingV.Scripting](https://github.com/RisingV-Mods/RisingV.Scripting) is a scripting mod for V Rising that allows you to write reloadable scripts in a sandboxed domain.
9+
> It only depends on RisingV.Shared so does not need to be run from a core plugin.”*
1010
1111
## Features
1212
- **Live reload** – iterate on scripts without restarting the server
@@ -29,59 +29,82 @@ dotnet add package RisingV.Scripting
2929
```
3030

3131
## Getting started
32-
```csharp
33-
// Added to your plugin class
34-
[BepInDependency("RisingV.Scripting")]
35-
```
36-
37-
Creating a new script is as simple as creating a new C# file in the `BepInEx/config/<YOURMOD_GUID>/Scripts` directory.
38-
```csharp
39-
using RisingV.Scripting.Managers;
40-
using RisingV.Scripting.RuntimeHost;
41-
using RisingV.Shared.Logging;
42-
using RisingV.Shared.Managers;
43-
using RisingV.Shared.Plugins;
44-
45-
// Optional (namespace should match the plugin namespace or remove this line)
46-
namespace RisingV.Scripting.Tests;
47-
48-
/// <summary>
49-
/// Sample script for testing purposes to demonstrate how it can be used.
50-
/// </summary>
51-
/// <param name="context">The script context containing the script data.</param>
52-
public class SampleScript(IScriptContext<ScriptData> context) : Script(context), IReloadableScript
53-
{
54-
public override void Initialize(ScriptManager manager, List<IPlugin> plugins)
55-
{
56-
Log.Info("SampleScript initialized.");
57-
// Called then the plugin is initializing, before any scripts are loaded.
58-
}
59-
60-
public override void Load(ScriptManager manager, List<IPlugin> plugins)
61-
{
62-
Log.Info("SampleScript loaded.");
63-
// Called when the Shared Components are loading, after the plugin is initialized.
64-
}
65-
66-
public override void Unload(ScriptManager manager, List<IPlugin> plugins)
67-
{
68-
Log.Info("SampleScript unloaded.");
69-
// Called when the Shared Components are unloading and before the plugin is terminated or reloading.
70-
}
71-
72-
public override void Terminate(ScriptManager manager, List<IPlugin> plugins)
73-
{
74-
Log.Info("SampleScript terminated.");
75-
// Called when the plugin is being terminated, after all scripts are unloaded.
76-
}
77-
78-
public override void Reload(ScriptManager manager, List<IPlugin> plugins, ReloadReason reason)
79-
{
80-
Log.Info("SampleScript reloaded. Reason: " + reason);
81-
// Called when the script is being reloaded, e.g. due to a change in the script file.
82-
}
83-
}
84-
```
32+
1. Add the `RisingV.Scripting` dependency to your plugin class to enable scripting support:
33+
```csharp
34+
// Added to your plugin class
35+
[BepInDependency("RisingV.Scripting")]
36+
```
37+
2. Add the `ScriptingEngine` to your plugin's `Initialize` method:
38+
```csharp
39+
public override void OnInitialize()
40+
{
41+
EngineManager.AddEngine<ScripingEngine>();
42+
}
43+
```
44+
or, if you aren't using the RisingPlugin base class you can add the engine directly:
45+
```csharp
46+
[BepInPlugin(MyPluginInfo.PLUGIN_GUID, MyPluginInfo.PLUGIN_NAME, MyPluginInfo.PLUGIN_VERSION)]
47+
[BepInDependency("RisingV.Scripting")]
48+
public class Plugin : BasePlugin
49+
{
50+
public override void Load()
51+
{
52+
Bootstrap.Load(p => {
53+
var engineManager = Bootstrap.SharedComponents.Get<EngineManager>();
54+
engineManager!.AddEngine<ScriptingEngine>(p);
55+
});
56+
}
57+
}
58+
```
59+
60+
3. Creating a new script is as simple as creating a new C# file in the `BepInEx/config/<YOURMOD_GUID>/Scripts` directory.
61+
```csharp
62+
using RisingV.Scripting.Managers;
63+
using RisingV.Scripting.RuntimeHost;
64+
using RisingV.Shared.Logging;
65+
using RisingV.Shared.Managers;
66+
using RisingV.Shared.Plugins;
67+
68+
// Optional (namespace should match the plugin namespace or remove this line)
69+
namespace RisingV.Scripting.Tests;
70+
71+
/// <summary>
72+
/// Sample script for testing purposes to demonstrate how it can be used.
73+
/// </summary>
74+
/// <param name="context">The script context containing the script data.</param>
75+
public class SampleScript(IScriptContext<ScriptData> context) : Script(context), IReloadableScript
76+
{
77+
public override void Initialize(ScriptManager manager, List<IPlugin> plugins)
78+
{
79+
Log.Info("SampleScript initialized.");
80+
// Called then the plugin is initializing, before any scripts are loaded.
81+
}
82+
83+
public override void Load(ScriptManager manager, List<IPlugin> plugins)
84+
{
85+
Log.Info("SampleScript loaded.");
86+
// Called when the Shared Components are loading, after the plugin is initialized.
87+
}
88+
89+
public override void Unload(ScriptManager manager, List<IPlugin> plugins)
90+
{
91+
Log.Info("SampleScript unloaded.");
92+
// Called when the Shared Components are unloading and before the plugin is terminated or reloading.
93+
}
94+
95+
public override void Terminate(ScriptManager manager, List<IPlugin> plugins)
96+
{
97+
Log.Info("SampleScript terminated.");
98+
// Called when the plugin is being terminated, after all scripts are unloaded.
99+
}
100+
101+
public override void Reload(ScriptManager manager, List<IPlugin> plugins, ReloadReason reason)
102+
{
103+
Log.Info("SampleScript reloaded. Reason: " + reason);
104+
// Called when the script is being reloaded, e.g. due to a change in the script file.
105+
}
106+
}
107+
```
85108
The script will be automatically compiled and loaded by the Scripting Engine. Make sure the script is marked with `IReloadableScript` interface to enable hot-reloading.
86109

87110
## Configurations

RisingV.Scripting/Plugin.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,12 +27,12 @@ public class Plugin : BasePlugin
2727

2828
public override void Load()
2929
{
30-
Log.Info($"Plugin {MyPluginInfo.PLUGIN_GUID} version {MyPluginInfo.PLUGIN_VERSION} is loaded!");
30+
Log.Debug($"Plugin {MyPluginInfo.PLUGIN_GUID} version {MyPluginInfo.PLUGIN_VERSION} is loaded!");
3131
}
3232

3333
public override bool Unload()
3434
{
35-
Log.Info($"Unloading Plugin {MyPluginInfo.PLUGIN_GUID} version {MyPluginInfo.PLUGIN_VERSION}");
35+
Log.Debug($"Unloading Plugin {MyPluginInfo.PLUGIN_GUID} version {MyPluginInfo.PLUGIN_VERSION}");
3636
return base.Unload();
3737
}
3838
}

0 commit comments

Comments
 (0)