feat: add enable/disable/toggle commands

This commit is contained in:
Anna 2021-05-10 11:44:26 -04:00
parent 5a85476cac
commit 3ee6213cf7
3 changed files with 221 additions and 145 deletions

View File

@ -1,5 +1,7 @@
using System;
using System.Linq;
using Dalamud.Game.Command;
using SoundFilter.Resources;
namespace SoundFilter {
internal class Commands : IDisposable {
@ -20,7 +22,45 @@ namespace SoundFilter {
}
private void OnCommand(string command, string args) {
this.Plugin.Ui.Settings.Toggle();
if (string.IsNullOrWhiteSpace(args)) {
this.Plugin.Ui.Settings.Toggle();
return;
}
var chat = this.Plugin.Interface.Framework.Gui.Chat;
var split = args.Split(' ');
if (split.Length < 1) {
chat.PrintError($"[{SoundFilterPlugin.Name}] {Language.CommandNotEnoughArguments}");
return;
}
var filterName = split.Length > 1 ? string.Join(" ", split.Skip(1)) : null;
var filter = filterName == null ? null : this.Plugin.Config.Filtered.Values.FirstOrDefault(filter => filter.Name == filterName);
if (filterName != null && filter == null) {
chat.PrintError($"[{SoundFilterPlugin.Name}] {Language.CommandNoSuchFilter}");
return;
}
bool? enabled = split[0] switch {
"enable" => true,
"disable" => false,
"toggle" when filter == null => !this.Plugin.Config.Enabled,
"toggle" => !filter.Enabled,
_ => null,
};
if (enabled == null) {
chat.PrintError($"[{SoundFilterPlugin.Name}] {Language.CommandInvalidSubcommand}");
return;
}
if (filter != null) {
filter.Enabled = enabled.Value;
} else {
this.Plugin.Config.Enabled = enabled.Value;
}
this.Plugin.Config.Save();
}
}
}

View File

@ -1,144 +1,171 @@
//------------------------------------------------------------------------------
// <auto-generated>
// This code was generated by a tool.
// Runtime Version:4.0.30319.42000
//
// Changes to this file may cause incorrect behavior and will be lost if
// the code is regenerated.
// </auto-generated>
//------------------------------------------------------------------------------
namespace SoundFilter.Resources {
using System;
/// <summary>
/// A strongly-typed resource class, for looking up localized strings, etc.
/// </summary>
// This class was auto-generated by the StronglyTypedResourceBuilder
// class via a tool like ResGen or Visual Studio.
// To add or remove a member, edit your .ResX file then rerun ResGen
// with the /str option, or rebuild your VS project.
[global::System.CodeDom.Compiler.GeneratedCodeAttribute("System.Resources.Tools.StronglyTypedResourceBuilder", "4.0.0.0")]
[global::System.Diagnostics.DebuggerNonUserCodeAttribute()]
[global::System.Runtime.CompilerServices.CompilerGeneratedAttribute()]
internal class Language {
private static global::System.Resources.ResourceManager resourceMan;
private static global::System.Globalization.CultureInfo resourceCulture;
[global::System.Diagnostics.CodeAnalysis.SuppressMessageAttribute("Microsoft.Performance", "CA1811:AvoidUncalledPrivateCode")]
internal Language() {
}
/// <summary>
/// Returns the cached ResourceManager instance used by this class.
/// </summary>
[global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Advanced)]
internal static global::System.Resources.ResourceManager ResourceManager {
get {
if (object.ReferenceEquals(resourceMan, null)) {
global::System.Resources.ResourceManager temp = new global::System.Resources.ResourceManager("SoundFilter.Resources.Language", typeof(Language).Assembly);
resourceMan = temp;
}
return resourceMan;
}
}
/// <summary>
/// Overrides the current thread's CurrentUICulture property for all
/// resource lookups using this strongly typed resource class.
/// </summary>
[global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Advanced)]
internal static global::System.Globalization.CultureInfo Culture {
get {
return resourceCulture;
}
set {
resourceCulture = value;
}
}
/// <summary>
/// Looks up a localized string similar to Due to the way FFXIV&apos;s resource loading works, {0} has to hear a sound once before it can filter it after a fresh install or update. Restart your game after installing or updating if this is a problem for you..
/// </summary>
internal static string LoadWarning {
get {
return ResourceManager.GetString("LoadWarning", resourceCulture);
}
}
/// <summary>
/// Looks up a localized string similar to Max sounds.
/// </summary>
internal static string LogMaxRecentSounds {
get {
return ResourceManager.GetString("LogMaxRecentSounds", resourceCulture);
}
}
/// <summary>
/// Looks up a localized string similar to Search.
/// </summary>
internal static string LogSearch {
get {
return ResourceManager.GetString("LogSearch", resourceCulture);
}
}
/// <summary>
/// Looks up a localized string similar to Sound log.
/// </summary>
internal static string LogWindowTitle {
get {
return ResourceManager.GetString("LogWindowTitle", resourceCulture);
}
}
/// <summary>
/// Looks up a localized string similar to Filter name.
/// </summary>
internal static string SettingsAddFilterName {
get {
return ResourceManager.GetString("SettingsAddFilterName", resourceCulture);
}
}
/// <summary>
/// Looks up a localized string similar to Sound path to filter.
/// </summary>
internal static string SettingsAddPathToFilter {
get {
return ResourceManager.GetString("SettingsAddPathToFilter", resourceCulture);
}
}
/// <summary>
/// Looks up a localized string similar to Enable sound filter.
/// </summary>
internal static string SettingsEnableSoundFilter {
get {
return ResourceManager.GetString("SettingsEnableSoundFilter", resourceCulture);
}
}
/// <summary>
/// Looks up a localized string similar to Show sound log window.
/// </summary>
internal static string SettingsShowSoundLogWindow {
get {
return ResourceManager.GetString("SettingsShowSoundLogWindow", resourceCulture);
}
}
/// <summary>
/// Looks up a localized string similar to {0} settings.
/// </summary>
internal static string SettingsWindowTitle {
get {
return ResourceManager.GetString("SettingsWindowTitle", resourceCulture);
}
}
}
}
//------------------------------------------------------------------------------
// <auto-generated>
// This code was generated by a tool.
// Runtime Version:4.0.30319.42000
//
// Changes to this file may cause incorrect behavior and will be lost if
// the code is regenerated.
// </auto-generated>
//------------------------------------------------------------------------------
namespace SoundFilter.Resources {
using System;
/// <summary>
/// A strongly-typed resource class, for looking up localized strings, etc.
/// </summary>
// This class was auto-generated by the StronglyTypedResourceBuilder
// class via a tool like ResGen or Visual Studio.
// To add or remove a member, edit your .ResX file then rerun ResGen
// with the /str option, or rebuild your VS project.
[global::System.CodeDom.Compiler.GeneratedCodeAttribute("System.Resources.Tools.StronglyTypedResourceBuilder", "4.0.0.0")]
[global::System.Diagnostics.DebuggerNonUserCodeAttribute()]
[global::System.Runtime.CompilerServices.CompilerGeneratedAttribute()]
internal class Language {
private static global::System.Resources.ResourceManager resourceMan;
private static global::System.Globalization.CultureInfo resourceCulture;
[global::System.Diagnostics.CodeAnalysis.SuppressMessageAttribute("Microsoft.Performance", "CA1811:AvoidUncalledPrivateCode")]
internal Language() {
}
/// <summary>
/// Returns the cached ResourceManager instance used by this class.
/// </summary>
[global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Advanced)]
internal static global::System.Resources.ResourceManager ResourceManager {
get {
if (object.ReferenceEquals(resourceMan, null)) {
global::System.Resources.ResourceManager temp = new global::System.Resources.ResourceManager("SoundFilter.Resources.Language", typeof(Language).Assembly);
resourceMan = temp;
}
return resourceMan;
}
}
/// <summary>
/// Overrides the current thread's CurrentUICulture property for all
/// resource lookups using this strongly typed resource class.
/// </summary>
[global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Advanced)]
internal static global::System.Globalization.CultureInfo Culture {
get {
return resourceCulture;
}
set {
resourceCulture = value;
}
}
/// <summary>
/// Looks up a localized string similar to Invalid subcommand..
/// </summary>
internal static string CommandInvalidSubcommand {
get {
return ResourceManager.GetString("CommandInvalidSubcommand", resourceCulture);
}
}
/// <summary>
/// Looks up a localized string similar to No such filter..
/// </summary>
internal static string CommandNoSuchFilter {
get {
return ResourceManager.GetString("CommandNoSuchFilter", resourceCulture);
}
}
/// <summary>
/// Looks up a localized string similar to Not enough arguments. Please specify &apos;enable&apos; or &apos;disable&apos; and an optional filter name.
/// </summary>
internal static string CommandNotEnoughArguments {
get {
return ResourceManager.GetString("CommandNotEnoughArguments", resourceCulture);
}
}
/// <summary>
/// Looks up a localized string similar to Due to the way FFXIV&apos;s resource loading works, {0} has to hear a sound once before it can filter it after a fresh install or update. Restart your game after installing or updating if this is a problem for you..
/// </summary>
internal static string LoadWarning {
get {
return ResourceManager.GetString("LoadWarning", resourceCulture);
}
}
/// <summary>
/// Looks up a localized string similar to Max sounds.
/// </summary>
internal static string LogMaxRecentSounds {
get {
return ResourceManager.GetString("LogMaxRecentSounds", resourceCulture);
}
}
/// <summary>
/// Looks up a localized string similar to Search.
/// </summary>
internal static string LogSearch {
get {
return ResourceManager.GetString("LogSearch", resourceCulture);
}
}
/// <summary>
/// Looks up a localized string similar to Sound log.
/// </summary>
internal static string LogWindowTitle {
get {
return ResourceManager.GetString("LogWindowTitle", resourceCulture);
}
}
/// <summary>
/// Looks up a localized string similar to Filter name.
/// </summary>
internal static string SettingsAddFilterName {
get {
return ResourceManager.GetString("SettingsAddFilterName", resourceCulture);
}
}
/// <summary>
/// Looks up a localized string similar to Sound path to filter.
/// </summary>
internal static string SettingsAddPathToFilter {
get {
return ResourceManager.GetString("SettingsAddPathToFilter", resourceCulture);
}
}
/// <summary>
/// Looks up a localized string similar to Enable sound filter.
/// </summary>
internal static string SettingsEnableSoundFilter {
get {
return ResourceManager.GetString("SettingsEnableSoundFilter", resourceCulture);
}
}
/// <summary>
/// Looks up a localized string similar to Show sound log window.
/// </summary>
internal static string SettingsShowSoundLogWindow {
get {
return ResourceManager.GetString("SettingsShowSoundLogWindow", resourceCulture);
}
}
/// <summary>
/// Looks up a localized string similar to {0} settings.
/// </summary>
internal static string SettingsWindowTitle {
get {
return ResourceManager.GetString("SettingsWindowTitle", resourceCulture);
}
}
}
}

View File

@ -45,4 +45,13 @@
<data name="SettingsAddPathToFilter" xml:space="preserve">
<value>Sound path to filter</value>
</data>
<data name="CommandNotEnoughArguments" xml:space="preserve">
<value>Not enough arguments. Please specify 'enable' or 'disable' and an optional filter name</value>
</data>
<data name="CommandInvalidSubcommand" xml:space="preserve">
<value>Invalid subcommand.</value>
</data>
<data name="CommandNoSuchFilter" xml:space="preserve">
<value>No such filter.</value>
</data>
</root>