diff --git a/ElectronicObserver/Window/Tools/EquipmentList/EquipmentListViewModel.cs b/ElectronicObserver/Window/Tools/EquipmentList/EquipmentListViewModel.cs index 18479b43f..7423ab95b 100644 --- a/ElectronicObserver/Window/Tools/EquipmentList/EquipmentListViewModel.cs +++ b/ElectronicObserver/Window/Tools/EquipmentList/EquipmentListViewModel.cs @@ -9,9 +9,9 @@ using ElectronicObserver.Common; using ElectronicObserver.Common.Datagrid; using ElectronicObserver.Data; +using ElectronicObserver.Services; using ElectronicObserver.ViewModels; using ElectronicObserver.ViewModels.Translations; -using ElectronicObserver.Window.Dialog; using ElectronicObserver.Window.Control.EquipmentFilter; using ElectronicObserver.Window.Tools.DialogAlbumMasterEquipment; using ElectronicObserver.Window.Wpf.Fleet; @@ -22,6 +22,7 @@ namespace ElectronicObserver.Window.Tools.EquipmentList; public partial class EquipmentListViewModel : WindowViewModelBase { + private DataSerializationService DataSerializationService { get; } public DialogEquipmentListTranslationViewModel DialogEquipmentList { get; } private Microsoft.Win32.SaveFileDialog SaveCsvDialog { get; } = new() { @@ -48,7 +49,8 @@ public partial class EquipmentListViewModel : WindowViewModelBase public EquipmentListViewModel() { - DialogEquipmentList = Ioc.Default.GetService()!; + DataSerializationService = Ioc.Default.GetRequiredService(); + DialogEquipmentList = Ioc.Default.GetRequiredService()!; EquipmentGridViewModel = new(); EquipmentDetailGridViewModel = new(); @@ -350,6 +352,8 @@ private void Update() [RelayCommand] private void CopyToFleetAnalysis() { - Clipboard.SetDataObject(FleetViewModel.GenerateEquipList(!ShowLockedEquipmentOnly)); + string json = DataSerializationService.FleetAnalysisEquipment(!ShowLockedEquipmentOnly); + + Clipboard.SetDataObject(json); } } diff --git a/ElectronicObserver/Window/Wpf/Fleet/FleetViewModel.cs b/ElectronicObserver/Window/Wpf/Fleet/FleetViewModel.cs index 7ebe69d93..381c95085 100644 --- a/ElectronicObserver/Window/Wpf/Fleet/FleetViewModel.cs +++ b/ElectronicObserver/Window/Wpf/Fleet/FleetViewModel.cs @@ -508,44 +508,7 @@ private static void CopyKanmusuList() [RelayCommand] private void CopyFleetAnalysis() { - KCDatabase db = KCDatabase.Instance; - List ships = new List(); - - foreach (ShipData ship in db.Ships.Values.Where(s => s.IsLocked)) - { - int[] apiKyouka = - { - ship.FirepowerModernized, - ship.TorpedoModernized, - ship.AAModernized, - ship.ArmorModernized, - ship.LuckModernized, - ship.HPMaxModernized, - ship.ASWModernized - }; - - int expProgress = 0; - if (ExpTable.ShipExp.ContainsKey(ship.Level + 1) && ship.Level != 99) - { - expProgress = (ExpTable.ShipExp[ship.Level].Next - ship.ExpNext) - / ExpTable.ShipExp[ship.Level].Next; - } - - int[] apiExp = { ship.ExpTotal, ship.ExpNext, expProgress }; - - string shipId = $"\"api_ship_id\":{ship.ShipID}"; - string level = $"\"api_lv\":{ship.Level}"; - string kyouka = $"\"api_kyouka\":[{string.Join(",", apiKyouka)}]"; - string exp = $"\"api_exp\":[{string.Join(",", apiExp)}]"; - string slotEx = $"\"api_slot_ex\":{ship.ExpansionSlot}"; - string sallyArea = $"\"api_sally_area\":{(ship.SallyArea)}"; - - string[] analysisData = { shipId, level, kyouka, exp, slotEx, sallyArea }; - - ships.Add($"{{{string.Join(",", analysisData)}}}"); - } - - string json = $"[{string.Join(",", ships)}]"; + string json = DataSerializationService.FleetAnalysisShips(true); Clipboard.SetDataObject(json); } @@ -556,34 +519,17 @@ private void CopyFleetAnalysis() [RelayCommand] private void CopyFleetAnalysisEquip() { - Clipboard.SetDataObject(GenerateEquipList(false)); + string json = DataSerializationService.FleetAnalysisEquipment(false); + + Clipboard.SetDataObject(json); } [RelayCommand] private void CopyFleetAnalysisAllEquip() { - Clipboard.SetDataObject(GenerateEquipList(true)); - } - - public static string GenerateEquipList(bool allEquipment) - { - StringBuilder sb = new StringBuilder(); - KCDatabase db = KCDatabase.Instance; - - // 手書き json の悲しみ - // pain and suffering - - sb.Append("["); - - foreach (EquipmentData equip in db.Equipments.Values.Where(eq => allEquipment || eq.IsLocked)) - { - sb.Append($"{{\"api_slotitem_id\":{equip.EquipmentID},\"api_level\":{equip.Level}}},"); - } - - sb.Remove(sb.Length - 1, 1); // remove "," - sb.Append("]"); + string json = DataSerializationService.FleetAnalysisEquipment(true); - return sb.ToString(); + Clipboard.SetDataObject(json); } ///