ADD : stacksizen and css of the inventory item

master
Lucie Bedouret 2 years ago
parent ff94267e86
commit 2fb4419042

@ -128,6 +128,7 @@ namespace Minecraft.Crafting.Api.Controllers
data.ToArray()[Int32.Parse(infos[1]) - 1].ItemName = infos[0]; data.ToArray()[Int32.Parse(infos[1]) - 1].ItemName = infos[0];
data.ToArray()[Int32.Parse(infos[1]) - 1].Position = Int32.Parse(infos[1]); data.ToArray()[Int32.Parse(infos[1]) - 1].Position = Int32.Parse(infos[1]);
data.ToArray()[Int32.Parse(infos[1]) - 1].Number = Int32.Parse(infos[2]); data.ToArray()[Int32.Parse(infos[1]) - 1].Number = Int32.Parse(infos[2]);
data.ToArray()[Int32.Parse(infos[1]) - 1].StackSize = Int32.Parse(infos[3]);
System.IO.File.WriteAllText("Data/inventory.json", JsonSerializer.Serialize(data, _jsonSerializerOptions)); System.IO.File.WriteAllText("Data/inventory.json", JsonSerializer.Serialize(data, _jsonSerializerOptions));

@ -4,13 +4,16 @@
"position": 1 "position": 1
}, },
{ {
"itemName": "lili", "itemName": "toto",
"position": 2, "position": 2,
"number": 11 "number": 3,
"stackSize": 6
}, },
{ {
"itemName": "null", "itemName": "lulu",
"position": 3 "position": 3,
"number": 11,
"stackSize": 12
}, },
{ {
"itemName": "null", "itemName": "null",
@ -33,17 +36,20 @@
"position": 8 "position": 8
}, },
{ {
"itemName": "null", "itemName": "toto",
"position": 9 "position": 9,
"number": 3,
"stackSize": 6
}, },
{ {
"itemName": "lulu", "itemName": "null",
"position": 10, "position": 10
"number": 11
}, },
{ {
"itemName": "null", "itemName": "lili",
"position": 11 "position": 11,
"number": 11,
"stackSize": 64
}, },
{ {
"itemName": "null", "itemName": "null",

@ -22,5 +22,7 @@ namespace Minecraft.Crafting.Api.Models
public int Position { get; set; } public int Position { get; set; }
public int Number { get; set; } public int Number { get; set; }
public int StackSize { get; set; }
} }
} }

@ -8,6 +8,7 @@ namespace myBlazorApp.Components
public int Index { get; set; } public int Index { get; set; }
public string ItemName { get; set; } public string ItemName { get; set; }
public int Number { get; set; } public int Number { get; set; }
public int StackSize { get; set; }
} }
} }

@ -9,12 +9,13 @@
@ondragleave="@OnDragLeave"> @ondragleave="@OnDragLeave">
@if (Item != "null") @if (Item != "null")
{ {
<p>@Item</p> <label id="name">@Item</label>
<p>@Number</p> <label id="number">@Number</label>
<label id="stackSize">@StackSize</label>
} }
else else
{ {
<p>Empty</p> <p id="vide">Empty</p>
} }
</div> </div>

@ -17,6 +17,9 @@ public partial class InventoryItem
[Parameter] [Parameter]
public int Number { get; set; } public int Number { get; set; }
[Parameter]
public int StackSize { get; set; }
[Parameter] [Parameter]
public bool NoDrop { get; set; } public bool NoDrop { get; set; }
@ -29,7 +32,7 @@ public partial class InventoryItem
{ {
return; return;
} }
Parent.Actions.Add(new InventoryAction { Action = "Drag Enter", ItemName = this.Item, Index = this.Index, Number = this.Number }); Parent.Actions.Add(new InventoryAction { Action = "Drag Enter", ItemName = this.Item, Index = this.Index, Number = this.Number, StackSize = this.StackSize });
} }
internal void OnDragLeave() internal void OnDragLeave()
@ -38,7 +41,7 @@ public partial class InventoryItem
{ {
return; return;
} }
Parent.Actions.Add(new InventoryAction { Action = "Drag Leave", ItemName = this.Item, Index = this.Index, Number = this.Number }); Parent.Actions.Add(new InventoryAction { Action = "Drag Leave", ItemName = this.Item, Index = this.Index, Number = this.Number, StackSize = this.StackSize });
} }
internal void OnDrop() internal void OnDrop()
@ -54,22 +57,26 @@ public partial class InventoryItem
this.Number = this.Number + Parent.CurrentDragNumber; this.Number = this.Number + Parent.CurrentDragNumber;
Parent.CurrentInventoryItem.Number = 0; Parent.CurrentInventoryItem.Number = 0;
Parent.CurrentInventoryItem.Item = "null"; Parent.CurrentInventoryItem.Item = "null";
Parent.ItemsInventory[Parent.CurrentInventoryItem.Index-1] = new InventoryListItem(Parent.CurrentInventoryItem.Item, Parent.CurrentInventoryItem.Index, Parent.CurrentInventoryItem.Number); Parent.CurrentInventoryItem.StackSize = 0;
Parent.Actions.Add(new InventoryAction { Action = "End", ItemName = Parent.CurrentInventoryItem.Item, Index = Parent.CurrentInventoryItem.Index, Number = Parent.CurrentInventoryItem.Number }); Parent.ItemsInventory[Parent.CurrentInventoryItem.Index-1] = new InventoryListItem(Parent.CurrentInventoryItem.Item, Parent.CurrentInventoryItem.Index, Parent.CurrentInventoryItem.Number, Parent.CurrentInventoryItem.StackSize);
Parent.Actions.Add(new InventoryAction { Action = "End", ItemName = Parent.CurrentInventoryItem.Item, Index = Parent.CurrentInventoryItem.Index, Number = Parent.CurrentInventoryItem.Number, StackSize = Parent.CurrentInventoryItem.StackSize });
} }
else else
{ {
string tmpItem = this.Item; string tmpItem = this.Item;
int tmpNumber = this.Number; int tmpNumber = this.Number;
Parent.ItemsInventory[Parent.CurrentDragIndex-1] = new InventoryListItem(tmpItem, Parent.CurrentDragIndex, tmpNumber); int tmpStackSize = this.StackSize;
Parent.ItemsInventory[Parent.CurrentDragIndex-1] = new InventoryListItem(tmpItem, Parent.CurrentDragIndex, tmpNumber, tmpStackSize);
this.Item = Parent.CurrentDragItem; this.Item = Parent.CurrentDragItem;
this.Number = Parent.CurrentDragNumber; this.Number = Parent.CurrentDragNumber;
this.StackSize = Parent.CurrentDragStackSize;
Parent.CurrentInventoryItem.Item = tmpItem; Parent.CurrentInventoryItem.Item = tmpItem;
Parent.CurrentInventoryItem.Number = tmpNumber; Parent.CurrentInventoryItem.Number = tmpNumber;
Parent.CurrentInventoryItem.StackSize = tmpStackSize;
} }
} }
Parent.Actions.Add(new InventoryAction { Action = "Drop", ItemName = this.Item, Index = this.Index, Number = this.Number }); Parent.Actions.Add(new InventoryAction { Action = "Drop", ItemName = this.Item, Index = this.Index, Number = this.Number, StackSize = this.StackSize });
} }
internal void OnDragEnd() internal void OnDragEnd()
@ -80,14 +87,16 @@ public partial class InventoryItem
} }
if (Parent.CurrentDragIndex != -1 && Parent.CurrentDragIndex != this.Index) if (Parent.CurrentDragIndex != -1 && Parent.CurrentDragIndex != this.Index)
{ {
Parent.ItemsInventory[this.Index-1] = new InventoryListItem(Parent.CurrentDragItem, Parent.CurrentDragIndex, Parent.CurrentDragNumber); Parent.ItemsInventory[this.Index-1] = new InventoryListItem(Parent.CurrentDragItem, Parent.CurrentDragIndex, Parent.CurrentDragNumber, Parent.CurrentDragStackSize);
this.Item = Parent.CurrentDragItem; this.Item = Parent.CurrentDragItem;
this.Number = Parent.CurrentDragNumber; this.Number = Parent.CurrentDragNumber;
this.StackSize = Parent.CurrentDragStackSize;
} }
Parent.CurrentDragIndex = -1; Parent.CurrentDragIndex = -1;
Parent.CurrentDragItem = "null"; Parent.CurrentDragItem = "null";
Parent.CurrentDragNumber = 0; Parent.CurrentDragNumber = 0;
Parent.Actions.Add(new InventoryAction { Action = "End", ItemName = this.Item, Index = this.Index, Number = this.Number }); Parent.CurrentDragStackSize = 0;
Parent.Actions.Add(new InventoryAction { Action = "End", ItemName = this.Item, Index = this.Index, Number = this.Number, StackSize = this.StackSize });
} }
@ -97,9 +106,11 @@ public partial class InventoryItem
Parent.CurrentDragIndex = this.Index; Parent.CurrentDragIndex = this.Index;
Parent.CurrentDragItem = this.Item; Parent.CurrentDragItem = this.Item;
Parent.CurrentDragNumber = this.Number; Parent.CurrentDragNumber = this.Number;
Parent.CurrentDragStackSize = this.StackSize;
this.Item = "null"; this.Item = "null";
this.Number = 0; this.Number = 0;
Parent.Actions.Add(new InventoryAction { Action = "Drag Start", ItemName = this.Item, Index = this.Index, Number = this.Number}); this.StackSize = 0;
Parent.Actions.Add(new InventoryAction { Action = "Drag Start", ItemName = this.Item, Index = this.Index, Number = this.Number, StackSize = this.StackSize});
} }
} }

@ -1,7 +1,26 @@
.inventory-item { .inventory-item {
display:flex;
flex-direction:column;
width: 64px; width: 64px;
height: 64px; height: 64px;
border: 1px solid; border: 1px solid;
overflow: hidden; overflow: hidden;
align-content:center align-content:center;
}
#name {
text-align: center;
}
#number {
text-align: center;
}
#stackSize {
font-weight:lighter;
text-align:right;
margin-top:-5px;
margin-right:2px;
}
#vide {
align-self:center;
margin-top:20px;
} }

@ -6,16 +6,18 @@ namespace myBlazorApp.Components
{ {
//public InventoryListItem() { } //public InventoryListItem() { }
public InventoryListItem(string itemName, int position, int number) public InventoryListItem(string itemName, int position, int number, int stackSize)
{ {
this.itemName = itemName; this.itemName = itemName;
this.position = position; this.position = position;
this.number = number; this.number = number;
this.stackSize = stackSize;
} }
public string itemName { get; set; } public string itemName { get; set; }
public int position { get; set; } public int position { get; set; }
public int number { get; set; } public int number { get; set; }
public int stackSize { get; set; }
} }
} }

@ -5,7 +5,7 @@
<div class="inventory-items"> <div class="inventory-items">
@foreach(InventoryListItem i in ItemsInventory) @foreach(InventoryListItem i in ItemsInventory)
{ {
<InventoryItem Index="@i.position" Item="@i.itemName" Number="@i.number" /> <InventoryItem Index="@i.position" Item="@i.itemName" Number="@i.number" StackSize="@i.stackSize" />
} }
</div> </div>

@ -19,6 +19,7 @@ namespace myBlazorApp.Components
public string CurrentDragItem { get; set; } public string CurrentDragItem { get; set; }
public int CurrentDragIndex { get; set; } public int CurrentDragIndex { get; set; }
public int CurrentDragNumber { get; set; } public int CurrentDragNumber { get; set; }
public int CurrentDragStackSize { get; set; }
public InventoryItem CurrentInventoryItem {get; set;} = new InventoryItem(); public InventoryItem CurrentInventoryItem {get; set;} = new InventoryItem();
public MyInventory() public MyInventory()
@ -45,7 +46,7 @@ namespace myBlazorApp.Components
JavaScriptRuntime.InvokeVoidAsync("MyInventory.AddActions", e.NewItems); JavaScriptRuntime.InvokeVoidAsync("MyInventory.AddActions", e.NewItems);
if (this.Actions.Last().Action == "End" || this.Actions.Last().Action == "Drop" || this.Actions.Last().Action == "Start") if (this.Actions.Last().Action == "End" || this.Actions.Last().Action == "Drop" || this.Actions.Last().Action == "Start")
{ {
string[] infos = new string[] { this.Actions.Last().ItemName, this.Actions.Last().Index.ToString(), this.Actions.Last().Number.ToString() }; string[] infos = new string[] { this.Actions.Last().ItemName, this.Actions.Last().Index.ToString(), this.Actions.Last().Number.ToString(), this.Actions.Last().StackSize.ToString() };
await DataService.UpdateInventory(infos); await DataService.UpdateInventory(infos);
} }
} }

Loading…
Cancel
Save