diff --git a/ValblazeProject/Components/InventoryAction.cs b/ValblazeProject/Components/InventoryAction.cs
new file mode 100644
index 0000000..b768eda
--- /dev/null
+++ b/ValblazeProject/Components/InventoryAction.cs
@@ -0,0 +1,11 @@
+using ValblazeProject.Models;
+
+namespace ValblazeProject.Components
+{
+ public class InventoryAction
+ {
+ public string Action { get; set; }
+ public int Index { get; set; }
+ public Item Item { get; set; }
+ }
+}
diff --git a/ValblazeProject/Components/InventoryItem.razor b/ValblazeProject/Components/InventoryItem.razor
index d11a60a..a29e6fe 100644
--- a/ValblazeProject/Components/InventoryItem.razor
+++ b/ValblazeProject/Components/InventoryItem.razor
@@ -1,14 +1,23 @@
-
+
@if (Item != null)
{
-
)
+
+
)
@if (Item.Num > 0)
+ {
+
+ @(
+ Item.Num
+ )
+
+ }
+
}
\ No newline at end of file
diff --git a/ValblazeProject/Components/InventoryItem.razor.cs b/ValblazeProject/Components/InventoryItem.razor.cs
index fff03de..88d27c6 100644
--- a/ValblazeProject/Components/InventoryItem.razor.cs
+++ b/ValblazeProject/Components/InventoryItem.razor.cs
@@ -1,4 +1,6 @@
using Microsoft.AspNetCore.Components;
+using System.Text.Json;
+using ValblazeProject.Factories;
using ValblazeProject.Models;
using ValblazeProject.Pages;
@@ -18,6 +20,9 @@ namespace ValblazeProject.Components
[CascadingParameter]
public Inventaire Parent { get; set; }
+ ///
+ /// method call when a drag enter a slot and send an action
+ ///
internal void OnDragEnter()
{
if (NoDrop)
@@ -25,9 +30,11 @@ namespace ValblazeProject.Components
return;
}
- Parent.Actions.Add(new CraftingAction { Action = "Drag Enter", Item = this.Item, Index = this.Index });
+ Parent.Actions.Add(new InventoryAction { Action = "Drag Enter", Item = this.Item, Index = this.Index });
}
-
+ ///
+ /// method call when a drag leave a slot and send an action
+ ///
internal void OnDragLeave()
{
if (NoDrop)
@@ -35,27 +42,67 @@ namespace ValblazeProject.Components
return;
}
- Parent.Actions.Add(new CraftingAction { Action = "Drag Leave", Item = this.Item, Index = this.Index });
+ Parent.Actions.Add(new InventoryAction { Action = "Drag Leave", Item = this.Item, Index = this.Index });
}
-
+ ///
+ /// method that manage a drop and send an action
+ ///
internal void OnDrop()
{
- if (NoDrop)
+
+ if (NoDrop == true || Parent.CurrentDragItem == null)
{
return;
}
+ if (this.Item == null)
+ {
+ this.Item = ItemFactory.Create(Parent.CurrentDragItem);
+ }
+ else if (this.Item.Id == Parent.CurrentDragItem.Id)
+ {
+ if (this.Item.StackSize > this.Item.Num)
+ {
+ ItemFactory.Add1(this.Item, this.Item);
+ }
+
+ }
- this.Item = Parent.CurrentDragItem;
+ Parent.Jitems[this.Index] = this.Item;
+ string fileName = "Inventory.json";
+ string jsonString = JsonSerializer.Serialize(Parent.Jitems);
+ File.WriteAllText(fileName, jsonString);
+
+
+ Parent.Actions.Add(new InventoryAction { Action = "Drop", Item = this.Item, Index = this.Index });
- Parent.Actions.Add(new CraftingAction { Action = "Drop", Item = this.Item, Index = this.Index });
}
+ ///
+ /// method call when darg start and send an action
+ ///
- internal void OnDragStart()
+ private void OnDragStart()
{
+
Parent.CurrentDragItem = this.Item;
- Parent.Actions.Add(new CraftingAction { Action = "Drag Start", Item = this.Item, Index = this.Index });
+ Parent.Actions.Add(new InventoryAction { Action = "Drag Start", Item = this.Item, Index = this.Index });
+ }
+ ///
+ /// method call when drag end and send an action specialy when outside the inventory
+ ///
+ private void OnDragEnd()
+ {
+ if (Parent.Actions.Last().Action == "Drag Leave")
+ {
+ this.Item = null;
+ }
+ Parent.Actions.Add(new InventoryAction { Action = "Delete", Item = this.Item, Index = this.Index });
+
+ Parent.Jitems[this.Index] = null;
+ string fileName = "Inventory.json";
+ string jsonString = JsonSerializer.Serialize(Parent.Jitems);
+ File.WriteAllText(fileName, jsonString);
}
}
}
diff --git a/ValblazeProject/Factories/ItemFactory.cs b/ValblazeProject/Factories/ItemFactory.cs
index 8c49500..5bf0b6b 100644
--- a/ValblazeProject/Factories/ItemFactory.cs
+++ b/ValblazeProject/Factories/ItemFactory.cs
@@ -32,7 +32,8 @@ namespace ValblazeProject.Factories
MaxDurability = model.MaxDurability,
StackSize = model.StackSize,
CreatedDate = DateTime.Now,
- ImageBase64 = Convert.ToBase64String(model.ImageContent)
+ ImageBase64 = Convert.ToBase64String(model.ImageContent),
+ Num = 1
};
}
@@ -47,5 +48,39 @@ namespace ValblazeProject.Factories
item.UpdatedDate = DateTime.Now;
item.ImageBase64 = Convert.ToBase64String(model.ImageContent);
}
+ public static Item Create(Item model)
+ {
+ return new Item
+ {
+ Id = model.Id,
+ DisplayName = model.DisplayName,
+ Name = model.Name,
+ RepairWith = model.RepairWith,
+ EnchantCategories = model.EnchantCategories,
+ MaxDurability = model.MaxDurability,
+ StackSize = model.StackSize,
+ CreatedDate = DateTime.Now,
+ ImageBase64 = model.ImageBase64,
+ Num = 1,
+ };
+ }
+
+ public static void Update(Item item, Item model)
+ {
+ item.DisplayName = model.DisplayName;
+ item.Name = model.Name;
+ item.RepairWith = model.RepairWith;
+ item.EnchantCategories = model.EnchantCategories;
+ item.MaxDurability = model.MaxDurability;
+ item.StackSize = model.StackSize;
+ item.UpdatedDate = DateTime.Now;
+ item.ImageBase64 = model.ImageBase64;
+ item.Num = model.Num;
+ }
+
+ public static void Add1(Item item, Item model)
+ {
+ item.Num = model.Num + 1;
+ }
}
}
diff --git a/ValblazeProject/Inventory.json b/ValblazeProject/Inventory.json
new file mode 100644
index 0000000..36b0943
--- /dev/null
+++ b/ValblazeProject/Inventory.json
@@ -0,0 +1 @@
+[null,null,null,null,null,null,{"Id":4,"DisplayName":"Cobblestone","Name":"cobblestone","StackSize":64,"MaxDurability":0,"EnchantCategories":[],"RepairWith":[],"CreatedDate":"2022-12-30T18:25:35.8494594+01:00","UpdatedDate":null,"ImageBase64":"iVBORw0KGgoAAAANSUhEUgAAABAAAAAQCAYAAAAf8/9hAAAA0ElEQVQ4y22S0Q2FMAwDMyMbMABvjcck3YD5QKl01WHxUVDcxElc1\u002B847n3f7zHGPNu2zRjsuq75P//nxPpvrJzYQJ8m6diJ4JB04xdBB/33RBQaT5JiXICMjUPGOk1W/XECYxNDCM7hrvqiCVIHjwxmTZYGqbB390o0Md6E5WRYc2\u002BvRQ53ZTbUzmJIrQnalYtTeU9Ed686Rcyi7EKhReUllgZO8J7e3S\u002BCS5cGTk5N0okWeVk5PW8rf73My8p2Vlr3q9i\u002BmSKmZb9I3DVf7AEDw33Q7E89pwAAAABJRU5ErkJggg==","Num":1},{"Id":4,"DisplayName":"Cobblestone","Name":"cobblestone","StackSize":64,"MaxDurability":0,"EnchantCategories":[],"RepairWith":[],"CreatedDate":"2022-12-30T18:25:28.241733+01:00","UpdatedDate":null,"ImageBase64":"iVBORw0KGgoAAAANSUhEUgAAABAAAAAQCAYAAAAf8/9hAAAA0ElEQVQ4y22S0Q2FMAwDMyMbMABvjcck3YD5QKl01WHxUVDcxElc1\u002B847n3f7zHGPNu2zRjsuq75P//nxPpvrJzYQJ8m6diJ4JB04xdBB/33RBQaT5JiXICMjUPGOk1W/XECYxNDCM7hrvqiCVIHjwxmTZYGqbB390o0Md6E5WRYc2\u002BvRQ53ZTbUzmJIrQnalYtTeU9Ed686Rcyi7EKhReUllgZO8J7e3S\u002BCS5cGTk5N0okWeVk5PW8rf73My8p2Vlr3q9i\u002BmSKmZb9I3DVf7AEDw33Q7E89pwAAAABJRU5ErkJggg==","Num":2},null,null,null,null,null,null,null,null,null,null]
\ No newline at end of file
diff --git a/ValblazeProject/Models/Item.cs b/ValblazeProject/Models/Item.cs
index 3d8d9de..cfb6037 100644
--- a/ValblazeProject/Models/Item.cs
+++ b/ValblazeProject/Models/Item.cs
@@ -12,5 +12,7 @@
public DateTime CreatedDate { get; set; }
public DateTime? UpdatedDate { get; set; }
public string ImageBase64 { get; set; }
+ public int Num { get; set; }
+
}
}
diff --git a/ValblazeProject/Pages/Inventaire.razor.cs b/ValblazeProject/Pages/Inventaire.razor.cs
index 0cf59f8..6d9e9fd 100644
--- a/ValblazeProject/Pages/Inventaire.razor.cs
+++ b/ValblazeProject/Pages/Inventaire.razor.cs
@@ -15,6 +15,7 @@ using System.Linq;
using Microsoft.JSInterop;
using System.Collections.Specialized;
using Microsoft.AspNetCore.Components.Web;
+using System.Text.Json;
namespace ValblazeProject.Pages
{
@@ -36,7 +37,7 @@ namespace ValblazeProject.Pages
private List
- items;
private int totalItem;
- private List invents;
+ public List
- Jitems;
private DataGrid
- dataGrid;
private string _searchText;
@@ -45,14 +46,18 @@ namespace ValblazeProject.Pages
// Gestion logs
- public ObservableCollection Actions { get; set; }
+ public ObservableCollection Actions { get; set; }
public Item CurrentDragItem { get; set; }
public Inventaire()
{
- Actions = new ObservableCollection();
+ Actions = new ObservableCollection();
Actions.CollectionChanged += OnActionsCollectionChanged;
+
+ string fileName = "Inventory.json";
+ string jsonString = File.ReadAllText(fileName);
+ this.Jitems = JsonSerializer.Deserialize
>(jsonString)!;
}
private void OnActionsCollectionChanged(object? sender, NotifyCollectionChangedEventArgs e)
@@ -61,7 +66,7 @@ namespace ValblazeProject.Pages
}
// Drag
-/* protected override async Task OnAfterRenderAsync(bool firstRender)
+ protected override async Task OnAfterRenderAsync(bool firstRender)
{
base.OnAfterRenderAsync(firstRender);
@@ -70,10 +75,8 @@ namespace ValblazeProject.Pages
return;
}
- //invents = await DataService.List(0, await DataService.Count());
-
StateHasChanged();
- }*/
+ }
/******************* Attribut modifier *******************/
private string search
diff --git a/ValblazeProject/obj/Debug/net6.0/ValblazeProject.assets.cache b/ValblazeProject/obj/Debug/net6.0/ValblazeProject.assets.cache
index 303f5d4..d3c0373 100644
Binary files a/ValblazeProject/obj/Debug/net6.0/ValblazeProject.assets.cache and b/ValblazeProject/obj/Debug/net6.0/ValblazeProject.assets.cache differ
diff --git a/ValblazeProject/obj/ValblazeProject.csproj.nuget.dgspec.json b/ValblazeProject/obj/ValblazeProject.csproj.nuget.dgspec.json
index acaea74..2ad09ff 100644
--- a/ValblazeProject/obj/ValblazeProject.csproj.nuget.dgspec.json
+++ b/ValblazeProject/obj/ValblazeProject.csproj.nuget.dgspec.json
@@ -1,17 +1,17 @@
{
"format": 1,
"restore": {
- "E:\\Documents\\Cloud\\DUT\\Blazor\\Projet\\ValblazeProject\\ValblazeProject.csproj": {}
+ "E:\\Temporaire\\MyProject\\ValblazeProject\\ValblazeProject.csproj": {}
},
"projects": {
- "E:\\Documents\\Cloud\\DUT\\Blazor\\Projet\\ValblazeProject\\ValblazeProject.csproj": {
+ "E:\\Temporaire\\MyProject\\ValblazeProject\\ValblazeProject.csproj": {
"version": "1.0.0",
"restore": {
- "projectUniqueName": "E:\\Documents\\Cloud\\DUT\\Blazor\\Projet\\ValblazeProject\\ValblazeProject.csproj",
+ "projectUniqueName": "E:\\Temporaire\\MyProject\\ValblazeProject\\ValblazeProject.csproj",
"projectName": "ValblazeProject",
- "projectPath": "E:\\Documents\\Cloud\\DUT\\Blazor\\Projet\\ValblazeProject\\ValblazeProject.csproj",
+ "projectPath": "E:\\Temporaire\\MyProject\\ValblazeProject\\ValblazeProject.csproj",
"packagesPath": "C:\\Users\\louis\\.nuget\\packages\\",
- "outputPath": "E:\\Documents\\Cloud\\DUT\\Blazor\\Projet\\ValblazeProject\\obj\\",
+ "outputPath": "E:\\Temporaire\\MyProject\\ValblazeProject\\obj\\",
"projectStyle": "PackageReference",
"fallbackFolders": [
"C:\\Program Files (x86)\\Microsoft Visual Studio\\Shared\\NuGetPackages"
diff --git a/ValblazeProject/obj/project.assets.json b/ValblazeProject/obj/project.assets.json
index fcfde08..4ab40b9 100644
--- a/ValblazeProject/obj/project.assets.json
+++ b/ValblazeProject/obj/project.assets.json
@@ -959,11 +959,11 @@
"project": {
"version": "1.0.0",
"restore": {
- "projectUniqueName": "E:\\Documents\\Cloud\\DUT\\Blazor\\Projet\\ValblazeProject\\ValblazeProject.csproj",
+ "projectUniqueName": "E:\\Temporaire\\MyProject\\ValblazeProject\\ValblazeProject.csproj",
"projectName": "ValblazeProject",
- "projectPath": "E:\\Documents\\Cloud\\DUT\\Blazor\\Projet\\ValblazeProject\\ValblazeProject.csproj",
+ "projectPath": "E:\\Temporaire\\MyProject\\ValblazeProject\\ValblazeProject.csproj",
"packagesPath": "C:\\Users\\louis\\.nuget\\packages\\",
- "outputPath": "E:\\Documents\\Cloud\\DUT\\Blazor\\Projet\\ValblazeProject\\obj\\",
+ "outputPath": "E:\\Temporaire\\MyProject\\ValblazeProject\\obj\\",
"projectStyle": "PackageReference",
"fallbackFolders": [
"C:\\Program Files (x86)\\Microsoft Visual Studio\\Shared\\NuGetPackages"