Skip to content

Commit

Permalink
Added: IMod into ModContext & Replace Mentions of Start() to Mod.cs
Browse files Browse the repository at this point in the history
  • Loading branch information
Sewer56 committed Aug 26, 2022
1 parent a77d602 commit e7c3bfc
Show file tree
Hide file tree
Showing 6 changed files with 16 additions and 4 deletions.
2 changes: 1 addition & 1 deletion docs/DependencyInjection_Publisher.md
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ public class Exports : IExports

### Share it with Mod Loader

During initialization (`Start()`), register your interface with the Mod Loader using the `IModLoader` instance.
During initialization (`Mod.cs`), register your interface with the Mod Loader using the `IModLoader` instance.

```csharp
void PublishInterface()
Expand Down
4 changes: 2 additions & 2 deletions docs/OptimizingMods.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ Focusing mainly on techniques which may not be immediately obvious, the main goa

Lazy loading is simply the process of deferring initialization of an object/thing until the point at which it is needed.

Sometimes in your `Start()` entry point, you might not need to necessarily need to initialize everything related to your mod immediately.
Sometimes in your `Mod.cs` entry point, you might not need to necessarily need to initialize everything related to your mod immediately.

For example, if you need to make a connection to a server which will be used later in execution (say you are interacting with a chatroom in a mod etc.), the initial startup of the mod does not have to be halted until this connection is made. You can make the connection in the background and any code depending on the connection can wait for the connection task to finish.

Expand Down Expand Up @@ -49,7 +49,7 @@ Consider creating a connection to a server.
// Inside class fields.
private Task _connectToServerTask;

// Inside Start()
// Inside Mod.cs Constructor
_connectToServerTask = Task.Run(() => { /* Code to Connect to a Server */ });

// Somewhere else in code that needs the server to be created.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

<PropertyGroup>
<PackageType>Template</PackageType>
<PackageVersion>1.3.1</PackageVersion>
<PackageVersion>1.4.0</PackageVersion>
<PackageId>Reloaded.Mod.Templates</PackageId>
<Title>Reloaded-II Mod Templates</Title>
<Authors>Sewer56</Authors>
Expand Down
6 changes: 6 additions & 0 deletions source/Reloaded.Mod.Template/templates/configurable/Mod.cs
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,11 @@ public class Mod : ModBase // <= Do not Remove.
/// </summary>
private readonly ILogger _logger;

/// <summary>
/// Entry point into the mod, instance that created this class.
/// </summary>
private readonly IMod _owner;

#if (IncludeConfig)
/// <summary>
/// Provides access to this mod's configuration.
Expand All @@ -48,6 +53,7 @@ public Mod(ModContext context)
_modLoader = context.ModLoader;
_hooks = context.Hooks;
_logger = context.Logger;
_owner = context.Owner;
#if (IncludeConfig)
_configuration = context.Configuration;
#endif
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,4 +37,9 @@ public class ModContext
/// Configuration of this mod.
/// </summary>
public IModConfig ModConfig { get; set; } = null!;

/// <summary>
/// Instance of the IMod interface that created this mod instance.
/// </summary>
public IMod Owner { get; set; } = null!;
}
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,7 @@ public void StartEx(IModLoaderV1 loaderApi, IModConfigV1 modConfig)
Hooks = _hooks,
ModLoader = _modLoader,
ModConfig = _modConfig,
Owner = this,
#if (IncludeConfig)
Configuration = _configuration,
#endif
Expand Down

0 comments on commit e7c3bfc

Please sign in to comment.