Enable nullable

This commit is contained in:
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
public bool FirstUse { get; set; } = true;
public EMode Mode { get; set; } = EMode.Offline;
public string DebugAccountId { get; set; }
public string AccountId { get; set; }
public string? DebugAccountId { get; set; }
public string? AccountId { get; set; }
public bool ShowTraps { get; set; } = true;
public Vector4 TrapColor { get; set; } = new Vector4(1, 0, 0, 0.4f);
@ -27,7 +27,7 @@ namespace Pal.Client
#endregion
public delegate void OnSaved();
public event OnSaved Saved;
public event OnSaved? Saved;
public void Save()
{

View File

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

View File

@ -16,7 +16,7 @@ namespace Pal.Client
public bool RemoteSeen { get; set; } = false;
[JsonIgnore]
public Element SplatoonElement { get; set; }
public Element? SplatoonElement { get; set; }
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);
}
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;
}
public static bool operator ==(Marker a, object b)
public static bool operator ==(Marker? a, object? 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);
}

View File

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

View File

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

View File

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

View File

@ -14,7 +14,7 @@ namespace Pal.Client
public class Service
{
[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 ObjectTable ObjectTable { get; private set; } = null!;
[PluginService] public static Framework Framework { get; set; } = null!;

View File

@ -5,7 +5,7 @@ namespace Pal.Client
{
internal static class WindowSystemExtensions
{
public static T GetWindow<T>(this WindowSystem windowSystem)
public static T? GetWindow<T>(this WindowSystem windowSystem)
where T : Window
{
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 bool _fillSilverCoffers;
private string _connectionText;
private string? _connectionText;
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";
Size = new Vector2(500, 400);
SizeCondition = ImGuiCond.FirstUseEver;
@ -153,17 +153,17 @@ namespace Pal.Client.Windows
{
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")}");
}
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")}");
}
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");
}
@ -184,11 +184,13 @@ namespace Pal.Client.Windows
{
try
{
var pos = Service.ClientState.LocalPlayer.Position;
Vector3? pos = Service.ClientState.LocalPlayer?.Position;
if (pos != null)
{
var elements = new List<Element>
{
Plugin.CreateSplatoonElement(Marker.EType.Trap, pos, _trapColor),
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 }))
@ -196,6 +198,7 @@ namespace Pal.Client.Windows
Service.Chat.PrintError("Could not draw markers :(");
}
}
}
catch (Exception)
{
Service.Chat.PrintError("Could not draw markers, is Splatoon installed and enabled?");

View File

@ -24,7 +24,7 @@ namespace Pal.Client.Windows
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)
{
if (_territoryStatistics.TryGetValue((ETerritoryType)floor.TerritoryType, out TerritoryStatistics territoryStatistics))
if (_territoryStatistics.TryGetValue((ETerritoryType)floor.TerritoryType, out TerritoryStatistics? territoryStatistics))
{
territoryStatistics.TrapCount = floor.TrapCount;
territoryStatistics.HoardCofferCount = floor.HoardCount;
@ -83,6 +83,11 @@ namespace Pal.Client.Windows
public string TerritoryName { get; set; }
public uint? TrapCount { get; set; }
public uint? HoardCofferCount { get; set; }
public TerritoryStatistics(string territoryName)
{
TerritoryName = territoryName;
}
}
}
}