Skip to content

Commit 18defd3

Browse files
committed
Changed commands
1 parent 5faa21c commit 18defd3

File tree

2 files changed

+97
-46
lines changed

2 files changed

+97
-46
lines changed

CustomizePlus/Core/Services/CommandService.cs

Lines changed: 97 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,8 @@
1010
using CustomizePlus.Game.Services;
1111
using CustomizePlus.UI.Windows.MainWindow.Tabs.Templates;
1212
using CustomizePlus.UI.Windows.MainWindow;
13+
using static System.Windows.Forms.AxHost;
14+
using CustomizePlus.Profiles.Data;
1315

1416
namespace CustomizePlus.Core.Services;
1517

@@ -76,11 +78,8 @@ private void OnMainCommand(string command, string arguments)
7678
{
7779
switch (argumentList[0].ToLowerInvariant())
7880
{
79-
case "apply":
80-
Apply(argument);
81-
return;
82-
case "toggle":
83-
Apply(argument, true);
81+
case "profile":
82+
ProfileCommand(argument);
8483
return;
8584
default:
8685
case "help":
@@ -100,83 +99,136 @@ private bool PrintHelp(string argument)
10099
else
101100
_chatService.PrintInChat(new SeStringBuilder().AddText("Valid arguments for /customize are:").BuiltString);
102101

103-
_chatService.PrintInChat(new SeStringBuilder().AddCommand("apply", "Applies a given profile for a given character. Use without arguments for help.")
102+
_chatService.PrintInChat(new SeStringBuilder().AddCommand("profile", "Change the state of profiles. Use without arguments for help.")
104103
.BuiltString);
105-
_chatService.PrintInChat(new SeStringBuilder().AddCommand("toggle", "Toggles a given profile for a given character. Use without arguments for help.")
106-
.BuiltString);
107104
return true;
108105
}
109106

110-
private void Apply(string argument, bool toggle = false)
107+
private void ProfileCommand(string argument)
111108
{
112-
var argumentList = argument.Split(',', 2, StringSplitOptions.RemoveEmptyEntries | StringSplitOptions.TrimEntries);
113-
if (argumentList.Length != 2)
109+
var argumentList = argument.Split(' ', 2, StringSplitOptions.RemoveEmptyEntries | StringSplitOptions.TrimEntries);
110+
string[]? subArgumentList = null;
111+
112+
if(argumentList.Length == 2)
113+
subArgumentList = argumentList[1].Split(',', 2, StringSplitOptions.RemoveEmptyEntries | StringSplitOptions.TrimEntries);
114+
115+
bool isTurningOffAllProfiles = subArgumentList != null && subArgumentList.Length != 2 && argumentList[0] == "disable";
116+
117+
if (argumentList.Length != 2 || subArgumentList == null || (subArgumentList.Length != 2 && !isTurningOffAllProfiles))
114118
{
115-
_chatService.PrintInChat(new SeStringBuilder().AddText($"Usage: /customize {(toggle ? "toggle" : "apply")} ").AddBlue("Character Name", true)
119+
_chatService.PrintInChat(new SeStringBuilder().AddText($"Usage: /customize profile ")
120+
.AddBlue("enable, disable or toggle", true)
121+
.AddText(" ")
122+
.AddRed("Character Name", true)
116123
.AddText(",")
117-
.AddRed("Profile Name", true)
124+
.AddYellow("Profile Name", true)
118125
.BuiltString);
126+
_chatService.PrintInChat(new SeStringBuilder().AddText(" 》 ").AddBlue("disable", true)
127+
.AddText(" option can also be used without supplying profile name to turn off currently active profile for the character").BuiltString);
119128
_chatService.PrintInChat(new SeStringBuilder().AddText(" 》 ")
120-
.AddBlue("Character Name", true).AddText("can be either full character name or one of the following:").BuiltString);
129+
.AddRed("Character Name", true).AddText(" can be either full character name or one of the following:").BuiltString);
121130
_chatService.PrintInChat(new SeStringBuilder().AddText(" 》 To apply to yourself: ").AddBlue("<me>").AddText(", ").AddBlue("self").BuiltString);
122131
_chatService.PrintInChat(new SeStringBuilder().AddText(" 》 To apply to target: ").AddBlue("<t>").AddText(", ").AddBlue("target").BuiltString);
123132
return;
124133
}
125134

126-
string charaName = "", profName = "";
135+
string characterName = "", profileName = "";
127136

128137
try
129138
{
130-
(charaName, profName) = argumentList switch { var a => (a[0].Trim(), a[1].Trim()) };
139+
if (!_profileManager.Profiles.Any())
140+
{
141+
_chatService.PrintInChat(new SeStringBuilder().AddText("This command cannot be executed because no profiles exist").BuiltString);
142+
return;
143+
}
144+
145+
bool? state = null;
146+
switch (argumentList[0].ToLowerInvariant())
147+
{
148+
case "enabled":
149+
case "enable":
150+
case "on":
151+
case "true":
152+
state = true;
153+
break;
154+
case "disabled":
155+
case "disable":
156+
case "off":
157+
case "false":
158+
state = false;
159+
break;
160+
case "toggle":
161+
case "switch":
162+
break;
163+
}
164+
165+
Profile? targetProfile = null;
131166

132-
charaName = charaName switch
167+
characterName = subArgumentList[0].Trim();
168+
characterName = characterName switch
133169
{
134170
"<me>" => _gameObjectService.GetCurrentPlayerName() ?? string.Empty,
135171
"self" => _gameObjectService.GetCurrentPlayerName() ?? string.Empty,
136172
"<t>" => _gameObjectService.GetCurrentPlayerTargetName() ?? string.Empty,
137173
"target" => _gameObjectService.GetCurrentPlayerTargetName() ?? string.Empty,
138-
_ => charaName,
174+
_ => characterName,
139175
};
140176

141-
if (!_profileManager.Profiles.Any())
177+
if (!isTurningOffAllProfiles)
142178
{
143-
_chatService.PrintInChat(
144-
$"Can't {(toggle ? "toggle" : "apply")} profile \"{profName}\" for character \"{charaName}\" because no profiles exist", ChatService.ChatMessageColor.Error);
145-
return;
179+
profileName = subArgumentList[1].Trim();
180+
targetProfile = _profileManager.Profiles.FirstOrDefault(x => x.Name == profileName && x.CharacterName == characterName);
146181
}
182+
else
183+
targetProfile = _profileManager.Profiles.FirstOrDefault(x => x.CharacterName == characterName && x.Enabled);
147184

148-
if (_profileManager.Profiles.Count(x => x.Name == profName && x.CharacterName == charaName) > 1)
185+
if (targetProfile == null)
149186
{
150-
_logger.Warning(
151-
$"Found more than one profile matching profile \"{profName}\" and character \"{charaName}\". Using first match.");
187+
_chatService.PrintInChat(new SeStringBuilder()
188+
.AddText("Cannot execute command because profile ")
189+
.AddYellow(string.IsNullOrWhiteSpace(profileName) ? "[Any enabled profile]" : profileName)
190+
.AddText(" for ")
191+
.AddRed(characterName)
192+
.AddText(" was not found").BuiltString);
193+
return;
152194
}
153195

154-
var outProf = _profileManager.Profiles.FirstOrDefault(x => x.Name == profName && x.CharacterName == charaName);
155-
156-
if (outProf == null)
196+
if (state != null)
157197
{
158-
_chatService.PrintInChat(
159-
$"Can't {(toggle ? "toggle" : "apply")} profile \"{(string.IsNullOrWhiteSpace(profName) ? "empty (none provided)" : profName)}\" " +
160-
$"for Character \"{(string.IsNullOrWhiteSpace(charaName) ? "empty (none provided)" : charaName)}\"\n" +
161-
"Check if the profile and character names were provided correctly and said profile exists for chosen character", ChatService.ChatMessageColor.Error);
162-
return;
163-
}
198+
if(targetProfile.Enabled == state)
199+
{
200+
_chatService.PrintInChat(new SeStringBuilder()
201+
.AddText("Profile ")
202+
.AddYellow(targetProfile.Name)
203+
.AddText(" for ")
204+
.AddBlue(characterName)
205+
.AddText(" is already ")
206+
.AddGreen((bool)state ? "enabled" : "disabled").BuiltString);
207+
return;
208+
}
164209

165-
if (!toggle)
166-
_profileManager.SetEnabled(outProf, true);
210+
_profileManager.SetEnabled(targetProfile, (bool)state);
211+
}
167212
else
168-
_profileManager.SetEnabled(outProf, !outProf.Enabled);
169-
170-
_chatService.PrintInChat(
171-
$"{outProf.Name} was successfully {(toggle ? "toggled" : "applied")} for {outProf.CharacterName}", ChatService.ChatMessageColor.Info);
213+
_profileManager.SetEnabled(targetProfile, !targetProfile.Enabled);
214+
215+
_chatService.PrintInChat(new SeStringBuilder()
216+
.AddText("Profile ")
217+
.AddYellow(targetProfile.Name)
218+
.AddText(" was successfully ")
219+
.AddBlue(state != null ? ((bool)state ? "enabled" : "disabled") : "toggled")
220+
.AddText(" for ")
221+
.AddRed(targetProfile.CharacterName).BuiltString);
172222
}
173223
catch (Exception e)
174224
{
175-
_chatService.PrintInChat($"Error while {(toggle ? "toggling" : "applying")} profile, details are available in dalamud log", ChatService.ChatMessageColor.Error);
176-
_logger.Error($"Error {(toggle ? "toggling" : "applying")} profile by command: \n" +
177-
$"Profile name \"{(string.IsNullOrWhiteSpace(profName) ? "empty (none provided)" : profName)}\"\n" +
178-
$"Character name \"{(string.IsNullOrWhiteSpace(charaName) ? "empty (none provided)" : charaName)}\"\n" +
179-
$"Error: {e}");
225+
_chatService.PrintInChat(new SeStringBuilder()
226+
.AddRed($"Error while changing state of profile, details are available in dalamud log").BuiltString);
227+
228+
_logger.Error($"Error while changing state of profile by command:\n" +
229+
$"Profile name \"{(string.IsNullOrWhiteSpace(profileName) ? "empty (none provided)" : profileName)}\"\n" +
230+
$"Character name \"{(string.IsNullOrWhiteSpace(characterName) ? "empty (none provided)" : characterName)}\"\n" +
231+
$"Arguments: {argument}\nError: {e}");
180232
}
181233
}
182234
}

CustomizePlus/UI/Windows/CPlusChangeLog.cs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,6 @@ private static void Add2_0_0_0(Changelog log)
4646
.RegisterEntry("All bone edits are now stored in templates which can be used by multiple profiles and single profile can reference unlimited number of templates.", 2)
4747

4848
.RegisterImportant("Chat commands have been changed, refer to \"/customize help\" for information about available commands.", 1)
49-
.RegisterEntry("Added \"toggle\" chat command which can be used to toggle given profile on a given character.", 2)
5049

5150
.RegisterEntry("Profiles can be applied to summons, mounts and pets without any limitations.", 1)
5251
.RegisterImportant("Root scaling of mounts is not available for now.", 2)

0 commit comments

Comments
 (0)