Skip to content

Commit

Permalink
config commands and fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
Jaksuhn committed Apr 10, 2024
1 parent b68d580 commit 1781965
Show file tree
Hide file tree
Showing 5 changed files with 60 additions and 10 deletions.
8 changes: 8 additions & 0 deletions SomethingNeedDoing/Interface/HelpWindow.cs
Original file line number Diff line number Diff line change
Expand Up @@ -328,6 +328,14 @@ static void DisplayChangelog(string date, string changes, bool separator = true)

ImGui.PushFont(UiBuilder.MonoFont);

DisplayChangelog(
"2024-04-10",
"- Fixed GetPassageLocation() return type\n" +
"- Changed TeleportToGCTown() to use tickets optionally\n" +
"- Added the cfg argument to the main plugin command\n" +
"- Added SetSNDProperty()\n" +
"- Added GetSNDProperty()\n");

DisplayChangelog(
"2024-04-08",
"- Added GetObjectDataID()\n" +
Expand Down
23 changes: 13 additions & 10 deletions SomethingNeedDoing/Misc/Commands/ActionCommands.cs
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ public List<string> ListAllFunctions()

public void LeaveDuty() => this.abandonDuty(false);

public unsafe void TeleportToGCTown()
public unsafe void TeleportToGCTown(bool useTickets = false)
{
var gc = UIState.Instance()->PlayerState.GrandCompany;
var aetheryte = gc switch
Expand All @@ -42,16 +42,19 @@ public unsafe void TeleportToGCTown()
3 => 9u,
_ => 0u
};
var ticket = gc switch
if (useTickets)
{
0 => 0u,
1 => 21069u,
2 => 21070u,
3 => 21071u,
_ => 0u
};
if (InventoryManager.Instance()->GetInventoryItemCount(ticket) > 0)
AgentInventoryContext.Instance()->UseItem(ticket);
var ticket = gc switch
{
0 => 0u,
1 => 21069u,
2 => 21070u,
3 => 21071u,
_ => 0u
};
if (InventoryManager.Instance()->GetInventoryItemCount(ticket) > 0)
AgentInventoryContext.Instance()->UseItem(ticket);
}
else
Telepo.Instance()->Teleport(aetheryte, 0);
}
Expand Down
3 changes: 3 additions & 0 deletions SomethingNeedDoing/Misc/Commands/InternalCommands.cs
Original file line number Diff line number Diff line change
Expand Up @@ -19,4 +19,7 @@ public class InternalCommands
.Select(line => $" {line}")
.Join('\n');
}

public void SetSNDProperty(string key, string value) => Service.Configuration.SetProperty(key, value);
public object GetSNDProperty(string key) => Service.Configuration.GetProperty(key);
}
26 changes: 26 additions & 0 deletions SomethingNeedDoing/SomethingNeedDoingConfiguration.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
using Dalamud.Configuration;
using Dalamud.Game.Text;
using ECommons.DalamudServices;
using Newtonsoft.Json;
using System.Collections.Generic;
using System.IO;
Expand Down Expand Up @@ -202,4 +203,29 @@ internal bool TryFindParent(INode node, out FolderNode? parent)
parent = null;
return false;
}

internal void SetProperty(string key, string value)
{
var property = typeof(SomethingNeedDoingConfiguration).GetProperty(key);
if (property != null && property.Name != "Version" && property.CanWrite && (property.PropertyType == typeof(int) || property.PropertyType == typeof(bool)))
{
if (property.PropertyType == typeof(int) && int.TryParse(value, out int intValue))
property.SetValue(this, intValue);
else if (property.PropertyType == typeof(bool) && bool.TryParse(value, out bool boolValue))
property.SetValue(this, boolValue);
else
Svc.Log.Error($"Value type does not match property type for {key}: {value.GetType()} != {property.PropertyType}");
}
else
Svc.Log.Error($"Invalid configuration key or type");
}

internal object GetProperty(string key)
{
var property = typeof(SomethingNeedDoingConfiguration).GetProperty(key);
if (property != null && property.Name != "Version" && property.CanWrite)
return property.GetValue(this)!;
else
return null;
}
}
10 changes: 10 additions & 0 deletions SomethingNeedDoing/SomethingNeedDoingPlugin.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,15 @@
using Dalamud.Interface.Windowing;
using Dalamud.Plugin;
using ECommons;
using ECommons.DalamudServices;
using SomethingNeedDoing.Interface;
using SomethingNeedDoing.Managers;
using SomethingNeedDoing.Misc.Commands;
using System;
using System.Collections.Generic;
using System.Configuration;
using System.Linq;
using System.Windows.Forms;

namespace SomethingNeedDoing;

Expand Down Expand Up @@ -223,5 +227,11 @@ private void OnChatCommand(string command, string arguments)
this.OpenHelpWindow();
return;
}
else if (arguments.StartsWith("cfg"))
{
var args = arguments[4..].Trim().Split(" ");
Service.Configuration.SetProperty(args[0], args[1]);
return;
}
}
}

0 comments on commit 1781965

Please sign in to comment.