[LuaTTS] Added owner context check & wrapper

This commit is contained in:
NotAKidoS 2024-05-31 22:41:05 -05:00
parent 0a0e6d849b
commit 683c407358

View file

@ -6,13 +6,11 @@ using MoonSharp.Interpreter;
namespace NAK.LuaTTS.Modules; namespace NAK.LuaTTS.Modules;
[PublicAPI] // fak off its used [PublicAPI] // fak off its used
public class TTSLuaModule public class TTSLuaModule : BaseScriptedStaticWrapper
{ {
private CVRLuaContext context; public TTSLuaModule(CVRLuaContext context) : base(context)
internal TTSLuaModule(CVRLuaContext context)
{ {
this.context = context; // we don't really need the context for this shit module // yes
} }
internal static object RegisterUserData(Script script, CVRLuaContext context) internal static object RegisterUserData(Script script, CVRLuaContext context)
@ -22,46 +20,101 @@ public class TTSLuaModule
} }
// Check if TTS is playing // Check if TTS is playing
public static bool IsPlaying() public bool IsPlaying()
=> Comms_TTSHandler.Instance.IsPlaying; {
CheckIfCanAccessMethod(nameof(IsPlaying), false,
CVRLuaEnvironmentContext.CLIENT, CVRLuaObjectContext.ALL_BUT_EVENTS, CVRLuaOwnerContext.LOCAL);
return Comms_TTSHandler.Instance.IsPlaying;
}
// Check if TTS is processing a message // Check if TTS is processing a message
public static bool IsProcessing() public bool IsProcessing()
=> Comms_TTSHandler.Instance.IsProcessing; {
CheckIfCanAccessMethod(nameof(IsProcessing), false,
CVRLuaEnvironmentContext.CLIENT, CVRLuaObjectContext.ALL_BUT_EVENTS, CVRLuaOwnerContext.LOCAL);
return Comms_TTSHandler.Instance.IsProcessing;
}
// Check if TTS has no modules (only true for proton?) // Check if TTS has no modules (only true for proton?)
public static bool HasAnyModules() public bool HasAnyModules()
=> Comms_TTSHandler._modules.Count > 0; {
CheckIfCanAccessMethod(nameof(HasAnyModules), false,
CVRLuaEnvironmentContext.CLIENT, CVRLuaObjectContext.ALL_BUT_EVENTS, CVRLuaOwnerContext.LOCAL);
return Comms_TTSHandler._modules.Count > 0;
}
// Get all available TTS modules // Get all available TTS modules
public static string[] GetAvailableModules() public string[] GetAvailableModules()
=> Comms_TTSHandler._modules.Keys.ToArray(); {
CheckIfCanAccessMethod(nameof(GetAvailableModules), false,
CVRLuaEnvironmentContext.CLIENT, CVRLuaObjectContext.ALL_BUT_EVENTS, CVRLuaOwnerContext.LOCAL);
return Comms_TTSHandler._modules.Keys.ToArray();
}
// Get the current TTS module // Get the current TTS module
public static string GetCurrentModule() public string GetCurrentModule()
=> Comms_TTSHandler.Instance.CurrentModuleId; {
CheckIfCanAccessMethod(nameof(GetCurrentModule), false,
CVRLuaEnvironmentContext.CLIENT, CVRLuaObjectContext.ALL_BUT_EVENTS, CVRLuaOwnerContext.LOCAL);
return Comms_TTSHandler.Instance.CurrentModuleId;
}
// Set the current TTS module // Set the current TTS module
public static void SetCurrentModule(string moduleId) public void SetCurrentModule(string moduleId)
=> Comms_TTSHandler.Instance.ChangeModule(moduleId); {
CheckIfCanAccessMethod(nameof(SetCurrentModule), false,
CVRLuaEnvironmentContext.CLIENT, CVRLuaObjectContext.ALL_BUT_EVENTS, CVRLuaOwnerContext.LOCAL);
Comms_TTSHandler.Instance.ChangeModule(moduleId);
}
// Process a message for TTS playback // Process a message for TTS playback
public static void ProcessMessage(string message) public void ProcessMessage(string message)
=> Comms_TTSHandler.Instance.ProcessMessage(message); {
CheckIfCanAccessMethod(nameof(ProcessMessage), false,
CVRLuaEnvironmentContext.CLIENT, CVRLuaObjectContext.ALL_BUT_EVENTS, CVRLuaOwnerContext.LOCAL);
Comms_TTSHandler.Instance.ProcessMessage(message);
}
// Cancel any currently playing TTS message // Cancel any currently playing TTS message
public static void CancelMessage() public void CancelMessage()
=> Comms_TTSHandler.Instance.ProcessMessage(string.Empty); // empty message cancels the current message {
CheckIfCanAccessMethod(nameof(CancelMessage), false,
CVRLuaEnvironmentContext.CLIENT, CVRLuaObjectContext.ALL_BUT_EVENTS, CVRLuaOwnerContext.LOCAL);
Comms_TTSHandler.Instance.ProcessMessage(string.Empty); // empty message cancels the current message
}
// Get all available voices for the current module // Get all available voices for the current module
public static string[] GetAvailableVoices() public string[] GetAvailableVoices()
=> Comms_TTSHandler.Instance.CurrentModule.Voices.Keys.ToArray(); {
CheckIfCanAccessMethod(nameof(GetAvailableVoices), false,
CVRLuaEnvironmentContext.CLIENT, CVRLuaObjectContext.ALL_BUT_EVENTS, CVRLuaOwnerContext.LOCAL);
return Comms_TTSHandler.Instance.CurrentModule.Voices.Keys.ToArray();
}
// Get the current voice for the module // Get the current voice for the module
public static string GetCurrentVoice() public string GetCurrentVoice()
=> Comms_TTSHandler.Instance.CurrentModule.CurrentVoice; {
CheckIfCanAccessMethod(nameof(GetCurrentVoice), false,
CVRLuaEnvironmentContext.CLIENT, CVRLuaObjectContext.ALL_BUT_EVENTS, CVRLuaOwnerContext.LOCAL);
return Comms_TTSHandler.Instance.CurrentModule.CurrentVoice;
}
// Set the current voice for the module // Set the current voice for the module
public static void SetCurrentVoice(string voiceName) public void SetCurrentVoice(string voiceName)
=> Comms_TTSHandler.Instance.ChangeVoice(voiceName); {
CheckIfCanAccessMethod(nameof(SetCurrentVoice), false,
CVRLuaEnvironmentContext.CLIENT, CVRLuaObjectContext.ALL_BUT_EVENTS, CVRLuaOwnerContext.LOCAL);
Comms_TTSHandler.Instance.ChangeVoice(voiceName);
}
} }