🔥 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) @if (InventoryModel is not null && IsInInventory)
{ {
<div> <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 class="slot-count">@InventoryModel.NumberItem</div>
</div> </div>
} }

@ -1,6 +1,7 @@
using blazor_lab.Services; using blazor_lab.Services;
using Microsoft.AspNetCore.Components; using Microsoft.AspNetCore.Components;
using Microsoft.AspNetCore.Components.Web; using Microsoft.AspNetCore.Components.Web;
using Minecraft.Crafting.Api;
using Minecraft.Crafting.Api.Models; using Minecraft.Crafting.Api.Models;
using System.Diagnostics; using System.Diagnostics;
using Item = blazor_lab.Models.Item; using Item = blazor_lab.Models.Item;
@ -27,9 +28,6 @@ namespace blazor_lab.Components
[CascadingParameter] [CascadingParameter]
public Inventory? InventoryParent { get; set; } public Inventory? InventoryParent { get; set; }
[Inject]
public IDataService DataService { get; set; }
public InventoryModel InventoryModel { get; set; } = new InventoryModel(); public InventoryModel InventoryModel { get; set; } = new InventoryModel();
public InventoryItem() public InventoryItem()
@ -54,7 +52,7 @@ namespace blazor_lab.Components
{ {
InventoryModel = InventoryParent!.CurrentDragItem!; InventoryModel = InventoryParent!.CurrentDragItem!;
InventoryModel.Position = Position; InventoryModel.Position = Position;
InventoryParent.InventoryContent.Add(InventoryModel); InventoryParent.InventoryContent.Insert(Position, InventoryModel);
} }
else else
{ {
@ -64,6 +62,7 @@ namespace blazor_lab.Components
} }
} }
} }
StateHasChanged();
} }
internal void OnDragEnd() 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