Empty cases

aurian
Aurian JAULT 2 years ago
parent f758144ee8
commit c11278f6c7

@ -5,14 +5,15 @@
<div class="css-grid"> <div class="css-grid">
@for(int i = 0; i<InventoryList.size;i++) @for(int i = 0; i<InventoryList.size;i++)
{ {
if (inventory.InvItems[i] != null) if (inventory.inventoryItems[i] != null)
{ {
<InventoryItem item="@inventory.InvItems[i]" /> <ItemInventory items="@inventory.inventoryItems[i]" />
} }
else else
{ {
/*Empty case*/ <div class="item">
<h3>0</h3> <img src="data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAEAAAABACAYAAACqaXHeAAAAZElEQVR42u3QAQ0AAAQAMAppJz85zB/h2VUTj6UAAQIECBAgQIAAAQIECBAgQIAAAQIECBAgQIAAAQIECBAgQIAAAQIECBAgQIAAAQIECBAgQIAAAQIECBAgQIAAAQIECBBw3wKq0HRBv18xwgAAAABJRU5ErkJggg==" class="img-thumbnail" title="Empty" style="width: 64px; height: 64px" />
</div>
} }
} }
</div> </div>

@ -1,4 +1,5 @@
using Blazor.Models; using Blazor.Models;
using Blazor.Pages;
using Microsoft.AspNetCore.Components; using Microsoft.AspNetCore.Components;
namespace Blazor.Components namespace Blazor.Components
{ {
@ -6,5 +7,52 @@ namespace Blazor.Components
{ {
[Parameter] [Parameter]
public InventoryList inventory { get; set; } 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*/
}
}
} }
} }

@ -2,5 +2,5 @@
grid-template-columns: repeat(6,minmax(0,1fr)); grid-template-columns: repeat(6,minmax(0,1fr));
gap: 10px; gap: 10px;
display: grid; display: grid;
width: 286px; width: 40%;
} }

@ -0,0 +1,3 @@
<div class="item">
@items.item
</div>

@ -3,9 +3,9 @@ using Microsoft.AspNetCore.Components;
namespace Blazor.Components namespace Blazor.Components
{ {
public partial class InventoryItem public partial class ItemInventory
{ {
[Parameter] [Parameter]
public Models.InventoryItem item { get; set; } public InventoryItem items { get; set; }
} }
} }

@ -0,0 +1,6 @@
.item {
width: 64px;
height: 64px;
border: 1px solid;
overflow: hidden;
}

@ -5,13 +5,11 @@ namespace Blazor.Models
public partial class InventoryList public partial class InventoryList
{ {
static public int size = 18; static public int size = 18;
List<InventoryItem> inventoryItems = new List<InventoryItem>(new InventoryItem[size]); public List<InventoryItem> inventoryItems = new List<InventoryItem>(new InventoryItem[size]);
public List<InventoryItem> InvItems { get; set; }
public InventoryList() public InventoryList()
{ {
InvItems = new List<InventoryItem>(new InventoryItem[size]); inventoryItems[0] = new InventoryItem();
/*InvItems[0] = new InventoryItem();*/
} }
} }
} }

Loading…
Cancel
Save