コミットメタ情報

リビジョンcd0b5f5621e38e5c18479b12490b3e195ca0cc72 (tree)
日時2018-07-21 15:46:44
作者Kazuhiro Fujieda <fujieda@user...>
コミッターKazuhiro Fujieda

ログメッセージ

ファイルから数値を読むクラスをstaticにするのをやめる

変更サマリ

差分

--- a/KancolleSniffer.Test/BattleTest.cs
+++ b/KancolleSniffer.Test/BattleTest.cs
@@ -35,7 +35,7 @@ namespace KancolleSniffer.Test
3535 public void Initialize()
3636 {
3737 _itemInfo = new ItemInfo();
38- _shipInfo = new ShipInfo(_itemInfo);
38+ _shipInfo = new ShipInfo(new ShipMaster(), _itemInfo);
3939 _battleInfo = new BattleInfo(_shipInfo, _itemInfo);
4040 }
4141
--- a/KancolleSniffer.Test/SnifferTest.cs
+++ b/KancolleSniffer.Test/SnifferTest.cs
@@ -25,8 +25,8 @@ namespace KancolleSniffer.Test
2525 [TestClass]
2626 public class SnifferTest
2727 {
28- [TestInitialize]
29- public void Intialize()
28+ [ClassInitialize]
29+ public static void Intialize(TestContext context)
3030 {
3131 ExpressionToCodeConfiguration.GlobalAssertionConfiguration = ExpressionToCodeConfiguration
3232 .GlobalAssertionConfiguration.WithPrintedListLengthLimit(200).WithMaximumValueLength(1000);
@@ -373,13 +373,11 @@ namespace KancolleSniffer.Test
373373 [TestMethod]
374374 public void TransportPoint()
375375 {
376- DataLoader.LoadTpSpec();
377-
376+ var sniffer = new Sniffer();
378377 var msgs = new[] {"", "鬼怒改二+特大発+おにぎり", "駆逐艦+士魂部隊", "補給艦"};
379378 var results = new[] {47, 19, 13, 15};
380379 for (var i = 0; i < msgs.Length; i++)
381380 {
382- var sniffer = new Sniffer();
383381 SniffLogFile(sniffer, "transportpoint_00" + (i + 1));
384382 var j = i;
385383 PAssert.That(() => (int)sniffer.Fleets[0].TransportPoint == results[j], msgs[j]);
--- a/KancolleSniffer/DataLoader.cs
+++ b/KancolleSniffer/AdditionalData.cs
@@ -19,14 +19,14 @@ using System.Linq;
1919
2020 namespace KancolleSniffer
2121 {
22- public static class DataLoader
22+ public class AdditionalData
2323 {
2424 private static readonly string EnemySlotFile =
2525 Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "EnemySlot.csv");
2626
27- private static Dictionary<int, int[]> _maxEq;
27+ private Dictionary<int, int[]> _maxEq;
2828
29- public static void LoadEnemySlot()
29+ public void LoadEnemySlot()
3030 {
3131 try
3232 {
@@ -39,16 +39,16 @@ namespace KancolleSniffer
3939 }
4040 }
4141
42- public static int[] EnemySlot(int id) =>
42+ public int[] EnemySlot(int id) =>
4343 _maxEq != null ? _maxEq.TryGetValue(id, out var slot) ? slot : null : null;
4444
45- private const string FileName = "TP.csv";
45+ private const string TpFileName = "TP.csv";
4646
47- private static readonly string TpFile = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, FileName);
47+ private static readonly string TpFile = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, TpFileName);
4848
49- private static Dictionary<int, double> _tpSpec;
49+ private Dictionary<int, double> _tpSpec;
5050
51- public static void LoadTpSpec()
51+ public void LoadTpSpec()
5252 {
5353 try
5454 {
@@ -61,11 +61,11 @@ namespace KancolleSniffer
6161 }
6262 catch (Exception ex)
6363 {
64- throw new Exception(FileName + "が壊れています。", ex);
64+ throw new Exception(TpFileName + "が壊れています。", ex);
6565 }
6666 }
6767
68- public static double ItemTp(int id) =>
68+ public double ItemTp(int id) =>
6969 _tpSpec != null ? _tpSpec.TryGetValue(id, out var tp) ? tp : -1 : -1;
7070 }
7171 }
\ No newline at end of file
--- a/KancolleSniffer/ItemInfo.cs
+++ b/KancolleSniffer/ItemInfo.cs
@@ -12,6 +12,7 @@
1212 // See the License for the specific language governing permissions and
1313 // limitations under the License.
1414
15+using System;
1516 using System.Collections.Generic;
1617 using System.Drawing;
1718 using System.Linq;
@@ -158,13 +159,15 @@ namespace KancolleSniffer
158159 }
159160 }
160161
162+ public Func<int, double?> GetItemTp { private get; set; }
163+
161164 public double TransportPoint
162165 {
163166 get
164167 {
165- var tp = DataLoader.ItemTp(Id);
168+ var tp = GetItemTp?.Invoke(Id);
166169 if (tp >= 0)
167- return tp;
170+ return (double)tp;
168171 switch (Id)
169172 {
170173 case 75: // ドラム缶(輸送用)
@@ -648,6 +651,8 @@ namespace KancolleSniffer
648651 MarginEquips = 10;
649652 }
650653
654+ public AdditionalData AdditionalData { get; set; }
655+
651656 public void InspectBasic(dynamic json)
652657 {
653658 MaxShips = (int)json.api_max_chara;
@@ -662,6 +667,7 @@ namespace KancolleSniffer
662667 var dict = new Dictionary<int, string>();
663668 foreach (var entry in json.api_mst_slotitem_equiptype)
664669 dict[(int)entry.api_id] = entry.api_name;
670+ AdditionalData?.LoadTpSpec();
665671 foreach (var entry in json.api_mst_slotitem)
666672 {
667673 var type = (int)entry.api_type[2];
@@ -680,7 +686,8 @@ namespace KancolleSniffer
680686 Bomber = (int)entry.api_baku,
681687 Interception = type == 48 ? (int)entry.api_houk : 0, // 局地戦闘機は回避の値が迎撃
682688 AntiBomber = type == 48 ? (int)entry.api_houm : 0, // 〃命中の値が対爆
683- Distance = entry.api_distance() ? (int)entry.api_distance : 0
689+ Distance = entry.api_distance() ? (int)entry.api_distance : 0,
690+ GetItemTp = id => AdditionalData?.ItemTp(id)
684691 };
685692 }
686693 _itemSpecs[-1] = _itemSpecs[0] = new ItemSpec();
--- a/KancolleSniffer/KancolleSniffer.csproj
+++ b/KancolleSniffer/KancolleSniffer.csproj
@@ -105,7 +105,7 @@
105105 <Compile Include="LogServer.cs" />
106106 <Compile Include="MaterialInfo.cs" />
107107 <Compile Include="MiscTextInfo.cs" />
108- <Compile Include="DataLoader.cs" />
108+ <Compile Include="AdditionalData.cs" />
109109 <Compile Include="NotificationConfigDialog.cs">
110110 <SubType>Form</SubType>
111111 </Compile>
--- a/KancolleSniffer/MainForm.cs
+++ b/KancolleSniffer/MainForm.cs
@@ -115,7 +115,6 @@ namespace KancolleSniffer
115115 {
116116 var target = "";
117117 _sniffer.LoadState();
118- DataLoader.LoadTpSpec();
119118 _watcher.SynchronizingObject = this;
120119 _watcherTimer.Tick += (sender, ev) =>
121120 {
@@ -126,7 +125,7 @@ namespace KancolleSniffer
126125 _sniffer.LoadState();
127126 break;
128127 case "TP.csv":
129- DataLoader.LoadTpSpec();
128+ _sniffer.AdditionalData.LoadTpSpec();
130129 break;
131130 }
132131 };
--- a/KancolleSniffer/ShipInfo.cs
+++ b/KancolleSniffer/ShipInfo.cs
@@ -27,7 +27,7 @@ namespace KancolleSniffer
2727
2828 private readonly Fleet[] _fleets;
2929 private readonly Dictionary<int, ShipStatus> _shipInfo = new Dictionary<int, ShipStatus>();
30- private readonly ShipMaster _shipMaster = new ShipMaster();
30+ private readonly ShipMaster _shipMaster;
3131 private readonly ItemInfo _itemInfo;
3232 private readonly List<int> _escapedShips = new List<int>();
3333 private ShipStatus[] _battleResult = new ShipStatus[0];
@@ -48,8 +48,9 @@ namespace KancolleSniffer
4848 }
4949 }
5050
51- public ShipInfo(ItemInfo itemInfo)
51+ public ShipInfo(ShipMaster shipMaster, ItemInfo itemInfo)
5252 {
53+ _shipMaster = shipMaster;
5354 _fleets = Enumerable.Range(0, FleetCount).Select((x, i) => new Fleet(this, i)).ToArray();
5455 _itemInfo = itemInfo;
5556 ClearShipInfo();
--- a/KancolleSniffer/ShipMaster.cs
+++ b/KancolleSniffer/ShipMaster.cs
@@ -12,6 +12,7 @@
1212 // See the License for the specific language governing permissions and
1313 // limitations under the License.
1414
15+using System;
1516 using System.Collections.Generic;
1617
1718 namespace KancolleSniffer
@@ -20,6 +21,7 @@ namespace KancolleSniffer
2021 {
2122 public const int NumSlots = 5;
2223 private readonly Dictionary<int, ShipSpec> _shipSpecs = new Dictionary<int, ShipSpec>();
24+ public AdditionalData AdditionalData { get; set; }
2325
2426 public static bool IsEnemyId(int id) => id > 1500;
2527
@@ -29,7 +31,7 @@ namespace KancolleSniffer
2931 foreach (var entry in json.api_mst_stype)
3032 dict[entry.api_id] = entry.api_name;
3133 dict[8] = "巡洋戦艦";
32- DataLoader.LoadEnemySlot();
34+ AdditionalData?.LoadEnemySlot();
3335 foreach (var entry in json.api_mst_ship)
3436 {
3537 var shipSpec = _shipSpecs[(int)entry.api_id] = new ShipSpec
@@ -49,9 +51,9 @@ namespace KancolleSniffer
4951 shipSpec.Remodel.Level = (int)entry.api_afterlv;
5052 shipSpec.Remodel.After = int.Parse(entry.api_aftershipid);
5153 }
52- shipSpec.MaxEq = entry.api_maxeq()
53- ? entry.api_maxeq
54- : DataLoader.EnemySlot(shipSpec.Id);
54+ shipSpec.GetMaxEq = entry.api_maxeq()
55+ ? (Func<int[]>)(() => entry.api_maxeq)
56+ : () => AdditionalData?.EnemySlot(shipSpec.Id);
5557 }
5658 _shipSpecs[-1] = new ShipSpec();
5759 SetRemodelBaseAndStep();
@@ -113,7 +115,8 @@ namespace KancolleSniffer
113115 public int FuelMax { get; set; }
114116 public int BullMax { get; set; }
115117 public int SlotNum { get; set; }
116- public int[] MaxEq { get; set; }
118+ public Func<int[]> GetMaxEq { get; set; }
119+ public int[] MaxEq => GetMaxEq?.Invoke();
117120 public int ShipType { get; set; }
118121 public int ShipClass { get; set; }
119122 public string ShipTypeName { get; set; }
@@ -131,7 +134,6 @@ namespace KancolleSniffer
131134 {
132135 Id = -1;
133136 Name = "";
134- MaxEq = new int[0];
135137 }
136138
137139 public double RepairWeight
--- a/KancolleSniffer/Sniffer.cs
+++ b/KancolleSniffer/Sniffer.cs
@@ -25,6 +25,7 @@ namespace KancolleSniffer
2525 private readonly MaterialInfo _materialInfo = new MaterialInfo();
2626 private readonly QuestInfo _questInfo;
2727 private readonly MissionInfo _missionInfo = new MissionInfo();
28+ private readonly ShipMaster _shipMaster = new ShipMaster();
2829 private readonly ShipInfo _shipInfo;
2930 private readonly ConditionTimer _conditionTimer;
3031 private readonly DockInfo _dockInfo;
@@ -40,6 +41,7 @@ namespace KancolleSniffer
4041 private readonly Status _status = new Status();
4142 private bool _saveState;
4243 private readonly List<IHaveState> _haveState;
44+ private AdditionalData _additionalData;
4345
4446 public interface IRepeatingTimerController
4547 {
@@ -71,7 +73,7 @@ namespace KancolleSniffer
7173 public Sniffer(bool start = false)
7274 {
7375 _start = start;
74- _shipInfo = new ShipInfo(_itemInfo);
76+ _shipInfo = new ShipInfo(_shipMaster, _itemInfo);
7577 _conditionTimer = new ConditionTimer(_shipInfo);
7678 _dockInfo = new DockInfo(_shipInfo, _materialInfo);
7779 _akashiTimer = new AkashiTimer(_shipInfo, _dockInfo, _presetDeck);
@@ -81,6 +83,18 @@ namespace KancolleSniffer
8183 _baseAirCoprs = new BaseAirCoprs(_itemInfo);
8284 _miscTextInfo = new MiscTextInfo(_shipInfo, _itemInfo);
8385 _haveState = new List<IHaveState> {_achievement, _materialInfo, _conditionTimer, _exMapInfo, _questInfo};
86+ AdditionalData = new AdditionalData();
87+ }
88+
89+ public AdditionalData AdditionalData
90+ {
91+ get => _additionalData;
92+ set
93+ {
94+ _additionalData = value;
95+ _shipMaster.AdditionalData = value;
96+ _itemInfo.AdditionalData = value;
97+ }
8498 }
8599
86100 public void SaveState()
旧リポジトリブラウザで表示