diff --git a/.vs/Blazor/v17/workspaceFileList.bin b/.vs/Blazor/v17/workspaceFileList.bin index 5cc3944..d0f5411 100644 Binary files a/.vs/Blazor/v17/workspaceFileList.bin and b/.vs/Blazor/v17/workspaceFileList.bin differ diff --git a/.vs/VSWorkspaceState.json b/.vs/VSWorkspaceState.json index 0de7b7e..e295364 100644 --- a/.vs/VSWorkspaceState.json +++ b/.vs/VSWorkspaceState.json @@ -2,7 +2,8 @@ "ExpandedNodes": [ "", "\\Code", - "\\Code\\ProjetBlazor" + "\\Code\\ProjetBlazor", + "\\Code\\ProjetBlazor\\Properties" ], "SelectedNode": "\\Code\\BlazorApp.sln", "PreviewInSolutionExplorer": false diff --git a/.vs/slnx.sqlite b/.vs/slnx.sqlite index 6d2bd59..d6d3ffe 100644 Binary files a/.vs/slnx.sqlite and b/.vs/slnx.sqlite differ diff --git a/Code/.vs/BlazorApp/DesignTimeBuild/.dtbcache.v2 b/Code/.vs/BlazorApp/DesignTimeBuild/.dtbcache.v2 index 0db4935..f6e7d66 100644 Binary files a/Code/.vs/BlazorApp/DesignTimeBuild/.dtbcache.v2 and b/Code/.vs/BlazorApp/DesignTimeBuild/.dtbcache.v2 differ diff --git a/Code/.vs/BlazorApp/FileContentIndex/07dc51eb-34a1-4ebf-9173-ea3b93c77946.vsidx b/Code/.vs/BlazorApp/FileContentIndex/07dc51eb-34a1-4ebf-9173-ea3b93c77946.vsidx new file mode 100644 index 0000000..85875e3 Binary files /dev/null and b/Code/.vs/BlazorApp/FileContentIndex/07dc51eb-34a1-4ebf-9173-ea3b93c77946.vsidx differ diff --git a/Code/.vs/BlazorApp/FileContentIndex/1805f92d-1ec1-4291-8231-9b47c20141e2.vsidx b/Code/.vs/BlazorApp/FileContentIndex/1805f92d-1ec1-4291-8231-9b47c20141e2.vsidx new file mode 100644 index 0000000..794f3cd Binary files /dev/null and b/Code/.vs/BlazorApp/FileContentIndex/1805f92d-1ec1-4291-8231-9b47c20141e2.vsidx differ diff --git a/Code/.vs/BlazorApp/FileContentIndex/18b490ed-e977-40a6-bce8-b82e3114ce75.vsidx b/Code/.vs/BlazorApp/FileContentIndex/18b490ed-e977-40a6-bce8-b82e3114ce75.vsidx new file mode 100644 index 0000000..6e9b7c3 Binary files /dev/null and b/Code/.vs/BlazorApp/FileContentIndex/18b490ed-e977-40a6-bce8-b82e3114ce75.vsidx differ diff --git a/Code/.vs/BlazorApp/FileContentIndex/1a5d1297-767e-46dc-a4a2-6252602bcbca.vsidx b/Code/.vs/BlazorApp/FileContentIndex/1a5d1297-767e-46dc-a4a2-6252602bcbca.vsidx deleted file mode 100644 index 9d35591..0000000 Binary files a/Code/.vs/BlazorApp/FileContentIndex/1a5d1297-767e-46dc-a4a2-6252602bcbca.vsidx and /dev/null differ diff --git a/Code/.vs/BlazorApp/FileContentIndex/1cefaf64-14b0-41ad-b779-d8cb80bd0f45.vsidx b/Code/.vs/BlazorApp/FileContentIndex/1cefaf64-14b0-41ad-b779-d8cb80bd0f45.vsidx new file mode 100644 index 0000000..a1d4b11 Binary files /dev/null and b/Code/.vs/BlazorApp/FileContentIndex/1cefaf64-14b0-41ad-b779-d8cb80bd0f45.vsidx differ diff --git a/Code/.vs/BlazorApp/FileContentIndex/28f485bb-7b83-47f7-8d62-a16c6b33ba63.vsidx b/Code/.vs/BlazorApp/FileContentIndex/28f485bb-7b83-47f7-8d62-a16c6b33ba63.vsidx new file mode 100644 index 0000000..e76aacf Binary files /dev/null and b/Code/.vs/BlazorApp/FileContentIndex/28f485bb-7b83-47f7-8d62-a16c6b33ba63.vsidx differ diff --git a/Code/.vs/BlazorApp/FileContentIndex/999be290-e067-4e02-bf48-a20efa430ece.vsidx b/Code/.vs/BlazorApp/FileContentIndex/2fbe34e6-8f66-4d8f-aea1-4667e2f54984.vsidx similarity index 51% rename from Code/.vs/BlazorApp/FileContentIndex/999be290-e067-4e02-bf48-a20efa430ece.vsidx rename to Code/.vs/BlazorApp/FileContentIndex/2fbe34e6-8f66-4d8f-aea1-4667e2f54984.vsidx index 4fc957d..0f2a8cd 100644 Binary files a/Code/.vs/BlazorApp/FileContentIndex/999be290-e067-4e02-bf48-a20efa430ece.vsidx and b/Code/.vs/BlazorApp/FileContentIndex/2fbe34e6-8f66-4d8f-aea1-4667e2f54984.vsidx differ diff --git a/Code/.vs/BlazorApp/FileContentIndex/36808a5a-6526-4e68-87dc-e67e8df9e112.vsidx b/Code/.vs/BlazorApp/FileContentIndex/36808a5a-6526-4e68-87dc-e67e8df9e112.vsidx deleted file mode 100644 index 28ec17f..0000000 Binary files a/Code/.vs/BlazorApp/FileContentIndex/36808a5a-6526-4e68-87dc-e67e8df9e112.vsidx and /dev/null differ diff --git a/Code/.vs/BlazorApp/FileContentIndex/4bdc4976-b063-41db-8770-0180eeac26f2.vsidx b/Code/.vs/BlazorApp/FileContentIndex/4bdc4976-b063-41db-8770-0180eeac26f2.vsidx new file mode 100644 index 0000000..7feaeb6 Binary files /dev/null and b/Code/.vs/BlazorApp/FileContentIndex/4bdc4976-b063-41db-8770-0180eeac26f2.vsidx differ diff --git a/Code/.vs/BlazorApp/FileContentIndex/58baa8b6-8573-4709-a6f1-ee4253f8dac2.vsidx b/Code/.vs/BlazorApp/FileContentIndex/58baa8b6-8573-4709-a6f1-ee4253f8dac2.vsidx new file mode 100644 index 0000000..b0fb053 Binary files /dev/null and b/Code/.vs/BlazorApp/FileContentIndex/58baa8b6-8573-4709-a6f1-ee4253f8dac2.vsidx differ diff --git a/Code/.vs/BlazorApp/FileContentIndex/fae07cf4-2a96-4d16-877a-80279331219e.vsidx b/Code/.vs/BlazorApp/FileContentIndex/5d4db531-01b1-4c89-894c-e597e34bcb54.vsidx similarity index 55% rename from Code/.vs/BlazorApp/FileContentIndex/fae07cf4-2a96-4d16-877a-80279331219e.vsidx rename to Code/.vs/BlazorApp/FileContentIndex/5d4db531-01b1-4c89-894c-e597e34bcb54.vsidx index f617f53..54ece0e 100644 Binary files a/Code/.vs/BlazorApp/FileContentIndex/fae07cf4-2a96-4d16-877a-80279331219e.vsidx and b/Code/.vs/BlazorApp/FileContentIndex/5d4db531-01b1-4c89-894c-e597e34bcb54.vsidx differ diff --git a/Code/.vs/BlazorApp/FileContentIndex/6b4f9e14-a09a-4b9b-80aa-1760162dfa52.vsidx b/Code/.vs/BlazorApp/FileContentIndex/6b4f9e14-a09a-4b9b-80aa-1760162dfa52.vsidx deleted file mode 100644 index e6f5cc6..0000000 Binary files a/Code/.vs/BlazorApp/FileContentIndex/6b4f9e14-a09a-4b9b-80aa-1760162dfa52.vsidx and /dev/null differ diff --git a/Code/.vs/BlazorApp/FileContentIndex/3bdf1a72-30d7-46d3-b600-39f0a7e2153e.vsidx b/Code/.vs/BlazorApp/FileContentIndex/6d5c90d7-5105-464b-8be2-4e38c1d48e4f.vsidx similarity index 56% rename from Code/.vs/BlazorApp/FileContentIndex/3bdf1a72-30d7-46d3-b600-39f0a7e2153e.vsidx rename to Code/.vs/BlazorApp/FileContentIndex/6d5c90d7-5105-464b-8be2-4e38c1d48e4f.vsidx index 73032bd..5f1dd68 100644 Binary files a/Code/.vs/BlazorApp/FileContentIndex/3bdf1a72-30d7-46d3-b600-39f0a7e2153e.vsidx and b/Code/.vs/BlazorApp/FileContentIndex/6d5c90d7-5105-464b-8be2-4e38c1d48e4f.vsidx differ diff --git a/Code/.vs/BlazorApp/FileContentIndex/8650cf75-b5be-4b3e-be26-dda1b05afea4.vsidx b/Code/.vs/BlazorApp/FileContentIndex/8650cf75-b5be-4b3e-be26-dda1b05afea4.vsidx deleted file mode 100644 index 28df2d2..0000000 Binary files a/Code/.vs/BlazorApp/FileContentIndex/8650cf75-b5be-4b3e-be26-dda1b05afea4.vsidx and /dev/null differ diff --git a/Code/.vs/BlazorApp/FileContentIndex/8c234033-10d9-4c3a-8a92-8d6883592f89.vsidx b/Code/.vs/BlazorApp/FileContentIndex/8c234033-10d9-4c3a-8a92-8d6883592f89.vsidx deleted file mode 100644 index 501ccba..0000000 Binary files a/Code/.vs/BlazorApp/FileContentIndex/8c234033-10d9-4c3a-8a92-8d6883592f89.vsidx and /dev/null differ diff --git a/Code/.vs/BlazorApp/FileContentIndex/95b3e9f2-11c1-43f9-85f9-944c3e371e90.vsidx b/Code/.vs/BlazorApp/FileContentIndex/95b3e9f2-11c1-43f9-85f9-944c3e371e90.vsidx deleted file mode 100644 index 809ec43..0000000 Binary files a/Code/.vs/BlazorApp/FileContentIndex/95b3e9f2-11c1-43f9-85f9-944c3e371e90.vsidx and /dev/null differ diff --git a/Code/.vs/BlazorApp/FileContentIndex/9a4b3348-7300-4cc7-bf27-a724b7ed34b5.vsidx b/Code/.vs/BlazorApp/FileContentIndex/9a4b3348-7300-4cc7-bf27-a724b7ed34b5.vsidx new file mode 100644 index 0000000..4d53071 Binary files /dev/null and b/Code/.vs/BlazorApp/FileContentIndex/9a4b3348-7300-4cc7-bf27-a724b7ed34b5.vsidx differ diff --git a/Code/.vs/BlazorApp/FileContentIndex/a6e4c72a-acd9-439c-973f-6d78e4af5d9b.vsidx b/Code/.vs/BlazorApp/FileContentIndex/a6e4c72a-acd9-439c-973f-6d78e4af5d9b.vsidx deleted file mode 100644 index b892001..0000000 Binary files a/Code/.vs/BlazorApp/FileContentIndex/a6e4c72a-acd9-439c-973f-6d78e4af5d9b.vsidx and /dev/null differ diff --git a/Code/.vs/BlazorApp/FileContentIndex/c0207694-2d62-4acd-a237-6f39b94ee5d8.vsidx b/Code/.vs/BlazorApp/FileContentIndex/c0207694-2d62-4acd-a237-6f39b94ee5d8.vsidx new file mode 100644 index 0000000..0d04e1a Binary files /dev/null and b/Code/.vs/BlazorApp/FileContentIndex/c0207694-2d62-4acd-a237-6f39b94ee5d8.vsidx differ diff --git a/Code/.vs/BlazorApp/FileContentIndex/c34b4465-5697-462b-9ccd-dd50b8e5e8c3.vsidx b/Code/.vs/BlazorApp/FileContentIndex/c34b4465-5697-462b-9ccd-dd50b8e5e8c3.vsidx deleted file mode 100644 index 5d3899f..0000000 Binary files a/Code/.vs/BlazorApp/FileContentIndex/c34b4465-5697-462b-9ccd-dd50b8e5e8c3.vsidx and /dev/null differ diff --git a/Code/.vs/BlazorApp/FileContentIndex/ca11b913-9f14-4c02-aa6e-6da0a9dac299.vsidx b/Code/.vs/BlazorApp/FileContentIndex/ca11b913-9f14-4c02-aa6e-6da0a9dac299.vsidx new file mode 100644 index 0000000..da71cc6 Binary files /dev/null and b/Code/.vs/BlazorApp/FileContentIndex/ca11b913-9f14-4c02-aa6e-6da0a9dac299.vsidx differ diff --git a/Code/.vs/BlazorApp/FileContentIndex/e66051a1-cdcb-4b06-a787-228a1ee8d3a6.vsidx b/Code/.vs/BlazorApp/FileContentIndex/e66051a1-cdcb-4b06-a787-228a1ee8d3a6.vsidx deleted file mode 100644 index bf82817..0000000 Binary files a/Code/.vs/BlazorApp/FileContentIndex/e66051a1-cdcb-4b06-a787-228a1ee8d3a6.vsidx and /dev/null differ diff --git a/Code/.vs/BlazorApp/FileContentIndex/e922ec8b-f964-46a6-bebe-eed936960c4f.vsidx b/Code/.vs/BlazorApp/FileContentIndex/e922ec8b-f964-46a6-bebe-eed936960c4f.vsidx new file mode 100644 index 0000000..7533e4c Binary files /dev/null and b/Code/.vs/BlazorApp/FileContentIndex/e922ec8b-f964-46a6-bebe-eed936960c4f.vsidx differ diff --git a/Code/.vs/BlazorApp/FileContentIndex/f135c143-1819-4240-acfe-069a867bc81f.vsidx b/Code/.vs/BlazorApp/FileContentIndex/f135c143-1819-4240-acfe-069a867bc81f.vsidx deleted file mode 100644 index e713353..0000000 Binary files a/Code/.vs/BlazorApp/FileContentIndex/f135c143-1819-4240-acfe-069a867bc81f.vsidx and /dev/null differ diff --git a/Code/.vs/BlazorApp/FileContentIndex/fcd1937c-e3ad-49d8-9a8e-8a1bcf13f68e.vsidx b/Code/.vs/BlazorApp/FileContentIndex/fcd1937c-e3ad-49d8-9a8e-8a1bcf13f68e.vsidx new file mode 100644 index 0000000..2a434ba Binary files /dev/null and b/Code/.vs/BlazorApp/FileContentIndex/fcd1937c-e3ad-49d8-9a8e-8a1bcf13f68e.vsidx differ diff --git a/Code/.vs/BlazorApp/FileContentIndex/ff452e90-2882-4a1b-b077-4aeaae30ceb2.vsidx b/Code/.vs/BlazorApp/FileContentIndex/ff452e90-2882-4a1b-b077-4aeaae30ceb2.vsidx deleted file mode 100644 index 3c50ce3..0000000 Binary files a/Code/.vs/BlazorApp/FileContentIndex/ff452e90-2882-4a1b-b077-4aeaae30ceb2.vsidx and /dev/null differ diff --git a/Code/.vs/BlazorApp/v17/.futdcache.v2 b/Code/.vs/BlazorApp/v17/.futdcache.v2 index 40edc09..0df3c73 100644 Binary files a/Code/.vs/BlazorApp/v17/.futdcache.v2 and b/Code/.vs/BlazorApp/v17/.futdcache.v2 differ diff --git a/Code/.vs/BlazorApp/v17/.suo b/Code/.vs/BlazorApp/v17/.suo index 2cb0592..11aa72d 100644 Binary files a/Code/.vs/BlazorApp/v17/.suo and b/Code/.vs/BlazorApp/v17/.suo differ diff --git a/Code/.vs/ProjectEvaluation/blazorapp.metadata.v5.2 b/Code/.vs/ProjectEvaluation/blazorapp.metadata.v5.2 index 1045c82..aebb8c1 100644 Binary files a/Code/.vs/ProjectEvaluation/blazorapp.metadata.v5.2 and b/Code/.vs/ProjectEvaluation/blazorapp.metadata.v5.2 differ diff --git a/Code/.vs/ProjectEvaluation/blazorapp.projects.v5.2 b/Code/.vs/ProjectEvaluation/blazorapp.projects.v5.2 index 50ee3f7..1a266ca 100644 Binary files a/Code/.vs/ProjectEvaluation/blazorapp.projects.v5.2 and b/Code/.vs/ProjectEvaluation/blazorapp.projects.v5.2 differ diff --git a/Code/ProjetBlazor/Components/ActionInInventory.cs b/Code/ProjetBlazor/Components/ActionInInventory.cs new file mode 100644 index 0000000..9469ef0 --- /dev/null +++ b/Code/ProjetBlazor/Components/ActionInInventory.cs @@ -0,0 +1,17 @@ +using ProjetBlazor.Models; + +namespace ProjetBlazor.Components +{ + public class ActionInInventory + { + public ActionInInventory(String ac, int num, Item objet) + { + Action = ac; + Index = num; + Item = objet; + } + public string Action { get; set; } + public int Index { get; set; } + public Item Item { get; set; } + } +} diff --git a/Code/ProjetBlazor/Components/GetItemInInventory.razor b/Code/ProjetBlazor/Components/GetItemInInventory.razor index 8139f38..d49e5e3 100644 --- a/Code/ProjetBlazor/Components/GetItemInInventory.razor +++ b/Code/ProjetBlazor/Components/GetItemInInventory.razor @@ -1,13 +1,30 @@ 
- - @if (Item != null) + @if(Items != null) { - @Item.DisplayName + @if(!string.IsNullOrWhiteSpace(Items.item.ImageBase64)) + { +
+ @Items.item.DisplayName + @Items.Stack +
+ } + else + { +
+ @Items.item.DisplayName + @Items.Stack +
+ } } -
+ else + { +
+ empty slot +
+ } + \ No newline at end of file diff --git a/Code/ProjetBlazor/Components/GetItemInInventory.razor.cs b/Code/ProjetBlazor/Components/GetItemInInventory.razor.cs index 548af18..a6690e1 100644 --- a/Code/ProjetBlazor/Components/GetItemInInventory.razor.cs +++ b/Code/ProjetBlazor/Components/GetItemInInventory.razor.cs @@ -1,4 +1,5 @@ -using Blazorise; +using Blazored.LocalStorage; +using Blazorise; using Microsoft.AspNetCore.Components; using ProjetBlazor.Models; @@ -7,48 +8,123 @@ namespace ProjetBlazor.Components public partial class GetItemInInventory { [Parameter] - public int Index { get; set; } + public bool NoDrop { get; set; } [Parameter] - public Item? Item { get; set; } + public ItemInInventory? Items { get; set; } [Parameter] - public bool NoDrop { get; set; } + public int Index { get; set; } [CascadingParameter] public ItemsList Parent { get; set; } - internal void OnDragEnter() + [Inject] + public ILocalStorageService LocalStorage { get; set; } + + public async Task OnDragStartAsync() { - if (NoDrop){ + + if (this.Items == null) + { + Parent.CurrentDragItem = null; return; } - this.Item = Parent.CurrentDragItem; + Parent.CurrentDragItem = this.Items; + Parent.Actions.Add(new ActionInInventory("On drag start", this.Index, Items.item)); + this.Items = null; + Parent.inventory.inventoryItems[this.Index] = null; + await LocalStorage.RemoveItemAsync("data" + this.Index); + await LocalStorage.RemoveItemAsync("stack" + this.Index); } - internal void OnDragLeave() + + public async Task OnDropAsync() { - if (NoDrop) + + if (Parent.CurrentDragItem == null) { return; } - } + if (this.Items == null) + { + this.Items = Parent.CurrentDragItem; + Parent.CurrentDragItem = null; + await LocalStorage.SetItemAsync("data" + this.Index, this.Items.item); + await LocalStorage.SetItemAsync("stack" + this.Index, this.Items.Stack); + Parent.Actions.Add(new ActionInInventory("On drag drop", this.Index, Items.item)); + return; + } - internal void OnDrop() - { - if (NoDrop) + if (Parent.CurrentDragItem.item.Id != this.Items.item.Id) { + this.Items = Parent.CurrentDragItem; + Parent.CurrentDragItem = null; + await LocalStorage.SetItemAsync("data" + this.Index, this.Items.item); + await LocalStorage.SetItemAsync("stack" + this.Index, this.Items.Stack); + Parent.Actions.Add(new ActionInInventory("On drag drop", this.Index, Items.item)); return; } + else + { + int total = Parent.CurrentDragItem.Stack + this.Items.Stack; + if (total > this.Items.item.StackSize) + { + this.Items.Stack = this.Items.item.StackSize; + Parent.CurrentDragItem = null; - this.Item = Parent.CurrentDragItem; + await LocalStorage.SetItemAsync("data" + this.Index, this.Items.item); + await LocalStorage.SetItemAsync("stack" + this.Index, this.Items.Stack); + Parent.Actions.Add(new ActionInInventory("On drag drop", this.Index, Items.item)); + return; + } + else + { + this.Items.Stack = total; + Parent.CurrentDragItem = null; + await LocalStorage.SetItemAsync("data" + this.Index, this.Items.item); + await LocalStorage.SetItemAsync("stack" + this.Index, this.Items.Stack); + Parent.Actions.Add(new ActionInInventory("On drag drop", this.Index, Items.item)); + return; + } + } + } + internal void OnDragEnter() + { + if (this.Items == null) return; + Parent.Actions.Add(new ActionInInventory("Drag Enter", this.Index, Items.item)); } - private void OnDragStart() + internal void OnDragLeave() { - Parent.CurrentDragItem = this.Item; + if (this.Items == null) return; + Parent.Actions.Add(new ActionInInventory("Drag Leave", this.Index, Items.item)); + } + + + protected override async Task OnAfterRenderAsync(bool firstRender) + { + base.OnAfterRenderAsync(firstRender); + + if (!firstRender) + { + return; + } + var item = await LocalStorage.GetItemAsync("data" + this.Index); + int stack = await LocalStorage.GetItemAsync("stack" + this.Index); + + if (item != null) + { + this.Items = new Models.ItemInInventory(item, stack); + } + else + { + this.Items = null; + } + StateHasChanged(); + return; } } } diff --git a/Code/ProjetBlazor/Components/GetItemInInventory.razor.css b/Code/ProjetBlazor/Components/GetItemInInventory.razor.css index 36e7b4a..10796f3 100644 --- a/Code/ProjetBlazor/Components/GetItemInInventory.razor.css +++ b/Code/ProjetBlazor/Components/GetItemInInventory.razor.css @@ -3,5 +3,14 @@ width: 100px; height: 100px; border: 1px solid; - overflow: hidden; } + +.number-item { + position: absolute; + bottom: 5px; + right: 5px; + font-size: 1em; + font-weight: bold; + -webkit-text-stroke: 2px black; + font-family: 'Segoe UI', Tahoma, Verdana, Geneva, Tahoma, sans-serif +} \ No newline at end of file diff --git a/Code/ProjetBlazor/Components/InventoryImageList.razor b/Code/ProjetBlazor/Components/InventoryImageList.razor new file mode 100644 index 0000000..aed2ef7 --- /dev/null +++ b/Code/ProjetBlazor/Components/InventoryImageList.razor @@ -0,0 +1,23 @@ +@using ProjetBlazor.Models; + + + + +
+ + @if (!string.IsNullOrWhiteSpace(Item.ImageBase64)) + { + Item.DisplayName + } + else + { + Item.DisplayName + } + +
\ No newline at end of file diff --git a/Code/ProjetBlazor/Components/InventoryImageList.razor.cs b/Code/ProjetBlazor/Components/InventoryImageList.razor.cs new file mode 100644 index 0000000..456c40c --- /dev/null +++ b/Code/ProjetBlazor/Components/InventoryImageList.razor.cs @@ -0,0 +1,42 @@ +using Microsoft.AspNetCore.Components; +using ProjetBlazor.Models; + +namespace ProjetBlazor.Components +{ + public partial class InventoryImageList + { + + [Parameter] + public Item Item { get; set; } + + [CascadingParameter] + public ItemsList Parent { get; set; } + + internal void OnDragEnter() + { + + Parent.Actions.Add(new ActionInInventory("On drag enter", Item.Id, Item)); + return; + } + + internal void OnDragLeave() + { + Parent.Actions.Add(new ActionInInventory("On drag leave", Item.Id, Item)); + return; + } + + internal void OnDrop() + { + Parent.Actions.Add(new ActionInInventory("On drop", Item.Id, Item)); + Parent.CurrentDragItem = null; + return; + } + + private void OnDragStart() + { + Parent.CurrentDragItem = new ItemInInventory(Item); + Parent.Actions.Add(new ActionInInventory("On drag start", Item.Id, Item)); + return; + } + } +} diff --git a/Code/ProjetBlazor/Components/ItemsList.razor b/Code/ProjetBlazor/Components/ItemsList.razor index 1f5ebb6..6bcc1f0 100644 --- a/Code/ProjetBlazor/Components/ItemsList.razor +++ b/Code/ProjetBlazor/Components/ItemsList.razor @@ -2,37 +2,42 @@
-

@Localizer["List"]

+

@Localizer["List"]

+ TotalItems="8" + PageSize="8" + Filterable + ShowPager + Responsive> - @if (!string.IsNullOrWhiteSpace(context.ImageBase64)) - { - @context.DisplayName - } + @if (!string.IsNullOrWhiteSpace(context.ImageBase64)) + { + @context.DisplayName + }
-

@Localizer["Inventory"]

-
- @for (int i = 0; i < 27; i++) +
+ @for(int i = 0; i - + } -
+ else + { + + } + + } +
diff --git a/Code/ProjetBlazor/Components/ItemsList.razor.cs b/Code/ProjetBlazor/Components/ItemsList.razor.cs index cf7e555..3086c78 100644 --- a/Code/ProjetBlazor/Components/ItemsList.razor.cs +++ b/Code/ProjetBlazor/Components/ItemsList.razor.cs @@ -1,10 +1,7 @@ -using Blazored.Modal; -using Blazored.Modal.Services; -using Blazorise.DataGrid; +using Blazored.Modal.Services; using Microsoft.AspNetCore.Components; using Microsoft.Extensions.Localization; using Microsoft.JSInterop; -using ProjetBlazor.Modals; using ProjetBlazor.Models; using ProjetBlazor.Services; using System.Collections.ObjectModel; @@ -14,7 +11,9 @@ namespace ProjetBlazor.Components { public partial class ItemsList { - public Item CurrentDragItem { get; set; } + public Models.Inventory inventory = new Models.Inventory(); + public ObservableCollection Actions { get; set; } + public ItemInInventory CurrentDragItem { get; set; } [Parameter] public List Items { get; set; } diff --git a/Code/ProjetBlazor/Components/ItemsList.razor.css b/Code/ProjetBlazor/Components/ItemsList.razor.css index 6712e90..7f9ac5e 100644 --- a/Code/ProjetBlazor/Components/ItemsList.razor.css +++ b/Code/ProjetBlazor/Components/ItemsList.razor.css @@ -14,6 +14,7 @@ padding-top: 1px; padding-left: 5px; border: 1px solid black; - height: 250px; + height: 200px; clear: both; + overflow: scroll; } diff --git a/Code/ProjetBlazor/Components/ItemsList.razor.js b/Code/ProjetBlazor/Components/ItemsList.razor.js new file mode 100644 index 0000000..263a9bf --- /dev/null +++ b/Code/ProjetBlazor/Components/ItemsList.razor.js @@ -0,0 +1,16 @@ +window.Inventory = +{ + AddActions: function (data) { + + data.forEach(element => { + var div = document.createElement('div'); + div.innerHTML = 'Action: ' + element.action + ' - Index: ' + element.index; + + if (element.item) { + div.innerHTML += ' - Item Name: ' + element.item.name; + } + + document.getElementById('actions').appendChild(div); + }); + } +} \ No newline at end of file diff --git a/Code/ProjetBlazor/Models/Inventory.cs b/Code/ProjetBlazor/Models/Inventory.cs new file mode 100644 index 0000000..3f4a273 --- /dev/null +++ b/Code/ProjetBlazor/Models/Inventory.cs @@ -0,0 +1,22 @@ +namespace ProjetBlazor.Models +{ + public partial class Inventory + { + + static public int size = 18; + + /// + /// List of inventory items. + /// + public List inventoryItems = new List(new ItemInInventory[size]); + + /// + /// Constructor for InventoryList. + /// + public Inventory() + { + inventoryItems[0] = new ItemInInventory(); + } + } +} + diff --git a/Code/ProjetBlazor/Models/ItemInInventory.cs b/Code/ProjetBlazor/Models/ItemInInventory.cs new file mode 100644 index 0000000..ba26c6f --- /dev/null +++ b/Code/ProjetBlazor/Models/ItemInInventory.cs @@ -0,0 +1,42 @@ +namespace ProjetBlazor.Models +{ + public class ItemInInventory + { + public Item item; + int stack; + + /// + /// The number of items in the stack. + /// + public int Stack { get; set; } + + /// + /// Constructor for InventoryItem with no parameters. + /// + public ItemInInventory() + { + item = new Item(); + Stack = 64; + } + /// + /// Constructor for InventoryItem with a single item. + /// + /// The item. + public ItemInInventory(Item item) + { + this.item = item; + Stack = 1; + } + + /// + /// Constructor for InventoryItem with a stack of items. + /// + /// The item + /// The number of items in the stack. + public ItemInInventory(Item item, int stock) + { + this.item = item; + Stack = stock; + } + } +} diff --git a/Code/ProjetBlazor/Services/DataApiService.cs b/Code/ProjetBlazor/Services/DataApiService.cs index f26811a..1e7ac7d 100644 --- a/Code/ProjetBlazor/Services/DataApiService.cs +++ b/Code/ProjetBlazor/Services/DataApiService.cs @@ -8,53 +8,87 @@ namespace ProjetBlazor.Services { private readonly HttpClient _http; - public DataApiService( - HttpClient http) + /// + /// Constructor for DataApiService. + /// + /// HttpClient for making API requests. + public DataApiService(HttpClient http) { _http = http; } + /// + /// Add a new item to the API. + /// + /// Model containing data for the new item. public async Task Add(ItemModel model) { // Get the item var item = ItemFactory.Create(model); // Save the data - await _http.PostAsJsonAsync("https://localhost:7234/api/Crafting/", item); + await _http.PostAsJsonAsync("https://codefirst.iut.uca.fr/containers/container-blazor-web-api-marcchevaldonne/api/Crafting/", item); } + /// + /// Get the number of items in the API. + /// + /// Task representing the asynchronous operation, returning the number of items. public async Task Count() { - return await _http.GetFromJsonAsync("https://localhost:7234/api/Crafting/count"); + return await _http.GetFromJsonAsync("https://codefirst.iut.uca.fr/containers/container-blazor-web-api-marcchevaldonne/api/Crafting/count"); } + /// + /// Get a list of items from the API, paginated. + /// + /// The current page number. + /// The number of items per page. + /// Task representing the asynchronous operation, returning a list of items. public async Task> List(int currentPage, int pageSize) { - return await _http.GetFromJsonAsync>($"https://localhost:7234/api/Crafting/?currentPage={currentPage}&pageSize={pageSize}"); + return await _http.GetFromJsonAsync>($"https://codefirst.iut.uca.fr/containers/container-blazor-web-api-marcchevaldonne/api/Crafting/?currentPage={currentPage}&pageSize={pageSize}"); } + /// + /// Get a list of all items from the API. + /// + /// Task representing the asynchronous operation, returning a list of items. + public async Task> getAll() + { + return await _http.GetFromJsonAsync>($"https://codefirst.iut.uca.fr/containers/container-blazor-web-api-marcchevaldonne/api/Crafting/all"); + } + + /// + /// Get a single item from the API by its ID. + /// + /// The ID of the item to retrieve. + /// Task representing the asynchronous operation, returning the item with the specified ID. public async Task GetById(int id) { - return await _http.GetFromJsonAsync($"https://localhost:7234/api/Crafting/{id}"); + return await _http.GetFromJsonAsync($"https://codefirst.iut.uca.fr/containers/container-blazor-web-api-marcchevaldonne/api/Crafting/{id}"); } + /// + /// Update an existing item in the API. + /// + /// The ID of the item to update. + /// Model containing the updated data for the item. public async Task Update(int id, ItemModel model) { // Get the item var item = ItemFactory.Create(model); - await _http.PutAsJsonAsync($"https://localhost:7234/api/Crafting/{id}", item); + await _http.PutAsJsonAsync($"https://codefirst.iut.uca.fr/containers/container-blazor-web-api-marcchevaldonne/api/Crafting/{id}", item); } + /// + /// Delete an existing item from the API. + /// + /// The ID of the item to delete. public async Task Delete(int id) { - await _http.DeleteAsync($"https://localhost:7234/api/Crafting/{id}"); + await _http.DeleteAsync($"https://codefirst.iut.uca.fr/containers/container-blazor-web-api-marcchevaldonne/api/Crafting/{id}"); } - - public async Task> getAll() - { - return await _http.GetFromJsonAsync>($"https://codefirst.iut.uca.fr/containers/container-blazor-web-api-marcchevaldonne/api/Crafting/all"); - } - } }