Enhance command handling and add namespace imports
- Added `using` directives for essential namespaces in `Plugin.cs`. - Implemented a "set" subcommand for configuring activity options, including color and prefix/suffix settings. - Added error handling for duplicate and invalid inputs, with user feedback via chat. - Updated the configuration for the first activity based on user input.
This commit is contained in:
@@ -6,6 +6,12 @@ using Dalamud.Plugin.Services;
|
||||
using SpotifyHonorific.Windows;
|
||||
using SpotifyHonorific.Activities;
|
||||
using SpotifyHonorific.Updaters;
|
||||
using System;
|
||||
using System.Diagnostics;
|
||||
using System.Globalization;
|
||||
using System.Linq;
|
||||
using System.Xml.Linq;
|
||||
using System.Numerics;
|
||||
|
||||
namespace SpotifyHonorific;
|
||||
|
||||
@@ -70,6 +76,87 @@ public sealed class Plugin : IDalamudPlugin
|
||||
Config.Save();
|
||||
Updater.Stop();
|
||||
}
|
||||
else if (subcommand == "set")
|
||||
{
|
||||
var splitArgs = args.Trim().Split(' ', 2, StringSplitOptions.TrimEntries | StringSplitOptions.RemoveEmptyEntries);
|
||||
if (splitArgs.Length != 2)
|
||||
{
|
||||
return;
|
||||
}
|
||||
var setArgs = splitArgs[1].Split('|', StringSplitOptions.TrimEntries | StringSplitOptions.RemoveEmptyEntries);
|
||||
bool? prefix = null;
|
||||
Vector3? color = null;
|
||||
Vector3? glow = null;
|
||||
|
||||
foreach (var a in setArgs)
|
||||
{
|
||||
|
||||
var arg = a.ToLower();
|
||||
|
||||
var colorArg = arg.Skip(arg.StartsWith('#') ? 1 : 0).ToArray();
|
||||
|
||||
if (colorArg.Length == 6 && colorArg.All(chr => chr is >= '0' and <= '9' or >= 'a' and <= 'f'))
|
||||
{
|
||||
|
||||
if (color != null && glow != null)
|
||||
{
|
||||
ChatGui.PrintError($"Duplicate Option in Set: '{a}'", "SpotifyHonorific");
|
||||
return;
|
||||
}
|
||||
|
||||
var rHex = string.Join(null, colorArg.Skip(0).Take(2));
|
||||
var gHex = string.Join(null, colorArg.Skip(2).Take(2));
|
||||
var bHex = string.Join(null, colorArg.Skip(4).Take(2));
|
||||
|
||||
|
||||
if (byte.TryParse(rHex, NumberStyles.HexNumber, NumberFormatInfo.InvariantInfo, out var r) &&
|
||||
byte.TryParse(gHex, NumberStyles.HexNumber, NumberFormatInfo.InvariantInfo, out var g) &&
|
||||
byte.TryParse(bHex, NumberStyles.HexNumber, NumberFormatInfo.InvariantInfo, out var b))
|
||||
{
|
||||
|
||||
var c = new Vector3(r / 255f, g / 255f, b / 255f);
|
||||
if (color == null)
|
||||
{
|
||||
color = c;
|
||||
continue;
|
||||
}
|
||||
|
||||
glow = c;
|
||||
continue;
|
||||
}
|
||||
}
|
||||
|
||||
if (arg is "p" or "prefix" or "pre")
|
||||
{
|
||||
if (prefix != null)
|
||||
{
|
||||
ChatGui.PrintError($"Duplicate Option in Set: '{a}'", "SpotifyHonorific");
|
||||
return;
|
||||
}
|
||||
|
||||
prefix = true;
|
||||
continue;
|
||||
}
|
||||
|
||||
if (arg is "s" or "suffix")
|
||||
{
|
||||
if (prefix != null)
|
||||
{
|
||||
ChatGui.PrintError($"Duplicate Option in Set: '{a}'", "SpotifyHonorific");
|
||||
return;
|
||||
}
|
||||
prefix = false;
|
||||
continue;
|
||||
}
|
||||
ChatGui.PrintError($"Invalid Option in Set: '{a}'", "SpotifyHonorific");
|
||||
return;
|
||||
}
|
||||
|
||||
Config.ActivityConfigs.First().Color = color;
|
||||
Config.ActivityConfigs.First().Glow = glow;
|
||||
Config.ActivityConfigs.First().IsPrefix = prefix ?? false;
|
||||
ChatGui.Print("Updated Title", "SpotifyHonorific");
|
||||
}
|
||||
else
|
||||
{
|
||||
ChatGui.Print(CommandHelpMessage);
|
||||
|
||||
Reference in New Issue
Block a user