Code cleanup bits

This commit is contained in:
Liza 2023-02-11 21:10:45 +01:00
parent 12de110b04
commit 2bfcfee753
22 changed files with 120 additions and 103 deletions

View File

@ -38,15 +38,15 @@ namespace Pal.Client
public List<ImportHistoryEntry> ImportHistory { get; set; } = new(); public List<ImportHistoryEntry> ImportHistory { get; set; } = new();
public bool ShowTraps { get; set; } = true; public bool ShowTraps { get; set; } = true;
public Vector4 TrapColor { get; set; } = new Vector4(1, 0, 0, 0.4f); public Vector4 TrapColor { get; set; } = new(1, 0, 0, 0.4f);
public bool OnlyVisibleTrapsAfterPomander { get; set; } = true; public bool OnlyVisibleTrapsAfterPomander { get; set; } = true;
public bool ShowHoard { get; set; } = true; public bool ShowHoard { get; set; } = true;
public Vector4 HoardColor { get; set; } = new Vector4(0, 1, 1, 0.4f); public Vector4 HoardColor { get; set; } = new(0, 1, 1, 0.4f);
public bool OnlyVisibleHoardAfterPomander { get; set; } = true; public bool OnlyVisibleHoardAfterPomander { get; set; } = true;
public bool ShowSilverCoffers { get; set; } = false; public bool ShowSilverCoffers { get; set; }
public Vector4 SilverCofferColor { get; set; } = new Vector4(1, 1, 1, 0.4f); public Vector4 SilverCofferColor { get; set; } = new(1, 1, 1, 0.4f);
public bool FillSilverCoffers { get; set; } = true; public bool FillSilverCoffers { get; set; } = true;
/// <summary> /// <summary>
@ -120,7 +120,7 @@ namespace Pal.Client
// Only notify offline users - we can just re-download the backup markers from the server seamlessly. // Only notify offline users - we can just re-download the backup markers from the server seamlessly.
if (Mode == EMode.Offline && changedAnyFile) if (Mode == EMode.Offline && changedAnyFile)
{ {
new TickScheduler(delegate _ = new TickScheduler(delegate
{ {
Service.Chat.PalError("Due to a bug, some coffers were accidentally saved as traps. To fix the related display issue, locally cached data was cleaned up."); Service.Chat.PalError("Due to a bug, some coffers were accidentally saved as traps. To fix the related display issue, locally cached data was cleaned up.");
Service.Chat.PrintError($"If you have any backup tools installed, please restore the contents of '{Service.PluginInterface.GetPluginConfigDirectory()}' to any backup from February 2, 2023 or before."); Service.Chat.PrintError($"If you have any backup tools installed, please restore the contents of '{Service.PluginInterface.GetPluginConfigDirectory()}' to any backup from February 2, 2023 or before.");

View File

@ -1,10 +1,11 @@
using Dalamud.Game.Gui; using Dalamud.Game.Gui;
using Pal.Client.Properties; using Pal.Client.Properties;
namespace Pal.Client.Extensions; namespace Pal.Client.Extensions
{
public static class ChatExtensions public static class ChatExtensions
{ {
public static void PalError(this ChatGui chat, string e) public static void PalError(this ChatGui chat, string e)
=> chat.PrintError($"[{Localization.Palace_Pal}] {e}"); => chat.PrintError($"[{Localization.Palace_Pal}] {e}");
} }
}

View File

@ -0,0 +1,13 @@
using System;
namespace Pal.Client.Extensions
{
public static class GuidExtensions
{
public static string ToPartialId(this Guid g, int length = 13)
=> g.ToString().ToPartialId();
public static string ToPartialId(this string s, int length = 13)
=> s.PadRight(length + 1).Substring(0, length);
}
}

View File

@ -5,6 +5,7 @@ using System.Collections.Generic;
using System.IO; using System.IO;
using System.Linq; using System.Linq;
using System.Text.Json; using System.Text.Json;
using Pal.Client.Extensions;
namespace Pal.Client namespace Pal.Client
{ {
@ -72,7 +73,7 @@ namespace Pal.Client
if (version <= 3) if (version <= 3)
{ {
foreach (var marker in localState.Markers) foreach (var marker in localState.Markers)
marker.RemoteSeenOn = marker.RemoteSeenOn.Select(x => x.PadRight(14).Substring(0, 13)).ToList(); marker.RemoteSeenOn = marker.RemoteSeenOn.Select(x => x.ToPartialId()).ToList();
} }
if (version < CurrentVersion) if (version < CurrentVersion)

View File

@ -65,7 +65,7 @@ namespace Pal.Client.Net
private class NullScope : IDisposable private class NullScope : IDisposable
{ {
public static NullScope Instance { get; } = new NullScope(); public static NullScope Instance { get; } = new();
private NullScope() private NullScope()
{ {

View File

@ -48,7 +48,7 @@ namespace Pal.Client.Net
internal class JwtRoleConverter : JsonConverter<List<string>> internal class JwtRoleConverter : JsonConverter<List<string>>
{ {
public override List<string>? Read(ref Utf8JsonReader reader, Type typeToConvert, JsonSerializerOptions options) public override List<string> Read(ref Utf8JsonReader reader, Type typeToConvert, JsonSerializerOptions options)
{ {
if (reader.TokenType == JsonTokenType.String) if (reader.TokenType == JsonTokenType.String)
return new List<string> { reader.GetString() ?? throw new JsonException("no value present") }; return new List<string> { reader.GetString() ?? throw new JsonException("no value present") };

View File

@ -88,7 +88,7 @@ namespace Pal.Client.Net
var account = Account; var account = Account;
if (account != null) if (account != null)
{ {
account.CachedRoles = _loginInfo.Claims?.Roles?.ToList() ?? new List<string>(); account.CachedRoles = _loginInfo.Claims?.Roles.ToList() ?? new List<string>();
Service.Configuration.Save(); Service.Configuration.Save();
} }
} }
@ -156,7 +156,7 @@ namespace Pal.Client.Net
{ {
IsLoggedIn = true; IsLoggedIn = true;
AuthToken = authToken; AuthToken = authToken;
Claims = JwtClaims.FromAuthToken(authToken!); Claims = JwtClaims.FromAuthToken(authToken);
} }
else else
IsLoggedIn = false; IsLoggedIn = false;

View File

@ -18,7 +18,7 @@ namespace Pal.Client.Net
var palaceClient = new PalaceService.PalaceServiceClient(_channel); var palaceClient = new PalaceService.PalaceServiceClient(_channel);
var downloadReply = await palaceClient.DownloadFloorsAsync(new DownloadFloorsRequest { TerritoryType = territoryId }, headers: AuthorizedHeaders(), cancellationToken: cancellationToken); var downloadReply = await palaceClient.DownloadFloorsAsync(new DownloadFloorsRequest { TerritoryType = territoryId }, headers: AuthorizedHeaders(), cancellationToken: cancellationToken);
return (downloadReply.Success, downloadReply.Objects.Select(o => CreateMarkerFromNetworkObject(o)).ToList()); return (downloadReply.Success, downloadReply.Objects.Select(CreateMarkerFromNetworkObject).ToList());
} }
public async Task<(bool, List<Marker>)> UploadMarker(ushort territoryType, IList<Marker> markers, CancellationToken cancellationToken = default) public async Task<(bool, List<Marker>)> UploadMarker(ushort territoryType, IList<Marker> markers, CancellationToken cancellationToken = default)
@ -42,7 +42,7 @@ namespace Pal.Client.Net
Z = m.Position.Z Z = m.Position.Z
})); }));
var uploadReply = await palaceClient.UploadFloorsAsync(uploadRequest, headers: AuthorizedHeaders(), cancellationToken: cancellationToken); var uploadReply = await palaceClient.UploadFloorsAsync(uploadRequest, headers: AuthorizedHeaders(), cancellationToken: cancellationToken);
return (uploadReply.Success, uploadReply.Objects.Select(o => CreateMarkerFromNetworkObject(o)).ToList()); return (uploadReply.Success, uploadReply.Objects.Select(CreateMarkerFromNetworkObject).ToList());
} }
public async Task<bool> MarkAsSeen(ushort territoryType, IList<Marker> markers, CancellationToken cancellationToken = default) public async Task<bool> MarkAsSeen(ushort territoryType, IList<Marker> markers, CancellationToken cancellationToken = default)

View File

@ -1,4 +1,5 @@
using Dalamud.Logging; using System;
using Dalamud.Logging;
using Grpc.Core; using Grpc.Core;
using System.Net.Security; using System.Net.Security;
using System.Security.Cryptography.X509Certificates; using System.Security.Cryptography.X509Certificates;
@ -7,14 +8,14 @@ namespace Pal.Client.Net
{ {
internal partial class RemoteApi internal partial class RemoteApi
{ {
private Metadata UnauthorizedHeaders() => new Metadata private Metadata UnauthorizedHeaders() => new()
{ {
{ "User-Agent", _userAgent }, { "User-Agent", _userAgent },
}; };
private Metadata AuthorizedHeaders() => new Metadata private Metadata AuthorizedHeaders() => new()
{ {
{ "Authorization", $"Bearer {_loginInfo?.AuthToken}" }, { "Authorization", $"Bearer {_loginInfo.AuthToken}" },
{ "User-Agent", _userAgent }, { "User-Agent", _userAgent },
}; };
@ -34,7 +35,9 @@ namespace Pal.Client.Net
return null; return null;
var bytes = new byte[manifestResourceStream.Length]; var bytes = new byte[manifestResourceStream.Length];
manifestResourceStream.Read(bytes, 0, bytes.Length); int read = manifestResourceStream.Read(bytes, 0, bytes.Length);
if (read != bytes.Length)
throw new InvalidOperationException();
var certificate = new X509Certificate2(bytes, pass, X509KeyStorageFlags.DefaultKeySet); var certificate = new X509Certificate2(bytes, pass, X509KeyStorageFlags.DefaultKeySet);
PluginLog.Debug($"Using client certificate {certificate.GetCertHashString()}"); PluginLog.Debug($"Using client certificate {certificate.GetCertHashString()}");

View File

@ -2,6 +2,7 @@
using Grpc.Net.Client; using Grpc.Net.Client;
using Microsoft.Extensions.Logging; using Microsoft.Extensions.Logging;
using System; using System;
using Pal.Client.Extensions;
namespace Pal.Client.Net namespace Pal.Client.Net
{ {
@ -18,7 +19,7 @@ namespace Pal.Client.Net
private GrpcChannel? _channel; private GrpcChannel? _channel;
private LoginInfo _loginInfo = new(null); private LoginInfo _loginInfo = new(null);
private bool _warnedAboutUpgrade = false; private bool _warnedAboutUpgrade;
public Configuration.AccountInfo? Account public Configuration.AccountInfo? Account
{ {
@ -34,7 +35,7 @@ namespace Pal.Client.Net
public Guid? AccountId => Account?.Id; public Guid? AccountId => Account?.Id;
public string? PartialAccountId => Account?.Id?.ToString()?.PadRight(14).Substring(0, 13); public string? PartialAccountId => Account?.Id?.ToPartialId();
private string FormattedPartialAccountId => PartialAccountId ?? "[no account id]"; private string FormattedPartialAccountId => PartialAccountId ?? "[no account id]";

View File

@ -2,7 +2,7 @@
"Name": "Palace Pal", "Name": "Palace Pal",
"Author": "Liza Carvelli", "Author": "Liza Carvelli",
"Punchline": "Shows possible trap & hoard coffer locations in Palace of the Dead & Heaven on High.", "Punchline": "Shows possible trap & hoard coffer locations in Palace of the Dead & Heaven on High.",
"Description": "Shows possible trap & hoard coffer locations in Palace of the Dead & Heaven on High. Requires Splatoon to be installed.", "Description": "Shows possible trap & hoard coffer locations in Palace of the Dead & Heaven on High.\n\nThe default configuration requires Splatoon to be installed. If you do not wish to install Splatoon, you can switch to the experimental 'Simple' renderer in the configuration.",
"RepoUrl": "https://github.com/carvelli/PalacePal", "RepoUrl": "https://github.com/carvelli/PalacePal",
"IconUrl": "https://raw.githubusercontent.com/carvelli/Dalamud-Plugins/master/dist/Palace Pal.png", "IconUrl": "https://raw.githubusercontent.com/carvelli/Dalamud-Plugins/master/dist/Palace Pal.png",
"Tags": [ "potd", "palace", "hoh", "splatoon" ] "Tags": [ "potd", "palace", "hoh", "splatoon" ]

View File

@ -39,10 +39,10 @@ namespace Pal.Client
internal ConcurrentDictionary<ushort, LocalState> FloorMarkers { get; } = new(); internal ConcurrentDictionary<ushort, LocalState> FloorMarkers { get; } = new();
internal ConcurrentBag<Marker> EphemeralMarkers { get; set; } = new(); internal ConcurrentBag<Marker> EphemeralMarkers { get; set; } = new();
internal ushort LastTerritory { get; set; } internal ushort LastTerritory { get; set; }
public SyncState TerritorySyncState { get; set; } internal SyncState TerritorySyncState { get; set; }
public PomanderState PomanderOfSight { get; set; } = PomanderState.Inactive; internal PomanderState PomanderOfSight { get; private set; } = PomanderState.Inactive;
public PomanderState PomanderOfIntuition { get; set; } = PomanderState.Inactive; internal PomanderState PomanderOfIntuition { get; private set; } = PomanderState.Inactive;
public string? DebugMessage { get; set; } internal string? DebugMessage { get; set; }
internal Queue<IQueueOnFrameworkThread> EarlyEventQueue { get; } = new(); internal Queue<IQueueOnFrameworkThread> EarlyEventQueue { get; } = new();
internal Queue<IQueueOnFrameworkThread> LateEventQueue { get; } = new(); internal Queue<IQueueOnFrameworkThread> LateEventQueue { get; } = new();
internal ConcurrentQueue<nint> NextUpdateObjects { get; } = new(); internal ConcurrentQueue<nint> NextUpdateObjects { get; } = new();
@ -98,7 +98,7 @@ namespace Pal.Client
} }
pluginInterface.UiBuilder.Draw += Draw; pluginInterface.UiBuilder.Draw += Draw;
pluginInterface.UiBuilder.OpenConfigUi += OnOpenConfigUi; pluginInterface.UiBuilder.OpenConfigUi += OpenConfigUi;
pluginInterface.LanguageChanged += LanguageChanged; pluginInterface.LanguageChanged += LanguageChanged;
Service.Framework.Update += OnFrameworkUpdate; Service.Framework.Update += OnFrameworkUpdate;
Service.Chat.ChatMessage += OnChatMessage; Service.Chat.ChatMessage += OnChatMessage;
@ -110,7 +110,7 @@ namespace Pal.Client
ReloadLanguageStrings(); ReloadLanguageStrings();
} }
public void OnOpenConfigUi() private void OpenConfigUi()
{ {
Window? configWindow; Window? configWindow;
if (Service.Configuration.FirstUse) if (Service.Configuration.FirstUse)
@ -162,7 +162,7 @@ namespace Pal.Client
break; break;
case "near": case "near":
DebugNearest(m => true); DebugNearest(_ => true);
break; break;
case "tnear": case "tnear":
@ -191,7 +191,7 @@ namespace Pal.Client
Service.CommandManager.RemoveHandler("/pal"); Service.CommandManager.RemoveHandler("/pal");
Service.PluginInterface.UiBuilder.Draw -= Draw; Service.PluginInterface.UiBuilder.Draw -= Draw;
Service.PluginInterface.UiBuilder.OpenConfigUi -= OnOpenConfigUi; Service.PluginInterface.UiBuilder.OpenConfigUi -= OpenConfigUi;
Service.PluginInterface.LanguageChanged -= LanguageChanged; Service.PluginInterface.LanguageChanged -= LanguageChanged;
Service.Framework.Update -= OnFrameworkUpdate; Service.Framework.Update -= OnFrameworkUpdate;
Service.Chat.ChatMessage -= OnChatMessage; Service.Chat.ChatMessage -= OnChatMessage;
@ -246,14 +246,12 @@ namespace Pal.Client
{ {
PomanderOfIntuition = PomanderState.FoundOnCurrentFloor; PomanderOfIntuition = PomanderState.FoundOnCurrentFloor;
} }
else
return;
} }
private void LanguageChanged(string langcode) private void LanguageChanged(string langcode)
{ {
Localization.Culture = new CultureInfo(langcode); Localization.Culture = new CultureInfo(langcode);
Service.WindowSystem?.Windows.OfType<ILanguageChanged>().Each(w => w.LanguageChanged()); Service.WindowSystem.Windows.OfType<ILanguageChanged>().Each(w => w.LanguageChanged());
} }
private void OnFrameworkUpdate(Framework framework) private void OnFrameworkUpdate(Framework framework)
@ -267,7 +265,7 @@ namespace Pal.Client
bool saveMarkers = false; bool saveMarkers = false;
while (EarlyEventQueue.TryDequeue(out IQueueOnFrameworkThread? queued)) while (EarlyEventQueue.TryDequeue(out IQueueOnFrameworkThread? queued))
queued?.Run(this, ref recreateLayout, ref saveMarkers); queued.Run(this, ref recreateLayout, ref saveMarkers);
if (LastTerritory != Service.ClientState.TerritoryType) if (LastTerritory != Service.ClientState.TerritoryType)
{ {
@ -294,7 +292,7 @@ namespace Pal.Client
} }
while (LateEventQueue.TryDequeue(out IQueueOnFrameworkThread? queued)) while (LateEventQueue.TryDequeue(out IQueueOnFrameworkThread? queued))
queued?.Run(this, ref recreateLayout, ref saveMarkers); queued.Run(this, ref recreateLayout, ref saveMarkers);
var currentFloor = GetFloorMarkers(LastTerritory); var currentFloor = GetFloorMarkers(LastTerritory);
@ -334,7 +332,7 @@ namespace Pal.Client
// This requires you to have seen a trap/hoard marker once per floor to synchronize this for older local states, // This requires you to have seen a trap/hoard marker once per floor to synchronize this for older local states,
// markers discovered afterwards are automatically marked seen. // markers discovered afterwards are automatically marked seen.
if (partialAccountId != null && knownMarker.NetworkId != null && !knownMarker.RemoteSeenRequested && !knownMarker.RemoteSeenOn.Contains(partialAccountId)) if (partialAccountId != null && knownMarker is { NetworkId: { }, RemoteSeenRequested: false } && !knownMarker.RemoteSeenOn.Contains(partialAccountId))
updateSeenMarkers = true; updateSeenMarkers = true;
continue; continue;
@ -372,7 +370,7 @@ namespace Pal.Client
if (updateSeenMarkers && partialAccountId != null) if (updateSeenMarkers && partialAccountId != null)
{ {
var markersToUpdate = currentFloorMarkers.Where(x => x.Seen && x.NetworkId != null && !x.RemoteSeenRequested && !x.RemoteSeenOn.Contains(partialAccountId)).ToList(); var markersToUpdate = currentFloorMarkers.Where(x => x is { Seen: true, NetworkId: { }, RemoteSeenRequested: false } && !x.RemoteSeenOn.Contains(partialAccountId)).ToList();
foreach (var marker in markersToUpdate) foreach (var marker in markersToUpdate)
marker.RemoteSeenRequested = true; marker.RemoteSeenRequested = true;
Task.Run(async () => await SyncSeenMarkersForTerritory(LastTerritory, markersToUpdate)); Task.Run(async () => await SyncSeenMarkersForTerritory(LastTerritory, markersToUpdate));
@ -401,7 +399,7 @@ namespace Pal.Client
List<IRenderElement> elements = new(); List<IRenderElement> elements = new();
foreach (var marker in currentFloorMarkers) foreach (var marker in currentFloorMarkers)
{ {
if (marker.Seen || config.Mode == Configuration.EMode.Online || (marker.WasImported && marker.Imports.Count > 0)) if (marker.Seen || config.Mode == Configuration.EMode.Online || marker is { WasImported: true, Imports.Count: > 0 })
{ {
if (marker.Type == Marker.EType.Trap && config.ShowTraps) if (marker.Type == Marker.EType.Trap && config.ShowTraps)
{ {
@ -583,12 +581,12 @@ namespace Pal.Client
var nearbyMarkers = state.Markers var nearbyMarkers = state.Markers
.Where(m => predicate(m)) .Where(m => predicate(m))
.Where(m => m.RenderElement != null && m.RenderElement.Color != ColorInvisible) .Where(m => m.RenderElement != null && m.RenderElement.Color != ColorInvisible)
.Select(m => new { m = m, distance = (playerPosition - m.Position)?.Length() ?? float.MaxValue }) .Select(m => new { m, distance = (playerPosition - m.Position)?.Length() ?? float.MaxValue })
.OrderBy(m => m.distance) .OrderBy(m => m.distance)
.Take(5) .Take(5)
.ToList(); .ToList();
foreach (var nearbyMarker in nearbyMarkers) foreach (var nearbyMarker in nearbyMarkers)
Service.Chat.Print($"{nearbyMarker.distance:F2} - {nearbyMarker.m.Type} {nearbyMarker.m.NetworkId?.ToString()?.Substring(0, 8)} - {nearbyMarker.m.Position}"); Service.Chat.Print($"{nearbyMarker.distance:F2} - {nearbyMarker.m.Type} {nearbyMarker.m.NetworkId?.ToPartialId(length: 8)} - {nearbyMarker.m.Position}");
} }
#endregion #endregion
@ -690,12 +688,12 @@ namespace Pal.Client
private class LocalizedChatMessages private class LocalizedChatMessages
{ {
public string MapRevealed { get; set; } = "???"; //"The map for this floor has been revealed!"; public string MapRevealed { get; init; } = "???"; //"The map for this floor has been revealed!";
public string AllTrapsRemoved { get; set; } = "???"; // "All the traps on this floor have disappeared!"; public string AllTrapsRemoved { get; init; } = "???"; // "All the traps on this floor have disappeared!";
public string HoardOnCurrentFloor { get; set; } = "???"; // "You sense the Accursed Hoard calling you..."; public string HoardOnCurrentFloor { get; init; } = "???"; // "You sense the Accursed Hoard calling you...";
public string HoardNotOnCurrentFloor { get; set; } = "???"; // "You do not sense the call of the Accursed Hoard on this floor..."; public string HoardNotOnCurrentFloor { get; init; } = "???"; // "You do not sense the call of the Accursed Hoard on this floor...";
public string HoardCofferOpened { get; set; } = "???"; // "You discover a piece of the Accursed Hoard!"; public string HoardCofferOpened { get; init; } = "???"; // "You discover a piece of the Accursed Hoard!";
public Regex FloorChanged { get; set; } = new Regex(@"This isn't a game message, but will be replaced"); // new Regex(@"^Floor (\d+)$"); public Regex FloorChanged { get; init; } = new(@"This isn't a game message, but will be replaced"); // new Regex(@"^Floor (\d+)$");
} }
} }
} }

View File

@ -4,17 +4,17 @@ namespace Pal.Client.Rendering
{ {
internal class MarkerConfig internal class MarkerConfig
{ {
private static readonly MarkerConfig EmptyConfig = new();
private readonly static Dictionary<Marker.EType, MarkerConfig> _markerConfig = new Dictionary<Marker.EType, MarkerConfig> private static readonly Dictionary<Marker.EType, MarkerConfig> MarkerConfigs = new()
{ {
{ Marker.EType.Trap, new MarkerConfig { Radius = 1.7f } }, { Marker.EType.Trap, new MarkerConfig { Radius = 1.7f } },
{ Marker.EType.Hoard, new MarkerConfig { Radius = 1.7f, OffsetY = -0.03f } }, { Marker.EType.Hoard, new MarkerConfig { Radius = 1.7f, OffsetY = -0.03f } },
{ Marker.EType.SilverCoffer, new MarkerConfig { Radius = 1f } }, { Marker.EType.SilverCoffer, new MarkerConfig { Radius = 1f } },
}; };
public float OffsetY { get; set; } = 0; public float OffsetY { get; set; }
public float Radius { get; set; } = 0.25f; public float Radius { get; set; } = 0.25f;
public static MarkerConfig ForType(Marker.EType type) => _markerConfig[type] ?? new MarkerConfig(); public static MarkerConfig ForType(Marker.EType type) => MarkerConfigs.GetValueOrDefault(type, EmptyConfig);
} }
} }

View File

@ -22,11 +22,11 @@ namespace Pal.Client.Rendering
/// </summary> /// </summary>
internal class SimpleRenderer : IRenderer, IDisposable internal class SimpleRenderer : IRenderer, IDisposable
{ {
private ConcurrentDictionary<ELayer, SimpleLayer> layers = new(); private readonly ConcurrentDictionary<ELayer, SimpleLayer> _layers = new();
public void SetLayer(ELayer layer, IReadOnlyList<IRenderElement> elements) public void SetLayer(ELayer layer, IReadOnlyList<IRenderElement> elements)
{ {
layers[layer] = new SimpleLayer _layers[layer] = new SimpleLayer
{ {
TerritoryType = Service.ClientState.TerritoryType, TerritoryType = Service.ClientState.TerritoryType,
Elements = elements.Cast<SimpleElement>().ToList() Elements = elements.Cast<SimpleElement>().ToList()
@ -35,7 +35,7 @@ namespace Pal.Client.Rendering
public void ResetLayer(ELayer layer) public void ResetLayer(ELayer layer)
{ {
if (layers.Remove(layer, out var l)) if (_layers.Remove(layer, out var l))
l.Dispose(); l.Dispose();
} }
@ -54,7 +54,7 @@ namespace Pal.Client.Rendering
public void DrawLayers() public void DrawLayers()
{ {
if (layers.Count == 0) if (_layers.Count == 0)
return; return;
ImGuiHelpers.ForceNextWindowMainViewport(); ImGuiHelpers.ForceNextWindowMainViewport();
@ -65,10 +65,10 @@ namespace Pal.Client.Rendering
{ {
ushort territoryType = Service.ClientState.TerritoryType; ushort territoryType = Service.ClientState.TerritoryType;
foreach (var layer in layers.Values.Where(l => l.TerritoryType == territoryType)) foreach (var layer in _layers.Values.Where(l => l.TerritoryType == territoryType))
layer.Draw(); layer.Draw();
foreach (var key in layers.Where(l => l.Value.TerritoryType != territoryType).Select(l => l.Key).ToList()) foreach (var key in _layers.Where(l => l.Value.TerritoryType != territoryType).Select(l => l.Key).ToList())
ResetLayer(key); ResetLayer(key);
ImGui.End(); ImGui.End();
@ -78,14 +78,14 @@ namespace Pal.Client.Rendering
public void Dispose() public void Dispose()
{ {
foreach (var l in layers.Values) foreach (var l in _layers.Values)
l.Dispose(); l.Dispose();
} }
public class SimpleLayer : IDisposable public class SimpleLayer : IDisposable
{ {
public required ushort TerritoryType { get; init; } public required ushort TerritoryType { get; init; }
public required IReadOnlyList<SimpleElement> Elements { get; set; } public required IReadOnlyList<SimpleElement> Elements { get; init; }
public void Draw() public void Draw()
{ {
@ -102,14 +102,14 @@ namespace Pal.Client.Rendering
public class SimpleElement : IRenderElement public class SimpleElement : IRenderElement
{ {
private const int segmentCount = 20; private const int SegmentCount = 20;
public bool IsValid { get; set; } = true; public bool IsValid { get; set; } = true;
public required Marker.EType Type { get; set; } public required Marker.EType Type { get; init; }
public required Vector3 Position { get; set; } public required Vector3 Position { get; init; }
public required uint Color { get; set; } public required uint Color { get; set; }
public required float Radius { get; set; } public required float Radius { get; init; }
public required bool Fill { get; set; } public required bool Fill { get; init; }
public void Draw() public void Draw()
{ {
@ -136,12 +136,12 @@ namespace Pal.Client.Rendering
} }
bool onScreen = false; bool onScreen = false;
for (int index = 0; index < 2 * segmentCount; ++index) for (int index = 0; index < 2 * SegmentCount; ++index)
{ {
onScreen |= Service.GameGui.WorldToScreen(new Vector3( onScreen |= Service.GameGui.WorldToScreen(new Vector3(
Position.X + Radius * (float)Math.Sin(Math.PI / segmentCount * index), Position.X + Radius * (float)Math.Sin(Math.PI / SegmentCount * index),
Position.Y, Position.Y,
Position.Z + Radius * (float)Math.Cos(Math.PI / segmentCount * index)), Position.Z + Radius * (float)Math.Cos(Math.PI / SegmentCount * index)),
out Vector2 vector2); out Vector2 vector2);
ImGui.GetWindowDrawList().PathLineTo(vector2); ImGui.GetWindowDrawList().PathLineTo(vector2);

View File

@ -18,8 +18,8 @@ namespace Pal.Client.Rendering
{ {
internal class SplatoonRenderer : IRenderer, IDrawDebugItems, IDisposable internal class SplatoonRenderer : IRenderer, IDrawDebugItems, IDisposable
{ {
private const long ON_TERRITORY_CHANGE = -2; private const long OnTerritoryChange = -2;
private bool IsDisposed { get; set; } = false; private bool IsDisposed { get; set; }
public SplatoonRenderer(DalamudPluginInterface pluginInterface, IDalamudPlugin plugin) public SplatoonRenderer(DalamudPluginInterface pluginInterface, IDalamudPlugin plugin)
{ {
@ -29,11 +29,11 @@ namespace Pal.Client.Rendering
public void SetLayer(ELayer layer, IReadOnlyList<IRenderElement> elements) public void SetLayer(ELayer layer, IReadOnlyList<IRenderElement> elements)
{ {
// we need to delay this, as the current framework update could be before splatoon's, in which case it would immediately delete the layout // we need to delay this, as the current framework update could be before splatoon's, in which case it would immediately delete the layout
new TickScheduler(delegate _ = new TickScheduler(delegate
{ {
try try
{ {
Splatoon.AddDynamicElements(ToLayerName(layer), elements.Cast<SplatoonElement>().Select(x => x.Delegate).ToArray(), new long[] { Environment.TickCount64 + 60 * 60 * 1000, ON_TERRITORY_CHANGE }); Splatoon.AddDynamicElements(ToLayerName(layer), elements.Cast<SplatoonElement>().Select(x => x.Delegate).ToArray(), new[] { Environment.TickCount64 + 60 * 60 * 1000, OnTerritoryChange });
} }
catch (Exception e) catch (Exception e)
{ {
@ -91,7 +91,7 @@ namespace Pal.Client.Rendering
CreateElement(Marker.EType.Hoard, pos.Value, ImGui.ColorConvertFloat4ToU32(hoardColor)), CreateElement(Marker.EType.Hoard, pos.Value, ImGui.ColorConvertFloat4ToU32(hoardColor)),
}; };
if (!Splatoon.AddDynamicElements("PalacePal.Test", elements.Cast<SplatoonElement>().Select(x => x.Delegate).ToArray(), new long[] { Environment.TickCount64 + 10000 })) if (!Splatoon.AddDynamicElements("PalacePal.Test", elements.Cast<SplatoonElement>().Select(x => x.Delegate).ToArray(), new[] { Environment.TickCount64 + 10000 }))
{ {
Service.Chat.PrintError("Could not draw markers :("); Service.Chat.PrintError("Could not draw markers :(");
} }
@ -134,17 +134,17 @@ namespace Pal.Client.Rendering
public class SplatoonElement : IRenderElement public class SplatoonElement : IRenderElement
{ {
private readonly SplatoonRenderer renderer; private readonly SplatoonRenderer _renderer;
public SplatoonElement(SplatoonRenderer renderer, Element element) public SplatoonElement(SplatoonRenderer renderer, Element element)
{ {
this.renderer = renderer; _renderer = renderer;
Delegate = element; Delegate = element;
} }
public Element Delegate { get; } public Element Delegate { get; }
public bool IsValid => !renderer.IsDisposed && Delegate.IsValid(); public bool IsValid => !_renderer.IsDisposed && Delegate.IsValid();
public uint Color public uint Color
{ {
get => Delegate.color; get => Delegate.color;

View File

@ -15,12 +15,12 @@ namespace Pal.Client.Scheduled
{ {
private readonly ExportRoot _export; private readonly ExportRoot _export;
private Guid _exportId; private Guid _exportId;
private int importedTraps; private int _importedTraps;
private int importedHoardCoffers; private int _importedHoardCoffers;
public QueuedImport(string sourcePath) public QueuedImport(string sourcePath)
{ {
using (var input = File.OpenRead(sourcePath)) using var input = File.OpenRead(sourcePath);
_export = ExportRoot.Parser.ParseFrom(input); _export = ExportRoot.Parser.ParseFrom(input);
} }
@ -58,7 +58,7 @@ namespace Pal.Client.Scheduled
recreateLayout = true; recreateLayout = true;
saveMarkers = true; saveMarkers = true;
Service.Chat.Print(string.Format(Localization.ImportCompleteStatistics, importedTraps, importedHoardCoffers)); Service.Chat.Print(string.Format(Localization.ImportCompleteStatistics, _importedTraps, _importedHoardCoffers));
} }
catch (Exception e) catch (Exception e)
{ {
@ -103,9 +103,9 @@ namespace Pal.Client.Scheduled
localMarker = remoteMarker; localMarker = remoteMarker;
if (localMarker.Type == Marker.EType.Trap) if (localMarker.Type == Marker.EType.Trap)
importedTraps++; _importedTraps++;
else if (localMarker.Type == Marker.EType.Hoard) else if (localMarker.Type == Marker.EType.Hoard)
importedHoardCoffers++; _importedHoardCoffers++;
} }
remoteMarker.Imports.Add(_exportId); remoteMarker.Imports.Add(_exportId);

View File

@ -9,10 +9,10 @@ namespace Pal.Client.Scheduled
{ {
internal class QueuedSyncResponse : IQueueOnFrameworkThread internal class QueuedSyncResponse : IQueueOnFrameworkThread
{ {
public SyncType Type { get; set; } public required SyncType Type { get; init; }
public ushort TerritoryType { get; set; } public required ushort TerritoryType { get; init; }
public bool Success { get; set; } public required bool Success { get; init; }
public List<Marker> Markers { get; set; } = new(); public required List<Marker> Markers { get; init; }
public void Run(Plugin plugin, ref bool recreateLayout, ref bool saveMarkers) public void Run(Plugin plugin, ref bool recreateLayout, ref bool saveMarkers)
{ {

View File

@ -24,10 +24,10 @@ namespace Pal.Client
[PluginService] public static DataManager DataManager { get; set; } = null!; [PluginService] public static DataManager DataManager { get; set; } = null!;
[PluginService] public static GameGui GameGui { get; set; } = null!; [PluginService] public static GameGui GameGui { get; set; } = null!;
public static Plugin Plugin { get; set; } = null!; internal static Plugin Plugin { get; set; } = null!;
public static WindowSystem WindowSystem { get; set; } = new(typeof(Service).AssemblyQualifiedName); internal static WindowSystem WindowSystem { get; } = new(typeof(Service).AssemblyQualifiedName);
internal static RemoteApi RemoteApi { get; set; } = new RemoteApi(); internal static RemoteApi RemoteApi { get; } = new();
public static Configuration Configuration { get; set; } = null!; internal static Configuration Configuration { get; set; } = null!;
internal static Hooks Hooks { get; set; } = null!; internal static Hooks Hooks { get; set; } = null!;
} }
} }

View File

@ -22,7 +22,7 @@ using Pal.Client.Properties;
namespace Pal.Client.Windows namespace Pal.Client.Windows
{ {
internal class ConfigWindow : Window internal class ConfigWindow : Window, ILanguageChanged
{ {
private const string WindowId = "###PalPalaceConfig"; private const string WindowId = "###PalPalaceConfig";
private int _mode; private int _mode;
@ -43,8 +43,8 @@ namespace Pal.Client.Windows
private string _saveExportPath = string.Empty; private string _saveExportPath = string.Empty;
private string? _openImportDialogStartPath = Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments); private string? _openImportDialogStartPath = Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments);
private string? _saveExportDialogStartPath = Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments); private string? _saveExportDialogStartPath = Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments);
private FileDialogManager _importDialog; private readonly FileDialogManager _importDialog;
private FileDialogManager _exportDialog; private readonly FileDialogManager _exportDialog;
public ConfigWindow() : base(WindowId) public ConfigWindow() : base(WindowId)
{ {
@ -358,7 +358,7 @@ namespace Pal.Client.Windows
/// <summary> /// <summary>
/// None of the default BeginTabItem methods allow using flags without making the tab have a close button for some reason. /// None of the default BeginTabItem methods allow using flags without making the tab have a close button for some reason.
/// </summary> /// </summary>
private unsafe static bool BeginTabItemEx(string label, ImGuiTabItemFlags flags) private static unsafe bool BeginTabItemEx(string label, ImGuiTabItemFlags flags)
{ {
int labelLength = Encoding.UTF8.GetByteCount(label); int labelLength = Encoding.UTF8.GetByteCount(label);
byte* labelPtr = stackalloc byte[labelLength + 1]; byte* labelPtr = stackalloc byte[labelLength + 1];
@ -392,17 +392,17 @@ namespace Pal.Client.Windows
}); });
} }
internal void DoImport(string sourcePath) private void DoImport(string sourcePath)
{ {
Service.Plugin.EarlyEventQueue.Enqueue(new QueuedImport(sourcePath)); Service.Plugin.EarlyEventQueue.Enqueue(new QueuedImport(sourcePath));
} }
internal void UndoImport(Guid importId) private void UndoImport(Guid importId)
{ {
Service.Plugin.EarlyEventQueue.Enqueue(new QueuedUndoImport(importId)); Service.Plugin.EarlyEventQueue.Enqueue(new QueuedUndoImport(importId));
} }
internal void DoExport(string destinationPath) private void DoExport(string destinationPath)
{ {
Task.Run(async () => Task.Run(async () =>
{ {
@ -411,7 +411,7 @@ namespace Pal.Client.Windows
(bool success, ExportRoot export) = await Service.RemoteApi.DoExport(); (bool success, ExportRoot export) = await Service.RemoteApi.DoExport();
if (success) if (success)
{ {
using var output = File.Create(destinationPath); await using var output = File.Create(destinationPath);
export.WriteTo(output); export.WriteTo(output);
Service.Chat.Print($"Export saved as {destinationPath}."); Service.Chat.Print($"Export saved as {destinationPath}.");

View File

@ -17,7 +17,7 @@ namespace Pal.Client.Windows
internal class StatisticsWindow : Window, ILanguageChanged internal class StatisticsWindow : Window, ILanguageChanged
{ {
private const string WindowId = "###PalacePalStats"; private const string WindowId = "###PalacePalStats";
private SortedDictionary<ETerritoryType, TerritoryStatistics> _territoryStatistics = new(); private readonly SortedDictionary<ETerritoryType, TerritoryStatistics> _territoryStatistics = new();
public StatisticsWindow() : base(WindowId) public StatisticsWindow() : base(WindowId)
{ {

View File

@ -8,6 +8,6 @@ namespace Pal.Common
{ {
public static class ExportConfig public static class ExportConfig
{ {
public static int ExportVersion { get; } = 1; public static int ExportVersion => 1;
} }
} }

View File

@ -4,7 +4,7 @@ namespace Pal.Common
{ {
public class PalaceMath public class PalaceMath
{ {
private static readonly Vector3 ScaleFactor = new Vector3(5); private static readonly Vector3 ScaleFactor = new(5);
public static bool IsNearlySamePosition(Vector3 a, Vector3 b) public static bool IsNearlySamePosition(Vector3 a, Vector3 b)
{ {