From f758144ee8bad1b0dc84c6a6b2f1cf25a1ee3b13 Mon Sep 17 00:00:00 2001 From: aujault Date: Fri, 2 Dec 2022 10:49:21 +0100 Subject: [PATCH 1/7] gestion item vide --- Blazor/Blazor/Components/Inventory.razor | 18 ++++++++++++++++++ Blazor/Blazor/Components/Inventory.razor.cs | 10 ++++++++++ Blazor/Blazor/Components/Inventory.razor.css | 6 ++++++ Blazor/Blazor/Components/InventoryItem.razor | Bin 0 -> 200 bytes .../Blazor/Components/InventoryItem.razor.cs | 11 +++++++++++ Blazor/Blazor/Models/InventoryItem.cs | 15 +++++++++++++++ Blazor/Blazor/Models/InventoryList.cs | 17 +++++++++++++++++ Blazor/Blazor/Models/Item.cs | 12 ++++++++++++ Blazor/Blazor/Pages/Index.razor | 2 +- Blazor/Blazor/Pages/Index.razor.cs | 6 ++++++ Blazor/Blazor/Pages/_Layout.cshtml | 2 +- 11 files changed, 97 insertions(+), 2 deletions(-) create mode 100644 Blazor/Blazor/Components/Inventory.razor create mode 100644 Blazor/Blazor/Components/Inventory.razor.cs create mode 100644 Blazor/Blazor/Components/Inventory.razor.css create mode 100644 Blazor/Blazor/Components/InventoryItem.razor create mode 100644 Blazor/Blazor/Components/InventoryItem.razor.cs create mode 100644 Blazor/Blazor/Models/InventoryItem.cs create mode 100644 Blazor/Blazor/Models/InventoryList.cs diff --git a/Blazor/Blazor/Components/Inventory.razor b/Blazor/Blazor/Components/Inventory.razor new file mode 100644 index 0000000..ac79db9 --- /dev/null +++ b/Blazor/Blazor/Components/Inventory.razor @@ -0,0 +1,18 @@ +@using Models; + +

Inventory

+ +
+ @for(int i = 0; i + } + else + { + /*Empty case*/ +

0

+ } + } +
\ No newline at end of file diff --git a/Blazor/Blazor/Components/Inventory.razor.cs b/Blazor/Blazor/Components/Inventory.razor.cs new file mode 100644 index 0000000..8c2fccb --- /dev/null +++ b/Blazor/Blazor/Components/Inventory.razor.cs @@ -0,0 +1,10 @@ +using Blazor.Models; +using Microsoft.AspNetCore.Components; +namespace Blazor.Components +{ + partial class Inventory + { + [Parameter] + public InventoryList inventory { get; set; } + } +} diff --git a/Blazor/Blazor/Components/Inventory.razor.css b/Blazor/Blazor/Components/Inventory.razor.css new file mode 100644 index 0000000..5d012f5 --- /dev/null +++ b/Blazor/Blazor/Components/Inventory.razor.css @@ -0,0 +1,6 @@ +.css-grid { + grid-template-columns: repeat(6,minmax(0,1fr)); + gap: 10px; + display: grid; + width: 286px; +} \ No newline at end of file diff --git a/Blazor/Blazor/Components/InventoryItem.razor b/Blazor/Blazor/Components/InventoryItem.razor new file mode 100644 index 0000000000000000000000000000000000000000..5037586ef5626ed7f7d64601bf08ac7f925c0c31 GIT binary patch literal 200 LcmZQz7#;us0LTCV literal 0 HcmV?d00001 diff --git a/Blazor/Blazor/Components/InventoryItem.razor.cs b/Blazor/Blazor/Components/InventoryItem.razor.cs new file mode 100644 index 0000000..96ab613 --- /dev/null +++ b/Blazor/Blazor/Components/InventoryItem.razor.cs @@ -0,0 +1,11 @@ +using Blazor.Models; +using Microsoft.AspNetCore.Components; + +namespace Blazor.Components +{ + public partial class InventoryItem + { + [Parameter] + public Models.InventoryItem item { get; set; } + } +} diff --git a/Blazor/Blazor/Models/InventoryItem.cs b/Blazor/Blazor/Models/InventoryItem.cs new file mode 100644 index 0000000..e6f09b3 --- /dev/null +++ b/Blazor/Blazor/Models/InventoryItem.cs @@ -0,0 +1,15 @@ +namespace Blazor.Models +{ + public class InventoryItem + { + public Item item; + int stack; + public int Stack { get; set; } + + public InventoryItem() + { + item = new Item(); + Stack = 64; + } + } +} diff --git a/Blazor/Blazor/Models/InventoryList.cs b/Blazor/Blazor/Models/InventoryList.cs new file mode 100644 index 0000000..4bac837 --- /dev/null +++ b/Blazor/Blazor/Models/InventoryList.cs @@ -0,0 +1,17 @@ +using Microsoft.AspNetCore.Http.Features; + +namespace Blazor.Models +{ + public partial class InventoryList + { + static public int size = 18; + List inventoryItems = new List(new InventoryItem[size]); + public List InvItems { get; set; } + + public InventoryList() + { + InvItems = new List(new InventoryItem[size]); + /*InvItems[0] = new InventoryItem();*/ + } + } +} diff --git a/Blazor/Blazor/Models/Item.cs b/Blazor/Blazor/Models/Item.cs index c5410a1..ad086c3 100644 --- a/Blazor/Blazor/Models/Item.cs +++ b/Blazor/Blazor/Models/Item.cs @@ -12,5 +12,17 @@ public DateTime CreatedDate { get; set; } public DateTime? UpdatedDate { get; set; } public string ImageBase64 { get; set; } + public Item() + { + Id = 2; + DisplayName = "Dirt"; + Name = "Block_of_dirt"; + StackSize = 64; + MaxDurability= 9999; + EnchantCategories = new List(); + RepairWith = new List(); + CreatedDate= DateTime.Now; + UpdatedDate = DateTime.Now; + } } } diff --git a/Blazor/Blazor/Pages/Index.razor b/Blazor/Blazor/Pages/Index.razor index 6765355..b919667 100644 --- a/Blazor/Blazor/Pages/Index.razor +++ b/Blazor/Blazor/Pages/Index.razor @@ -1,5 +1,5 @@ @page "/" @using Blazor.Components;
- +
diff --git a/Blazor/Blazor/Pages/Index.razor.cs b/Blazor/Blazor/Pages/Index.razor.cs index 0a77a38..1f3179b 100644 --- a/Blazor/Blazor/Pages/Index.razor.cs +++ b/Blazor/Blazor/Pages/Index.razor.cs @@ -7,6 +7,12 @@ namespace Blazor.Pages { public partial class Index { + /* TEST */ + + InventoryList inventory = new InventoryList(); + + + [Inject] public IDataService DataService { get; set; } diff --git a/Blazor/Blazor/Pages/_Layout.cshtml b/Blazor/Blazor/Pages/_Layout.cshtml index a647c05..1fdfc6e 100644 --- a/Blazor/Blazor/Pages/_Layout.cshtml +++ b/Blazor/Blazor/Pages/_Layout.cshtml @@ -7,7 +7,7 @@ - + @**@ From c11278f6c73b488d23e8cb080abdecb9220dc04e Mon Sep 17 00:00:00 2001 From: aujault Date: Tue, 6 Dec 2022 09:03:37 +0100 Subject: [PATCH 2/7] Empty cases --- Blazor/Blazor/Components/Inventory.razor | 9 ++-- Blazor/Blazor/Components/Inventory.razor.cs | 48 ++++++++++++++++++ Blazor/Blazor/Components/Inventory.razor.css | 2 +- Blazor/Blazor/Components/InventoryItem.razor | Bin 200 -> 0 bytes Blazor/Blazor/Components/ItemInventory.razor | 3 ++ ...ryItem.razor.cs => ItemInventory.razor.cs} | 4 +- .../Blazor/Components/ItemInventory.razor.css | 6 +++ Blazor/Blazor/Models/InventoryList.cs | 6 +-- 8 files changed, 67 insertions(+), 11 deletions(-) delete mode 100644 Blazor/Blazor/Components/InventoryItem.razor create mode 100644 Blazor/Blazor/Components/ItemInventory.razor rename Blazor/Blazor/Components/{InventoryItem.razor.cs => ItemInventory.razor.cs} (57%) create mode 100644 Blazor/Blazor/Components/ItemInventory.razor.css diff --git a/Blazor/Blazor/Components/Inventory.razor b/Blazor/Blazor/Components/Inventory.razor index ac79db9..c02d63c 100644 --- a/Blazor/Blazor/Components/Inventory.razor +++ b/Blazor/Blazor/Components/Inventory.razor @@ -5,14 +5,15 @@
@for(int i = 0; i + } else { - /*Empty case*/ -

0

+
+ +
} }
\ No newline at end of file diff --git a/Blazor/Blazor/Components/Inventory.razor.cs b/Blazor/Blazor/Components/Inventory.razor.cs index 8c2fccb..cb45dde 100644 --- a/Blazor/Blazor/Components/Inventory.razor.cs +++ b/Blazor/Blazor/Components/Inventory.razor.cs @@ -1,4 +1,5 @@ using Blazor.Models; +using Blazor.Pages; using Microsoft.AspNetCore.Components; namespace Blazor.Components { @@ -6,5 +7,52 @@ namespace Blazor.Components { [Parameter] public InventoryList inventory { get; set; } + + public void Add(Item item) + { + foreach(InventoryItem element in inventory.inventoryItems) + { + if(item.Id == element.item.Id) + { + if(element.Stack == element.item.StackSize) + { + addEnd(item); + return; + } + else + { + element.Stack += 1; + return; + } + } + if(element == null) + { + element.item = item; + element.Stack = 1; + 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) + { + 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/Inventory.razor.css b/Blazor/Blazor/Components/Inventory.razor.css index 5d012f5..1995814 100644 --- a/Blazor/Blazor/Components/Inventory.razor.css +++ b/Blazor/Blazor/Components/Inventory.razor.css @@ -2,5 +2,5 @@ grid-template-columns: repeat(6,minmax(0,1fr)); gap: 10px; display: grid; - width: 286px; + width: 40%; } \ No newline at end of file diff --git a/Blazor/Blazor/Components/InventoryItem.razor b/Blazor/Blazor/Components/InventoryItem.razor deleted file mode 100644 index 5037586ef5626ed7f7d64601bf08ac7f925c0c31..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 200 LcmZQz7#;us0LTCV diff --git a/Blazor/Blazor/Components/ItemInventory.razor b/Blazor/Blazor/Components/ItemInventory.razor new file mode 100644 index 0000000..9053490 --- /dev/null +++ b/Blazor/Blazor/Components/ItemInventory.razor @@ -0,0 +1,3 @@ +
+ @items.item +
\ No newline at end of file diff --git a/Blazor/Blazor/Components/InventoryItem.razor.cs b/Blazor/Blazor/Components/ItemInventory.razor.cs similarity index 57% rename from Blazor/Blazor/Components/InventoryItem.razor.cs rename to Blazor/Blazor/Components/ItemInventory.razor.cs index 96ab613..92b0953 100644 --- a/Blazor/Blazor/Components/InventoryItem.razor.cs +++ b/Blazor/Blazor/Components/ItemInventory.razor.cs @@ -3,9 +3,9 @@ using Microsoft.AspNetCore.Components; namespace Blazor.Components { - public partial class InventoryItem + public partial class ItemInventory { [Parameter] - public Models.InventoryItem item { get; set; } + public InventoryItem items { get; set; } } } diff --git a/Blazor/Blazor/Components/ItemInventory.razor.css b/Blazor/Blazor/Components/ItemInventory.razor.css new file mode 100644 index 0000000..b2d4521 --- /dev/null +++ b/Blazor/Blazor/Components/ItemInventory.razor.css @@ -0,0 +1,6 @@ +.item { + width: 64px; + height: 64px; + border: 1px solid; + overflow: hidden; +} diff --git a/Blazor/Blazor/Models/InventoryList.cs b/Blazor/Blazor/Models/InventoryList.cs index 4bac837..6dfd9fb 100644 --- a/Blazor/Blazor/Models/InventoryList.cs +++ b/Blazor/Blazor/Models/InventoryList.cs @@ -5,13 +5,11 @@ namespace Blazor.Models public partial class InventoryList { static public int size = 18; - List inventoryItems = new List(new InventoryItem[size]); - public List InvItems { get; set; } + public List inventoryItems = new List(new InventoryItem[size]); public InventoryList() { - InvItems = new List(new InventoryItem[size]); - /*InvItems[0] = new InventoryItem();*/ + inventoryItems[0] = new InventoryItem(); } } } From 4f10a6acdb5ef658669b868e380d1dfe50bc4092 Mon Sep 17 00:00:00 2001 From: aujault Date: Fri, 9 Dec 2022 09:34:57 +0100 Subject: [PATCH 3/7] display img and default one --- Blazor/Blazor/Components/Inventory.razor | 11 +---------- Blazor/Blazor/Components/Inventory.razor.cs | 15 ++++++++++++++- Blazor/Blazor/Components/InventoryAction.cs | 11 +++++++++++ Blazor/Blazor/Components/ItemInventory.razor | 18 +++++++++++++++++- .../Blazor/Components/ItemInventory.razor.cs | 3 +++ .../Blazor/Components/ItemInventory.razor.css | 6 ------ 6 files changed, 46 insertions(+), 18 deletions(-) create mode 100644 Blazor/Blazor/Components/InventoryAction.cs delete mode 100644 Blazor/Blazor/Components/ItemInventory.razor.css diff --git a/Blazor/Blazor/Components/Inventory.razor b/Blazor/Blazor/Components/Inventory.razor index c02d63c..e711bf1 100644 --- a/Blazor/Blazor/Components/Inventory.razor +++ b/Blazor/Blazor/Components/Inventory.razor @@ -5,15 +5,6 @@
@for(int i = 0; i - } - else - { -
- -
- } + }
\ No newline at end of file diff --git a/Blazor/Blazor/Components/Inventory.razor.cs b/Blazor/Blazor/Components/Inventory.razor.cs index cb45dde..5ecc191 100644 --- a/Blazor/Blazor/Components/Inventory.razor.cs +++ b/Blazor/Blazor/Components/Inventory.razor.cs @@ -1,15 +1,24 @@ using Blazor.Models; using Blazor.Pages; using Microsoft.AspNetCore.Components; +using System.Collections.ObjectModel; + namespace Blazor.Components { partial class Inventory { + + public Inventory() + { + Actions = new ObservableCollection(); + } + public ObservableCollection Actions { get; set; } [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) @@ -17,11 +26,13 @@ namespace Blazor.Components if(element.Stack == element.item.StackSize) { addEnd(item); + this.StateHasChanged(); return; } else { element.Stack += 1; + this.StateHasChanged(); return; } } @@ -29,6 +40,7 @@ namespace Blazor.Components { element.item = item; element.Stack = 1; + this.StateHasChanged(); return; } } @@ -36,6 +48,7 @@ namespace Blazor.Components } public void addEnd(Item item) + /*peut être useless*/ { int i = 0; while (inventory.inventoryItems[i]!=null) diff --git a/Blazor/Blazor/Components/InventoryAction.cs b/Blazor/Blazor/Components/InventoryAction.cs new file mode 100644 index 0000000..746e0f2 --- /dev/null +++ b/Blazor/Blazor/Components/InventoryAction.cs @@ -0,0 +1,11 @@ +using Blazor.Models; + +namespace Blazor.Components +{ + public class InventoryAction + { + public string Action { get; set; } + public int Index { get; set; } + public Item Item { get; set; } + } +} diff --git a/Blazor/Blazor/Components/ItemInventory.razor b/Blazor/Blazor/Components/ItemInventory.razor index 9053490..56d5c4a 100644 --- a/Blazor/Blazor/Components/ItemInventory.razor +++ b/Blazor/Blazor/Components/ItemInventory.razor @@ -1,3 +1,19 @@ 
- @items.item + @if(items != null) + { + @if(!string.IsNullOrWhiteSpace(items.item.ImageBase64)) + { + @items.item.DisplayName + } + else + { + @items.item.DisplayName + } + } + else + { +
+ +
+ }
\ No newline at end of file diff --git a/Blazor/Blazor/Components/ItemInventory.razor.cs b/Blazor/Blazor/Components/ItemInventory.razor.cs index 92b0953..c1ad38e 100644 --- a/Blazor/Blazor/Components/ItemInventory.razor.cs +++ b/Blazor/Blazor/Components/ItemInventory.razor.cs @@ -7,5 +7,8 @@ namespace Blazor.Components { [Parameter] public InventoryItem items { get; set; } + + [Parameter] + public int index { get; set; } } } diff --git a/Blazor/Blazor/Components/ItemInventory.razor.css b/Blazor/Blazor/Components/ItemInventory.razor.css deleted file mode 100644 index b2d4521..0000000 --- a/Blazor/Blazor/Components/ItemInventory.razor.css +++ /dev/null @@ -1,6 +0,0 @@ -.item { - width: 64px; - height: 64px; - border: 1px solid; - overflow: hidden; -} From 14c9004c269abcf5dc8026cd4f21ac6ccbe44528 Mon Sep 17 00:00:00 2001 From: aujault Date: Fri, 9 Dec 2022 10:52:05 +0100 Subject: [PATCH 4/7] Action handler in inventory --- Blazor/Blazor/Components/Inventory.razor | 22 ++++--- Blazor/Blazor/Components/Inventory.razor.cs | 8 ++- Blazor/Blazor/Components/InventoryAction.cs | 2 +- Blazor/Blazor/Components/ItemInventory.razor | 15 +++-- .../Blazor/Components/ItemInventory.razor.cs | 61 ++++++++++++++++++- Blazor/Blazor/Pages/_Layout.cshtml | 1 + 6 files changed, 93 insertions(+), 16 deletions(-) diff --git a/Blazor/Blazor/Components/Inventory.razor b/Blazor/Blazor/Components/Inventory.razor index e711bf1..350dd59 100644 --- a/Blazor/Blazor/Components/Inventory.razor +++ b/Blazor/Blazor/Components/Inventory.razor @@ -1,10 +1,18 @@ @using Models;

Inventory

- -
- @for(int i = 0; i - } -
\ No newline at end of file + +
+ @for(int i = 0; i + } + else + { + + } + } +
+
\ No newline at end of file diff --git a/Blazor/Blazor/Components/Inventory.razor.cs b/Blazor/Blazor/Components/Inventory.razor.cs index 5ecc191..c8846b1 100644 --- a/Blazor/Blazor/Components/Inventory.razor.cs +++ b/Blazor/Blazor/Components/Inventory.razor.cs @@ -7,12 +7,18 @@ namespace Blazor.Components { partial class Inventory { + public InventoryItem CurrentDragItem { get; set; } + public ObservableCollection Actions { get; set; } public Inventory() { Actions = new ObservableCollection(); } - public ObservableCollection Actions { get; set; } + public void update() + { + this.StateHasChanged(); + } + [Parameter] public InventoryList inventory { get; set; } public void Add(Item item) diff --git a/Blazor/Blazor/Components/InventoryAction.cs b/Blazor/Blazor/Components/InventoryAction.cs index 746e0f2..b3436d5 100644 --- a/Blazor/Blazor/Components/InventoryAction.cs +++ b/Blazor/Blazor/Components/InventoryAction.cs @@ -6,6 +6,6 @@ namespace Blazor.Components { public string Action { get; set; } public int Index { get; set; } - public Item Item { get; set; } + public ItemInventory Item { get; set; } } } diff --git a/Blazor/Blazor/Components/ItemInventory.razor b/Blazor/Blazor/Components/ItemInventory.razor index 56d5c4a..fdee5e9 100644 --- a/Blazor/Blazor/Components/ItemInventory.razor +++ b/Blazor/Blazor/Components/ItemInventory.razor @@ -1,13 +1,18 @@ -
- @if(items != null) +
+ @if(Items != null) { - @if(!string.IsNullOrWhiteSpace(items.item.ImageBase64)) + @if(!string.IsNullOrWhiteSpace(Items.item.ImageBase64)) { - @items.item.DisplayName + @Items.item.DisplayName } else { - @items.item.DisplayName + @Items.item.DisplayName } } else diff --git a/Blazor/Blazor/Components/ItemInventory.razor.cs b/Blazor/Blazor/Components/ItemInventory.razor.cs index c1ad38e..e7e80e2 100644 --- a/Blazor/Blazor/Components/ItemInventory.razor.cs +++ b/Blazor/Blazor/Components/ItemInventory.razor.cs @@ -1,4 +1,5 @@ using Blazor.Models; +using Blazorise.Extensions; using Microsoft.AspNetCore.Components; namespace Blazor.Components @@ -6,9 +7,65 @@ namespace Blazor.Components public partial class ItemInventory { [Parameter] - public InventoryItem items { get; set; } + public bool NoDrop { get; set; } [Parameter] - public int index { get; set; } + public InventoryItem Items { get; set; } + + [Parameter] + public int Index { get; set; } + + [CascadingParameter] + public Inventory Parent { get; set; } + + public void OnDragStart() + { + if(!NoDrop) + { + return; + } + Parent.CurrentDragItem = this.Items; + Parent.inventory.inventoryItems[Index] = null; + Parent.update(); + } + + + public void OnDrop() + { + if (!NoDrop) + { + this.Items = Parent.CurrentDragItem; + NoDrop = true; + } + + if (Parent.CurrentDragItem != this.Items) + { + InventoryItem tmp = Parent.CurrentDragItem; + Parent.CurrentDragItem = this.Items; + this.Items = tmp; + } + else + { + int total = Parent.CurrentDragItem.Stack + this.Items.Stack; + if (total >this.Items.item.StackSize) + { + this.Items.Stack = this.Items.item.StackSize; + Parent.CurrentDragItem.Stack=total - this.Items.item.StackSize; + } + else + { + this.Items.Stack = total; + } + } + } + internal void OnDragEnter() + { + Parent.Actions.Add(new InventoryAction { Action = "Drag Enter", Item = this, Index = this.Index }); + } + + internal void OnDragLeave() + { + Parent.Actions.Add(new InventoryAction { Action = "Drag Leave", Item = this, Index = this.Index }); + } } } diff --git a/Blazor/Blazor/Pages/_Layout.cshtml b/Blazor/Blazor/Pages/_Layout.cshtml index 1fdfc6e..f647c5b 100644 --- a/Blazor/Blazor/Pages/_Layout.cshtml +++ b/Blazor/Blazor/Pages/_Layout.cshtml @@ -8,6 +8,7 @@ @**@ + From f1cfce9fe65b21d606e0622e94dd3280791cd900 Mon Sep 17 00:00:00 2001 From: aujault Date: Mon, 12 Dec 2022 08:03:43 +0100 Subject: [PATCH 5/7] finalisation --- Blazor/Blazor/Components/ItemInventory.razor.cs | 2 ++ 1 file changed, 2 insertions(+) diff --git a/Blazor/Blazor/Components/ItemInventory.razor.cs b/Blazor/Blazor/Components/ItemInventory.razor.cs index e7e80e2..1a43f69 100644 --- a/Blazor/Blazor/Components/ItemInventory.razor.cs +++ b/Blazor/Blazor/Components/ItemInventory.razor.cs @@ -36,6 +36,8 @@ namespace Blazor.Components { this.Items = Parent.CurrentDragItem; NoDrop = true; + Parent.CurrentDragItem = null; + return; } if (Parent.CurrentDragItem != this.Items) From 413a6f2db35da8d5acfc02eaad234087ae487116 Mon Sep 17 00:00:00 2001 From: aujault Date: Fri, 16 Dec 2022 08:03:04 +0100 Subject: [PATCH 6/7] "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)); } } } From fab2ba4605c66320b4e2ca4a21c9007ac97cc75c Mon Sep 17 00:00:00 2001 From: RemRem et ToTo Date: Fri, 16 Dec 2022 08:10:16 +0100 Subject: [PATCH 7/7] Update 'Blazor/Blazor/Pages/_Layout.cshtml' --- Blazor/Blazor/Pages/_Layout.cshtml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Blazor/Blazor/Pages/_Layout.cshtml b/Blazor/Blazor/Pages/_Layout.cshtml index f647c5b..8b87a04 100644 --- a/Blazor/Blazor/Pages/_Layout.cshtml +++ b/Blazor/Blazor/Pages/_Layout.cshtml @@ -8,7 +8,7 @@ @**@ - +