Enable nullable

rendering v1.10
Liza 2022-10-30 11:02:49 +01:00
parent 2adf030ec5
commit 7ab274696c
10 changed files with 52 additions and 40 deletions

View File

@ -10,8 +10,8 @@ namespace Pal.Client
#region Saved configuration values #region Saved configuration values
public bool FirstUse { get; set; } = true; public bool FirstUse { get; set; } = true;
public EMode Mode { get; set; } = EMode.Offline; public EMode Mode { get; set; } = EMode.Offline;
public string DebugAccountId { get; set; } public string? DebugAccountId { get; set; }
public string AccountId { get; set; } public string? AccountId { get; set; }
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 Vector4(1, 0, 0, 0.4f);
@ -27,7 +27,7 @@ namespace Pal.Client
#endregion #endregion
public delegate void OnSaved(); public delegate void OnSaved();
public event OnSaved Saved; public event OnSaved? Saved;
public void Save() public void Save()
{ {

View File

@ -29,7 +29,7 @@ namespace Pal.Client
Markers = new ConcurrentBag<Marker>(Markers.Where(x => x.Seen)); Markers = new ConcurrentBag<Marker>(Markers.Where(x => x.Seen));
} }
public static LocalState Load(uint territoryType) public static LocalState? Load(uint territoryType)
{ {
string path = GetSaveLocation(territoryType); string path = GetSaveLocation(territoryType);
if (!File.Exists(path)) if (!File.Exists(path))
@ -46,12 +46,15 @@ namespace Pal.Client
// v1 only had a list of markers, not a JSON object as root // v1 only had a list of markers, not a JSON object as root
localState = new LocalState(territoryType) localState = new LocalState(territoryType)
{ {
Markers = new ConcurrentBag<Marker>(JsonSerializer.Deserialize<HashSet<Marker>>(content, _jsonSerializerOptions)), Markers = new ConcurrentBag<Marker>(JsonSerializer.Deserialize<HashSet<Marker>>(content, _jsonSerializerOptions) ?? new()),
}; };
} }
else else
{ {
var save = JsonSerializer.Deserialize<SaveFile>(content, _jsonSerializerOptions); var save = JsonSerializer.Deserialize<SaveFile>(content, _jsonSerializerOptions);
if (save == null)
return null;
localState = new LocalState(territoryType) localState = new LocalState(territoryType)
{ {
Markers = new ConcurrentBag<Marker>(save.Markers), Markers = new ConcurrentBag<Marker>(save.Markers),
@ -85,7 +88,7 @@ namespace Pal.Client
{ {
foreach (ETerritoryType territory in typeof(ETerritoryType).GetEnumValues()) foreach (ETerritoryType territory in typeof(ETerritoryType).GetEnumValues())
{ {
LocalState localState = Load((ushort)territory); LocalState? localState = Load((ushort)territory);
if (localState != null) if (localState != null)
localState.Save(); localState.Save();
} }

View File

@ -16,7 +16,7 @@ namespace Pal.Client
public bool RemoteSeen { get; set; } = false; public bool RemoteSeen { get; set; } = false;
[JsonIgnore] [JsonIgnore]
public Element SplatoonElement { get; set; } public Element? SplatoonElement { get; set; }
public Marker(EType type, Vector3 position) public Marker(EType type, Vector3 position)
{ {
@ -29,17 +29,17 @@ namespace Pal.Client
return HashCode.Combine(Type, (int)Position.X, (int)Position.Y, (int)Position.Z); return HashCode.Combine(Type, (int)Position.X, (int)Position.Y, (int)Position.Z);
} }
public override bool Equals(object obj) public override bool Equals(object? obj)
{ {
return obj is Marker otherMarker && Type == otherMarker.Type && (int)Position.X == (int)otherMarker.Position.X && (int)Position.Y == (int)otherMarker.Position.Y && (int)Position.Z == (int)otherMarker.Position.Z; return obj is Marker otherMarker && Type == otherMarker.Type && (int)Position.X == (int)otherMarker.Position.X && (int)Position.Y == (int)otherMarker.Position.Y && (int)Position.Z == (int)otherMarker.Position.Z;
} }
public static bool operator ==(Marker a, object b) public static bool operator ==(Marker? a, object? b)
{ {
return Equals(a, b); return Equals(a, b);
} }
public static bool operator !=(Marker a, object b) public static bool operator !=(Marker? a, object? b)
{ {
return !Equals(a, b); return !Equals(a, b);
} }

View File

@ -3,7 +3,8 @@
<PropertyGroup> <PropertyGroup>
<TargetFramework>net6.0-windows</TargetFramework> <TargetFramework>net6.0-windows</TargetFramework>
<LangVersion>9.0</LangVersion> <LangVersion>9.0</LangVersion>
<Version>1.9.0.0</Version> <Version>1.10.0.0</Version>
<Nullable>enable</Nullable>
</PropertyGroup> </PropertyGroup>
<PropertyGroup> <PropertyGroup>

View File

@ -47,7 +47,7 @@ namespace Pal.Client
public SyncState TerritorySyncState { get; set; } public SyncState TerritorySyncState { get; set; }
public PomanderState PomanderOfSight { get; set; } = PomanderState.Inactive; public PomanderState PomanderOfSight { get; set; } = PomanderState.Inactive;
public PomanderState PomanderOfIntuition { get; set; } = PomanderState.Inactive; public PomanderState PomanderOfIntuition { get; set; } = PomanderState.Inactive;
public string DebugMessage { get; set; } public string? DebugMessage { get; set; }
public string Name => "Palace Pal"; public string Name => "Palace Pal";
@ -58,7 +58,7 @@ namespace Pal.Client
pluginInterface.Create<Service>(); pluginInterface.Create<Service>();
Service.Plugin = this; Service.Plugin = this;
Service.Configuration = (Configuration)pluginInterface.GetPluginConfig() ?? pluginInterface.Create<Configuration>(); Service.Configuration = (Configuration?)pluginInterface.GetPluginConfig() ?? pluginInterface.Create<Configuration>()!;
var agreementWindow = pluginInterface.Create<AgreementWindow>(); var agreementWindow = pluginInterface.Create<AgreementWindow>();
if (agreementWindow is not null) if (agreementWindow is not null)
@ -94,7 +94,7 @@ namespace Pal.Client
public void OnOpenConfigUi() public void OnOpenConfigUi()
{ {
Window configWindow; Window? configWindow;
if (Service.Configuration.FirstUse) if (Service.Configuration.FirstUse)
configWindow = Service.WindowSystem.GetWindow<AgreementWindow>(); configWindow = Service.WindowSystem.GetWindow<AgreementWindow>();
else else
@ -282,7 +282,7 @@ namespace Pal.Client
foreach (var visibleMarker in visibleMarkers) foreach (var visibleMarker in visibleMarkers)
{ {
Marker knownMarker = currentFloorMarkers.SingleOrDefault(x => x == visibleMarker); Marker? knownMarker = currentFloorMarkers.SingleOrDefault(x => x == visibleMarker);
if (knownMarker != null) if (knownMarker != null)
{ {
if (!knownMarker.Seen) if (!knownMarker.Seen)
@ -462,7 +462,7 @@ namespace Pal.Client
var (success, floorStatistics) = await Service.RemoteApi.FetchStatistics(); var (success, floorStatistics) = await Service.RemoteApi.FetchStatistics();
if (success) if (success)
{ {
var statisticsWindow = Service.WindowSystem.GetWindow<StatisticsWindow>(); var statisticsWindow = Service.WindowSystem.GetWindow<StatisticsWindow>()!;
statisticsWindow.SetFloorData(floorStatistics); statisticsWindow.SetFloorData(floorStatistics);
statisticsWindow.IsOpen = true; statisticsWindow.IsOpen = true;
} }
@ -490,7 +490,7 @@ namespace Pal.Client
{ {
foreach (var downloadedMarker in downloadedMarkers) foreach (var downloadedMarker in downloadedMarkers)
{ {
Marker seenMarker = currentFloor.Markers.SingleOrDefault(x => x == downloadedMarker); Marker? seenMarker = currentFloor.Markers.SingleOrDefault(x => x == downloadedMarker);
if (seenMarker != null) if (seenMarker != null)
{ {
seenMarker.RemoteSeen = true; seenMarker.RemoteSeen = true;
@ -517,7 +517,7 @@ namespace Pal.Client
List<Marker> result = new(); List<Marker> result = new();
for (int i = 246; i < Service.ObjectTable.Length; i++) for (int i = 246; i < Service.ObjectTable.Length; i++)
{ {
GameObject obj = Service.ObjectTable[i]; GameObject? obj = Service.ObjectTable[i];
if (obj == null) if (obj == null)
continue; continue;
@ -584,7 +584,7 @@ namespace Pal.Client
private string GetLocalizedString(uint id) private string GetLocalizedString(uint id)
{ {
return Service.DataManager.GetExcelSheet<LogMessage>().GetRow(id).Text?.ToString() ?? "Unknown"; return Service.DataManager.GetExcelSheet<LogMessage>()?.GetRow(id)?.Text?.ToString() ?? "Unknown";
} }
public enum SyncState public enum SyncState

View File

@ -19,8 +19,8 @@ namespace Pal.Client
#else #else
private const string remoteUrl = "https://pal.μ.tv"; private const string remoteUrl = "https://pal.μ.tv";
#endif #endif
private GrpcChannel _channel; private GrpcChannel? _channel;
private LoginReply _lastLoginReply; private LoginReply? _lastLoginReply;
private async Task<bool> Connect(CancellationToken cancellationToken, bool retry = true) private async Task<bool> Connect(CancellationToken cancellationToken, bool retry = true)
{ {
@ -43,9 +43,9 @@ namespace Pal.Client
var accountClient = new AccountService.AccountServiceClient(_channel); var accountClient = new AccountService.AccountServiceClient(_channel);
#if DEBUG #if DEBUG
string accountId = Service.Configuration.DebugAccountId; string? accountId = Service.Configuration.DebugAccountId;
#else #else
string accountId = Service.Configuration.AccountId; string? accountId = Service.Configuration.AccountId;
#endif #endif
if (string.IsNullOrEmpty(accountId)) if (string.IsNullOrEmpty(accountId))
{ {

View File

@ -14,7 +14,7 @@ namespace Pal.Client
public class Service public class Service
{ {
[PluginService] public static DalamudPluginInterface PluginInterface { get; private set; } = null!; [PluginService] public static DalamudPluginInterface PluginInterface { get; private set; } = null!;
[PluginService] public static ClientState ClientState { get; set; } = null; [PluginService] public static ClientState ClientState { get; set; } = null!;
[PluginService] public static ChatGui Chat { get; private set; } = null!; [PluginService] public static ChatGui Chat { get; private set; } = null!;
[PluginService] public static ObjectTable ObjectTable { get; private set; } = null!; [PluginService] public static ObjectTable ObjectTable { get; private set; } = null!;
[PluginService] public static Framework Framework { get; set; } = null!; [PluginService] public static Framework Framework { get; set; } = null!;

View File

@ -5,7 +5,7 @@ namespace Pal.Client
{ {
internal static class WindowSystemExtensions internal static class WindowSystemExtensions
{ {
public static T GetWindow<T>(this WindowSystem windowSystem) public static T? GetWindow<T>(this WindowSystem windowSystem)
where T : Window where T : Window
{ {
return windowSystem.Windows.Select(w => w as T).FirstOrDefault(w => w != null); return windowSystem.Windows.Select(w => w as T).FirstOrDefault(w => w != null);

View File

@ -23,11 +23,11 @@ namespace Pal.Client.Windows
private Vector4 _silverCofferColor; private Vector4 _silverCofferColor;
private bool _fillSilverCoffers; private bool _fillSilverCoffers;
private string _connectionText; private string? _connectionText;
public ConfigWindow() : base("Palace Pal###PalPalaceConfig") public ConfigWindow() : base("Palace Pal###PalPalaceConfig")
{ {
var version = typeof(Plugin).Assembly.GetName().Version.ToString(2); var version = typeof(Plugin).Assembly.GetName().Version!.ToString(2);
WindowName = $"Palace Pal v{version}###PalPalaceConfig"; WindowName = $"Palace Pal v{version}###PalPalaceConfig";
Size = new Vector2(500, 400); Size = new Vector2(500, 400);
SizeCondition = ImGuiCond.FirstUseEver; SizeCondition = ImGuiCond.FirstUseEver;
@ -153,17 +153,17 @@ namespace Pal.Client.Windows
{ {
if (_showTraps) if (_showTraps)
{ {
int traps = currentFloor.Markers.Count(x => x != null && x.Type == Marker.EType.Trap); int traps = currentFloor.Markers.Count(x => x.Type == Marker.EType.Trap);
ImGui.Text($"{traps} known trap{(traps == 1 ? "" : "s")}"); ImGui.Text($"{traps} known trap{(traps == 1 ? "" : "s")}");
} }
if (_showHoard) if (_showHoard)
{ {
int hoardCoffers = currentFloor.Markers.Count(x => x != null && x.Type == Marker.EType.Hoard); int hoardCoffers = currentFloor.Markers.Count(x => x.Type == Marker.EType.Hoard);
ImGui.Text($"{hoardCoffers} known hoard coffer{(hoardCoffers == 1 ? "" : "s")}"); ImGui.Text($"{hoardCoffers} known hoard coffer{(hoardCoffers == 1 ? "" : "s")}");
} }
if (_showSilverCoffers) if (_showSilverCoffers)
{ {
int silverCoffers = plugin.EphemeralMarkers.Count(x => x != null && x.Type == Marker.EType.SilverCoffer); int silverCoffers = plugin.EphemeralMarkers.Count(x => x.Type == Marker.EType.SilverCoffer);
ImGui.Text($"{silverCoffers} silver coffer{(silverCoffers == 1 ? "" : "s")} visible on current floor"); ImGui.Text($"{silverCoffers} silver coffer{(silverCoffers == 1 ? "" : "s")} visible on current floor");
} }
@ -184,16 +184,19 @@ namespace Pal.Client.Windows
{ {
try try
{ {
var pos = Service.ClientState.LocalPlayer.Position; Vector3? pos = Service.ClientState.LocalPlayer?.Position;
var elements = new List<Element> if (pos != null)
{ {
Plugin.CreateSplatoonElement(Marker.EType.Trap, pos, _trapColor), var elements = new List<Element>
Plugin.CreateSplatoonElement(Marker.EType.Hoard, pos, _hoardColor), {
}; Plugin.CreateSplatoonElement(Marker.EType.Trap, pos.Value, _trapColor),
Plugin.CreateSplatoonElement(Marker.EType.Hoard, pos.Value, _hoardColor),
};
if (!Splatoon.AddDynamicElements("PalacePal.Test", elements.ToArray(), new long[] { Environment.TickCount64 + 10000 })) if (!Splatoon.AddDynamicElements("PalacePal.Test", elements.ToArray(), new long[] { Environment.TickCount64 + 10000 }))
{ {
Service.Chat.PrintError("Could not draw markers :("); Service.Chat.PrintError("Could not draw markers :(");
}
} }
} }
catch (Exception) catch (Exception)

View File

@ -24,7 +24,7 @@ namespace Pal.Client.Windows
foreach (ETerritoryType territory in typeof(ETerritoryType).GetEnumValues()) foreach (ETerritoryType territory in typeof(ETerritoryType).GetEnumValues())
{ {
_territoryStatistics[territory] = new TerritoryStatistics { TerritoryName = territory.ToString() }; _territoryStatistics[territory] = new TerritoryStatistics(territory.ToString());
} }
} }
@ -70,7 +70,7 @@ namespace Pal.Client.Windows
foreach (var floor in floorStatistics) foreach (var floor in floorStatistics)
{ {
if (_territoryStatistics.TryGetValue((ETerritoryType)floor.TerritoryType, out TerritoryStatistics territoryStatistics)) if (_territoryStatistics.TryGetValue((ETerritoryType)floor.TerritoryType, out TerritoryStatistics? territoryStatistics))
{ {
territoryStatistics.TrapCount = floor.TrapCount; territoryStatistics.TrapCount = floor.TrapCount;
territoryStatistics.HoardCofferCount = floor.HoardCount; territoryStatistics.HoardCofferCount = floor.HoardCount;
@ -83,6 +83,11 @@ namespace Pal.Client.Windows
public string TerritoryName { get; set; } public string TerritoryName { get; set; }
public uint? TrapCount { get; set; } public uint? TrapCount { get; set; }
public uint? HoardCofferCount { get; set; } public uint? HoardCofferCount { get; set; }
public TerritoryStatistics(string territoryName)
{
TerritoryName = territoryName;
}
} }
} }
} }