Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 7 additions & 1 deletion src/TrackerCouncil.Smz3.Abstractions/TrackerBase.cs
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ public abstract class TrackerBase : IDisposable
/// <summary>
/// Gets the configured responses.
/// </summary>
public ResponseConfig Responses { get; protected init; } = null!;
public ResponseConfig Responses { get; protected set; } = null!;

/// <summary>
/// Gets a collection of basic requests and responses.
Expand Down Expand Up @@ -370,5 +370,11 @@ protected virtual void OnVoiceRecognitionEnabledChanged()
VoiceRecognitionEnabledChanged?.Invoke(this, EventArgs.Empty);
}

/// <summary>
/// Updates the responses to reflect the selected tracker image pack
/// </summary>
/// <param name="packName">The name of the pack</param>
public abstract void SetImagePack(string? packName);

public abstract void Dispose();
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
namespace TrackerCouncil.Smz3.Data.Configuration.ConfigFiles;

public class TrackerProfileConfig
{
public bool UseAltVoice { get; set; }
public ResponseConfig? ResponseConfig { get; set; }
}
1 change: 1 addition & 0 deletions src/TrackerCouncil.Smz3.Data/Options/GeneralOptions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -265,6 +265,7 @@ public bool Validate()
AutoMapUpdateBehavior = AutoMapUpdateBehavior ?? Options.AutoMapUpdateBehavior.Disabled,
VoiceFrequency = TrackerVoiceFrequency,
TrackerProfiles = SelectedProfiles,
TrackerImagePackName = TrackerSpeechImagePack,
UndoExpirationTime = UndoExpirationTime,
TrackDisplayFormat = TrackDisplayFormat,
MsuTrackOutputPath = MsuTrackOutputPath,
Expand Down
5 changes: 5 additions & 0 deletions src/TrackerCouncil.Smz3.Data/Options/TrackerOptions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,11 @@ public record TrackerOptions
/// </summary>
public ICollection<string?> TrackerProfiles { get; set; } = new List<string?>() { "Sassy" };

/// <summary>
/// Gets the name of the tracker images that the user selected
/// </summary>
public string? TrackerImagePackName { get; set; }

/// <summary>
/// The output style for the current song (Deprecated)
/// </summary>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using System.Collections.Generic;
using TrackerCouncil.Smz3.Data.Configuration.ConfigFiles;

namespace TrackerCouncil.Smz3.Data.Options;

Expand Down Expand Up @@ -38,6 +39,8 @@ public class TrackerSpeechImagePack
/// </summary>
public required Dictionary<string, TrackerSpeechReactionImages> Reactions { get; set; }

public required TrackerProfileConfig? ProfileConfig { get; set; }

/// <summary>
/// Gets the reaction images for a given reaction type. Will return the default reaction type if not specified
/// or the requested reaction type is not present in this pack.
Expand Down
35 changes: 33 additions & 2 deletions src/TrackerCouncil.Smz3.Data/Services/TrackerSpriteService.cs
Original file line number Diff line number Diff line change
@@ -1,16 +1,20 @@
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using Microsoft.Extensions.Logging;
using TrackerCouncil.Smz3.Data.Configuration.ConfigFiles;
using TrackerCouncil.Smz3.Data.Options;
using YamlDotNet.Serialization;
using YamlDotNet.Serialization.NamingConventions;

namespace TrackerCouncil.Smz3.Data.Services;

/// <summary>
/// Service for loading tracker speech sprites
/// </summary>
/// <param name="optionsFactory"></param>
public class TrackerSpriteService(OptionsFactory optionsFactory)
public class TrackerSpriteService(OptionsFactory optionsFactory, ILogger<TrackerSpriteService> logger)

Check warning on line 17 in src/TrackerCouncil.Smz3.Data/Services/TrackerSpriteService.cs

View workflow job for this annotation

GitHub Actions / build

Parameter 'logger' has no matching param tag in the XML comment for 'TrackerSpriteService.TrackerSpriteService(OptionsFactory, ILogger<TrackerSpriteService>)' (but other parameters do)

Check warning on line 17 in src/TrackerCouncil.Smz3.Data/Services/TrackerSpriteService.cs

View workflow job for this annotation

GitHub Actions / build

Parameter 'logger' has no matching param tag in the XML comment for 'TrackerSpriteService.TrackerSpriteService(OptionsFactory, ILogger<TrackerSpriteService>)' (but other parameters do)
{
private List<TrackerSpeechImagePack> _packs = [];

Expand Down Expand Up @@ -82,6 +86,9 @@
packName += " (Custom)";
}

var config = GetConfig(Path.Combine(folder, "config.yml"))
?? GetConfig(Path.Combine(folder, "config.yaml"));

_packs.Add(new TrackerSpeechImagePack
{
Name = packName,
Expand All @@ -90,7 +97,31 @@
IdleImage = Path.Combine(folder, "default_idle.png"),
TalkingImage = Path.Combine(folder, "default_talk.png"),
},
Reactions = reactions
Reactions = reactions,
ProfileConfig = config,
});
}

private TrackerProfileConfig? GetConfig(string path)
{
if (!File.Exists(path))
{
return null;
}

var yml = File.ReadAllText(path);
var deserializer = new DeserializerBuilder()
.WithNamingConvention(PascalCaseNamingConvention.Instance)
.IgnoreUnmatchedProperties()
.Build();
try
{
return deserializer.Deserialize<TrackerProfileConfig>(yml);
}
catch (Exception e)
{
logger.LogError(e, "Unable to parse tracker profile config {Path}", path);
return null;
}
}
}
2 changes: 1 addition & 1 deletion src/TrackerCouncil.Smz3.Tracking/Services/ICommunicator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ public void Abort() { }
/// When overridden in an implementing class, uses an alternate voice
/// when communicating with the player.
/// </summary>
public void UseAlternateVoice() { }
public void UseAlternateVoice(bool useAlt = true) { }

/// <summary>
/// When overridden in an implementing class, increases the
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -72,14 +72,14 @@ public TextToSpeechCommunicator(TrackerOptionsAccessor trackerOptionsAccessor, I
/// <summary>
/// Selects a different text-to-speech voice.
/// </summary>
public void UseAlternateVoice()
public void UseAlternateVoice(bool useAlt = true)
{
if (!OperatingSystem.IsWindows())
{
return;
}

_tts.SelectVoiceByHints(VoiceGender.Male);
_tts.SelectVoiceByHints(useAlt ? VoiceGender.Male : VoiceGender.Female);
}

/// <summary>
Expand Down
49 changes: 36 additions & 13 deletions src/TrackerCouncil.Smz3.Tracking/Tracker.cs
Original file line number Diff line number Diff line change
Expand Up @@ -47,10 +47,13 @@ public sealed class Tracker : TrackerBase, IDisposable
private readonly ITrackerStateService _stateService;
private readonly ITrackerTimerService _timerService;
private readonly ISpeechRecognitionService _recognizer;
private readonly TrackerSpriteService _trackerSpriteService;
private readonly HashSet<SchrodingersString> _saidLines = new();

private bool _disposed;
private string? _lastSpokenText;
private readonly bool _alternateTracker;
private readonly HashSet<SchrodingersString> _saidLines = new();
private string? _previousImagePackName;
private ResponseConfig _defaultResponseConfig;

/// <summary>
/// Initializes a new instance of the <see cref="Tracker"/> class.
Expand All @@ -71,6 +74,7 @@ public sealed class Tracker : TrackerBase, IDisposable
/// <param name="stateService"></param>
/// <param name="timerService"></param>
/// <param name="serviceProvider"></param>
/// <param name="trackerSpriteService"></param>
public Tracker(IWorldAccessor worldAccessor,
TrackerModuleFactory moduleFactory,
IChatClient chatClient,
Expand All @@ -82,7 +86,8 @@ public Tracker(IWorldAccessor worldAccessor,
Configs configs,
ITrackerStateService stateService,
ITrackerTimerService timerService,
IServiceProvider serviceProvider)
IServiceProvider serviceProvider,
TrackerSpriteService trackerSpriteService)
{
if (trackerOptions.Options == null)
throw new InvalidOperationException("Tracker options have not yet been activated.");
Expand All @@ -98,10 +103,12 @@ public Tracker(IWorldAccessor worldAccessor,
_communicator = communicator;
_stateService = stateService;
_timerService = timerService;
_trackerSpriteService = trackerSpriteService;

// Initialize the tracker configuration
Configs = configs;
Responses = configs.Responses;
_defaultResponseConfig = Responses = configs.Responses;
SetImagePack(trackerOptions.Options.TrackerImagePackName);
Requests = configs.Requests;
PlayerProgressionService.ResetProgression();

Expand All @@ -119,14 +126,6 @@ public Tracker(IWorldAccessor worldAccessor,
_idleTimers = new();
}


// Initialize the text-to-speech
if (s_random.NextDouble() <= 0.01)
{
_alternateTracker = true;
_communicator.UseAlternateVoice();
}

// Initialize the speech recognition engine
if (_trackerOptions.Options.SpeechRecognitionMode == SpeechRecognitionMode.Disabled ||
!OperatingSystem.IsWindows())
Expand Down Expand Up @@ -217,6 +216,30 @@ public override bool Load(GeneratedRom rom, string romPath)
return false;
}

public override void SetImagePack(string? packName)
{
if (packName == _previousImagePackName)
{
return;
}

_previousImagePackName = packName;
var profileConfig = _trackerSpriteService.GetPack(packName).ProfileConfig;
_communicator.UseAlternateVoice(profileConfig?.UseAltVoice ?? false);

if (profileConfig?.ResponseConfig == null)
{
Responses = _defaultResponseConfig;
return;
}

var newResponseConfig = ResponseConfig.Default();
IMergeable<ResponseConfig> mergeableConfig = newResponseConfig;
mergeableConfig.MergeFrom(_defaultResponseConfig);
mergeableConfig.MergeFrom(profileConfig.ResponseConfig);
Responses = newResponseConfig;
}

private void LoadServices(IServiceProvider serviceProvider)
{
var interfaceNamespace = typeof(TrackerBase).Namespace;
Expand Down Expand Up @@ -319,7 +342,7 @@ public override bool TryStartTracking()
loadError = true;
}

Say(response: _alternateTracker ? Responses.StartingTrackingAlternate : Responses.StartedTracking);
Say(response: Responses.StartedTracking);
RestartIdleTimers();
return !loadError;
}
Expand Down
11 changes: 3 additions & 8 deletions src/TrackerCouncil.Smz3.Tracking/VoiceCommands/GoModeModule.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
using System.Diagnostics.CodeAnalysis;
using Microsoft.Extensions.Logging;
using TrackerCouncil.Smz3.Abstractions;
using TrackerCouncil.Smz3.Data.Configuration.ConfigFiles;
using TrackerCouncil.Smz3.Tracking.Services;

namespace TrackerCouncil.Smz3.Tracking.VoiceCommands;
Expand All @@ -12,20 +11,16 @@ namespace TrackerCouncil.Smz3.Tracking.VoiceCommands;
/// </summary>
public class GoModeModule : TrackerModule
{
private ResponseConfig _responseConfig;

/// <summary>
/// Initializes a new instance of the <see cref="GoModeModule"/> class.
/// </summary>
/// <param name="tracker">The tracker instance.</param>
/// <param name="playerProgressionService">Service to get item information</param>
/// <param name="worldQueryService">Service to get world information</param>
/// <param name="logger">Used to log information.</param>
/// <param name="responseConfig"></param>
public GoModeModule(TrackerBase tracker, IPlayerProgressionService playerProgressionService, IWorldQueryService worldQueryService, ILogger<GoModeModule> logger, ResponseConfig responseConfig)
public GoModeModule(TrackerBase tracker, IPlayerProgressionService playerProgressionService, IWorldQueryService worldQueryService, ILogger<GoModeModule> logger)
: base(tracker, playerProgressionService, worldQueryService, logger)
{
_responseConfig = responseConfig;
}

private GrammarBuilder GetGoModeRule(List<string> prompts)
Expand All @@ -38,12 +33,12 @@ private GrammarBuilder GetGoModeRule(List<string> prompts)
[SuppressMessage("Interoperability", "CA1416:Validate platform compatibility")]
public override void AddCommands()
{
if (_responseConfig.GoModePrompts == null)
if (TrackerBase.Responses.GoModePrompts == null)
{
return;
}

AddCommand("Toggle Go Mode", GetGoModeRule(_responseConfig.GoModePrompts), (result) =>
AddCommand("Toggle Go Mode", GetGoModeRule(TrackerBase.Responses.GoModePrompts), (result) =>
{
TrackerBase.ModeTracker.ToggleGoMode(result.Confidence);
});
Expand Down
5 changes: 1 addition & 4 deletions src/TrackerCouncil.Smz3.Tracking/VoiceCommands/GoalModule.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ namespace TrackerCouncil.Smz3.Tracking.VoiceCommands;
/// </summary>
public class GoalModule : TrackerModule
{
private ResponseConfig _responseConfig;
private const string ItemCountKey = "ItemCount";

/// <summary>
Expand All @@ -24,11 +23,9 @@ public class GoalModule : TrackerModule
/// <param name="playerProgressionService">Service to get item information</param>
/// <param name="worldQueryService">Service to get world information</param>
/// <param name="logger">Used to log information.</param>
/// <param name="responseConfig"></param>
public GoalModule(TrackerBase tracker, IPlayerProgressionService playerProgressionService, IWorldQueryService worldQueryService, ILogger<GoModeModule> logger, ResponseConfig responseConfig)
public GoalModule(TrackerBase tracker, IPlayerProgressionService playerProgressionService, IWorldQueryService worldQueryService, ILogger<GoModeModule> logger)
: base(tracker, playerProgressionService, worldQueryService, logger)
{
_responseConfig = responseConfig;
}

[SuppressMessage("Interoperability", "CA1416:Validate platform compatibility")]
Expand Down