Fan website of IMMORTAL: Gates of Pyre.
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.
 
 
 
 

91 lines
2.4 KiB

@inject IJSRuntime jsRuntime;
@inject IEconomyService economyService
@implements IDisposable
<FormLayoutComponent>
<FormDisplayComponent Label="Time">
<Display>@BuildOrderService.GetLastRequestInterval() | T @Interval.ToTime(BuildOrderService.GetLastRequestInterval())</Display>
</FormDisplayComponent>
<FormDisplayComponent Label="Alloy">
<Display>@economy.Alloy</Display>
</FormDisplayComponent>
<FormDisplayComponent Label="Ether">
<Display>@economy.Ether</Display>
</FormDisplayComponent>
<FormDisplayComponent Label="Supply">
<Display>@supplyTaken / @supplyGranted (@(supplyGranted / 16)@(extraBuildings > 0 ? "+" + extraBuildings : ""))</Display>
</FormDisplayComponent>
</FormLayoutComponent>
@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()
{
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();
}
}