Implementing python script
parent
e84d5ab6bf
commit
0492ade55b
|
@ -4,8 +4,9 @@ namespace stardew_access
|
|||
{
|
||||
internal class CustomCommands
|
||||
{
|
||||
internal static void Initialize(IModHelper helper)
|
||||
internal static void Initialize()
|
||||
{
|
||||
IModHelper helper = MainClass.ModHelper;
|
||||
|
||||
helper.ConsoleCommands.Add("readtile", "Toggle read tile feature.", (string commmand, string[] args) =>
|
||||
{
|
||||
|
|
|
@ -11,7 +11,7 @@ namespace stardew_access
|
|||
Footstep
|
||||
}
|
||||
|
||||
internal static void Initialize(IModHelper helper)
|
||||
internal static void Initialize()
|
||||
{
|
||||
try
|
||||
{
|
||||
|
@ -54,7 +54,7 @@ namespace stardew_access
|
|||
}
|
||||
|
||||
SoundEffect effect;
|
||||
string filePath = Path.Combine(helper.DirectoryPath, $"sounds/{soundEffect.Key}.wav");
|
||||
string filePath = Path.Combine(MainClass.ModHelper.DirectoryPath,"sounds" , $"{soundEffect.Key}.wav");
|
||||
using (FileStream stream = new(filePath, FileMode.Open))
|
||||
{
|
||||
effect = SoundEffect.FromStream(stream);
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
import libspeechd
|
||||
import wrapper
|
||||
|
||||
speech = libspeechd.Speech
|
||||
speech = wrapper.Speech
|
||||
|
||||
speech.Initialize(self=speech)
|
||||
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
import libspeechd
|
||||
import wrapper
|
||||
import time
|
||||
|
||||
speech = libspeechd.Speech
|
||||
speech = wrapper.Speech
|
||||
|
||||
speech.Initialize(self=speech)
|
||||
|
||||
|
|
|
@ -25,6 +25,12 @@ namespace stardew_access
|
|||
public static Radar radarFeature;
|
||||
public static ScreenReader screenReader;
|
||||
|
||||
private static IModHelper _modHelper;
|
||||
public static IModHelper ModHelper
|
||||
{
|
||||
get{return _modHelper;}
|
||||
}
|
||||
|
||||
/*********
|
||||
** Public methods
|
||||
*********/
|
||||
|
@ -35,6 +41,7 @@ namespace stardew_access
|
|||
#region Initializations
|
||||
|
||||
monitor = Monitor; // Inititalize monitor
|
||||
_modHelper = helper;
|
||||
|
||||
Game1.options.setGamepadMode("force_on");
|
||||
|
||||
|
@ -45,9 +52,9 @@ namespace stardew_access
|
|||
screenReader = new ScreenReader();
|
||||
screenReader.InitializeScreenReader();
|
||||
|
||||
CustomSoundEffects.Initialize(helper);
|
||||
CustomSoundEffects.Initialize();
|
||||
|
||||
CustomCommands.Initialize(helper);
|
||||
CustomCommands.Initialize();
|
||||
|
||||
radarFeature = new Radar();
|
||||
|
||||
|
|
|
@ -1,17 +1,40 @@
|
|||
using AccessibleOutput;
|
||||
using StardewModdingAPI;
|
||||
using System.Runtime.InteropServices;
|
||||
using IronPython.Hosting;
|
||||
|
||||
namespace stardew_access
|
||||
{
|
||||
public class ScreenReader
|
||||
{
|
||||
public IAccessibleOutput? screenReader = null;
|
||||
public dynamic wrapperInstance = null;
|
||||
public string prevText = "", prevTextTile = " ", prevChatText = "", prevMenuText = "";
|
||||
|
||||
/// <summary>Initializes the screen reader.</summary>
|
||||
public void InitializeScreenReader()
|
||||
{
|
||||
MainClass.monitor.Log($"here! {RuntimeInformation.OSDescription}", LogLevel.Debug);
|
||||
if(RuntimeInformation.IsOSPlatform(OSPlatform.Linux))
|
||||
{
|
||||
MainClass.monitor.Log($"here!", LogLevel.Debug);
|
||||
//instance of python engine
|
||||
var engine = Python.CreateEngine();
|
||||
//reading code from file
|
||||
var source = engine.CreateScriptSourceFromFile(Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "LinuxSpeech", "wrapper.py"));
|
||||
var scope = engine.CreateScope();
|
||||
//executing script in scope
|
||||
source.Execute(scope);
|
||||
var wrapper = scope.GetVariable("Speech");
|
||||
//initializing class
|
||||
wrapperInstance = engine.Operations.CreateInstance(wrapper);
|
||||
wrapperInstance.Initialize();
|
||||
|
||||
MainClass.monitor.Log($"here!", LogLevel.Debug);
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
if (!RuntimeInformation.IsOSPlatform(OSPlatform.Windows))
|
||||
return;
|
||||
|
||||
|
@ -55,6 +78,12 @@ namespace stardew_access
|
|||
/// <param name="interrupt">Whether to skip the currently speaking text or not.</param>
|
||||
public void Say(string text, bool interrupt)
|
||||
{
|
||||
if(RuntimeInformation.IsOSPlatform(OSPlatform.Linux))
|
||||
{
|
||||
wrapperInstance.Say(text, interrupt);
|
||||
return;
|
||||
}
|
||||
|
||||
if (screenReader == null)
|
||||
return;
|
||||
|
||||
|
@ -73,7 +102,7 @@ namespace stardew_access
|
|||
if (prevText != text)
|
||||
{
|
||||
prevText = text;
|
||||
screenReader.Speak(text, interrupt);
|
||||
Say(text, interrupt);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -90,7 +119,7 @@ namespace stardew_access
|
|||
if (prevMenuText != text)
|
||||
{
|
||||
prevMenuText = text;
|
||||
screenReader.Speak(text, interrupt);
|
||||
Say(text, interrupt);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -107,7 +136,7 @@ namespace stardew_access
|
|||
if (prevChatText != text)
|
||||
{
|
||||
prevChatText = text;
|
||||
screenReader.Speak(text, interrupt);
|
||||
Say(text, interrupt);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -128,7 +157,7 @@ namespace stardew_access
|
|||
if (prevTextTile != query)
|
||||
{
|
||||
prevTextTile = query;
|
||||
screenReader.Speak(text, interrupt);
|
||||
Say(text, interrupt);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -5,9 +5,10 @@
|
|||
<RootNamespace>stardew_access</RootNamespace>
|
||||
<ImplicitUsings>enable</ImplicitUsings>
|
||||
<Nullable>enable</Nullable>
|
||||
<LangVersion>preview</LangVersion>
|
||||
<PlatformTarget>AnyCPU</PlatformTarget>
|
||||
<GeneratePackageOnBuild>true</GeneratePackageOnBuild>
|
||||
<LangVersion>preview</LangVersion>
|
||||
<PlatformTarget>AnyCPU</PlatformTarget>
|
||||
<GeneratePackageOnBuild>true</GeneratePackageOnBuild>
|
||||
<RestoreProjectStyle>PackageReference</RestoreProjectStyle>
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
|
|
Loading…
Reference in New Issue