Skip to content

Commit

Permalink
add airbases to deckbuilder export
Browse files Browse the repository at this point in the history
  • Loading branch information
myangelkamikaze committed Nov 12, 2023
1 parent b7eea9d commit 1974b8a
Show file tree
Hide file tree
Showing 2 changed files with 44 additions and 55 deletions.
13 changes: 11 additions & 2 deletions ElectronicObserver/Window/Wpf/Fleet/FleetView.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:common="clr-namespace:ElectronicObserver.Common"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:data="clr-namespace:ElectronicObserver.Data"
xmlns:i="http://schemas.microsoft.com/xaml/behaviors"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:translations="clr-namespace:ElectronicObserver.Translations"
Expand Down Expand Up @@ -83,9 +84,17 @@
/>
<MenuItem
d:Header="Copy (deck-builder)"
Command="{Binding CopyDeckBuilderCommand}"
Header="{Binding FormFleet.ContextMenuFleet_CopyFleetDeckBuilder}"
/>
ItemsSource="{Binding AirBaseAreas}"
>
<MenuItem.ItemContainerStyle>
<Style BasedOn="{StaticResource DefaultMenuItemStyle}" TargetType="MenuItem">
<Setter Property="Command" Value="{Binding DataContext.CopyDeckBuilderCommand, Source={StaticResource Proxy}}" />
<Setter Property="CommandParameter" Value="{Binding AreaId}" />
<Setter Property="Header" Value="{Binding Display}" />
</Style>
</MenuItem.ItemContainerStyle>
</MenuItem>
<MenuItem
d:Header="Copy Ship List (kancolle-calc)"
Command="{Binding CopyKanmusuListCommand}"
Expand Down
86 changes: 33 additions & 53 deletions ElectronicObserver/Window/Wpf/Fleet/FleetViewModel.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
using System;
using System.Collections.Generic;
using System.Diagnostics.CodeAnalysis;
using System.Linq;
using System.Text;
using System.Windows;
Expand Down Expand Up @@ -41,6 +42,15 @@ public partial class FleetViewModel : AnchorableViewModel

public List<Color> ShipTagColors { get; set; } = GetShipTagColorList();

public IEnumerable<AirBaseArea> AirBaseAreas => KCDatabase.Instance.BaseAirCorps.Values
.Select(b => b.MapAreaID)
.Distinct()
.OrderBy(i => i)
.Select(i => KCDatabase.Instance.MapArea[i])
.Where(m => m != null)
.Select(m => new AirBaseArea(m.MapAreaID, m.NameEN))
.Prepend(new AirBaseArea(0, AirControlSimulatorResources.None));

public FleetViewModel(int fleetId) : base($"#{fleetId}", $"Fleet{fleetId}", IconContent.FormFleet)
{
FormFleet = Ioc.Default.GetRequiredService<FormFleetTranslationViewModel>();
Expand Down Expand Up @@ -105,6 +115,11 @@ private void SubscribeToApis()
o.ApiReqKaisou_SlotDeprive.ResponseReceived += Updated;
o.ApiReqKaisou_Marriage.ResponseReceived += Updated;
o.ApiReqMap_AnchorageRepair.ResponseReceived += Updated;

o.ApiGetMember_MapInfo.ResponseReceived += (_, _) =>
{
OnPropertyChanged(nameof(AirBaseAreas));
};
}

private void Updated(string apiname, dynamic data)
Expand Down Expand Up @@ -363,60 +378,25 @@ private void Copy()
/// <see cref="http://www.kancolle-calc.net/deckbuilder.html"/>
/// </summary>
[RelayCommand]
private void CopyDeckBuilder()
[SuppressMessage("ReSharper", "PossibleMultipleEnumeration")]
private void CopyDeckBuilder(int? areaId)
{

StringBuilder sb = new StringBuilder();
KCDatabase db = KCDatabase.Instance;

// 手書き json の悲しみ

sb.Append(@"{""version"":4,");

foreach (var fleet in db.Fleet.Fleets.Values)
{
if (fleet == null || fleet.MembersInstance.All(m => m == null)) continue;

sb.AppendFormat(@"""f{0}"":{{", fleet.FleetID);

int shipcount = 1;
foreach (var ship in fleet.MembersInstance)
{
if (ship == null) break;

sb.AppendFormat(@"""s{0}"":{{""id"":{1},""lv"":{2},""luck"":{3},""items"":{{",
shipcount,
ship.ShipID,
ship.Level,
ship.LuckBase);

int eqcount = 1;
foreach (var eq in ship.AllSlotInstance.Where(eq => eq != null))
{
if (eq == null) break;

sb.AppendFormat(@"""i{0}"":{{""id"":{1},""rf"":{2},""mas"":{3}}},", eqcount >= 6 ? "x" : eqcount.ToString(), eq.EquipmentID, eq.Level, eq.AircraftLevel);

eqcount++;
}

if (eqcount > 1)
sb.Remove(sb.Length - 1, 1); // remove ","
sb.Append(@"}},");

shipcount++;
}

if (shipcount > 0)
sb.Remove(sb.Length - 1, 1); // remove ","
sb.Append(@"},");

}

sb.Remove(sb.Length - 1, 1); // remove ","
sb.Append(@"}");

Clipboard.SetDataObject(sb.ToString());
IEnumerable<BaseAirCorpsData> airbases = KCDatabase.Instance.BaseAirCorps.Values
.Where(a => a.MapAreaID == areaId);

string deckBuilderData = DataSerializationService.DeckBuilder
(
KCDatabase.Instance.Admiral.Level,
KCDatabase.Instance.Fleet.Fleets.Values.Skip(0).FirstOrDefault(),
KCDatabase.Instance.Fleet.Fleets.Values.Skip(1).FirstOrDefault(),
KCDatabase.Instance.Fleet.Fleets.Values.Skip(2).FirstOrDefault(),
KCDatabase.Instance.Fleet.Fleets.Values.Skip(3).FirstOrDefault(),
airbases.Skip(0).FirstOrDefault(),
airbases.Skip(1).FirstOrDefault(),
airbases.Skip(2).FirstOrDefault()
);

Clipboard.SetDataObject(deckBuilderData);
}

/// <summary>
Expand Down

0 comments on commit 1974b8a

Please sign in to comment.