From ca5d6e4c884d679a418d28dac3ab6ec603bccb65 Mon Sep 17 00:00:00 2001 From: aujault Date: Tue, 20 Dec 2022 18:16:19 +0100 Subject: [PATCH] actions done Storage done --- .../Blazor/Components/ItemInventory.razor.cs | 31 ++++++++++++++----- Blazor/Blazor/Models/InventoryItem.cs | 10 +++++- 2 files changed, 33 insertions(+), 8 deletions(-) diff --git a/Blazor/Blazor/Components/ItemInventory.razor.cs b/Blazor/Blazor/Components/ItemInventory.razor.cs index 5de4720..b19c42d 100644 --- a/Blazor/Blazor/Components/ItemInventory.razor.cs +++ b/Blazor/Blazor/Components/ItemInventory.razor.cs @@ -35,7 +35,8 @@ namespace Blazor.Components Parent.Actions.Add(new InventoryAction("On drag start",this.Index,Items.item)); this.Items = null; Parent.inventory.inventoryItems[this.Index] = null ; - await LocalStorage.SetItemAsync("data" + this.Index, this.Items); + await LocalStorage.RemoveItemAsync("data" + this.Index); + await LocalStorage.RemoveItemAsync("stack" + this.Index); } @@ -51,7 +52,8 @@ namespace Blazor.Components { this.Items = Parent.CurrentDragItem; Parent.CurrentDragItem = null; - await LocalStorage.SetItemAsync("data" + this.Index, this.Items); + await LocalStorage.SetItemAsync("data" + this.Index, this.Items.item); + await LocalStorage.SetItemAsync("stack" + this.Index, this.Items.Stack); Parent.Actions.Add(new InventoryAction("On drag drop",this.Index,Items.item)); return; } @@ -60,7 +62,8 @@ namespace Blazor.Components { this.Items = Parent.CurrentDragItem; Parent.CurrentDragItem = null; - await LocalStorage.SetItemAsync("data" + this.Index, this.Items); + await LocalStorage.SetItemAsync("data" + this.Index, this.Items.item); + await LocalStorage.SetItemAsync("stack" + this.Index, this.Items.Stack); Parent.Actions.Add(new InventoryAction("On drag drop",this.Index,Items.item)); return; } @@ -71,7 +74,9 @@ namespace Blazor.Components { this.Items.Stack = this.Items.item.StackSize; Parent.CurrentDragItem = null; - await LocalStorage.SetItemAsync("data" + this.Index, this.Items); + + await LocalStorage.SetItemAsync("data" + this.Index, this.Items.item); + await LocalStorage.SetItemAsync("stack" + this.Index, this.Items.Stack); Parent.Actions.Add(new InventoryAction("On drag drop",this.Index,Items.item)); return; } @@ -79,7 +84,9 @@ namespace Blazor.Components { this.Items.Stack = total; Parent.CurrentDragItem = null; - await LocalStorage.SetItemAsync("data" + this.Index, this.Items); + await LocalStorage.SetItemAsync("data" + this.Index, this.Items.item); + await LocalStorage.SetItemAsync("stack" + this.Index, this.Items.Stack); + Parent.Actions.Add(new InventoryAction("On drag drop",this.Index,Items.item)); return; } } @@ -105,9 +112,19 @@ namespace Blazor.Components { return; } - Items = await LocalStorage.GetItemAsync("item" + this.Index); + var item = await LocalStorage.GetItemAsync("data" + this.Index); + int stack = await LocalStorage.GetItemAsync("stack" + this.Index); - StateHasChanged(); + if (item != null) + { + this.Items = new Models.InventoryItem(item, stack); + } + else + { + this.Items = null; + } + StateHasChanged(); + return; } } } diff --git a/Blazor/Blazor/Models/InventoryItem.cs b/Blazor/Blazor/Models/InventoryItem.cs index f3a0369..325573a 100644 --- a/Blazor/Blazor/Models/InventoryItem.cs +++ b/Blazor/Blazor/Models/InventoryItem.cs @@ -1,4 +1,6 @@ -namespace Blazor.Models +using System.Collections; + +namespace Blazor.Models { public class InventoryItem { @@ -16,5 +18,11 @@ this.item = item; Stack = 1; } + + public InventoryItem(Item item, int stock) + { + this.item = item; + Stack = stock; + } } }