forked from aly/qstbak
qstcompanion v1.0.5
This commit is contained in:
parent
52daefcfd7
commit
5e1e1decc5
9 changed files with 304 additions and 200 deletions
|
|
@ -1,6 +1,7 @@
|
|||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
using System.Text.RegularExpressions;
|
||||
using Dalamud.Plugin.Services;
|
||||
using Newtonsoft.Json.Linq;
|
||||
|
|
@ -228,7 +229,32 @@ public class SubmarineManager : IDisposable
|
|||
try
|
||||
{
|
||||
JObject json = JObject.Parse(jsonContent);
|
||||
FindReturnTimes(json, returnTimes);
|
||||
HashSet<string> enabledSubs = new HashSet<string>(StringComparer.OrdinalIgnoreCase);
|
||||
if (json.SelectTokens("$..EnabledSubs").FirstOrDefault() is JArray enabledSubsArray)
|
||||
{
|
||||
foreach (JToken item in enabledSubsArray)
|
||||
{
|
||||
string subName = item.Value<string>();
|
||||
if (!string.IsNullOrEmpty(subName))
|
||||
{
|
||||
enabledSubs.Add(subName);
|
||||
}
|
||||
}
|
||||
if (enabledSubs.Count > 0)
|
||||
{
|
||||
log.Information($"[SubmarineManager] Found {enabledSubs.Count} enabled submarines: {string.Join(", ", enabledSubs)}");
|
||||
}
|
||||
else
|
||||
{
|
||||
log.Information("[SubmarineManager] EnabledSubs array found but empty - NO submarines will be checked");
|
||||
}
|
||||
FindReturnTimes(json, returnTimes, enabledSubs);
|
||||
}
|
||||
else
|
||||
{
|
||||
log.Information("[SubmarineManager] No EnabledSubs found in config - checking all submarines");
|
||||
FindReturnTimes(json, returnTimes);
|
||||
}
|
||||
}
|
||||
catch
|
||||
{
|
||||
|
|
@ -244,21 +270,27 @@ public class SubmarineManager : IDisposable
|
|||
return returnTimes;
|
||||
}
|
||||
|
||||
private void FindReturnTimes(JToken token, List<long> returnTimes)
|
||||
private void FindReturnTimes(JToken token, List<long> returnTimes, HashSet<string>? enabledSubs = null)
|
||||
{
|
||||
if (token is JObject obj)
|
||||
{
|
||||
if (obj.TryGetValue("Name", out JToken nameToken) && obj.TryGetValue("ReturnTime", out JToken returnTimeToken))
|
||||
{
|
||||
string submarineName = nameToken.Value<string>();
|
||||
if ((enabledSubs == null || (submarineName != null && enabledSubs.Contains(submarineName))) && returnTimeToken.Type == JTokenType.Integer)
|
||||
{
|
||||
long returnTime = returnTimeToken.Value<long>();
|
||||
returnTimes.Add(returnTime);
|
||||
if (enabledSubs != null)
|
||||
{
|
||||
log.Debug($"[SubmarineManager] Including submarine '{submarineName}' (ReturnTime: {returnTime})");
|
||||
}
|
||||
}
|
||||
}
|
||||
{
|
||||
foreach (JProperty property in obj.Properties())
|
||||
{
|
||||
if (property.Name == "ReturnTime" && property.Value.Type == JTokenType.Integer)
|
||||
{
|
||||
returnTimes.Add(property.Value.Value<long>());
|
||||
}
|
||||
else
|
||||
{
|
||||
FindReturnTimes(property.Value, returnTimes);
|
||||
}
|
||||
FindReturnTimes(property.Value, returnTimes, enabledSubs);
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
|
@ -269,7 +301,7 @@ public class SubmarineManager : IDisposable
|
|||
}
|
||||
foreach (JToken item in array)
|
||||
{
|
||||
FindReturnTimes(item, returnTimes);
|
||||
FindReturnTimes(item, returnTimes, enabledSubs);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue