LuaGame legacy service

This commit is contained in:
EvilFactory
2025-02-26 12:25:42 -03:00
committed by Maplewheels
parent 7436ea3e8c
commit cb88d215fa
2 changed files with 21 additions and 5 deletions
@@ -49,6 +49,7 @@ namespace Barotrauma
_servicesProvider.RegisterServiceType<IPackageManagementService, PackageManagementService>(ServiceLifetime.Singleton); _servicesProvider.RegisterServiceType<IPackageManagementService, PackageManagementService>(ServiceLifetime.Singleton);
_servicesProvider.RegisterServiceType<IPluginManagementService, PluginManagementService>(ServiceLifetime.Singleton); _servicesProvider.RegisterServiceType<IPluginManagementService, PluginManagementService>(ServiceLifetime.Singleton);
_servicesProvider.RegisterServiceType<ILuaScriptManagementService, LuaScriptManagementService>(ServiceLifetime.Singleton); _servicesProvider.RegisterServiceType<ILuaScriptManagementService, LuaScriptManagementService>(ServiceLifetime.Singleton);
_servicesProvider.RegisterServiceType<LuaGame, LuaGame>(ServiceLifetime.Singleton);
// TODO: ILocalizationService // TODO: ILocalizationService
// TODO: IConfigService // TODO: IConfigService
// TODO: INetworkingService // TODO: INetworkingService
@@ -109,6 +110,8 @@ namespace Barotrauma
? svc : throw new NullReferenceException("Networking Manager service not found!"); ? svc : throw new NullReferenceException("Networking Manager service not found!");
public IEventService EventService => _servicesProvider.TryGetService<IEventService>(out var svc) public IEventService EventService => _servicesProvider.TryGetService<IEventService>(out var svc)
? svc : throw new NullReferenceException("Networking Manager service not found!"); ? svc : throw new NullReferenceException("Networking Manager service not found!");
public LuaGame Game => _servicesProvider.TryGetService<LuaGame>(out var svc)
? svc : throw new NullReferenceException("LuaGame service not found!");
/* /*
* === Config Vars * === Config Vars
@@ -175,8 +178,7 @@ namespace Barotrauma
#region LegacyRedirects #region LegacyRedirects
public ILuaCsHook Hook => this.EventService; public ILuaCsHook Hook => this.EventService;
#endregion #endregion
@@ -3,14 +3,15 @@ using System.Collections.Generic;
using System.Linq; using System.Linq;
using System.Xml.Linq; using System.Xml.Linq;
using Barotrauma.Items.Components; using Barotrauma.Items.Components;
using Barotrauma.LuaCs.Services;
using Barotrauma.Networking; using Barotrauma.Networking;
using FarseerPhysics.Dynamics; using FarseerPhysics.Dynamics;
using Microsoft.Xna.Framework; using Microsoft.Xna.Framework;
using MoonSharp.Interpreter; using MoonSharp.Interpreter;
namespace Barotrauma namespace Barotrauma.LuaCs.Services
{ {
partial class LuaGame partial class LuaGame : IReusableService
{ {
public bool IsSingleplayer => GameMain.IsSingleplayer; public bool IsSingleplayer => GameMain.IsSingleplayer;
public bool IsMultiplayer => GameMain.IsMultiplayer; public bool IsMultiplayer => GameMain.IsMultiplayer;
@@ -463,6 +464,8 @@ namespace Barotrauma
public List<DebugConsole.Command> Commands => DebugConsole.Commands; public List<DebugConsole.Command> Commands => DebugConsole.Commands;
public bool IsDisposed => throw new NotImplementedException();
public void AssignOnExecute(string names, object onExecute) => DebugConsole.AssignOnExecute(names, public void AssignOnExecute(string names, object onExecute) => DebugConsole.AssignOnExecute(names,
(string[] a) => (string[] a) =>
{ {
@@ -529,7 +532,7 @@ namespace Barotrauma
GameMain.Server.EndGame(); GameMain.Server.EndGame();
} }
public void AssignOnClientRequestExecute(string names, object onExecute) => DebugConsole.AssignOnClientRequestExecute(names, (Client a, Vector2 b, string[] c) => { GameMain.LuaCs.CallLuaFunction(onExecute, new object[] { a, b, c }); }); //public void AssignOnClientRequestExecute(string names, object onExecute) => DebugConsole.AssignOnClientRequestExecute(names, (Client a, Vector2 b, string[] c) => { GameMain.LuaCs.CallLuaFunction(onExecute, new object[] { a, b, c }); });
#endif #endif
@@ -543,6 +546,17 @@ namespace Barotrauma
DebugConsole.Commands.Remove(cmd); DebugConsole.Commands.Remove(cmd);
} }
} }
public FluentResults.Result Reset()
{
Stop();
return FluentResults.Result.Ok();
}
public void Dispose()
{
Stop();
}
} }
} }