ADD : stacksizen and css of the inventory item

master
Lucie Bedouret 2 years ago
parent ff94267e86
commit 2fb4419042

@ -125,9 +125,10 @@ namespace Minecraft.Crafting.Api.Controllers
throw new Exception("Unable to get the inventory.");
}
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].Number = Int32.Parse(infos[2]);
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].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));

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

@ -22,5 +22,7 @@ namespace Minecraft.Crafting.Api.Models
public int Position { 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 string ItemName { get; set; }
public int Number { get; set; }
public int StackSize { get; set; }
}
}

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

@ -17,6 +17,9 @@ public partial class InventoryItem
[Parameter]
public int Number { get; set; }
[Parameter]
public int StackSize { get; set; }
[Parameter]
public bool NoDrop { get; set; }
@ -29,7 +32,7 @@ public partial class InventoryItem
{
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()
@ -38,7 +41,7 @@ public partial class InventoryItem
{
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()
@ -54,22 +57,26 @@ public partial class InventoryItem
this.Number = this.Number + Parent.CurrentDragNumber;
Parent.CurrentInventoryItem.Number = 0;
Parent.CurrentInventoryItem.Item = "null";
Parent.ItemsInventory[Parent.CurrentInventoryItem.Index-1] = new InventoryListItem(Parent.CurrentInventoryItem.Item, Parent.CurrentInventoryItem.Index, Parent.CurrentInventoryItem.Number);
Parent.Actions.Add(new InventoryAction { Action = "End", ItemName = Parent.CurrentInventoryItem.Item, Index = Parent.CurrentInventoryItem.Index, Number = Parent.CurrentInventoryItem.Number });
Parent.CurrentInventoryItem.StackSize = 0;
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
{
string tmpItem = this.Item;
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.Number = Parent.CurrentDragNumber;
this.StackSize = Parent.CurrentDragStackSize;
Parent.CurrentInventoryItem.Item = tmpItem;
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()
@ -80,14 +87,16 @@ public partial class InventoryItem
}
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.Number = Parent.CurrentDragNumber;
this.StackSize = Parent.CurrentDragStackSize;
}
Parent.CurrentDragIndex = -1;
Parent.CurrentDragItem = "null";
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.CurrentDragItem = this.Item;
Parent.CurrentDragNumber = this.Number;
Parent.CurrentDragStackSize = this.StackSize;
this.Item = "null";
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 {
display:flex;
flex-direction:column;
width: 64px;
height: 64px;
border: 1px solid;
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(string itemName, int position, int number)
public InventoryListItem(string itemName, int position, int number, int stackSize)
{
this.itemName = itemName;
this.position = position;
this.number = number;
this.stackSize = stackSize;
}
public string itemName { get; set; }
public int position { get; set; }
public int number { get; set; }
public int stackSize { get; set; }
}
}

@ -5,7 +5,7 @@
<div class="inventory-items">
@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>

@ -19,6 +19,7 @@ namespace myBlazorApp.Components
public string CurrentDragItem { get; set; }
public int CurrentDragIndex { get; set; }
public int CurrentDragNumber { get; set; }
public int CurrentDragStackSize { get; set; }
public InventoryItem CurrentInventoryItem {get; set;} = new InventoryItem();
public MyInventory()
@ -45,7 +46,7 @@ namespace myBlazorApp.Components
JavaScriptRuntime.InvokeVoidAsync("MyInventory.AddActions", e.NewItems);
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);
}
}

Loading…
Cancel
Save