🔥 give up on pictures in inventory for now

pull/5/head
Alexis Drai 2 years ago
parent 089e8f4ee2
commit fe350955a0

@ -13,7 +13,10 @@
@if (InventoryModel is not null && IsInInventory)
{
<div>
<img src="@($" data:image/png;base64,{GetItemImageBase64()}")" alt="@InventoryModel.ItemName" />
@if (InventoryModel.NumberItem > 0)
{
<div>@InventoryModel.ItemName</div>
}
<div class="slot-count">@InventoryModel.NumberItem</div>
</div>
}

@ -1,6 +1,7 @@
using blazor_lab.Services;
using Microsoft.AspNetCore.Components;
using Microsoft.AspNetCore.Components.Web;
using Minecraft.Crafting.Api;
using Minecraft.Crafting.Api.Models;
using System.Diagnostics;
using Item = blazor_lab.Models.Item;
@ -27,9 +28,6 @@ namespace blazor_lab.Components
[CascadingParameter]
public Inventory? InventoryParent { get; set; }
[Inject]
public IDataService DataService { get; set; }
public InventoryModel InventoryModel { get; set; } = new InventoryModel();
public InventoryItem()
@ -54,7 +52,7 @@ namespace blazor_lab.Components
{
InventoryModel = InventoryParent!.CurrentDragItem!;
InventoryModel.Position = Position;
InventoryParent.InventoryContent.Add(InventoryModel);
InventoryParent.InventoryContent.Insert(Position, InventoryModel);
}
else
{
@ -64,6 +62,7 @@ namespace blazor_lab.Components
}
}
}
StateHasChanged();
}
internal void OnDragEnd()
@ -92,18 +91,5 @@ namespace blazor_lab.Components
}
}
}
public async Task<string?> GetItemImageBase64()
{
// FIXME probably not great to inject a service in each item and query the whole database everytime we display it
if (InventoryParent is not null)
{
return (await DataService.List(0, await DataService.Count()))
.FirstOrDefault(i => i.DisplayName == InventoryModel.ItemName)?
.ImageBase64;
}
else return null;
}
}
}

Loading…
Cancel
Save