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.
135 lines
3.7 KiB
135 lines
3.7 KiB
@inject IJSRuntime jsRuntime; |
|
|
|
@inject IEconomyService economyService |
|
|
|
|
|
@implements IDisposable |
|
|
|
<div class="bankContainer"> |
|
<FormDisplayComponent Label="Time"> |
|
<Display>@(BuildOrderService.GetLastRequestInterval() + 1) | T @Interval.ToTime(BuildOrderService.GetLastRequestInterval() + 1)</Display> |
|
</FormDisplayComponent> |
|
<div class="bankRow"> |
|
<FormDisplayComponent Label="Alloy"> |
|
<Display>@_economy.Alloy +@_economy.AlloyIncome</Display> |
|
</FormDisplayComponent> |
|
<FormDisplayComponent Label="Ether"> |
|
<Display>@Math.Round(_economy.Ether) +@Math.Round(_economy.EtherIncome)</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> |
|
|
|
<div> |
|
<div class="workerText">Workers</div> |
|
<div class="bankRow"> |
|
<FormDisplayComponent Label="Current"> |
|
<Display>@_economy.WorkerCount</Display> |
|
</FormDisplayComponent> |
|
<FormDisplayComponent Label="Busy"> |
|
<Display>@_economy.BusyWorkerCount</Display> |
|
</FormDisplayComponent> |
|
<FormDisplayComponent Label="Creating"> |
|
<Display>@_economy.CreatingWorkerCount</Display> |
|
</FormDisplayComponent> |
|
</div> |
|
</div> |
|
</div> |
|
|
|
<style> |
|
.bankContainer { |
|
display: flex; |
|
flex-direction: column; |
|
gap: 5px; |
|
} |
|
|
|
.workerText { |
|
margin-bottom: -2px; |
|
font-size: 0.8em; |
|
} |
|
|
|
.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() |
|
{ |
|
base.OnInitialized(); |
|
BuildOrderService.Subscribe(OnBuildOrderChanged); |
|
|
|
|
|
_economy = EconomyService.GetEconomy(BuildOrderService.GetLastRequestInterval() + 1); |
|
} |
|
|
|
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() + 1); |
|
|
|
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(); |
|
} |
|
|
|
} |