Преглед изворни кода

misc: Collapse LdnGameDataArray into the main class as an inner class
- privated the constructor; only obtainable by the static helper on the main LdnGameData class.
- constructor logic now in the static helper; constructor just directly sets the data it's given.

Evan Husted пре 1 година
родитељ
комит
56e45ae648

+ 26 - 0
src/Ryujinx.UI.Common/App/LdnGameData.cs

@@ -1,4 +1,7 @@
+using LibHac.Ns;
+using System;
 using System.Collections.Generic;
+using System.Linq;
 
 namespace Ryujinx.UI.App.Common
 {
@@ -12,5 +15,28 @@ namespace Ryujinx.UI.App.Common
         public string Mode { get; set; }
         public string Status { get; set; }
         public IEnumerable<string> Players { get; set; }
+
+        public static Array GetArrayForApp(
+            IEnumerable<LdnGameData> receivedData, ref ApplicationControlProperty acp)
+        {
+            LibHac.Common.FixedArrays.Array8<ulong> communicationId = acp.LocalCommunicationId;
+
+            return new Array(receivedData.Where(game =>
+                communicationId.Items.Contains(Convert.ToUInt64(game.TitleId, 16))
+            ));
+        }
+
+        public class Array
+        {
+            private readonly LdnGameData[] _ldnDatas;
+            
+            internal Array(IEnumerable<LdnGameData> receivedData)
+            {
+                _ldnDatas = receivedData.ToArray();
+            }
+
+            public int PlayerCount => _ldnDatas.Sum(it => it.PlayerCount);
+            public int GameCount => _ldnDatas.Length;
+        }
     }
 }

+ 0 - 24
src/Ryujinx.UI.Common/App/LdnGameDataList.cs

@@ -1,24 +0,0 @@
-using LibHac.Ns;
-using System;
-using System.Collections.Generic;
-using System.Linq;
-
-namespace Ryujinx.UI.App.Common
-{
-    public class LdnGameDataArray
-    {
-        private readonly LdnGameData[] _ldnDatas;
-
-        public LdnGameDataArray(IEnumerable<LdnGameData> receivedData, ref ApplicationControlProperty acp)
-        {
-            LibHac.Common.FixedArrays.Array8<ulong> communicationId = acp.LocalCommunicationId;
-
-            _ldnDatas = receivedData.Where(game =>
-                communicationId.Items.Contains(Convert.ToUInt64(game.TitleId, 16))
-            ).ToArray();
-        }
-
-        public int PlayerCount => _ldnDatas.Sum(it => it.PlayerCount);
-        public int GameCount => _ldnDatas.Length;
-    }
-}

+ 1 - 1
src/Ryujinx/UI/ViewModels/MainWindowViewModel.cs

@@ -127,7 +127,7 @@ namespace Ryujinx.Ava.UI.ViewModels
         public ApplicationData GridSelectedApplication;
         
         // Key is Title ID
-        public SafeDictionary<string, LdnGameDataArray> LdnData = [];
+        public SafeDictionary<string, LdnGameData.Array> LdnData = [];
 
         // The UI specifically uses a thicker bordered variant of the icon to avoid crunching out the border at lower resolutions.
         // For an example of this, download canary 1.2.95, then open the settings menu, and look at the icon in the top-left.

+ 6 - 3
src/Ryujinx/UI/Windows/MainWindow.axaml.cs

@@ -171,9 +171,12 @@ namespace Ryujinx.Ava.UI.Windows
                 ViewModel.LdnData.Clear();
                 foreach (var application in ViewModel.Applications)
                 {
-                    ViewModel.LdnData[application.IdString] = new LdnGameDataArray(
-                        ldnGameDataArray,
-                        ref application.ControlHolder.Value
+                    ref var controlHolder = ref application.ControlHolder.Value;
+                    
+                    ViewModel.LdnData[application.IdString] = 
+                        LdnGameData.GetArrayForApp(
+                            ldnGameDataArray, 
+                            ref controlHolder
                         );
                     
                     UpdateApplicationWithLdnData(application);