OSDN Git Service

拡張した編成記録枠にすぐに記録するとエラーになるのを直す
authorKazuhiro Fujieda <fujieda@users.osdn.me>
Mon, 24 Oct 2016 16:10:20 +0000 (01:10 +0900)
committerKazuhiro Fujieda <fujieda@users.osdn.me>
Wed, 26 Oct 2016 13:00:19 +0000 (22:00 +0900)
KancolleSniffer.Test/SnifferTest.cs
KancolleSniffer.Test/logs
KancolleSniffer/AkashiTimer.cs
KancolleSniffer/KancolleSniffer.csproj
KancolleSniffer/PresetDeck.cs [new file with mode: 0644]
KancolleSniffer/ShipInfo.cs
KancolleSniffer/Sniffer.cs

index e145043..5f60879 100644 (file)
@@ -621,6 +621,16 @@ namespace KancolleSniffer.Test
         }\r
 \r
         /// <summary>\r
+        /// 拡張した編成記録枠にすぐに記録してもエラーにならない\r
+        /// </summary>\r
+        [TestMethod]\r
+        public void PresetExpand()\r
+        {\r
+            var sniffer = new Sniffer();\r
+            SniffLogFile(sniffer, "preset_002");\r
+        }\r
+\r
+        /// <summary>\r
         /// 装備の交換を正しく反映する\r
         /// </summary>\r
         [TestMethod]\r
index 90e2e04..dcc1717 160000 (submodule)
@@ -1 +1 @@
-Subproject commit 90e2e0497ca3149b3f385fd41f04dd4d7bef590e
+Subproject commit dcc1717edd28e4eaf4bd2f30406f1748e961721e
index 5dd83a1..612f189 100644 (file)
@@ -22,6 +22,7 @@ namespace KancolleSniffer
     {\r
         private readonly ShipInfo _shipInfo;\r
         private readonly DockInfo _dockInfo;\r
+        private readonly PresetDeck _presetDeck;\r
         private readonly RepairStatus[] _repairStatuses = new RepairStatus[ShipInfo.FleetCount];\r
         private DateTime _start;\r
         private DateTime _prev;\r
@@ -134,10 +135,11 @@ namespace KancolleSniffer
             public string Completed { get; set; }\r
         }\r
 \r
-        public AkashiTimer(ShipInfo ship, DockInfo dock)\r
+        public AkashiTimer(ShipInfo ship, DockInfo dock, PresetDeck preset)\r
         {\r
             _shipInfo = ship;\r
             _dockInfo = dock;\r
+            _presetDeck = preset;\r
             for (var i = 0; i < _repairStatuses.Length; i++)\r
                 _repairStatuses[i] = new RepairStatus();\r
         }\r
@@ -233,7 +235,7 @@ namespace KancolleSniffer
         public bool CheckReparing() => Enumerable.Range(0, ShipInfo.FleetCount).Any(CheckReparing);\r
 \r
         public bool CheckPresetReparing()\r
-            => _shipInfo.PresetDeck.Where(deck => deck != null)\r
+            => _presetDeck.Decks.Where(deck => deck != null)\r
                 .Any(deck => RepairTarget(deck).Any(s => s.NowHp < s.MaxHp));\r
 \r
         public Notice[] GetNotice()\r
index 5781049..834acf2 100644 (file)
@@ -89,6 +89,7 @@
     <Compile Include="MaterialInfo.cs" />\r
     <Compile Include="MiscTextInfo.cs" />\r
     <Compile Include="MissingData.cs" />\r
+    <Compile Include="PresetDeck.cs" />\r
     <Compile Include="ShipLabels.cs" />\r
     <Compile Include="ListForm.cs">\r
       <SubType>Form</SubType>\r
diff --git a/KancolleSniffer/PresetDeck.cs b/KancolleSniffer/PresetDeck.cs
new file mode 100644 (file)
index 0000000..7d6f8a0
--- /dev/null
@@ -0,0 +1,44 @@
+// Copyright (C) 2016 Kazuhiro Fujieda <fujieda@users.osdn.me>\r
+//\r
+// Licensed under the Apache License, Version 2.0 (the "License");\r
+// you may not use this file except in compliance with the License.\r
+// You may obtain a copy of the License at\r
+//\r
+//    http://www.apache.org/licenses/LICENSE-2.0\r
+//\r
+// Unless required by applicable law or agreed to in writing, software\r
+// distributed under the License is distributed on an "AS IS" BASIS,\r
+// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\r
+// See the License for the specific language governing permissions and\r
+// limitations under the License.\r
+\r
+using System.Collections.Generic;\r
+using System.Linq;\r
+\r
+namespace KancolleSniffer\r
+{\r
+    public class PresetDeck\r
+    {\r
+        private readonly Dictionary<int, int[]> _presetDeck = new Dictionary<int, int[]>();\r
+\r
+        public void Inspect(dynamic json)\r
+        {\r
+            foreach (KeyValuePair<string, dynamic> entry in json.api_deck)\r
+                InspectRegister(entry.Value);\r
+        }\r
+\r
+        public void InspectRegister(dynamic json)\r
+        {\r
+            var no = (int)json.api_preset_no - 1;\r
+            _presetDeck[no] = json.api_ship;\r
+        }\r
+\r
+        public void InspectDelete(string request)\r
+        {\r
+            var values = HttpUtility.ParseQueryString(request);\r
+            _presetDeck[int.Parse(values["api_preset_no"]) - 1] = null;\r
+        }\r
+\r
+        public int[][] Decks => _presetDeck.Values.ToArray();\r
+    }\r
+}
\ No newline at end of file
index 57a7564..f708d4d 100644 (file)
@@ -253,7 +253,6 @@ namespace KancolleSniffer
         private int _hqLevel;\r
         private readonly List<int> _escapedShips = new List<int>();\r
         private int _combinedFleetType;\r
-        private int[][] _presetDeck = new int[0][];\r
 \r
         public ShipInfo(ItemInfo itemInfo)\r
         {\r
@@ -461,33 +460,12 @@ namespace KancolleSniffer
             _shipInfo.Remove(ship);\r
         }\r
 \r
-        public void InspectPresetDeck(dynamic json)\r
-        {\r
-            _presetDeck = new int[(int)json.api_max_num][];\r
-            foreach (KeyValuePair<string, dynamic> entry in json.api_deck)\r
-                InspectPresetRegister(entry.Value);\r
-        }\r
-\r
-        public void InspectPresetRegister(dynamic json)\r
-        {\r
-            var no = (int)json.api_preset_no - 1;\r
-            _presetDeck[no] = json.api_ship;\r
-        }\r
-\r
-        public void InspectPresetDelete(string request)\r
-        {\r
-            var values = HttpUtility.ParseQueryString(request);\r
-            _presetDeck[int.Parse(values["api_preset_no"]) - 1] = null;\r
-        }\r
-\r
         public void InspectCombined(string request)\r
         {\r
             var values = HttpUtility.ParseQueryString(request);\r
             _combinedFleetType = int.Parse(values["api_combined_type"]);\r
         }\r
 \r
-        public int[][] PresetDeck => _presetDeck;\r
-\r
         public void InspectMapStart(string request)\r
         {\r
             var values = HttpUtility.ParseQueryString(request);\r
index 8dec077..91725d2 100644 (file)
@@ -35,6 +35,7 @@ namespace KancolleSniffer
         private readonly ExMapInfo _exMapInfo = new ExMapInfo();\r
         private readonly MiscTextInfo _miscTextInfo = new MiscTextInfo();\r
         private readonly BaseAirCoprs _baseAirCoprs;\r
+        private readonly PresetDeck _presetDeck = new PresetDeck();\r
         private readonly Status _status = new Status();\r
         private bool _saveState;\r
         private readonly List<IHaveState> _haveState;\r
@@ -60,7 +61,7 @@ namespace KancolleSniffer
             _shipInfo = new ShipInfo(_itemInfo);\r
             _conditionTimer = new ConditionTimer(_shipInfo);\r
             _dockInfo = new DockInfo(_shipInfo, _materialInfo);\r
-            _akashiTimer = new AkashiTimer(_shipInfo, _dockInfo);\r
+            _akashiTimer = new AkashiTimer(_shipInfo, _dockInfo, _presetDeck);\r
             _battleInfo = new BattleInfo(_shipInfo, _itemInfo);\r
             _logger = new Logger(_shipInfo, _itemInfo, _battleInfo);\r
             _baseAirCoprs = new BaseAirCoprs(_itemInfo);\r
@@ -236,7 +237,7 @@ namespace KancolleSniffer
             }\r
             if (url.EndsWith("api_get_member/preset_deck"))\r
             {\r
-                _shipInfo.InspectPresetDeck(data);\r
+                _presetDeck.Inspect(data);\r
                 return Update.None;\r
             }\r
             if (url.EndsWith("api_get_member/base_air_corps"))\r
@@ -375,12 +376,12 @@ namespace KancolleSniffer
             }\r
             if (url.EndsWith("api_req_hensei/preset_register"))\r
             {\r
-                _shipInfo.InspectPresetRegister(data);\r
+                _presetDeck.InspectRegister(data);\r
                 return Update.None;\r
             }\r
             if (url.EndsWith("api_req_hensei/preset_delete"))\r
             {\r
-                _shipInfo.InspectPresetDelete(request);\r
+                _presetDeck.InspectDelete(request);\r
                 return Update.Timer;\r
             }\r
             if (url.EndsWith("api_req_hensei/combined"))\r