10
10
using CustomizePlus . Game . Services ;
11
11
using CustomizePlus . UI . Windows . MainWindow . Tabs . Templates ;
12
12
using CustomizePlus . UI . Windows . MainWindow ;
13
+ using static System . Windows . Forms . AxHost ;
14
+ using CustomizePlus . Profiles . Data ;
13
15
14
16
namespace CustomizePlus . Core . Services ;
15
17
@@ -76,11 +78,8 @@ private void OnMainCommand(string command, string arguments)
76
78
{
77
79
switch ( argumentList [ 0 ] . ToLowerInvariant ( ) )
78
80
{
79
- case "apply" :
80
- Apply ( argument ) ;
81
- return ;
82
- case "toggle" :
83
- Apply ( argument , true ) ;
81
+ case "profile" :
82
+ ProfileCommand ( argument ) ;
84
83
return ;
85
84
default :
86
85
case "help" :
@@ -100,83 +99,136 @@ private bool PrintHelp(string argument)
100
99
else
101
100
_chatService . PrintInChat ( new SeStringBuilder ( ) . AddText ( "Valid arguments for /customize are:" ) . BuiltString ) ;
102
101
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." )
104
103
. BuiltString ) ;
105
- _chatService . PrintInChat ( new SeStringBuilder ( ) . AddCommand ( "toggle" , "Toggles a given profile for a given character. Use without arguments for help." )
106
- . BuiltString ) ;
107
104
return true ;
108
105
}
109
106
110
- private void Apply ( string argument , bool toggle = false )
107
+ private void ProfileCommand ( string argument )
111
108
{
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 ) )
114
118
{
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 )
116
123
. AddText ( "," )
117
- . AddRed ( "Profile Name" , true )
124
+ . AddYellow ( "Profile Name" , true )
118
125
. 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 ) ;
119
128
_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 ) ;
121
130
_chatService . PrintInChat ( new SeStringBuilder ( ) . AddText ( " 》 To apply to yourself: " ) . AddBlue ( "<me>" ) . AddText ( ", " ) . AddBlue ( "self" ) . BuiltString ) ;
122
131
_chatService . PrintInChat ( new SeStringBuilder ( ) . AddText ( " 》 To apply to target: " ) . AddBlue ( "<t>" ) . AddText ( ", " ) . AddBlue ( "target" ) . BuiltString ) ;
123
132
return ;
124
133
}
125
134
126
- string charaName = "" , profName = "" ;
135
+ string characterName = "" , profileName = "" ;
127
136
128
137
try
129
138
{
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 ;
131
166
132
- charaName = charaName switch
167
+ characterName = subArgumentList [ 0 ] . Trim ( ) ;
168
+ characterName = characterName switch
133
169
{
134
170
"<me>" => _gameObjectService . GetCurrentPlayerName ( ) ?? string . Empty ,
135
171
"self" => _gameObjectService . GetCurrentPlayerName ( ) ?? string . Empty ,
136
172
"<t>" => _gameObjectService . GetCurrentPlayerTargetName ( ) ?? string . Empty ,
137
173
"target" => _gameObjectService . GetCurrentPlayerTargetName ( ) ?? string . Empty ,
138
- _ => charaName ,
174
+ _ => characterName ,
139
175
} ;
140
176
141
- if ( ! _profileManager . Profiles . Any ( ) )
177
+ if ( ! isTurningOffAllProfiles )
142
178
{
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 ) ;
146
181
}
182
+ else
183
+ targetProfile = _profileManager . Profiles . FirstOrDefault ( x => x . CharacterName == characterName && x . Enabled ) ;
147
184
148
- if ( _profileManager . Profiles . Count ( x => x . Name == profName && x . CharacterName == charaName ) > 1 )
185
+ if ( targetProfile == null )
149
186
{
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 ;
152
194
}
153
195
154
- var outProf = _profileManager . Profiles . FirstOrDefault ( x => x . Name == profName && x . CharacterName == charaName ) ;
155
-
156
- if ( outProf == null )
196
+ if ( state != null )
157
197
{
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
+ }
164
209
165
- if ( ! toggle )
166
- _profileManager . SetEnabled ( outProf , true ) ;
210
+ _profileManager . SetEnabled ( targetProfile , ( bool ) state ) ;
211
+ }
167
212
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 ) ;
172
222
}
173
223
catch ( Exception e )
174
224
{
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 } \n Error: { e } ") ;
180
232
}
181
233
}
182
234
}
0 commit comments