Skip to content

Commit

Permalink
fix fleet analysis export
Browse files Browse the repository at this point in the history
  • Loading branch information
myangelkamikaze committed Oct 12, 2023
1 parent 49b2b81 commit 03a5aa1
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 63 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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()
{
Expand All @@ -48,7 +49,8 @@ public partial class EquipmentListViewModel : WindowViewModelBase

public EquipmentListViewModel()
{
DialogEquipmentList = Ioc.Default.GetService<DialogEquipmentListTranslationViewModel>()!;
DataSerializationService = Ioc.Default.GetRequiredService<DataSerializationService>();
DialogEquipmentList = Ioc.Default.GetRequiredService<DialogEquipmentListTranslationViewModel>()!;

EquipmentGridViewModel = new();
EquipmentDetailGridViewModel = new();
Expand Down Expand Up @@ -350,6 +352,8 @@ private void Update()
[RelayCommand]
private void CopyToFleetAnalysis()
{
Clipboard.SetDataObject(FleetViewModel.GenerateEquipList(!ShowLockedEquipmentOnly));
string json = DataSerializationService.FleetAnalysisEquipment(!ShowLockedEquipmentOnly);

Clipboard.SetDataObject(json);
}
}
66 changes: 6 additions & 60 deletions ElectronicObserver/Window/Wpf/Fleet/FleetViewModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -508,44 +508,7 @@ private static void CopyKanmusuList()
[RelayCommand]
private void CopyFleetAnalysis()
{
KCDatabase db = KCDatabase.Instance;
List<string> ships = new List<string>();

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);
}
Expand All @@ -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);
}

/// <summary>
Expand Down

0 comments on commit 03a5aa1

Please sign in to comment.