Fix bullshit Lua issues
This commit is contained in:
@@ -2,7 +2,7 @@
|
||||
|
||||
namespace Barotrauma.LuaCs.Compatibility;
|
||||
|
||||
internal partial interface ILuaCsTimer : ILuaCsShim
|
||||
internal partial interface ILuaCsTimer : IReusableService, ILuaCsShim
|
||||
{
|
||||
public static double Time => Timing.TotalTime;
|
||||
public static double GetTime() => Time;
|
||||
|
||||
@@ -25,10 +25,7 @@ internal class HarmonyEventPatchesService : IService
|
||||
Harmony.PatchAll(typeof(HarmonyEventPatchesService));
|
||||
}
|
||||
|
||||
// TODO: This causes like hell in Debug.
|
||||
#if !DEBUG
|
||||
[HarmonyPatch(typeof(CoroutineManager), nameof(CoroutineManager.Update)), HarmonyPostfix]
|
||||
#endif
|
||||
public static void CoroutineManager_Update_Post()
|
||||
{
|
||||
_eventService.PublishEvent<IEventUpdate>(x => x.OnUpdate(Timing.TotalTime));
|
||||
|
||||
@@ -174,9 +174,8 @@ class LuaScriptManagementService : ILuaScriptManagementService, ILuaDataService
|
||||
_eventService.RegisterLuaEventAlias<IEventUpdate>("think", "OnUpdate");
|
||||
_eventService.RegisterLuaEventAlias<IEventKeyUpdate>("keyUpdate", "OnKeyUpdate");
|
||||
_eventService.RegisterLuaEventAlias<IEventCharacterCreated>("character.created", "OnCharacterCreated");
|
||||
_eventService.RegisterLuaEventAlias<IEventCharacterCreated>("character.giveJobItems", "OnGiveCharacterJobItems");
|
||||
_eventService.RegisterLuaEventAlias<IEventCharacterCreated>("afflictionUpdate", "OnAfflictionUpdate");
|
||||
|
||||
_eventService.RegisterLuaEventAlias<IEventGiveCharacterJobItems>("character.giveJobItems", "OnGiveCharacterJobItems");
|
||||
_eventService.RegisterLuaEventAlias<IEventAfflictionUpdate>("afflictionUpdate", "OnAfflictionUpdate");
|
||||
}
|
||||
|
||||
private void SetupEnvironment(bool enableSandbox)
|
||||
@@ -357,6 +356,7 @@ class LuaScriptManagementService : ILuaScriptManagementService, ILuaDataService
|
||||
{
|
||||
_luaScriptLoader.ClearCaches();
|
||||
_userDataService.Reset();
|
||||
_luaCsTimer.Reset();
|
||||
RegisterLuaEvents();
|
||||
return DisposeAllPackageResources();
|
||||
}
|
||||
|
||||
@@ -34,7 +34,7 @@ namespace Barotrauma
|
||||
|
||||
Script.GlobalOptions.CustomConverters.SetScriptToClrCustomConversion(DataType.Function, typeof(LuaCsAction), v => (LuaCsAction)(args =>
|
||||
{
|
||||
if (v.Function.OwnerScript == _luaScriptManagementService)
|
||||
if (v.Function.OwnerScript == _luaScriptManagementService.InternalScript)
|
||||
{
|
||||
Call(v.Function, args);
|
||||
}
|
||||
|
||||
@@ -61,7 +61,7 @@ namespace Barotrauma
|
||||
public LuaCsTimer(IEventService eventService)
|
||||
{
|
||||
_eventService = eventService;
|
||||
_eventService.Subscribe<IEventUpdate>(this);
|
||||
SubscribeToEvents();
|
||||
}
|
||||
|
||||
private void AddTimer(TimedAction timedAction)
|
||||
@@ -101,11 +101,6 @@ namespace Barotrauma
|
||||
AddTimer(timedAction);
|
||||
}
|
||||
|
||||
public void Dispose()
|
||||
{
|
||||
_eventService.Unsubscribe<IEventUpdate>(this);
|
||||
}
|
||||
|
||||
public void OnUpdate(double fixedDeltaTime)
|
||||
{
|
||||
lock (timedActions)
|
||||
@@ -135,6 +130,22 @@ namespace Barotrauma
|
||||
}
|
||||
}
|
||||
|
||||
private void SubscribeToEvents()
|
||||
{
|
||||
_eventService.Subscribe<IEventUpdate>(this);
|
||||
}
|
||||
|
||||
public FluentResults.Result Reset()
|
||||
{
|
||||
SubscribeToEvents();
|
||||
return FluentResults.Result.Ok();
|
||||
}
|
||||
|
||||
public void Dispose()
|
||||
{
|
||||
_eventService.Unsubscribe<IEventUpdate>(this);
|
||||
}
|
||||
|
||||
public bool IsDisposed => false;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user