Skip to content

Commit

Permalink
Fix occasional text doubling in cactbot popups (alarms, alerts, info)
Browse files Browse the repository at this point in the history
  • Loading branch information
joshua-software-dev committed Aug 9, 2023
1 parent 025a235 commit 5ed92b9
Show file tree
Hide file tree
Showing 4 changed files with 42 additions and 10 deletions.
35 changes: 32 additions & 3 deletions LMeter/src/Cactbot/CactbotState.cs
Original file line number Diff line number Diff line change
@@ -1,8 +1,11 @@
using AngleSharp.Dom;
using AngleSharp.Html.Dom;
using Dalamud.Game.Text;
using System;
using System.Collections.Concurrent;
using System.Collections.Generic;
using System.Collections.Specialized;
using System.Text;


namespace LMeter.Cactbot;
Expand Down Expand Up @@ -109,6 +112,32 @@ private void UpdateTimeline(IHtmlDocument html)
}
}

private string GetHolderTextContent(IElement? holder)
{
if (holder == null || holder.ChildElementCount < 1) return string.Empty;
if (holder.ChildElementCount > 1)
{
var set = new OrderedDictionary();
foreach (var child in holder.Children)
{
set[child.TextContent.Trim()] = string.Empty;
}

var sb = new StringBuilder();
var i = 0;
foreach (var result in set)
{
if (i > 0) sb.Append('\n');
sb.Append(((System.Collections.DictionaryEntry) result).Key);
i += 1;
}

return sb.ToString();
}

return holder.TextContent.Trim();
}

public void UpdateState(IHtmlDocument? html)
{
if (html == null)
Expand All @@ -130,7 +159,7 @@ public void UpdateState(IHtmlDocument? html)
var info = infoContainer?.GetElementsByClassName("holder")?[0];

var alarmWasEmpty = string.IsNullOrEmpty(Alarm);
Alarm = alarm?.TextContent.Trim();
Alarm = GetHolderTextContent(alarm);
if (alarmWasEmpty && !string.IsNullOrEmpty(Alarm))
{
AlarmStateChanged?.Invoke(this, EventArgs.Empty);
Expand All @@ -141,7 +170,7 @@ public void UpdateState(IHtmlDocument? html)
}

var alertWasEmpty = string.IsNullOrEmpty(Alert);
Alert = alert?.TextContent.Trim();
Alert = GetHolderTextContent(alert);
if (alertWasEmpty && !string.IsNullOrEmpty(Alert))
{
AlertStateChanged?.Invoke(this, EventArgs.Empty);
Expand All @@ -152,7 +181,7 @@ public void UpdateState(IHtmlDocument? html)
}

var infoWasEmpty = string.IsNullOrEmpty(Info);
Info = info?.TextContent.Trim();
Info = GetHolderTextContent(info);
if (infoWasEmpty && !string.IsNullOrEmpty(Info))
{
InfoStateChanged?.Invoke(this, EventArgs.Empty);
Expand Down
2 changes: 1 addition & 1 deletion Version/Version.csproj
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<Project>
<PropertyGroup>
<PluginVersion>0.2.0.18</PluginVersion>
<PluginVersion>0.2.0.19</PluginVersion>
</PropertyGroup>
</Project>
3 changes: 3 additions & 0 deletions deps/txt/changelog.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
# Version 0.2.0.19
- Fix occasional text doubling in cactbot popups (alarms, alerts, info)

# Version 0.2.0.18
- Add option to write all responses from background web browser to log file for
debugging purposes.
Expand Down
12 changes: 6 additions & 6 deletions repo.json
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,8 @@
"Name": "LMeter",
"Description": "Plugin to display ACT combat log data. Now with Cactbot integration!",
"InternalName": "LMeter",
"AssemblyVersion": "0.2.0.18",
"TestingAssemblyVersion": "0.2.0.18",
"AssemblyVersion": "0.2.0.19",
"TestingAssemblyVersion": "0.2.0.19",
"RepoUrl": "https://github.com/joshua-software-dev/LMeter",
"ApplicableVersion": "any",
"DalamudApiLevel": 8,
Expand All @@ -35,10 +35,10 @@
"DownloadCount": 0,
"LastUpdate": 0,
"LoadPriority": 69420,
"DownloadLinkInstall": "https://github.com/joshua-software-dev/LMeter/releases/download/v0.2.0.18/latest.zip",
"DownloadLinkTesting": "https://github.com/joshua-software-dev/LMeter/releases/download/v0.2.0.18/latest.zip",
"DownloadLinkUpdate": "https://github.com/joshua-software-dev/LMeter/releases/download/v0.2.0.18/latest.zip",
"DownloadLinkInstall": "https://github.com/joshua-software-dev/LMeter/releases/download/v0.2.0.19/latest.zip",
"DownloadLinkTesting": "https://github.com/joshua-software-dev/LMeter/releases/download/v0.2.0.19/latest.zip",
"DownloadLinkUpdate": "https://github.com/joshua-software-dev/LMeter/releases/download/v0.2.0.19/latest.zip",
"IconUrl": "https://raw.githubusercontent.com/joshua-software-dev/LMeter/master/deps/img/icon.png",
"Changelog": "# Version 0.2.0.18\n- Add option to write all responses from background web browser to log file for\n debugging purposes."
"Changelog": "# Version 0.2.0.19\n- Fix occasional text doubling in cactbot popups (alarms, alerts, info)"
}
]

0 comments on commit 5ed92b9

Please sign in to comment.