From 413a6f2db35da8d5acfc02eaad234087ae487116 Mon Sep 17 00:00:00 2001 From: aujault Date: Fri, 16 Dec 2022 08:03:04 +0100 Subject: [PATCH] "Inventory ended" --- Blazor/Blazor/Components/Inventory.razor | 5 ++ Blazor/Blazor/Components/Inventory.razor.cs | 52 +------------------ Blazor/Blazor/Components/InventoryAction.cs | 5 ++ Blazor/Blazor/Components/ItemInventory.razor | 8 ++- .../Blazor/Components/ItemInventory.razor.cs | 29 +++++++---- 5 files changed, 34 insertions(+), 65 deletions(-) diff --git a/Blazor/Blazor/Components/Inventory.razor b/Blazor/Blazor/Components/Inventory.razor index 350dd59..588b774 100644 --- a/Blazor/Blazor/Components/Inventory.razor +++ b/Blazor/Blazor/Components/Inventory.razor @@ -15,4 +15,9 @@ } } +
+
Actions
+
+
+
\ No newline at end of file diff --git a/Blazor/Blazor/Components/Inventory.razor.cs b/Blazor/Blazor/Components/Inventory.razor.cs index c8846b1..a7f99ba 100644 --- a/Blazor/Blazor/Components/Inventory.razor.cs +++ b/Blazor/Blazor/Components/Inventory.razor.cs @@ -17,61 +17,11 @@ namespace Blazor.Components public void update() { this.StateHasChanged(); + return; } [Parameter] public InventoryList inventory { get; set; } - public void Add(Item item) - /*peut être useless*/ - { - if (item == null) return; - foreach(InventoryItem element in inventory.inventoryItems) - { - if(item.Id == element.item.Id) - { - if(element.Stack == element.item.StackSize) - { - addEnd(item); - this.StateHasChanged(); - return; - } - else - { - element.Stack += 1; - this.StateHasChanged(); - return; - } - } - if(element == null) - { - element.item = item; - element.Stack = 1; - this.StateHasChanged(); - return; - } - } - /*Si c'est ici c'est que l'inventaire est plein jsais pas si il faut avertir le user*/ - } - - public void addEnd(Item item) - /*peut être useless*/ - { - int i = 0; - while (inventory.inventoryItems[i]!=null) - { - i += 1; - } - if(i < InventoryList.size) - { - inventory.inventoryItems[i].item = item; - inventory.inventoryItems[i].Stack = 1; - } - else - { - /*Inventaire plein même cas que la fonction add*/ - } - } - } } diff --git a/Blazor/Blazor/Components/InventoryAction.cs b/Blazor/Blazor/Components/InventoryAction.cs index b3436d5..50ddc5e 100644 --- a/Blazor/Blazor/Components/InventoryAction.cs +++ b/Blazor/Blazor/Components/InventoryAction.cs @@ -4,6 +4,11 @@ namespace Blazor.Components { public class InventoryAction { + public InventoryAction(String ac, int num,ItemInventory objet) { + Action = ac; + Index = num; + Item = objet; + } public string Action { get; set; } public int Index { get; set; } public ItemInventory Item { get; set; } diff --git a/Blazor/Blazor/Components/ItemInventory.razor b/Blazor/Blazor/Components/ItemInventory.razor index fdee5e9..950c574 100644 --- a/Blazor/Blazor/Components/ItemInventory.razor +++ b/Blazor/Blazor/Components/ItemInventory.razor @@ -8,17 +8,15 @@ { @if(!string.IsNullOrWhiteSpace(Items.item.ImageBase64)) { - @Items.item.DisplayName + @Items.item.DisplayName } else { - @Items.item.DisplayName + @Items.item.DisplayName } } else { -
- -
+ empty slot } \ No newline at end of file diff --git a/Blazor/Blazor/Components/ItemInventory.razor.cs b/Blazor/Blazor/Components/ItemInventory.razor.cs index 1a43f69..95df861 100644 --- a/Blazor/Blazor/Components/ItemInventory.razor.cs +++ b/Blazor/Blazor/Components/ItemInventory.razor.cs @@ -22,10 +22,13 @@ namespace Blazor.Components { if(!NoDrop) { + Parent.CurrentDragItem = null; return; } Parent.CurrentDragItem = this.Items; - Parent.inventory.inventoryItems[Index] = null; + Parent.inventory.inventoryItems[this.Index] = null; + this.NoDrop = false; + Parent.Actions.Add(new InventoryAction("On drag start",this.Index,this)); Parent.update(); } @@ -37,14 +40,20 @@ namespace Blazor.Components this.Items = Parent.CurrentDragItem; NoDrop = true; Parent.CurrentDragItem = null; + Parent.Actions.Add(new InventoryAction("On Drop",this.Index,this)); return; } - - if (Parent.CurrentDragItem != this.Items) + if(Parent.CurrentDragItem == null) + { + return; + } + if (Parent.CurrentDragItem.item.Id != this.Items.item.Id) { - InventoryItem tmp = Parent.CurrentDragItem; - Parent.CurrentDragItem = this.Items; - this.Items = tmp; + this.Items = Parent.CurrentDragItem; + this.NoDrop= true; + Parent.CurrentDragItem = null; + Parent.Actions.Add(new InventoryAction("On drag start",this.Index,this)); + return; } else { @@ -52,22 +61,24 @@ namespace Blazor.Components if (total >this.Items.item.StackSize) { this.Items.Stack = this.Items.item.StackSize; - Parent.CurrentDragItem.Stack=total - this.Items.item.StackSize; + Parent.Actions.Add(new InventoryAction("On drag start",this.Index,this)); + return; } else { this.Items.Stack = total; + return; } } } internal void OnDragEnter() { - Parent.Actions.Add(new InventoryAction { Action = "Drag Enter", Item = this, Index = this.Index }); + Parent.Actions.Add(new InventoryAction("Drag Enter",this.Index,this)); } internal void OnDragLeave() { - Parent.Actions.Add(new InventoryAction { Action = "Drag Leave", Item = this, Index = this.Index }); + Parent.Actions.Add(new InventoryAction("Drag Leave",this.Index,this)); } } }