You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
107 lines
2.8 KiB
107 lines
2.8 KiB
@inject IJSRuntime jsRuntime; |
|
|
|
@inject IEconomyService economyService |
|
|
|
|
|
@implements IDisposable |
|
|
|
<FormLayoutComponent> |
|
<FormDisplayComponent Label="Time"> |
|
<Display>@BuildOrderService.GetLastRequestInterval() | T @Interval.ToTime(BuildOrderService.GetLastRequestInterval())</Display> |
|
</FormDisplayComponent> |
|
<div class="bankRow"> |
|
<FormDisplayComponent Label="Alloy"> |
|
<Display>@economy.Alloy</Display> |
|
</FormDisplayComponent> |
|
<FormDisplayComponent Label="Ether"> |
|
<Display>@economy.Ether</Display> |
|
</FormDisplayComponent> |
|
</div> |
|
<div class="bankRow"> |
|
<FormDisplayComponent Label="Pyre"> |
|
<Display>@economy.Pyre</Display> |
|
</FormDisplayComponent> |
|
<FormDisplayComponent Label="Supply"> |
|
<Display>@supplyTaken / @supplyGranted (@(supplyGranted / 16)@(extraBuildings > 0 ? "+" + extraBuildings : ""))</Display> |
|
</FormDisplayComponent> |
|
</div> |
|
</FormLayoutComponent> |
|
|
|
<style> |
|
.bankRow { |
|
display: flex; |
|
gap: 8px; |
|
} |
|
</style> |
|
|
|
@code { |
|
|
|
[Inject] |
|
IBuildOrderService BuildOrderService { get; set; } = default!; |
|
|
|
[Inject] |
|
IEconomyService EconomyService { get; set; } = default!; |
|
|
|
EconomyModel economy = new(); |
|
int supplyGranted; |
|
int supplyTaken; |
|
int extraBuildings; |
|
|
|
protected override void OnInitialized() |
|
{ |
|
BuildOrderService.Subscribe(OnBuildOrderChanged); |
|
} |
|
|
|
protected override bool ShouldRender() |
|
{ |
|
#if DEBUG |
|
jsRuntime.InvokeVoidAsync("console.time", "BankComponent"); |
|
#endif |
|
|
|
return true; |
|
} |
|
|
|
protected override void OnAfterRender(bool firstRender) |
|
{ |
|
#if DEBUG |
|
jsRuntime.InvokeVoidAsync("console.timeEnd", "BankComponent"); |
|
#endif |
|
} |
|
|
|
void IDisposable.Dispose() |
|
{ |
|
BuildOrderService.Unsubscribe(OnBuildOrderChanged); |
|
} |
|
|
|
void OnBuildOrderChanged() |
|
{ |
|
Console.WriteLine("OnBuildOrderChanged()"); |
|
|
|
economy = EconomyService.GetEconomy(BuildOrderService.GetLastRequestInterval()); |
|
|
|
var ordersOverTime = BuildOrderService.GetOrders(); |
|
|
|
supplyTaken = (from ordersAtInterval in ordersOverTime |
|
from order in ordersAtInterval.Value |
|
where order.Supply() != null |
|
where order.Supply().Takes > 0 |
|
select order.Supply().Takes).Sum(); |
|
|
|
supplyGranted = (from ordersAtInterval in ordersOverTime |
|
from order in ordersAtInterval.Value |
|
where order.Supply() != null |
|
where order.Supply().Grants > 0 |
|
select order.Supply().Grants).Sum(); |
|
|
|
extraBuildings = 0; |
|
if (supplyGranted > 160) |
|
{ |
|
extraBuildings = (supplyGranted - 160) / 16; |
|
supplyGranted = 160; |
|
} |
|
|
|
|
|
StateHasChanged(); |
|
} |
|
|
|
} |