From 18a520bc780a54eeb1c5e01879426b0cbb2fe5de Mon Sep 17 00:00:00 2001 From: AmazingAlek Date: Tue, 28 Jul 2020 15:59:24 +0200 Subject: [PATCH] cleanup (#99) * cleanup --- QSB/Animation/QSBFlashlight.cs | 45 +++++++++---------- QSB/DebugActions.cs | 16 +++---- QSB/DebugLog.cs | 4 +- QSB/Events/EventHandler.cs | 40 ++++++++--------- QSB/Events/EventListener.cs | 7 +-- QSB/Events/EventMessage.cs | 4 +- QSB/Events/EventType.cs | 7 +-- QSB/Events/FullStateMessage.cs | 5 +-- QSB/Events/FullStateRequest.cs | 1 - QSB/Events/GameState.cs | 13 ++---- QSB/Events/PlayerJoin.cs | 1 - QSB/Events/PlayerLeave.cs | 1 - QSB/Events/StateRequestMessage.cs | 14 +----- QSB/PlayerInfo.cs | 15 +++++++ QSB/PlayerRegistry.cs | 57 +++++++----------------- QSB/QSB.cs | 1 - QSB/QSB.csproj | 2 + QSB/QSBNetworkManager.cs | 10 ++--- QSB/State.cs | 14 ++++++ QSB/TimeSync/PreventShipDestruction.cs | 5 ++- QSB/TimeSync/RespawnOnDeath.cs | 6 +-- QSB/TimeSync/WakeUpSync.cs | 12 +++-- QSB/TransformSync/PlayerCameraSync.cs | 8 +--- QSB/TransformSync/PlayerHUDMarker.cs | 22 ++++----- QSB/TransformSync/PlayerTransformSync.cs | 8 +--- QSB/TransformSync/SectorSync.cs | 16 +++---- QSB/Utility/FlagsHelper.cs | 19 +++----- QSB/Utility/PlayerToolsManager.cs | 2 +- 28 files changed, 147 insertions(+), 208 deletions(-) create mode 100644 QSB/PlayerInfo.cs create mode 100644 QSB/State.cs diff --git a/QSB/Animation/QSBFlashlight.cs b/QSB/Animation/QSBFlashlight.cs index b2f18578..18b63117 100644 --- a/QSB/Animation/QSBFlashlight.cs +++ b/QSB/Animation/QSBFlashlight.cs @@ -1,8 +1,4 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using UnityEngine; +using UnityEngine; namespace QSB.Animation { @@ -13,6 +9,7 @@ namespace QSB.Animation public Transform _root; public Transform _basePivot; public Transform _wobblePivot; + private bool _flashlightOn; private Vector3 _baseForward; private Quaternion _baseRotation; @@ -25,36 +22,38 @@ namespace QSB.Animation public void TurnOn() { - if (!_flashlightOn) + if (_flashlightOn) { - for (int i = 0; i < _lights.Length; i++) - { - _lights[i].GetLight().enabled = true; - } - _flashlightOn = true; - Quaternion rotation = _root.rotation; - _basePivot.rotation = rotation; - _baseRotation = rotation; - _baseForward = _basePivot.forward; + return; } + foreach (var light in _lights) + { + light.GetLight().enabled = true; + } + _flashlightOn = true; + var rotation = _root.rotation; + _basePivot.rotation = rotation; + _baseRotation = rotation; + _baseForward = _basePivot.forward; } public void TurnOff() { - if (_flashlightOn) + if (!_flashlightOn) { - for (int i = 0; i < _lights.Length; i++) - { - _lights[i].GetLight().enabled = false; - } - _flashlightOn = false; + return; } + foreach (var light in _lights) + { + light.GetLight().enabled = false; + } + _flashlightOn = false; } private void FixedUpdate() { - Quaternion lhs = Quaternion.FromToRotation(_basePivot.up, _root.up) * Quaternion.FromToRotation(_baseForward, _root.forward); - Quaternion b = lhs * _baseRotation; + var lhs = Quaternion.FromToRotation(_basePivot.up, _root.up) * Quaternion.FromToRotation(_baseForward, _root.forward); + var b = lhs * _baseRotation; _baseRotation = Quaternion.Slerp(_baseRotation, b, 6f * Time.deltaTime); _basePivot.rotation = _baseRotation; _baseForward = _basePivot.forward; diff --git a/QSB/DebugActions.cs b/QSB/DebugActions.cs index fd59fb8a..321b4d5f 100644 --- a/QSB/DebugActions.cs +++ b/QSB/DebugActions.cs @@ -1,23 +1,19 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using UnityEngine; +using UnityEngine; namespace QSB { - class DebugActions : MonoBehaviour + public class DebugActions : MonoBehaviour { - void GoToVessel() + private void GoToVessel() { var spawnPoint = GameObject.Find("Spawn_Vessel").GetComponent(); - OWRigidbody playerBody = Locator.GetPlayerBody(); + var playerBody = Locator.GetPlayerBody(); playerBody.WarpToPositionRotation(spawnPoint.transform.position, spawnPoint.transform.rotation); playerBody.SetVelocity(spawnPoint.GetPointVelocity()); } - void InsertWarpCore() + private void InsertWarpCore() { var warpCore = GameObject.Find("Prefab_NOM_WarpCoreVessel").GetComponent(); var socket = GameObject.Find("Interactibles_VesselBridge").GetComponentInChildren(); @@ -26,7 +22,7 @@ namespace QSB GetComponent().SetPillarRaised(true, true); } - void Update() + private void Update() { if (!QSB.DebugMode) { diff --git a/QSB/DebugLog.cs b/QSB/DebugLog.cs index e0e3f80d..508d6ad3 100644 --- a/QSB/DebugLog.cs +++ b/QSB/DebugLog.cs @@ -62,8 +62,8 @@ namespace QSB //ToConsole("* " + JoinAll(logObjects)); return; } - var data = new NotificationData(NotificationTarget.Player, JoinAll(logObjects), 5f, true); - NotificationManager.SharedInstance.PostNotification(data, false); + var data = new NotificationData(NotificationTarget.Player, JoinAll(logObjects)); + NotificationManager.SharedInstance.PostNotification(data); } public static void ToAll(params object[] logObjects) diff --git a/QSB/Events/EventHandler.cs b/QSB/Events/EventHandler.cs index 5407af6e..6591b893 100644 --- a/QSB/Events/EventHandler.cs +++ b/QSB/Events/EventHandler.cs @@ -1,7 +1,4 @@ using System.Collections; -using System.Collections.Generic; -using OWML.ModHelper.Events; -using QSB.Animation; using QSB.Messaging; using QSB.TransformSync; using UnityEngine; @@ -47,25 +44,26 @@ namespace QSB.Events private void OnClientReceiveMessage(EventMessage message) { - if (message.SenderId != PlayerTransformSync.LocalInstance.netId.Value) + if (message.SenderId == PlayerTransformSync.LocalInstance.netId.Value) { - switch ((EventType)message.EventType) - { - case EventType.TurnOnFlashlight: - PlayerRegistry.GetPlayerFlashlight(message.SenderId).TurnOn(); - PlayerRegistry.UpdateState(message.SenderId, State.Flashlight, true); - break; - case EventType.TurnOffFlashlight: - PlayerRegistry.GetPlayerFlashlight(message.SenderId).TurnOff(); - PlayerRegistry.UpdateState(message.SenderId, State.Flashlight, false); - break; - case EventType.SuitUp: - PlayerRegistry.UpdateState(message.SenderId, State.Suit, true); - break; - case EventType.RemoveSuit: - PlayerRegistry.UpdateState(message.SenderId, State.Suit, false); - break; - } + return; + } + switch ((EventType)message.EventType) + { + case EventType.TurnOnFlashlight: + PlayerRegistry.GetPlayerFlashlight(message.SenderId).TurnOn(); + PlayerRegistry.UpdateState(message.SenderId, State.Flashlight, true); + break; + case EventType.TurnOffFlashlight: + PlayerRegistry.GetPlayerFlashlight(message.SenderId).TurnOff(); + PlayerRegistry.UpdateState(message.SenderId, State.Flashlight, false); + break; + case EventType.SuitUp: + PlayerRegistry.UpdateState(message.SenderId, State.Suit, true); + break; + case EventType.RemoveSuit: + PlayerRegistry.UpdateState(message.SenderId, State.Suit, false); + break; } } } diff --git a/QSB/Events/EventListener.cs b/QSB/Events/EventListener.cs index a0070ff5..6f7b2623 100644 --- a/QSB/Events/EventListener.cs +++ b/QSB/Events/EventListener.cs @@ -1,16 +1,13 @@ using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; using UnityEngine; namespace QSB.Events { - class EventListener : MonoBehaviour + public class EventListener : MonoBehaviour { public static EventListener LocalInstance; - void Awake() + private void Awake() { LocalInstance = this; foreach (var item in Enum.GetNames(typeof(EventType))) diff --git a/QSB/Events/EventMessage.cs b/QSB/Events/EventMessage.cs index 55dbf9de..c658e973 100644 --- a/QSB/Events/EventMessage.cs +++ b/QSB/Events/EventMessage.cs @@ -1,6 +1,4 @@ -using System; -using System.Linq; -using QSB.Messaging; +using QSB.Messaging; using UnityEngine.Networking; namespace QSB.Events diff --git a/QSB/Events/EventType.cs b/QSB/Events/EventType.cs index 91ef26ab..4a97518a 100644 --- a/QSB/Events/EventType.cs +++ b/QSB/Events/EventType.cs @@ -1,9 +1,4 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; - -namespace QSB.Events +namespace QSB.Events { public enum EventType { diff --git a/QSB/Events/FullStateMessage.cs b/QSB/Events/FullStateMessage.cs index 104405ef..b4e3b031 100644 --- a/QSB/Events/FullStateMessage.cs +++ b/QSB/Events/FullStateMessage.cs @@ -1,7 +1,4 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using QSB.Messaging; +using QSB.Messaging; using UnityEngine.Networking; namespace QSB.Events diff --git a/QSB/Events/FullStateRequest.cs b/QSB/Events/FullStateRequest.cs index 7502487d..c5bb1960 100644 --- a/QSB/Events/FullStateRequest.cs +++ b/QSB/Events/FullStateRequest.cs @@ -1,5 +1,4 @@ using System.Collections; -using System.Collections.Generic; using QSB.Messaging; using QSB.TransformSync; using UnityEngine; diff --git a/QSB/Events/GameState.cs b/QSB/Events/GameState.cs index 8441f028..1a1398e6 100644 --- a/QSB/Events/GameState.cs +++ b/QSB/Events/GameState.cs @@ -1,13 +1,9 @@ -using System.Collections; -using System.Collections.Generic; -using QSB.Messaging; -using QSB.TransformSync; -using UnityEngine; +using QSB.Messaging; using UnityEngine.Networking; namespace QSB.Events { - class GameState : NetworkBehaviour + public class GameState : NetworkBehaviour { public static GameState LocalInstance { get; private set; } @@ -28,10 +24,9 @@ namespace QSB.Events public void Send() { - - foreach (var player in PlayerRegistry.GetPlayers()) + foreach (var player in PlayerRegistry.PlayerList) { - var message = new FullStateMessage() + var message = new FullStateMessage { PlayerName = player.Name, SenderId = player.NetId diff --git a/QSB/Events/PlayerJoin.cs b/QSB/Events/PlayerJoin.cs index 59bf379c..1a551841 100644 --- a/QSB/Events/PlayerJoin.cs +++ b/QSB/Events/PlayerJoin.cs @@ -1,5 +1,4 @@ using System.Collections; -using System.Collections.Generic; using QSB.Messaging; using QSB.TransformSync; using UnityEngine; diff --git a/QSB/Events/PlayerLeave.cs b/QSB/Events/PlayerLeave.cs index 7b6be6de..6d503363 100644 --- a/QSB/Events/PlayerLeave.cs +++ b/QSB/Events/PlayerLeave.cs @@ -1,6 +1,5 @@ using System.Linq; using QSB.Messaging; -using QSB.TransformSync; using UnityEngine; using UnityEngine.Networking; diff --git a/QSB/Events/StateRequestMessage.cs b/QSB/Events/StateRequestMessage.cs index b392864c..fd4138bc 100644 --- a/QSB/Events/StateRequestMessage.cs +++ b/QSB/Events/StateRequestMessage.cs @@ -1,21 +1,9 @@ -using System; -using System.Linq; -using QSB.Messaging; -using UnityEngine.Networking; +using QSB.Messaging; namespace QSB.Events { public class StateRequestMessage : PlayerMessage { public override MessageType MessageType => MessageType.FullStateRequest; - public override void Deserialize(NetworkReader reader) - { - base.Deserialize(reader); - } - - public override void Serialize(NetworkWriter writer) - { - base.Serialize(writer); - } } } diff --git a/QSB/PlayerInfo.cs b/QSB/PlayerInfo.cs new file mode 100644 index 00000000..e8c0f902 --- /dev/null +++ b/QSB/PlayerInfo.cs @@ -0,0 +1,15 @@ +using UnityEngine; + +namespace QSB +{ + public class PlayerInfo + { + public uint NetId { get; set; } + public GameObject Body { get; set; } + public GameObject Camera { get; set; } + public string Name { get; set; } + public bool Ready { get; set; } + public Transform ReferenceSector { get; set; } + public State State { get; set; } + } +} \ No newline at end of file diff --git a/QSB/PlayerRegistry.cs b/QSB/PlayerRegistry.cs index 3d529d34..21054c75 100644 --- a/QSB/PlayerRegistry.cs +++ b/QSB/PlayerRegistry.cs @@ -1,8 +1,6 @@ -using Newtonsoft.Json; -using QSB.Animation; +using QSB.Animation; using QSB.Events; using QSB.Utility; -using System; using System.Collections.Generic; using System.Linq; using UnityEngine; @@ -11,12 +9,7 @@ namespace QSB { public static class PlayerRegistry { - private static readonly List playerList = new List(); - - public static List GetPlayers() - { - return playerList; - } + public static List PlayerList { get; } = new List(); public static void RegisterPlayerBody(uint id, GameObject body) { @@ -26,21 +19,22 @@ namespace QSB public static bool PlayerExists(uint id) { - return playerList.Any(x => x.NetId == id); + return PlayerList.Any(x => x.NetId == id); } public static void CreatePlayer(uint id, string name) { - if (!PlayerExists(id)) + if (PlayerExists(id)) { - DebugLog.ToConsole($"Creating player: {id}"); - var player = new PlayerInfo() - { - NetId = id, - Name = name - }; - playerList.Add(player); + return; } + DebugLog.ToConsole($"Creating player: {id}"); + var player = new PlayerInfo + { + NetId = id, + Name = name + }; + PlayerList.Add(player); } public static void RegisterPlayerCamera(uint id, GameObject camera) @@ -52,12 +46,12 @@ namespace QSB public static void RemovePlayer(uint id) { DebugLog.ToConsole($"Removing player {id}"); - playerList.Remove(playerList.Find(x => x.NetId == id)); + PlayerList.Remove(PlayerList.Find(x => x.NetId == id)); } private static PlayerInfo GetPlayer(uint id) { - return playerList.Find(x => x.NetId == id); + return PlayerList.Find(x => x.NetId == id); } public static GameObject GetPlayerCamera(uint id) @@ -95,7 +89,7 @@ namespace QSB public static Dictionary GetPlayerNames() { var dict = new Dictionary(); - playerList.ForEach(x => dict.Add(x.NetId, x.Name)); + PlayerList.ForEach(x => dict.Add(x.NetId, x.Name)); return dict; } @@ -139,25 +133,4 @@ namespace QSB return FlagsHelper.IsSet(states, state); } } - - public class PlayerInfo - { - public uint NetId { get; set; } - public GameObject Body { get; set; } - public GameObject Camera { get; set; } - public string Name { get; set; } - public bool Ready { get; set; } - public Transform ReferenceSector { get; set; } - public State State { get; set; } - } - - [Flags] - public enum State - { - Flashlight = 0, - Suit = 1, - ProbeLauncher = 2, - SignalScope = 4 - //Increment these in binary to add more states - } } diff --git a/QSB/QSB.cs b/QSB/QSB.cs index a3771e82..e01e959a 100644 --- a/QSB/QSB.cs +++ b/QSB/QSB.cs @@ -1,7 +1,6 @@ using OWML.Common; using OWML.ModHelper; using QSB.Events; -using QSB.TimeSync; using UnityEngine; using UnityEngine.Networking; diff --git a/QSB/QSB.csproj b/QSB/QSB.csproj index d6def64e..8cdc67a2 100644 --- a/QSB/QSB.csproj +++ b/QSB/QSB.csproj @@ -134,6 +134,8 @@ + + diff --git a/QSB/QSBNetworkManager.cs b/QSB/QSBNetworkManager.cs index 75be3ff4..b32e140f 100644 --- a/QSB/QSBNetworkManager.cs +++ b/QSB/QSBNetworkManager.cs @@ -14,7 +14,7 @@ namespace QSB public class QSBNetworkManager : NetworkManager { public static UnityEvent OnNetworkManagerReady = new UnityEvent(); - public static bool IsReady = false; + public static bool IsReady; private const int MaxConnections = 128; @@ -77,11 +77,9 @@ namespace QSB profileManager.Initialize(); var profile = profileManager.GetValue("_currentProfile"); var profileName = profile?.profileName; - if (!string.IsNullOrEmpty(profileName)) - { - return profileName; - } - return _defaultNames.OrderBy(x => Guid.NewGuid()).First(); + return !string.IsNullOrEmpty(profileName) + ? profileName + : _defaultNames.OrderBy(x => Guid.NewGuid()).First(); } private void ConfigureNetworkManager() diff --git a/QSB/State.cs b/QSB/State.cs new file mode 100644 index 00000000..19a52233 --- /dev/null +++ b/QSB/State.cs @@ -0,0 +1,14 @@ +using System; + +namespace QSB +{ + [Flags] + public enum State + { + Flashlight = 0, + Suit = 1, + ProbeLauncher = 2, + SignalScope = 4 + //Increment these in binary to add more states + } +} \ No newline at end of file diff --git a/QSB/TimeSync/PreventShipDestruction.cs b/QSB/TimeSync/PreventShipDestruction.cs index cfc8469f..25526a31 100644 --- a/QSB/TimeSync/PreventShipDestruction.cs +++ b/QSB/TimeSync/PreventShipDestruction.cs @@ -21,9 +21,10 @@ namespace QSB.TimeSync private void OnEvent(MonoBehaviour behaviour, OWML.Common.Events ev) { - if (behaviour.GetType() == typeof(ShipDamageController) && ev == OWML.Common.Events.AfterAwake) + if (behaviour is ShipDamageController shipDamageController && + ev == OWML.Common.Events.AfterAwake) { - behaviour.SetValue("_exploded", true); + shipDamageController.SetValue("_exploded", true); } } diff --git a/QSB/TimeSync/RespawnOnDeath.cs b/QSB/TimeSync/RespawnOnDeath.cs index 827c9723..4e17d69b 100644 --- a/QSB/TimeSync/RespawnOnDeath.cs +++ b/QSB/TimeSync/RespawnOnDeath.cs @@ -14,7 +14,7 @@ namespace QSB.TimeSync { private static RespawnOnDeath _instance; - private static readonly DeathType[] _allowedDeathTypes = { + private static readonly DeathType[] AllowedDeathTypes = { DeathType.BigBang, DeathType.Supernova, DeathType.TimeLoop @@ -45,7 +45,7 @@ namespace QSB.TimeSync private void OnEvent(MonoBehaviour behaviour, OWML.Common.Events ev) { - if (behaviour.GetType() == typeof(PlayerResources) && ev == OWML.Common.Events.AfterStart) + if (behaviour is PlayerResources && ev == OWML.Common.Events.AfterStart) { Init(); } @@ -156,7 +156,7 @@ namespace QSB.TimeSync { public static bool PreFinishDeathSequence(DeathType deathType) { - if (_allowedDeathTypes.Contains(deathType)) + if (AllowedDeathTypes.Contains(deathType)) { // Allow real death return true; diff --git a/QSB/TimeSync/WakeUpSync.cs b/QSB/TimeSync/WakeUpSync.cs index 8945e886..3ba79e54 100644 --- a/QSB/TimeSync/WakeUpSync.cs +++ b/QSB/TimeSync/WakeUpSync.cs @@ -1,5 +1,4 @@ -using OWML.ModHelper.Events; -using QSB.Messaging; +using QSB.Messaging; using UnityEngine; using UnityEngine.Networking; using UnityEngine.SceneManagement; @@ -123,12 +122,11 @@ namespace QSB.TimeSync if (diff < -TimeThreshold) { - StartFastForwarding(diff); - return; + StartFastForwarding(); } } - private void StartFastForwarding(float diff) + private void StartFastForwarding() { if (_state == State.FastForwarding) { @@ -217,8 +215,8 @@ namespace QSB.TimeSync Time.timeScale = _timeScale; } - bool isDoneFastForwarding = _state == State.FastForwarding && Time.timeSinceLevelLoad >= _serverTime; - bool isDonePausing = _state == State.Pausing && Time.timeSinceLevelLoad < _serverTime; + var isDoneFastForwarding = _state == State.FastForwarding && Time.timeSinceLevelLoad >= _serverTime; + var isDonePausing = _state == State.Pausing && Time.timeSinceLevelLoad < _serverTime; if (isDoneFastForwarding || isDonePausing) { diff --git a/QSB/TransformSync/PlayerCameraSync.cs b/QSB/TransformSync/PlayerCameraSync.cs index 77c2894c..82acd3ce 100644 --- a/QSB/TransformSync/PlayerCameraSync.cs +++ b/QSB/TransformSync/PlayerCameraSync.cs @@ -1,8 +1,4 @@ -using OWML.ModHelper.Events; -using QSB.Animation; -using QSB.Events; -using QSB.Utility; -using System.Collections.Generic; +using QSB.Utility; using UnityEngine; namespace QSB.TransformSync @@ -16,7 +12,7 @@ namespace QSB.TransformSync LocalInstance = this; } - uint GetAttachedNetId() + private uint GetAttachedNetId() { /* Players are stored in PlayerRegistry using a specific ID. This ID has to remain the same diff --git a/QSB/TransformSync/PlayerHUDMarker.cs b/QSB/TransformSync/PlayerHUDMarker.cs index be003304..b1a379ff 100644 --- a/QSB/TransformSync/PlayerHUDMarker.cs +++ b/QSB/TransformSync/PlayerHUDMarker.cs @@ -1,13 +1,8 @@ -using QSB.Events; -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using UnityEngine; +using UnityEngine; namespace QSB.TransformSync { - class PlayerHUDMarker : HUDDistanceMarker + public class PlayerHUDMarker : HUDDistanceMarker { private uint _netId = uint.MaxValue; private bool _isReady; @@ -36,15 +31,16 @@ namespace QSB.TransformSync } } - void Update() + private void Update() { - if (_isReady && PlayerRegistry.IsPlayerReady(_netId)) + if (!_isReady || !PlayerRegistry.IsPlayerReady(_netId)) { - _markerLabel = PlayerRegistry.GetPlayerName(_netId); - _isReady = false; - - base.InitCanvasMarker(); + return; } + _markerLabel = PlayerRegistry.GetPlayerName(_netId); + _isReady = false; + + base.InitCanvasMarker(); } } } diff --git a/QSB/TransformSync/PlayerTransformSync.cs b/QSB/TransformSync/PlayerTransformSync.cs index cf10ecdb..a5464eb1 100644 --- a/QSB/TransformSync/PlayerTransformSync.cs +++ b/QSB/TransformSync/PlayerTransformSync.cs @@ -1,8 +1,4 @@ -using OWML.ModHelper.Events; -using QSB.Animation; -using QSB.Events; -using QSB.Utility; -using System.Collections.Generic; +using QSB.Animation; using UnityEngine; namespace QSB.TransformSync @@ -18,7 +14,7 @@ namespace QSB.TransformSync LocalInstance = this; } - uint GetAttachedNetId() + private uint GetAttachedNetId() { /* Players are stored in PlayerRegistry using a specific ID. This ID has to remain the same diff --git a/QSB/TransformSync/SectorSync.cs b/QSB/TransformSync/SectorSync.cs index d195a7fd..d3b8ad5d 100644 --- a/QSB/TransformSync/SectorSync.cs +++ b/QSB/TransformSync/SectorSync.cs @@ -1,5 +1,4 @@ -using System.Collections.Generic; -using QSB.Messaging; +using QSB.Messaging; using UnityEngine; using System.Linq; using UnityEngine.SceneManagement; @@ -12,6 +11,7 @@ namespace QSB.TransformSync private Sector[] _allSectors; private MessageHandler _sectorHandler; + private readonly Sector.Name[] _sectorWhitelist = { Sector.Name.BrambleDimension, Sector.Name.BrittleHollow, @@ -71,14 +71,10 @@ namespace QSB.TransformSync { _allSectors = FindObjectsOfType(); } - foreach (var sector in _allSectors) - { - if (sectorName == sector.GetName()) - { - return sector.transform; - } - } - return null; + return _allSectors + .Where(sector => sectorName == sector.GetName()) + .Select(sector => sector.transform) + .FirstOrDefault(); } private void OnClientReceiveMessage(SectorMessage message) diff --git a/QSB/Utility/FlagsHelper.cs b/QSB/Utility/FlagsHelper.cs index 9bbc7056..3b4e9315 100644 --- a/QSB/Utility/FlagsHelper.cs +++ b/QSB/Utility/FlagsHelper.cs @@ -1,9 +1,4 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; - -namespace QSB.Utility +namespace QSB.Utility { // Stolen from here : https://stackoverflow.com/questions/3261451/using-a-bitmask-in-c-sharp @@ -11,24 +6,24 @@ namespace QSB.Utility { public static bool IsSet(T flags, T flag) where T : struct { - int flagsValue = (int)(object)flags; - int flagValue = (int)(object)flag; + var flagsValue = (int)(object)flags; + var flagValue = (int)(object)flag; return (flagsValue & flagValue) != 0; } public static void Set(ref T flags, T flag) where T : struct { - int flagsValue = (int)(object)flags; - int flagValue = (int)(object)flag; + var flagsValue = (int)(object)flags; + var flagValue = (int)(object)flag; flags = (T)(object)(flagsValue | flagValue); } public static void Unset(ref T flags, T flag) where T : struct { - int flagsValue = (int)(object)flags; - int flagValue = (int)(object)flag; + var flagsValue = (int)(object)flags; + var flagValue = (int)(object)flag; flags = (T)(object)(flagsValue & (~flagValue)); } diff --git a/QSB/Utility/PlayerToolsManager.cs b/QSB/Utility/PlayerToolsManager.cs index c9ae7b56..2fc16374 100644 --- a/QSB/Utility/PlayerToolsManager.cs +++ b/QSB/Utility/PlayerToolsManager.cs @@ -4,7 +4,7 @@ using UnityEngine; namespace QSB.Utility { - class PlayerToolsManager + public class PlayerToolsManager { private static Transform _cameraBody; private static readonly Vector3 FlashlightOffset = new Vector3(0.7196316f, -0.2697681f, 0.3769455f);