Skip to content
This repository has been archived by the owner on May 28, 2023. It is now read-only.

Commit

Permalink
Added capability to place a preset by name from the command line (issue
Browse files Browse the repository at this point in the history
#13).
  • Loading branch information
PunishedPineapple committed Sep 9, 2021
1 parent 023b835 commit 604affe
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 7 deletions.
26 changes: 22 additions & 4 deletions WaymarkPresetPlugin/Plugin.cs
Original file line number Diff line number Diff line change
Expand Up @@ -159,7 +159,7 @@ protected string ProcessTextCommand_Help( string args )
}
else if( mConfiguration.AllowDirectPlacePreset && args.ToLower() == "place" )
{
return "Places the preset at the specified library index (if possible). Usage \"/pwaymark place <index>\". Index can be any valid libary preset number.";
return "Places the preset with the specified name (if possible). Quotes MUST be used around the name. May also specify preset index without quotes instead. Usage \"/pwaymark place \"<name>\"|<index>\". Name must match exactly (besides case). Index can be any valid libary preset number.";
}
else if( args.ToLower() == "import" )
{
Expand Down Expand Up @@ -215,9 +215,27 @@ protected string ProcessTextCommand_Place( string args )
{
if( mConfiguration.AllowDirectPlacePreset )
{
// The index we will want to try to place once we find it.
int libraryIndex = -1;
bool validIndex = int.TryParse( args.Trim(), out libraryIndex ) && libraryIndex >= 0 && libraryIndex < mConfiguration.PresetLibrary.Presets.Count;
if( validIndex )

// If argument is in quotes, search for the preset by name.
if( args.Trim().First() == '"' && args.Trim().Last() == '"' )
{
string presetName = args.Trim().Substring( 1, args.Trim().Length - 2 );
libraryIndex = mConfiguration.PresetLibrary.Presets.FindIndex( ( WaymarkPreset p ) => { return p.Name.Equals( presetName, StringComparison.OrdinalIgnoreCase ); } );
if( libraryIndex < 0 || libraryIndex >= mConfiguration.PresetLibrary.Presets.Count )
{
return $"Unable to find preset \"{presetName}\".";
}
}
// Otherwise, search by index.
else if( !int.TryParse( args.Trim(), out libraryIndex ) )
{
return $"Invalid preset number \"{args}\".";
}

// Try to do the actual placement.
if( libraryIndex >= 0 && libraryIndex < mConfiguration.PresetLibrary.Presets.Count )
{
try
{
Expand All @@ -232,7 +250,7 @@ protected string ProcessTextCommand_Place( string args )
}
else
{
return $"Invalid preset number \"{libraryIndex}\"";
return $"Invalid preset number \"{libraryIndex}\".";
}
}
else
Expand Down
2 changes: 1 addition & 1 deletion WaymarkPresetPlugin/WaymarkPresetPlugin.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
<PropertyGroup>
<TargetFramework>net5.0-windows</TargetFramework>
<Platforms>AnyCPU</Platforms>
<Version>1.3.0.0</Version>
<Version>1.3.1.0</Version>
<Authors>PunishedPineapple</Authors>
<Product />
<Copyright>Copyright © PunishedPineapple 2020-2021</Copyright>
Expand Down
4 changes: 2 additions & 2 deletions WaymarkPresetPlugin/WaymarkPresetPlugin.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
"Punchline": "Improved Waymark Management",
"Description": "Allows you to save, edit, place, import, export, and preview an unlimited number of waymark presets.",
"InternalName": "WaymarkPresetPlugin",
"AssemblyVersion": "1.3.0.0",
"AssemblyVersion": "1.3.1.0",
"RepoUrl": "https://github.com/PunishedPineapple/WaymarkPresetPlugin",
"IconUrl": "https://github.com/PunishedPineapple/WaymarkPresetPlugin/raw/master/docs/Images/icon.png",
"ImageUrls": [
Expand All @@ -15,5 +15,5 @@
"ApplicableVersion": "any",
"Tags": [ "Waymark", "Marker", "Preset", "Tool" ],
"DalamudApiLevel": 4,
"Changelog": "1.3.0.0: Updated for Dalamud API 4."
"Changelog": "1.3.1.0: Added preset placement by name to the text commands."
}

0 comments on commit 604affe

Please sign in to comment.