From 1eae53d118399913f48b2b7b8edbc17fc922a49d Mon Sep 17 00:00:00 2001 From: MyAngelKamikaze Date: Wed, 20 Dec 2023 19:06:52 +0900 Subject: [PATCH] add sortie record version --- ...0100307_AddSortieRecordVersion.Designer.cs | 349 ++++++++++++++++++ .../20231220100307_AddSortieRecordVersion.cs | 29 ++ .../ElectronicObserverContextModelSnapshot.cs | 3 + .../Database/Sortie/SortieRecord.cs | 1 + .../Services/ApiFileService/ApiFileService.cs | 9 +- ElectronicObserver/Services/ToolService.cs | 5 +- 6 files changed, 392 insertions(+), 4 deletions(-) create mode 100644 ElectronicObserver/Database/Migrations/20231220100307_AddSortieRecordVersion.Designer.cs create mode 100644 ElectronicObserver/Database/Migrations/20231220100307_AddSortieRecordVersion.cs diff --git a/ElectronicObserver/Database/Migrations/20231220100307_AddSortieRecordVersion.Designer.cs b/ElectronicObserver/Database/Migrations/20231220100307_AddSortieRecordVersion.Designer.cs new file mode 100644 index 000000000..360d5ba0e --- /dev/null +++ b/ElectronicObserver/Database/Migrations/20231220100307_AddSortieRecordVersion.Designer.cs @@ -0,0 +1,349 @@ +// +using System; +using ElectronicObserver.Database; +using Microsoft.EntityFrameworkCore; +using Microsoft.EntityFrameworkCore.Infrastructure; +using Microsoft.EntityFrameworkCore.Migrations; +using Microsoft.EntityFrameworkCore.Storage.ValueConversion; + +#nullable disable + +namespace ElectronicObserver.Database.Migrations +{ + [DbContext(typeof(ElectronicObserverContext))] + [Migration("20231220100307_AddSortieRecordVersion")] + partial class AddSortieRecordVersion + { + /// + protected override void BuildTargetModel(ModelBuilder modelBuilder) + { +#pragma warning disable 612, 618 + modelBuilder.HasAnnotation("ProductVersion", "8.0.0"); + + modelBuilder.Entity("ElectronicObserver.Database.Expedition.ExpeditionRecord", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("INTEGER"); + + b.Property("Expedition") + .HasColumnType("INTEGER"); + + b.Property("Fleet") + .IsRequired() + .HasColumnType("TEXT"); + + b.HasKey("Id"); + + b.ToTable("Expeditions"); + }); + + modelBuilder.Entity("ElectronicObserver.Database.KancolleApi.ApiFile", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("INTEGER"); + + b.Property("ApiFileType") + .HasColumnType("INTEGER"); + + b.Property("Content") + .IsRequired() + .HasColumnType("BLOB"); + + b.Property("ExpeditionRecordId") + .HasColumnType("INTEGER"); + + b.Property("Name") + .IsRequired() + .HasColumnType("TEXT"); + + b.Property("SortieRecordId") + .HasColumnType("INTEGER"); + + b.Property("TimeStamp") + .HasColumnType("TEXT"); + + b.Property("Version") + .HasColumnType("INTEGER"); + + b.HasKey("Id"); + + b.HasIndex("ExpeditionRecordId"); + + b.HasIndex("SortieRecordId"); + + b.ToTable("ApiFiles"); + }); + + modelBuilder.Entity("ElectronicObserver.Database.MapData.CellModel", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("INTEGER"); + + b.Property("CellId") + .HasColumnType("INTEGER"); + + b.Property("CellType") + .HasColumnType("INTEGER"); + + b.Property("MapId") + .HasColumnType("INTEGER"); + + b.Property("WorldId") + .HasColumnType("INTEGER"); + + b.HasKey("Id"); + + b.ToTable("Cells"); + }); + + modelBuilder.Entity("ElectronicObserver.Database.MapData.MapModel", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("INTEGER"); + + b.Property("MapId") + .HasColumnType("INTEGER"); + + b.Property("WorldId") + .HasColumnType("INTEGER"); + + b.HasKey("Id"); + + b.ToTable("Maps"); + }); + + modelBuilder.Entity("ElectronicObserver.Database.MapData.WorldModel", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("INTEGER"); + + b.HasKey("Id"); + + b.ToTable("Worlds"); + }); + + modelBuilder.Entity("ElectronicObserver.Database.Sortie.SortieRecord", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("INTEGER"); + + b.Property("FleetAfterSortieData") + .HasColumnType("TEXT"); + + b.Property("FleetData") + .IsRequired() + .HasColumnType("TEXT"); + + b.Property("Map") + .HasColumnType("INTEGER"); + + b.Property("MapData") + .IsRequired() + .HasColumnType("TEXT"); + + b.Property("Version") + .HasColumnType("INTEGER"); + + b.Property("World") + .HasColumnType("INTEGER"); + + b.HasKey("Id"); + + b.ToTable("Sorties"); + }); + + modelBuilder.Entity("ElectronicObserver.Window.Tools.AutoRefresh.AutoRefreshModel", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("INTEGER"); + + b.Property("IsSingleMapMode") + .HasColumnType("INTEGER"); + + b.Property("Rules") + .IsRequired() + .HasColumnType("TEXT"); + + b.Property("SingleMapModeMap") + .IsRequired() + .HasColumnType("TEXT"); + + b.HasKey("Id"); + + b.ToTable("AutoRefresh"); + }); + + modelBuilder.Entity("ElectronicObserver.Window.Tools.EquipmentUpgradePlanner.EquipmentAssignment.EquipmentAssignmentItemModel", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("INTEGER"); + + b.Property("EquipmentId") + .HasColumnType("INTEGER"); + + b.Property("EquipmentMasterDataId") + .HasColumnType("INTEGER"); + + b.Property("PlanId") + .HasColumnType("INTEGER"); + + b.Property("WillBeUsedForConversion") + .HasColumnType("INTEGER"); + + b.HasKey("Id"); + + b.HasIndex("PlanId"); + + b.ToTable("EquipmentAssignmentItems"); + }); + + modelBuilder.Entity("ElectronicObserver.Window.Tools.EquipmentUpgradePlanner.EquipmentUpgradePlanItemModel", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("INTEGER"); + + b.Property("DesiredUpgradeLevel") + .HasColumnType("INTEGER"); + + b.Property("EquipmentId") + .HasColumnType("INTEGER"); + + b.Property("EquipmentMasterId") + .HasColumnType("INTEGER"); + + b.Property("Finished") + .HasColumnType("INTEGER"); + + b.Property("ParentId") + .HasColumnType("INTEGER"); + + b.Property("Priority") + .HasColumnType("INTEGER"); + + b.Property("SelectedHelper") + .HasColumnType("INTEGER"); + + b.Property("ShouldBeConvertedInto") + .HasColumnType("INTEGER"); + + b.Property("SliderLevel") + .HasColumnType("INTEGER"); + + b.HasKey("Id"); + + b.HasIndex("ParentId"); + + b.ToTable("EquipmentUpgradePlanItems"); + }); + + modelBuilder.Entity("ElectronicObserver.Window.Tools.EventLockPlanner.EventLockPlannerModel", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("INTEGER"); + + b.Property("Locks") + .IsRequired() + .HasColumnType("TEXT"); + + b.Property("Phases") + .IsRequired() + .HasColumnType("TEXT"); + + b.Property("ShipLocks") + .IsRequired() + .HasColumnType("TEXT"); + + b.HasKey("Id"); + + b.ToTable("EventLockPlans"); + }); + + modelBuilder.Entity("ElectronicObserver.Window.Wpf.ShipTrainingPlanner.ShipTrainingPlanModel", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("INTEGER"); + + b.Property("NotifyOnAnyRemodelReady") + .HasColumnType("INTEGER"); + + b.Property("Priority") + .HasColumnType("INTEGER"); + + b.Property("ShipId") + .HasColumnType("INTEGER"); + + b.Property("TargetASWBonus") + .HasColumnType("INTEGER"); + + b.Property("TargetHPBonus") + .HasColumnType("INTEGER"); + + b.Property("TargetLevel") + .HasColumnType("INTEGER"); + + b.Property("TargetLuck") + .HasColumnType("INTEGER"); + + b.Property("TargetRemodel") + .HasColumnType("INTEGER"); + + b.HasKey("Id"); + + b.ToTable("ShipTrainingPlans"); + }); + + modelBuilder.Entity("ElectronicObserver.Database.KancolleApi.ApiFile", b => + { + b.HasOne("ElectronicObserver.Database.Expedition.ExpeditionRecord", null) + .WithMany("ApiFiles") + .HasForeignKey("ExpeditionRecordId"); + + b.HasOne("ElectronicObserver.Database.Sortie.SortieRecord", null) + .WithMany("ApiFiles") + .HasForeignKey("SortieRecordId"); + }); + + modelBuilder.Entity("ElectronicObserver.Window.Tools.EquipmentUpgradePlanner.EquipmentAssignment.EquipmentAssignmentItemModel", b => + { + b.HasOne("ElectronicObserver.Window.Tools.EquipmentUpgradePlanner.EquipmentUpgradePlanItemModel", "Plan") + .WithMany() + .HasForeignKey("PlanId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.Navigation("Plan"); + }); + + modelBuilder.Entity("ElectronicObserver.Window.Tools.EquipmentUpgradePlanner.EquipmentUpgradePlanItemModel", b => + { + b.HasOne("ElectronicObserver.Window.Tools.EquipmentUpgradePlanner.EquipmentUpgradePlanItemModel", "Parent") + .WithMany() + .HasForeignKey("ParentId"); + + b.Navigation("Parent"); + }); + + modelBuilder.Entity("ElectronicObserver.Database.Expedition.ExpeditionRecord", b => + { + b.Navigation("ApiFiles"); + }); + + modelBuilder.Entity("ElectronicObserver.Database.Sortie.SortieRecord", b => + { + b.Navigation("ApiFiles"); + }); +#pragma warning restore 612, 618 + } + } +} diff --git a/ElectronicObserver/Database/Migrations/20231220100307_AddSortieRecordVersion.cs b/ElectronicObserver/Database/Migrations/20231220100307_AddSortieRecordVersion.cs new file mode 100644 index 000000000..c63559da4 --- /dev/null +++ b/ElectronicObserver/Database/Migrations/20231220100307_AddSortieRecordVersion.cs @@ -0,0 +1,29 @@ +using Microsoft.EntityFrameworkCore.Migrations; + +#nullable disable + +namespace ElectronicObserver.Database.Migrations +{ + /// + public partial class AddSortieRecordVersion : Migration + { + /// + protected override void Up(MigrationBuilder migrationBuilder) + { + migrationBuilder.AddColumn( + name: "Version", + table: "Sorties", + type: "INTEGER", + nullable: false, + defaultValue: 0); + } + + /// + protected override void Down(MigrationBuilder migrationBuilder) + { + migrationBuilder.DropColumn( + name: "Version", + table: "Sorties"); + } + } +} diff --git a/ElectronicObserver/Database/Migrations/ElectronicObserverContextModelSnapshot.cs b/ElectronicObserver/Database/Migrations/ElectronicObserverContextModelSnapshot.cs index b399e0e59..ed43e94d9 100644 --- a/ElectronicObserver/Database/Migrations/ElectronicObserverContextModelSnapshot.cs +++ b/ElectronicObserver/Database/Migrations/ElectronicObserverContextModelSnapshot.cs @@ -144,6 +144,9 @@ protected override void BuildModel(ModelBuilder modelBuilder) .IsRequired() .HasColumnType("TEXT"); + b.Property("Version") + .HasColumnType("INTEGER"); + b.Property("World") .HasColumnType("INTEGER"); diff --git a/ElectronicObserver/Database/Sortie/SortieRecord.cs b/ElectronicObserver/Database/Sortie/SortieRecord.cs index 3aa666210..014a2bb0b 100644 --- a/ElectronicObserver/Database/Sortie/SortieRecord.cs +++ b/ElectronicObserver/Database/Sortie/SortieRecord.cs @@ -5,6 +5,7 @@ namespace ElectronicObserver.Database.Sortie; public class SortieRecord { + public required int Version { get; set; } public int Id { get; set; } public int World { get; set; } public int Map { get; set; } diff --git a/ElectronicObserver/Services/ApiFileService/ApiFileService.cs b/ElectronicObserver/Services/ApiFileService/ApiFileService.cs index ae5c82cd4..32e08b3e7 100644 --- a/ElectronicObserver/Services/ApiFileService/ApiFileService.cs +++ b/ElectronicObserver/Services/ApiFileService/ApiFileService.cs @@ -26,8 +26,12 @@ namespace ElectronicObserver.Services.ApiFileService; // migrating all at once is very expensive public class ApiFileService : ObservableObject { - // version 1 was saving HP max instead of hp current for ships - private static int CurrentApiFileVersion => 2; + private static int CurrentApiFileVersion => 1; + + // before version 1: + // fleet after sortie can be null + // hp value is set to hp max instead of hp current + private static int CurrentSortieRecordVersion => 1; private KCDatabase KcDatabase { get; } @@ -260,6 +264,7 @@ private async Task CreateNewSortie(ElectronicObserverContext db, ApiFile request SortieRecord sortieRecord = new() { + Version = CurrentSortieRecordVersion, World = response.ApiData.ApiMapareaId, Map = response.ApiData.ApiMapinfoNo, FleetData = fleetData, diff --git a/ElectronicObserver/Services/ToolService.cs b/ElectronicObserver/Services/ToolService.cs index 5c3eb88e6..a76c4241e 100644 --- a/ElectronicObserver/Services/ToolService.cs +++ b/ElectronicObserver/Services/ToolService.cs @@ -396,7 +396,7 @@ private static string GetSmokerCsvLine(SortieDetailViewModel sortieDetail, Phase }); } - public SortieDetailViewModel? GenerateSortieDetailViewModel(ElectronicObserverContext db, + public SortieDetailViewModel? GenerateSortieDetailViewModel(ElectronicObserverContext db, SortieRecordViewModel sortie) { try @@ -641,7 +641,7 @@ private string GetOperationRoomLink(SortieRecordViewModel sortie) return @$"https://jervis.vercel.app?predeck={Uri.EscapeDataString(operationRoomData)}"; } - public async Task CopySortieDataToClipboard(ElectronicObserverContext db, + public async Task CopySortieDataToClipboard(ElectronicObserverContext db, SortieRecordViewModel sortie) { await CopySortieDataToClipboard(db, new List { sortie.Model }); @@ -669,6 +669,7 @@ private async Task CopySortieDataToClipboard(ElectronicObserverContext db, List< List sorties = sortieRecords .Select(s => new SortieRecord { + Version = s.Version, Id = s.Id, World = s.World, Map = s.Map,