Bladeren bron

Reformat part 7 use implicit operator bool

Use Unity object implicit bool for null checking instead.

Ideally, non unity objects would use is (not) null for null checks and
unity objects would just use the implicit operator.

I'm not sure if implicit operator bool should be used for assignment to
a bool variable (ie. bool a = someUnityObject;) because it can be
confusing to read.
habeebweeb 2 jaren geleden
bovenliggende
commit
eeadecadc6
25 gewijzigde bestanden met toevoegingen van 42 en 42 verwijderingen
  1. 3 3
      src/MeidoPhotoStudio.Converter/Converters/MMConverter.cs
  2. 2 2
      src/MeidoPhotoStudio.Converter/Converters/MMPngConverter.cs
  3. 1 1
      src/MeidoPhotoStudio.Converter/PluginCore.cs
  4. 2 2
      src/MeidoPhotoStudio.Plugin/Constants.cs
  5. 2 2
      src/MeidoPhotoStudio.Plugin/DragPoint/DragPoint.cs
  6. 2 2
      src/MeidoPhotoStudio.Plugin/DragPoint/DragPointGravity.cs
  7. 2 2
      src/MeidoPhotoStudio.Plugin/DragPoint/DragPointProp.cs
  8. 1 1
      src/MeidoPhotoStudio.Plugin/GUI/Panes/BackgroundWindow2Panes/MyRoomPropsPane.cs
  9. 1 1
      src/MeidoPhotoStudio.Plugin/GUI/Panes/BackgroundWindow2Panes/PropManagerPane.cs
  10. 1 1
      src/MeidoPhotoStudio.Plugin/GUI/Panes/CallWindowPanes/MaidSelectorPane.cs
  11. 1 1
      src/MeidoPhotoStudio.Plugin/GUI/Panes/MainWindowPanes/PoseWindowPane.cs
  12. 1 1
      src/MeidoPhotoStudio.Plugin/GUI/Windows/MainWindow.cs
  13. 1 1
      src/MeidoPhotoStudio.Plugin/Managers/EffectManagers/BloomEffectManager.cs
  14. 1 1
      src/MeidoPhotoStudio.Plugin/Managers/EffectManagers/BlurEffectManager.cs
  15. 4 4
      src/MeidoPhotoStudio.Plugin/Managers/EffectManagers/DepthOfFieldManager.cs
  16. 2 2
      src/MeidoPhotoStudio.Plugin/Managers/EffectManagers/FogEffectManager.cs
  17. 2 2
      src/MeidoPhotoStudio.Plugin/Managers/EffectManagers/SepiaToneEffectManager.cs
  18. 1 1
      src/MeidoPhotoStudio.Plugin/Managers/EffectManagers/VignetteEffectManager.cs
  19. 1 1
      src/MeidoPhotoStudio.Plugin/Managers/InputManager.cs
  20. 1 1
      src/MeidoPhotoStudio.Plugin/Managers/LightManager.cs
  21. 3 3
      src/MeidoPhotoStudio.Plugin/Managers/MeidoManager.cs
  22. 1 1
      src/MeidoPhotoStudio.Plugin/Managers/PropManager.cs
  23. 2 2
      src/MeidoPhotoStudio.Plugin/Meido/Meido.cs
  24. 3 3
      src/MeidoPhotoStudio.Plugin/Meido/MeidoDragPointManager.cs
  25. 1 1
      src/MeidoPhotoStudio.Plugin/MeidoPhotoStudio.cs

+ 3 - 3
src/MeidoPhotoStudio.Converter/Converters/MMConverter.cs

@@ -61,7 +61,7 @@ public class MMConverter : IConverter
         }
         catch (Exception e)
         {
-            if (Plugin.Instance == null)
+            if (!Plugin.Instance)
                 return;
 
             Plugin.Instance.Logger.LogError($"Could not convert {Path.GetFileName(filePath)} scene because {e}");
@@ -104,7 +104,7 @@ public class MMConverter : IConverter
         }
         catch (Exception e)
         {
-            if (Plugin.Instance != null)
+            if (Plugin.Instance)
                 Plugin.Instance.Logger.LogWarning(
                     $"Could not {(e is IOException ? "read" : "parse")} ini file {filePath}"
                 );
@@ -115,7 +115,7 @@ public class MMConverter : IConverter
         if (iniFile.HasSection("scene"))
             return iniFile.GetSection("scene");
 
-        if (Plugin.Instance != null)
+        if (Plugin.Instance)
             Plugin.Instance.Logger.LogWarning(
                 $"{filePath} is not a valid MM config because '[scene]' section is missing"
             );

+ 2 - 2
src/MeidoPhotoStudio.Converter/Converters/MMPngConverter.cs

@@ -61,7 +61,7 @@ public class MMPngConverter : IConverter
         }
         catch (Exception e)
         {
-            if (Plugin.Instance == null)
+            if (!Plugin.Instance)
                 return;
 
             Plugin.Instance.Logger.LogWarning($"Could not decompress scene data from {pngFile} because {e}");
@@ -82,7 +82,7 @@ public class MMPngConverter : IConverter
         }
         catch (Exception e)
         {
-            if (Plugin.Instance == null)
+            if (!Plugin.Instance)
                 return;
 
             Plugin.Instance.Logger.LogError($"Could not convert {pngFile} because {e}");

+ 1 - 1
src/MeidoPhotoStudio.Converter/PluginCore.cs

@@ -29,7 +29,7 @@ public class PluginCore
             }
             catch (Exception e)
             {
-                if (Plugin.Instance == null)
+                if (!Plugin.Instance)
                     continue;
 
                 Plugin.Instance.Logger.LogError($"Could not convert data because {e}");

+ 2 - 2
src/MeidoPhotoStudio.Plugin/Constants.cs

@@ -617,7 +617,7 @@ public static class Constants
 
         var selectedList = ModPropDict[category];
 
-        if (selectedList[0].Icon == null)
+        if (!selectedList[0].Icon)
         {
             selectedList.Sort((a, b) =>
             {
@@ -633,7 +633,7 @@ public static class Constants
 
             selectedList.RemoveAll(item =>
             {
-                if (item.Icon != null)
+                if (item.Icon)
                     return false;
 
                 Texture2D icon;

+ 2 - 2
src/MeidoPhotoStudio.Plugin/DragPoint/DragPoint.cs

@@ -82,10 +82,10 @@ public abstract class DragPoint : MonoBehaviour
 
     public bool GizmoEnabled
     {
-        get => GizmoGo != null && gizmoEnabled;
+        get => GizmoGo && gizmoEnabled;
         set
         {
-            if (GizmoGo == null || gizmoEnabled == value)
+            if (!GizmoGo || gizmoEnabled == value)
                 return;
 
             gizmoEnabled = value;

+ 2 - 2
src/MeidoPhotoStudio.Plugin/DragPoint/DragPointGravity.cs

@@ -25,7 +25,7 @@ public class DragPointGravity : DragPointGeneral
         var gravityGoName = $"GravityDatas_{maid.status.guid}_{category}";
         var gravityTransform = maid.gameObject.transform.Find(gravityGoName);
 
-        if (gravityTransform == null)
+        if (!gravityTransform)
         {
             var go = new GameObject(gravityGoName);
 
@@ -45,7 +45,7 @@ public class DragPointGravity : DragPointGeneral
 
             var control = gravityTransform.GetComponent<GravityTransformControl>();
 
-            if (control != null)
+            if (control)
                 Destroy(control);
         }
 

+ 2 - 2
src/MeidoPhotoStudio.Plugin/DragPoint/DragPointProp.cs

@@ -32,7 +32,7 @@ public class DragPointProp : DragPointGeneral
     {
         var attachPoint = meido?.IKManager.GetAttachPointTransform(point);
 
-        AttachPointInfo = meido == null ? AttachPointInfo.Empty : new(point, meido);
+        AttachPointInfo = meido is null ? AttachPointInfo.Empty : new(point, meido);
 
         var position = MyObject.position;
         var rotation = MyObject.rotation;
@@ -51,7 +51,7 @@ public class DragPointProp : DragPointGeneral
 
         MyObject.localScale = scale;
 
-        if (attachPoint == null)
+        if (!attachPoint)
             Utility.FixGameObjectScale(MyGameObject);
     }
 

+ 1 - 1
src/MeidoPhotoStudio.Plugin/GUI/Panes/BackgroundWindow2Panes/MyRoomPropsPane.cs

@@ -88,7 +88,7 @@ public class MyRoomPropsPane : BasePane
         propListScrollPos = Vector2.zero;
         myRoomPropList = Constants.MyRoomPropDict[category];
 
-        if (myRoomPropList[0].Icon == null)
+        if (!myRoomPropList[0].Icon)
             foreach (var item in myRoomPropList)
                 item.Icon = (Texture2D)MyRoomCustom.PlacementData.GetData(item.ID).GetThumbnail();
     }

+ 1 - 1
src/MeidoPhotoStudio.Plugin/GUI/Panes/BackgroundWindow2Panes/PropManagerPane.cs

@@ -159,7 +159,7 @@ public class PropManagerPane : BasePane
     {
         var prop = propManager.CurrentProp;
 
-        if (prop == null)
+        if (!prop)
             return;
 
         updating = true;

+ 1 - 1
src/MeidoPhotoStudio.Plugin/GUI/Panes/CallWindowPanes/MaidSelectorPane.cs

@@ -111,7 +111,7 @@ public class MaidSelectorPane : BasePane
                 GUI.Label(new(0f, y + 5f, buttonWidth - 10f, buttonHeight), selectedIndex.ToString(), selectLabelStyle);
             }
 
-            if (meido.Portrait != null)
+            if (meido.Portrait)
                 GUI.DrawTexture(new(5f, y, buttonHeight, buttonHeight), meido.Portrait);
 
             GUI.Label(

+ 1 - 1
src/MeidoPhotoStudio.Plugin/GUI/Panes/MainWindowPanes/PoseWindowPane.cs

@@ -124,7 +124,7 @@ public class PoseWindowPane : BaseMainWindowPane
 
     public override void UpdatePanes()
     {
-        if (meidoManager.ActiveMeido == null)
+        if (meidoManager.ActiveMeido is null)
             return;
 
         if (ActiveWindow)

+ 1 - 1
src/MeidoPhotoStudio.Plugin/GUI/Windows/MainWindow.cs

@@ -151,7 +151,7 @@ public class MainWindow : BaseWindow
 
     private void SetCurrentWindow(Constants.Window window)
     {
-        if (currentWindowPane != null)
+        if (currentWindowPane is not null)
             currentWindowPane.ActiveWindow = false;
 
         selectedWindow = window;

+ 1 - 1
src/MeidoPhotoStudio.Plugin/Managers/EffectManagers/BloomEffectManager.cs

@@ -102,7 +102,7 @@ public class BloomEffectManager : IEffectManager
 
     public void Activate()
     {
-        if (Bloom == null)
+        if (!Bloom)
         {
             Ready = true;
             Bloom = GameMain.Instance.MainCamera.GetComponent<Bloom>();

+ 1 - 1
src/MeidoPhotoStudio.Plugin/Managers/EffectManagers/BlurEffectManager.cs

@@ -38,7 +38,7 @@ public class BlurEffectManager : IEffectManager
 
     public void Activate()
     {
-        if (Blur == null)
+        if (!Blur)
         {
             Ready = true;
             Blur = GameMain.Instance.MainCamera.GetComponent<Blur>();

+ 4 - 4
src/MeidoPhotoStudio.Plugin/Managers/EffectManagers/DepthOfFieldManager.cs

@@ -51,18 +51,18 @@ public class DepthOfFieldEffectManager : IEffectManager
 
     public void Activate()
     {
-        if (DepthOfField == null)
+        if (!DepthOfField)
         {
             Ready = true;
             DepthOfField = GameMain.Instance.MainCamera.GetOrAddComponent<DepthOfFieldScatter>();
 
-            if (DepthOfField.dofHdrShader == null)
+            if (!DepthOfField.dofHdrShader)
                 DepthOfField.dofHdrShader = Shader.Find("Hidden/Dof/DepthOfFieldHdr");
 
-            if (DepthOfField.dx11BokehShader == null)
+            if (!DepthOfField.dx11BokehShader)
                 DepthOfField.dx11BokehShader = Shader.Find("Hidden/Dof/DX11Dof");
 
-            if (DepthOfField.dx11BokehTexture == null)
+            if (!DepthOfField.dx11BokehTexture)
                 DepthOfField.dx11BokehTexture = Resources.Load("Textures/hexShape") as Texture2D;
         }
 

+ 2 - 2
src/MeidoPhotoStudio.Plugin/Managers/EffectManagers/FogEffectManager.cs

@@ -88,12 +88,12 @@ public class FogEffectManager : IEffectManager
 
     public void Activate()
     {
-        if (Fog == null)
+        if (!Fog)
         {
             Ready = true;
             Fog = GameMain.Instance.MainCamera.GetOrAddComponent<GlobalFog>();
 
-            if (Fog.fogShader == null)
+            if (!Fog.fogShader)
                 Fog.fogShader = Shader.Find("Hidden/GlobalFog");
 
             Distance = initialDistance;

+ 2 - 2
src/MeidoPhotoStudio.Plugin/Managers/EffectManagers/SepiaToneEffectManager.cs

@@ -13,12 +13,12 @@ public class SepiaToneEffectManger : IEffectManager
 
     public void Activate()
     {
-        if (SepiaTone == null)
+        if (!SepiaTone)
         {
             Ready = true;
             SepiaTone = GameMain.Instance.MainCamera.GetOrAddComponent<SepiaToneEffect>();
 
-            if (SepiaTone.shader == null)
+            if (!SepiaTone.shader)
                 SepiaTone.shader = Shader.Find("Hidden/Sepiatone Effect");
         }
 

+ 1 - 1
src/MeidoPhotoStudio.Plugin/Managers/EffectManagers/VignetteEffectManager.cs

@@ -44,7 +44,7 @@ public class VignetteEffectManager : IEffectManager
 
     public void Activate()
     {
-        if (Vignette == null)
+        if (!Vignette)
         {
             Ready = true;
             Vignette = GameMain.Instance.MainCamera.GetOrAddComponent<Vignetting>();

+ 1 - 1
src/MeidoPhotoStudio.Plugin/Managers/InputManager.cs

@@ -71,7 +71,7 @@ public static class InputManager
 
     public static void StartListening()
     {
-        if (inputListener == null)
+        if (!inputListener)
             inputListener = new GameObject().AddComponent<InputListener>();
         else if (inputListener.gameObject.activeSelf)
             StopListening();

+ 1 - 1
src/MeidoPhotoStudio.Plugin/Managers/LightManager.cs

@@ -142,7 +142,7 @@ public class LightManager : IManager
 
     private void DestroyLight(DragPointLight light)
     {
-        if (light == null)
+        if (!light)
             return;
 
         light.Rotate -= OnRotate;

+ 3 - 3
src/MeidoPhotoStudio.Plugin/Managers/MeidoManager.cs

@@ -46,7 +46,7 @@ public class MeidoManager : IManager
         tempEditMaidIndex >= 0 ? Meidos[tempEditMaidIndex] : Meidos[EditMaidIndex];
 
     public bool HasActiveMeido =>
-        ActiveMeido != null;
+        ActiveMeido is not null;
 
     public bool GlobalGravity
     {
@@ -77,7 +77,7 @@ public class MeidoManager : IManager
 
     private static void SetEditorMaid(Maid maid)
     {
-        if (maid == null)
+        if (!maid)
         {
             Utility.LogWarning("Refusing to change editing maid because the new maid is null!");
 
@@ -149,7 +149,7 @@ public class MeidoManager : IManager
     {
         EditMaidIndex = -1;
 
-        if (SceneEdit.Instance.maid == null)
+        if (!SceneEdit.Instance.maid)
             return;
 
         var originalEditingMaid = SceneEdit.Instance.maid;

+ 1 - 1
src/MeidoPhotoStudio.Plugin/Managers/PropManager.cs

@@ -340,7 +340,7 @@ public class PropManager : IManager
             var info = prop.AttachPointInfo;
             var meido = meidoManager.GetMeido(info.MaidGuid);
 
-            prop.AttachTo(meido, info.AttachPoint, meido == null);
+            prop.AttachTo(meido, info.AttachPoint, meido is null);
         }
     }
 

+ 2 - 2
src/MeidoPhotoStudio.Plugin/Meido/Meido.cs

@@ -846,13 +846,13 @@ public class Meido
     {
         var cache = Maid.gameObject.GetComponent<CacheBoneDataArray>();
 
-        if (cache == null)
+        if (!cache)
         {
             cache = Maid.gameObject.AddComponent<CacheBoneDataArray>();
             CreateCache();
         }
 
-        if (cache.bone_data?.transform == null)
+        if (!cache.bone_data?.transform)
         {
             Utility.LogDebug("Cache bone_data is null");
             CreateCache();

+ 3 - 3
src/MeidoPhotoStudio.Plugin/Meido/MeidoDragPointManager.cs

@@ -378,13 +378,13 @@ public class MeidoDragPointManager
     public void Destroy()
     {
         foreach (var dragPoint in DragPoints.Values)
-            if (dragPoint != null)
+            if (dragPoint)
                 UnityEngine.Object.Destroy(dragPoint.gameObject);
 
-        if (dragCube != null)
+        if (dragCube)
             UnityEngine.Object.Destroy(dragCube.gameObject);
 
-        if (dragBody != null)
+        if (dragBody)
             UnityEngine.Object.Destroy(dragBody.gameObject);
 
         BoneTransform.Clear();

+ 1 - 1
src/MeidoPhotoStudio.Plugin/MeidoPhotoStudio.cs

@@ -541,7 +541,7 @@ public class MeidoPhotoStudio : BaseUnityPlugin
             var dailyPanel = GameObject.Find("UI Root")?.transform.Find("DailyPanel")?.gameObject;
 
             // NOTE: using is (not) for null checks on UnityEngine.Object does not work
-            if (dailyPanel != null)
+            if (dailyPanel)
                 dailyPanel.SetActive(true);
         }
     }