Skip to content

Commit

Permalink
fix cultivation save consumption overwriteexisting
Browse files Browse the repository at this point in the history
  • Loading branch information
Lightczx committed Dec 2, 2024
1 parent 0acdd8e commit 99fefe5
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 11 deletions.
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright (c) DGP Studio. All rights reserved.
// Copyright (c) DGP Studio. All rights reserved.
// Licensed under the MIT license.

namespace Snap.Hutao.Service.Cultivation.Consumption;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -229,11 +229,7 @@ public void SaveCultivateItem(CultivateItemView item)

public async ValueTask<ConsumptionSaveResultKind> SaveConsumptionAsync(InputConsumption inputConsumption)
{
if (inputConsumption is { Strategy: not ConsumptionSaveStrategyKind.OverwriteExisting, Items: [] })
{
return ConsumptionSaveResultKind.NoItem;
}

// No selected project
if (!await EnsureCurrentProjectAsync().ConfigureAwait(false))
{
return ConsumptionSaveResultKind.NoProject;
Expand All @@ -243,12 +239,19 @@ public async ValueTask<ConsumptionSaveResultKind> SaveConsumptionAsync(InputCons

await taskContext.SwitchToBackgroundAsync();

// PreserveExisting or CreateNewEntry, but no item
if (inputConsumption is { Strategy: not ConsumptionSaveStrategyKind.OverwriteExisting, Items: [] })
{
return ConsumptionSaveResultKind.NoItem;
}

// PreserveExisting or OverwriteExisting
if (inputConsumption.Strategy is not ConsumptionSaveStrategyKind.CreateNewEntry)
{
// Check for existing entries
List<CultivateEntry> entries = cultivationRepository.GetCultivateEntryListByProjectIdAndItemId(Projects.CurrentItem.InnerId, inputConsumption.ItemId);

if (entries is [_, ..])
if (entries.Count > 0)
{
if (inputConsumption.Strategy is ConsumptionSaveStrategyKind.PreserveExisting)
{
Expand All @@ -270,6 +273,13 @@ public async ValueTask<ConsumptionSaveResultKind> SaveConsumptionAsync(InputCons
}
}
}
else
{
if (inputConsumption.Items is [])
{
return ConsumptionSaveResultKind.NoItem;
}
}
}

{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,10 @@
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
Visibility="{x:Bind Item.HasData, Mode=OneWay}"
mc:Ignorable="d">

<Grid
Padding="4"
ColumnSpacing="8"
Visibility="{x:Bind Item.HasData, Mode=OneWay}">
<Grid Padding="4" ColumnSpacing="8">
<Grid.ColumnDefinitions>
<ColumnDefinition Width="96"/>
<ColumnDefinition Width="64"/>
Expand Down

0 comments on commit 99fefe5

Please sign in to comment.