< Summary

Information
Class: RaidLoop.Client.Components.LoadoutPanel
Assembly: RaidLoop.Client
File(s): /home/runner/work/RaidLoop/RaidLoop/src/RaidLoop.Client/Components/LoadoutPanel.razor
Line coverage
0%
Covered lines: 0
Uncovered lines: 50
Coverable lines: 50
Total lines: 117
Line coverage: 0%
Branch coverage
0%
Covered branches: 0
Total branches: 28
Branch coverage: 0%
Method coverage

Feature is only available for sponsors

Upgrade to PRO version

Metrics

File(s)

/home/runner/work/RaidLoop/RaidLoop/src/RaidLoop.Client/Components/LoadoutPanel.razor

#LineLine coverage
 1<div>
 2    <h3>For Raid</h3>
 3    <p>You are taking these into raid with you and they will be lost if you die.</p>
 4    <p class="encumbrance-readout">
 5        <span class="encumbrance-label">Encumbrance:</span>
 06        <span class="encumbrance-value @GetEncumbranceSeverityCssClass()">@EncumbranceText</span>
 07        @if (ShouldShowEncumbranceTier())
 8        {
 09            <span class="encumbrance-tier @GetEncumbranceSeverityCssClass()">@GetEncumbranceTierLabel()</span>
 10        }
 11    </p>
 012    @if (OnPersonItems.Count == 0)
 13    {
 14        <p>Nothing selected.</p>
 15    }
 16    else
 17    {
 018        @for (var i = 0; i < OnPersonItems.Count; i++)
 19        {
 020            var onPersonIndex = i;
 021            var entry = OnPersonItems[onPersonIndex];
 22            <div class="row-item">
 23                <ItemTypeIcon Type="entry.Item.Type" />
 024                <span class="item-name rarity-@entry.Item.DisplayRarity.ToString().ToLower()">@ItemPresentationCatalog.G
 25                <div class="row-actions">
 026                    @if (IsSlotType(entry.Item.Type))
 27                    {
 028                        <button class="action" @onclick="() => ToggleEquipAsync(onPersonIndex, entry.IsEquipped)">@(entr
 29                    }
 030                    <button class="action" disabled="@(!CanStashItem)" @onclick="() => OnStore.InvokeAsync(onPersonIndex
 031                    <button class="action" disabled="@(!CanSellItem(entry.Item))" @onclick="() => OnSell.InvokeAsync(onP
 32                </div>
 33            </div>
 34        }
 035        @if (!CanStashItem)
 36        {
 37            <p>Stash full. Sell or use items first.</p>
 38        }
 39    }
 40
 041    <button class="action top-gap" disabled="@(!CanStartRaid)" @onclick="() => OnStartRaid.InvokeAsync()">Enter Raid</bu
 042    @if (!CanStartRaid && !string.IsNullOrWhiteSpace(RaidBlockReason))
 43    {
 044        <p>@RaidBlockReason</p>
 45    }
 46</div>
 47
 48@code {
 049    [Parameter, EditorRequired] public IReadOnlyList<OnPersonEntry> OnPersonItems { get; set; } = [];
 050    [Parameter, EditorRequired] public bool CanStashItem { get; set; }
 051    [Parameter, EditorRequired] public bool CanStartRaid { get; set; }
 052    [Parameter] public string? RaidBlockReason { get; set; }
 053    [Parameter, EditorRequired] public string EncumbranceText { get; set; } = string.Empty;
 054    [Parameter, EditorRequired] public int MaxEncumbrance { get; set; }
 055    [Parameter, EditorRequired] public Func<Item, bool> CanSellItem { get; set; } = _ => false;
 056    [Parameter, EditorRequired] public Func<Item, int> GetSellPrice { get; set; } = _ => 0;
 057    [Parameter, EditorRequired] public Func<ItemType, bool> IsSlotType { get; set; } = _ => false;
 058    [Parameter, EditorRequired] public EventCallback<int> OnEquip { get; set; }
 059    [Parameter, EditorRequired] public EventCallback<int> OnUnequip { get; set; }
 060    [Parameter, EditorRequired] public EventCallback<int> OnStore { get; set; }
 061    [Parameter, EditorRequired] public EventCallback<int> OnSell { get; set; }
 062    [Parameter, EditorRequired] public EventCallback OnStartRaid { get; set; }
 63
 64    private Task ToggleEquipAsync(int index, bool isEquipped)
 65    {
 066        return isEquipped ? OnUnequip.InvokeAsync(index) : OnEquip.InvokeAsync(index);
 67    }
 68
 69    private int GetCurrentEncumbrance()
 70    {
 071        return OnPersonItems.Sum(entry => Math.Max(0, entry.Item.Weight));
 72    }
 73
 74    private EncumbranceTier GetDisplayedEncumbranceTier()
 75    {
 076        if (MaxEncumbrance <= 0)
 77        {
 078            return EncumbranceTier.Light;
 79        }
 80
 081        var carriedWeight = GetCurrentEncumbrance();
 082        var lightThreshold = MaxEncumbrance / 3;
 083        var mediumThreshold = (MaxEncumbrance * 2) / 3;
 84
 085        if (carriedWeight <= lightThreshold)
 86        {
 087            return EncumbranceTier.Light;
 88        }
 89
 090        if (carriedWeight <= mediumThreshold)
 91        {
 092            return EncumbranceTier.Medium;
 93        }
 94
 095        return EncumbranceTier.Heavy;
 96    }
 97
 98    private bool ShouldShowEncumbranceTier()
 99    {
 0100        return GetDisplayedEncumbranceTier() is not EncumbranceTier.Light;
 101    }
 102
 103    private string GetEncumbranceTierLabel()
 104    {
 0105        return GetDisplayedEncumbranceTier().ToString();
 106    }
 107
 108    private string GetEncumbranceSeverityCssClass()
 109    {
 0110        return GetDisplayedEncumbranceTier() switch
 0111        {
 0112            EncumbranceTier.Medium => "encumbrance-medium",
 0113            EncumbranceTier.Heavy => "encumbrance-heavy",
 0114            _ => string.Empty
 0115        };
 116    }
 117}