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

View File

@@ -49,6 +49,7 @@ namespace Barotrauma
_servicesProvider.RegisterServiceType<IPackageManagementService, PackageManagementService>(ServiceLifetime.Singleton);
_servicesProvider.RegisterServiceType<IPluginManagementService, PluginManagementService>(ServiceLifetime.Singleton);
_servicesProvider.RegisterServiceType<ILuaScriptManagementService, LuaScriptManagementService>(ServiceLifetime.Singleton);
_servicesProvider.RegisterServiceType<LuaGame, LuaGame>(ServiceLifetime.Singleton);
// TODO: ILocalizationService
// TODO: IConfigService
// TODO: INetworkingService
@@ -109,6 +110,8 @@ namespace Barotrauma
? svc : throw new NullReferenceException("Networking Manager service not found!");
public IEventService EventService => _servicesProvider.TryGetService<IEventService>(out var svc)
? 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
@@ -175,8 +178,7 @@ namespace Barotrauma
#region LegacyRedirects
public ILuaCsHook Hook => this.EventService;
public ILuaCsHook Hook => this.EventService;
#endregion

View File

@@ -3,14 +3,15 @@ using System.Collections.Generic;
using System.Linq;
using System.Xml.Linq;
using Barotrauma.Items.Components;
using Barotrauma.LuaCs.Services;
using Barotrauma.Networking;
using FarseerPhysics.Dynamics;
using Microsoft.Xna.Framework;
using MoonSharp.Interpreter;
namespace Barotrauma
namespace Barotrauma.LuaCs.Services
{
partial class LuaGame
partial class LuaGame : IReusableService
{
public bool IsSingleplayer => GameMain.IsSingleplayer;
public bool IsMultiplayer => GameMain.IsMultiplayer;
@@ -463,6 +464,8 @@ namespace Barotrauma
public List<DebugConsole.Command> Commands => DebugConsole.Commands;
public bool IsDisposed => throw new NotImplementedException();
public void AssignOnExecute(string names, object onExecute) => DebugConsole.AssignOnExecute(names,
(string[] a) =>
{
@@ -529,7 +532,7 @@ namespace Barotrauma
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
@@ -543,6 +546,17 @@ namespace Barotrauma
DebugConsole.Commands.Remove(cmd);
}
}
public FluentResults.Result Reset()
{
Stop();
return FluentResults.Result.Ok();
}
public void Dispose()
{
Stop();
}
}
}