OSDN Git Service

TP.csvの処理をDataLoaderに移動する
authorKazuhiro Fujieda <fujieda@users.osdn.me>
Sun, 11 Mar 2018 04:20:28 +0000 (13:20 +0900)
committerKazuhiro Fujieda <fujieda@users.osdn.me>
Sun, 11 Mar 2018 14:51:02 +0000 (23:51 +0900)
KancolleSniffer.Test/SnifferTest.cs
KancolleSniffer/DataLoader.cs
KancolleSniffer/ItemInfo.cs
KancolleSniffer/MainForm.cs

index 5f0eefe..8e0565d 100644 (file)
@@ -337,7 +337,7 @@ namespace KancolleSniffer.Test
         [TestMethod]\r
         public void TransportPoint()\r
         {\r
-            ItemSpec.LoadTpSpec();\r
+            DataLoader.LoadTpSpec();\r
 \r
             var sniffer1 = new Sniffer();\r
             SniffLogFile(sniffer1, "transportpoint_001");\r
index 9e3ac31..a1170c1 100644 (file)
@@ -19,7 +19,7 @@ using System.Linq;
 \r
 namespace KancolleSniffer\r
 {\r
-    public static  class DataLoader\r
+    public static class DataLoader\r
     {\r
         private static readonly string EnemySlotFile =\r
             Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "EnemySlot.csv");\r
@@ -41,5 +41,27 @@ namespace KancolleSniffer
 \r
         public static int[] EnemySlot(int id) =>\r
             _maxEq != null ? _maxEq.TryGetValue(id, out var slot) ? slot : null : null;\r
+\r
+\r
+        private static readonly string TpFile =\r
+            Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "TP.csv");\r
+\r
+        private static Dictionary<int, double> _tpSpec;\r
+\r
+        public static void LoadTpSpec()\r
+        {\r
+            try\r
+            {\r
+                _tpSpec = File.ReadAllLines(TpFile)\r
+                    .Select(line => line.Split(','))\r
+                    .ToDictionary(f => int.Parse(f[0]), f => double.Parse(f[2]));\r
+            }\r
+            catch (IOException)\r
+            {\r
+            }\r
+        }\r
+\r
+        public static double ItemTp(int id) =>\r
+            _tpSpec != null ? _tpSpec.TryGetValue(id, out var tp) ? tp : -1 : -1;\r
     }\r
 }
\ No newline at end of file
index 2f66139..134427d 100644 (file)
@@ -159,26 +159,12 @@ namespace KancolleSniffer
             }\r
         }\r
 \r
-        private static Dictionary<int, double> _tpSpec;\r
-\r
-        public static void LoadTpSpec()\r
-        {\r
-            try\r
-            {\r
-                _tpSpec = File.ReadAllLines(Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "TP.csv"))\r
-                    .Select(line => line.Split(','))\r
-                    .ToDictionary(f => int.Parse(f[0]), f => double.Parse(f[2]));\r
-            }\r
-            catch (IOException)\r
-            {\r
-            }\r
-        }\r
-\r
         public double TransportPoint\r
         {\r
             get\r
             {\r
-                if (_tpSpec != null && _tpSpec.TryGetValue(Id, out var tp))\r
+                var tp = DataLoader.ItemTp(Id);\r
+                if (tp >= 0)\r
                     return tp;\r
                 switch (Id)\r
                 {\r
index 6d00e66..ba4cd25 100644 (file)
@@ -120,7 +120,7 @@ namespace KancolleSniffer
         {\r
             var target = "";\r
             _sniffer.LoadState();\r
-            ItemSpec.LoadTpSpec();\r
+            DataLoader.LoadTpSpec();\r
             _watcher.SynchronizingObject = this;\r
             _watcherTimer.Tick += (sender, ev) =>\r
             {\r
@@ -131,7 +131,7 @@ namespace KancolleSniffer
                         _sniffer.LoadState();\r
                         break;\r
                     case "TP.csv":\r
-                        ItemSpec.LoadTpSpec();\r
+                        DataLoader.LoadTpSpec();\r
                         break;\r
                 }\r
             };\r