Skip to content

Commit

Permalink
fix warnings
Browse files Browse the repository at this point in the history
(from no IDE in particular)
  • Loading branch information
Govorunb committed Jul 14, 2024
1 parent 586ddc6 commit e7978b1
Show file tree
Hide file tree
Showing 48 changed files with 98 additions and 124 deletions.
8 changes: 4 additions & 4 deletions Immersion/Trackers/Backseating.cs
Original file line number Diff line number Diff line change
Expand Up @@ -95,15 +95,15 @@ private void UpdateBaseGameAlerts()
CoroutineHost.StartCoroutine(ToggleHypothermiaAlerts(!enabled));
}

private void ToggleSurvivalAlerts(bool enabled)
private void ToggleSurvivalAlerts(bool enable)
{
SurvivalAlertPatches.EnableSurvivalAlerts = enabled;
SurvivalAlertPatches.EnableSurvivalAlerts = enable;
}
private IEnumerator ToggleHypothermiaAlerts(bool enabled)
private IEnumerator ToggleHypothermiaAlerts(bool enable)
{
yield return new WaitUntil(() => bodyTemp);
PDANotification notif = bodyTemp.hypothermiaWarningNotification;
notif.nextPlayTime = enabled ? 0 : float.PositiveInfinity;
notif.nextPlayTime = enable ? 0 : float.PositiveInfinity;
}

public void FixedUpdate()
Expand Down
8 changes: 4 additions & 4 deletions Immersion/Trackers/JukeboxTrackUnlocked.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,17 +5,17 @@ namespace Immersion.Trackers;
[HarmonyPatch]
public sealed class JukeboxTrackUnlocked : Tracker
{
internal static HashSet<string> _allowlist = new(StringComparer.InvariantCultureIgnoreCase)
internal static readonly HashSet<string> _allowlist = new(StringComparer.InvariantCultureIgnoreCase)
{
"truckersfm"
};

internal void NotifyUnlocked(Jukebox.UnlockableTrack track)
{
if (!Jukebox.unlockableMusic.TryGetValue(track, out string name)) return;
if (!_allowlist.Contains(name)) return;
if (!Jukebox.unlockableMusic.TryGetValue(track, out string trackId)) return;
if (!_allowlist.Contains(trackId)) return;

React(Priority.Low, Format.FormatPlayer($"{{player}} has unlocked a new jukebox track: {Jukebox.GetInfo(name).label}"));
React(Priority.Low, Format.FormatPlayer($"{{player}} has unlocked a new jukebox track: {Jukebox.GetInfo(trackId).label}"));
}

[HarmonyPatch(typeof(Jukebox), nameof(Jukebox.OnUnlock))]
Expand Down
4 changes: 2 additions & 2 deletions Immersion/Trackers/NewScans.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,8 @@ public void OnScanned(PDAScanner.Entry entry)

internal void NotifyScanned(TechType techType)
{
string name = Language.main.TryGet(techType, out string nameMaybe) ? nameMaybe : Format.ToTitleCase(techType);
string message = Format.FormatPlayer($"{{player}} has discovered a new creature: {name}.");
string techName = Language.main.TryGet(techType, out string nameMaybe) ? nameMaybe : Format.ToTitleCase(techType);
string message = Format.FormatPlayer($"{{player}} has discovered a new creature: {techName}.");

string encyKey = PDAScanner.GetEntryData(techType).encyclopedia;
if (!PDAEncyclopedia.GetEntryData(encyKey, out PDAEncyclopedia.EntryData data)) return;
Expand Down
4 changes: 2 additions & 2 deletions Immersion/Trackers/StoryGoals.Descriptions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,12 @@ namespace Immersion.Trackers;

partial class StoryGoals
{
private record class Description(string Message, bool IsImportant = false)
private record Description(string Message, bool IsImportant = false)
{
public Priority Priority => IsImportant ? Priority.High : Priority.Low;
public static implicit operator Description(string Message) => new(Message);
}
private static Dictionary<string, Description> StoryGoalDescriptions = new(StoryGoal.KeyComparer)
private static readonly Dictionary<string, Description> StoryGoalDescriptions = new(StoryGoal.KeyComparer)
{
// sorted roughly in story order

Expand Down
2 changes: 1 addition & 1 deletion Immersion/Trackers/Tracker.cs
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ protected internal enum Priority
public static bool ForceLowPriority
{
get => PlayerPrefsExtra.GetBool(forceLowPrioPrefsKey, false);
set => PlayerPrefsExtra.SetBool(forceLowPrioPrefsKey, false);
set => PlayerPrefsExtra.SetBool(forceLowPrioPrefsKey, value);
}
private string startEnabledPrefsKey => $"{GetType().FullName}_Enabled";
internal bool startEnabled
Expand Down
2 changes: 2 additions & 0 deletions SCHIZO/Commands/Attributes/CommandAttribute.cs
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
using System;
using JetBrains.Annotations;

namespace SCHIZO.Commands.Attributes;

[AttributeUsage(AttributeTargets.Class | AttributeTargets.Method)]
[MeansImplicitUse]
public class CommandAttribute : Attribute
{
public required string Name { get; set; }
Expand Down
8 changes: 4 additions & 4 deletions SCHIZO/Commands/Base/MethodCommand.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,15 +14,15 @@ internal class MethodCommand : Command, IParameters
private readonly MethodInfo _method;
private readonly object? _instance;
private readonly bool _lastTakeAll;
public IReadOnlyList<Parameter> Parameters { get; protected set; } = [];
public IReadOnlyList<Parameter> Parameters { get; protected set; }

public MethodCommand(MethodInfo method, object? instance = null)
{
if (method.IsStatic && instance is { })
throw new ArgumentException("Static method does not need instance");
else if (!method.IsStatic && instance is null)
if (!method.IsStatic && instance is null)
throw new ArgumentException("Non-static method needs instance");
else if (method.Name.IndexOf('>') >= 0) // mangled (delegate, lambda, inner function, etc...)
if (method.Name.IndexOf('>') >= 0) // mangled (delegate, lambda, inner function, etc...)
throw new ArgumentException($"Use {nameof(DelegateCommand)} instead of {nameof(MethodCommand)} for delegate methods (lambda, inner function, etc.)");
_method = method;
_instance = instance;
Expand Down Expand Up @@ -105,7 +105,7 @@ internal static ArgParseResult TryParseNamedArgs(Dictionary<string, object?>? ar
return new(consumed == args.Count, parsed == parameters.Count, parsedArgs);
}

internal static ArgParseResult TryParsePositionalArgs(IReadOnlyList<string> args, IReadOnlyList<Parameter> parameters, bool lastTakeAll = false)
internal static ArgParseResult TryParsePositionalArgs(IReadOnlyList<string>? args, IReadOnlyList<Parameter> parameters, bool lastTakeAll = false)
{
if (args is null)
return new(true, parameters.All(p => p.IsOptional), []);
Expand Down
1 change: 1 addition & 0 deletions SCHIZO/Commands/Base/NautilusCommandWrapper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ public static NautilusCommandWrapper Register(Command command)
}
NautilusCommandWrapper wrapper = new(command);
wrapper.RegisterWithNautilus();
_registered[command.Name] = wrapper;
return wrapper;
}

Expand Down
4 changes: 2 additions & 2 deletions SCHIZO/Commands/DevCommands.cs
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ public static object PrintField(string typeName, string memberName)
Type type = ReflectionCache.GetType(typeName);
if (type is null) return $"Could not find type '{typeName}'";
MemberInfo[] member = type.GetMember(memberName, BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Static);
if (member is null) return $"Could not find '{memberName}' in type '{typeName}' (must be static)";
if (member.Length == 0) return $"Could not find '{memberName}' in type '{typeName}' (must be static)";
return ReflectionHelpers.GetStaticMemberValue<object>(member.Single());
}

Expand All @@ -111,7 +111,7 @@ public static object SetField(string typeName, string memberName, string valueSt
{
Type type = ReflectionCache.GetType(typeName);
if (type is null) return $"Could not find type '{typeName}'";
MemberInfo member = type.GetMember(memberName, BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Static).Single();
MemberInfo member = type.GetMember(memberName, BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Static).SingleOrDefault();
if (member is null) return $"Could not find '{memberName}' in type '{typeName}' (must be static)";
Type memberType = member switch
{
Expand Down
6 changes: 3 additions & 3 deletions SCHIZO/Commands/Input/Conversion.cs
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ public static bool TryParseOrConvert<T>(object? val, [MaybeNullWhen(false)] out
return false;
}

public static bool TryParseOrConvert(object? val, Type type, [MaybeNullWhen(false)] out object? value)
public static bool TryParseOrConvert(object? val, Type type, out object? value)
{
value = default;
if (type.IsEnum)
Expand All @@ -27,7 +27,7 @@ public static bool TryParseOrConvert(object? val, Type type, [MaybeNullWhen(fals
}
if (val is null)
return false;
if (type.IsAssignableFrom(val.GetType()))
if (type.IsInstanceOfType(val))
{
value = val;
return true;
Expand Down Expand Up @@ -64,7 +64,7 @@ public static bool TryParseEnum<TEnum>(object? val, [MaybeNullWhen(false)] out T
return false;
}

public static bool TryParseEnum(object? val, Type type, [MaybeNullWhen(false)] out object? value)
public static bool TryParseEnum(object? val, Type type, out object? value)
{
value = default;
if (val is null)
Expand Down
2 changes: 1 addition & 1 deletion SCHIZO/Commands/Input/JsonInputModel.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
using System;
using System.Collections.Generic;
using SwarmControl.Models.Game.Messages;
using SCHIZO.SwarmControl.Models.Game.Messages;

namespace SCHIZO.Commands.Input;

Expand Down
6 changes: 3 additions & 3 deletions SCHIZO/Commands/Input/RemoteInput.cs
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
using System.Collections.Generic;
using System.Linq;
using SwarmControl.Models.Game.Messages;
using SCHIZO.Commands.Base;
using SCHIZO.Helpers;
using SCHIZO.SwarmControl.Models.Game.Messages;

namespace SCHIZO.Commands.Input;

Expand All @@ -12,7 +12,7 @@ public class RemoteInput : CommandInput
public required RedeemMessage Model { get; init; }

public override string GetSubCommandName()
=> Model.Command.Split([' '], 3).ElementAtOrDefault(1);
=> Model.Command.Split([' '], 3).ElementAtOrDefault(1) ?? "";

public override IEnumerable<object?> GetPositionalArguments()
{
Expand All @@ -31,7 +31,7 @@ public override string GetSubCommandName()
public override NamedArgs GetNamedArguments() => new(Model.Args ?? []);

public override CommandInput GetSubCommandInput(Command subCommand)
=> new RemoteInput()
=> new RemoteInput
{
Command = subCommand,
Model = Model with { Command = Model.Command.SplitOnce(' ').After }
Expand Down
2 changes: 1 addition & 1 deletion SCHIZO/Commands/Input/Vector3Converter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ public override bool CanConvertTo(ITypeDescriptorContext context, Type destinati
return destinationType == typeof(Vector3);
}

public override object ConvertFrom(ITypeDescriptorContext context, CultureInfo culture, object value)
public override object ConvertFrom(ITypeDescriptorContext context, CultureInfo culture, object? value)
{
if (value is string[] arr && TryConvertStringArray(arr, out Vector3 v))
return v;
Expand Down
3 changes: 1 addition & 2 deletions SCHIZO/DataStructures/SavedRandomList.cs
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,7 @@ public bool Register(IdentifiableItem item)
{
string identifier = item.Identifier;

if (_identifiers.Contains(identifier)) throw new InvalidOperationException($"Duplicate identifier: {identifier}");
_identifiers.Add(identifier);
if (!_identifiers.Add(identifier)) throw new InvalidOperationException($"Duplicate identifier: {identifier}");

// possible gotcha to look out for: PlayerPrefsExtra stores some values like Vectors in multiple keys, so HasKey might return false even if the keys exist
// not the case for booleans though
Expand Down
19 changes: 9 additions & 10 deletions SCHIZO/Events/ErmfishDefenseForce/ErmfishDefenseForce.cs
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ protected override void Start()
{
instance = this;

_techTypes = new(protectedSpecies.Select(data => (TechType)data.ModItem));
_techTypes = [..protectedSpecies.Select(data => (TechType) data.ModItem)];
ActiveDefenders = [];
}

Expand Down Expand Up @@ -200,8 +200,8 @@ private IEnumerator SpawnDefenderGroup(Defender defender)
if (blockingHit.point != default)
spawnPos = blockingHit.point + blockingHit.normal * 0.1f;

GameObject instance = GameObject.Instantiate(prefab);
instance.transform.position = spawnPos;
GameObject spawnInstance = GameObject.Instantiate(prefab);
spawnInstance.transform.position = spawnPos;
if (debugSpawns)
{
if (blockingHit.point != default)
Expand All @@ -211,13 +211,13 @@ private IEnumerator SpawnDefenderGroup(Defender defender)
spawnMarker.transform.position = spawnPos;
Destroy(spawnMarker, 10f);
}
instance.transform.LookAt(player.transform);
spawnInstance.transform.LookAt(player.transform);

ActiveDefenders.Add(instance);
ActiveDefenders.Add(spawnInstance);
spawned++;

// don't save
LargeWorldEntity lwe = instance.GetComponent<LargeWorldEntity>();
LargeWorldEntity lwe = spawnInstance.GetComponent<LargeWorldEntity>();
if (lwe) LargeWorldStreamer.main.cellManager.UnregisterEntity(lwe);
}
if (debugSpawns) LOGGER.LogDebug($"(EDF) spawned {spawned} {defender.ClassId}");
Expand All @@ -226,12 +226,11 @@ private IEnumerator SpawnDefenderGroup(Defender defender)

private bool CanSpawn()
{
bool canSpawn;
canSpawn = player && !player.currentSub
bool canSpawn = player && !player.currentSub
#if BELOWZERO
&& player.currentInterior is null // don't spawn indoors
&& player.currentInterior is null // don't spawn indoors
#endif
&& player.IsUnderwaterForSwimming(); // there are no land kill squads... yet
&& player.IsUnderwaterForSwimming(); // there are no land kill squads... yet
return canSpawn;
}

Expand Down
6 changes: 2 additions & 4 deletions SCHIZO/Helpers/ObjectHelpers.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,7 @@ public static bool Exists(this object obj)
public static T Or<T>(this T obj, T other)
where T : UnityEngine.Object
{
if (obj) return obj;
return other;
return obj ? obj : other;
}

/// <summary>
Expand All @@ -25,7 +24,6 @@ public static T Or<T>(this T obj, T other)
public static T Or<T>(this T obj, Func<T> other)
where T : UnityEngine.Object
{
if (obj) return obj;
return other();
return obj ? obj : other();
}
}
2 changes: 1 addition & 1 deletion SCHIZO/Helpers/StringHelpers.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ public static (string Before, string After) SplitOnce(this string src, char deli
// splitting w/o span makes me want to take up woodworking
int split = src.IndexOf(delimiter);

if (split is < 0 || split == src.Length - 1)
if (split < 0 || split == src.Length - 1)
return (src, "");

return (src[..split], src[(split + 1)..]);
Expand Down
3 changes: 1 addition & 2 deletions SCHIZO/Items/ModItem.cs
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,7 @@ public ModItem(ItemData data)
{
LOGGER.LogDebug("Creating ModItem " + data.classId + " with name " + data.displayName);

if (_registeredItems.Contains(data.classId)) throw new Exception("Item with classId " + data.classId + " has already been created!");
_registeredItems.Add(data.classId);
if (!_registeredItems.Add(data.classId)) throw new Exception("Item with classId " + data.classId + " has already been created!");

if (data.ModItem != null) throw new Exception("ItemData with classId " + data.classId + " has already been created!");
data.ModItem = this;
Expand Down
8 changes: 4 additions & 4 deletions SCHIZO/SwarmControl/ControlWebSocket.Plumbing.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@
using System.Threading.Tasks;
using Newtonsoft.Json;
using SCHIZO.Helpers;
using SwarmControl.Models.Game.Messages;
using SCHIZO.Commands.Input;
using SCHIZO.SwarmControl.Models.Game.Messages;

namespace SCHIZO.SwarmControl;

Expand Down Expand Up @@ -77,7 +77,7 @@ private async Task SendThread()
LOGGER.LogWarning($"Re-queueing {msg.GetType().Name} ({msg.Guid})");
_sendQueue.Enqueue(msg);
}
if (e is WebSocketException we)
if (e is WebSocketException)
{
_socket.Dispose();
OnClose?.Invoke((WebSocketCloseStatus)1006, null);
Expand Down Expand Up @@ -144,12 +144,12 @@ public void SendMessage(GameMessage message)

ArraySegment<byte> buffer = new(rent.Array);
WebSocketReceiveResult? result = null;
int totalBytes = 0;
// int totalBytes = 0;
while (result is not { EndOfMessage: true })
{
result = await _socket.ReceiveAsync(buffer, killSocketCt);
ms.Write(buffer.Array, 0, result.Count);
totalBytes += result.Count;
// totalBytes += result.Count;
}
// LOGGER.LogDebug($"Received {result.MessageType} ({totalBytes} bytes)");
switch (result.MessageType)
Expand Down
6 changes: 4 additions & 2 deletions SCHIZO/SwarmControl/ControlWebSocket.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
using System.Net.WebSockets;
using System.Threading;
using System.Threading.Tasks;
using SwarmControl.Models.Game.Messages;
using SCHIZO.SwarmControl.Models.Game.Messages;

namespace SCHIZO.SwarmControl;

Expand Down Expand Up @@ -52,7 +52,9 @@ then enter "{SwarmControlManager.COMMAND_URL} <backend url>"
{
int timeout = BaseUri.IsLoopback ? 1 : 5;

using HttpClient client = new() { BaseAddress = BaseUri, Timeout = TimeSpan.FromSeconds(timeout) };
using HttpClient client = new();
client.BaseAddress = BaseUri;
client.Timeout = TimeSpan.FromSeconds(timeout);
HttpRequestMessage request = new(HttpMethod.Options, "/");
await client.SendAsync(request, ct);
}
Expand Down
Loading

0 comments on commit e7978b1

Please sign in to comment.