forked from FakeFishGames/Barotrauma
-
Notifications
You must be signed in to change notification settings - Fork 22
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Added some of the service interfaces.
- Added LightInject dependency - Added refactor notes to existing code.
- Loading branch information
1 parent
01207c8
commit e3bb44f
Showing
14 changed files
with
195 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -320,6 +320,7 @@ public void Update() | |
#endif | ||
} | ||
|
||
|
||
public void Stop() | ||
{ | ||
PluginPackageManager.UnloadPlugins(); | ||
|
6 changes: 6 additions & 0 deletions
6
Barotrauma/BarotraumaShared/SharedSource/LuaCs/Services/IAssemblyMgmtService.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
namespace Barotrauma.LuaCs.Services; | ||
|
||
public interface IAssemblyMgmtService : IService | ||
{ | ||
|
||
} |
6 changes: 6 additions & 0 deletions
6
Barotrauma/BarotraumaShared/SharedSource/LuaCs/Services/IConfigService.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
namespace Barotrauma.LuaCs.Services; | ||
|
||
public interface IConfigService : IService | ||
{ | ||
|
||
} |
6 changes: 6 additions & 0 deletions
6
Barotrauma/BarotraumaShared/SharedSource/LuaCs/Services/IHookMgmtService.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
namespace Barotrauma.LuaCs.Services; | ||
|
||
public interface IHookMgmtService : IService | ||
{ | ||
|
||
} |
6 changes: 6 additions & 0 deletions
6
Barotrauma/BarotraumaShared/SharedSource/LuaCs/Services/IHookService.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
namespace Barotrauma.LuaCs.Services; | ||
|
||
public interface IHookService : IService | ||
{ | ||
|
||
} |
25 changes: 25 additions & 0 deletions
25
Barotrauma/BarotraumaShared/SharedSource/LuaCs/Services/ILoggerService.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
using System; | ||
using Barotrauma.Networking; | ||
using Microsoft.Xna.Framework; | ||
|
||
namespace Barotrauma.LuaCs.Services; | ||
|
||
/// <summary> | ||
/// Provides console and debug logging services | ||
/// </summary> | ||
public interface ILoggerService : IService | ||
{ | ||
void HandleException(Exception exception, LuaCsMessageOrigin origin); | ||
void LogError(string message, LuaCsMessageOrigin origin); | ||
void LogError(string message); | ||
void LogMessage(string message, Color? serverColor = null, Color? clientColor = null); | ||
void Log(string message, Color? serverColor = null, ServerLog.MessageType messageType = ServerLog.MessageType.ServerMessage); | ||
} | ||
|
||
public enum LuaCsMessageOrigin | ||
{ | ||
LuaCs, | ||
Unknown, | ||
LuaMod, | ||
CSharpMod, | ||
} |
22 changes: 22 additions & 0 deletions
22
Barotrauma/BarotraumaShared/SharedSource/LuaCs/Services/ILuaScriptService.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
using System; | ||
|
||
namespace Barotrauma.LuaCs.Services; | ||
|
||
public interface ILuaScriptService | ||
{ | ||
#region Type_Registration | ||
|
||
void RegisterSafeType(Type type); | ||
void UnregisterSafeType(Type type); | ||
void UnregisterAllTypes(); | ||
|
||
#endregion | ||
|
||
#region Script_File_Runner | ||
|
||
void AddScriptFiles(string[] filePaths); | ||
void RemoveScriptFiles(string[] filePaths); | ||
void RunLoadedScripts(); | ||
|
||
#endregion | ||
} |
6 changes: 6 additions & 0 deletions
6
Barotrauma/BarotraumaShared/SharedSource/LuaCs/Services/INetworkingService.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
namespace Barotrauma.LuaCs.Services; | ||
|
||
public interface INetworkingService : IService | ||
{ | ||
|
||
} |
6 changes: 6 additions & 0 deletions
6
Barotrauma/BarotraumaShared/SharedSource/LuaCs/Services/IPluginMgmtService.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
namespace Barotrauma.LuaCs.Services; | ||
|
||
public interface IPluginMgmtService : IService | ||
{ | ||
|
||
} |
6 changes: 6 additions & 0 deletions
6
Barotrauma/BarotraumaShared/SharedSource/LuaCs/Services/IPluginService.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
namespace Barotrauma.LuaCs.Services; | ||
|
||
public interface IPluginService : IService | ||
{ | ||
|
||
} |
9 changes: 9 additions & 0 deletions
9
Barotrauma/BarotraumaShared/SharedSource/LuaCs/Services/IService.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
namespace Barotrauma.LuaCs.Services; | ||
|
||
/// <summary> | ||
/// Base interface inherited by all services | ||
/// </summary> | ||
public interface IService | ||
{ | ||
|
||
} |
94 changes: 94 additions & 0 deletions
94
Barotrauma/BarotraumaShared/SharedSource/LuaCs/Services/IServicesProvider.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,94 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
|
||
namespace Barotrauma.LuaCs.Services; | ||
|
||
/// <summary> | ||
/// Provides instancing and management of IServices. | ||
/// </summary> | ||
public interface IServicesProvider | ||
{ | ||
#region Type_Registration | ||
|
||
/// <summary> | ||
/// Registers a type as a service for a given interface. | ||
/// </summary> | ||
/// <param name="lifetime"></param> | ||
/// <typeparam name="TSvcInterface"></typeparam> | ||
/// <typeparam name="TService"></typeparam> | ||
void RegisterServiceType<TSvcInterface, TService>(ServiceLifetime lifetime) where TSvcInterface : class, IService where TService : class, IService; | ||
|
||
/// <summary> | ||
/// Removes a type's registration from being available for the given interface. | ||
/// </summary> | ||
/// <typeparam name="TSvcInterface"></typeparam> | ||
/// <typeparam name="TService"></typeparam> | ||
void UnregisterServiceType<TSvcInterface, TService>() where TSvcInterface : class, IService where TService : class, IService; | ||
|
||
/// <summary> | ||
/// Called whenever a new service type for a given interface is implemented. | ||
/// Args[0]: Interface type | ||
/// Args[1]: Implementing type | ||
/// </summary> | ||
event System.Action<Type, Type> OnServiceRegistered; | ||
|
||
#endregion | ||
|
||
#region Services_Instancing_Injection | ||
|
||
/// <summary> | ||
/// Injects services into the properties of already instanced objects. | ||
/// </summary> | ||
/// <param name="inst"></param> | ||
/// <typeparam name="T"></typeparam> | ||
void InjectServices<T>(T inst) where T : class; | ||
|
||
/// <summary> | ||
/// Tries to get a service for the given interface, returns success/failure. | ||
/// </summary> | ||
/// <param name="service"></param> | ||
/// <param name="lifetime"></param> | ||
/// <typeparam name="TSvcInterface"></typeparam> | ||
/// <returns></returns> | ||
bool TryGetService<TSvcInterface>(out IService service, out ServiceLifetime lifetime) where TSvcInterface : class, IService; | ||
|
||
/// <summary> | ||
/// Called whenever a new service is created/instanced. | ||
/// Args[0]: The interface type of the service. | ||
/// Args[1]: The instance of the service. | ||
/// </summary> | ||
event System.Action<Type, IService> OnServiceInstanced; | ||
|
||
#endregion | ||
|
||
#region ActiveServices | ||
|
||
/// <summary> | ||
/// Returns all services for the given interface. | ||
/// </summary> | ||
/// <typeparam name="TSvc"></typeparam> | ||
/// <returns></returns> | ||
List<TSvc> GetAllServices<TSvc>() where TSvc : class, IService; | ||
|
||
#endregion | ||
|
||
#region Internal_Use | ||
|
||
/// <summary> | ||
/// Disposes of all services for a type. Warning: unable to dispose of services held by other objects. | ||
/// </summary> | ||
/// <typeparam name="TSvc"></typeparam> | ||
internal void DisposeServicesOfType<TSvc>() where TSvc : class, IService; | ||
|
||
/// <summary> | ||
/// Disposes of all services and resets DI container. Warning: unable to dispose of services held by other objects. | ||
/// </summary> | ||
internal void DisposeAllServices(); | ||
|
||
#endregion | ||
} | ||
|
||
public enum ServiceLifetime | ||
{ | ||
Transient, Singleton, PerInstance, PerThread, Invalid, Custom | ||
} |