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.
109 lines
2.7 KiB
109 lines
2.7 KiB
@inject IJSRuntime jsRuntime; |
|
|
|
@inject IBuildOrderService BuildOrder |
|
|
|
@implements IDisposable |
|
|
|
<FormLayoutComponent> |
|
<FormDisplayComponent Label="Army ready at"> |
|
<Display>@lastInterval | T @Interval.ToTime(lastInterval)</Display> |
|
</FormDisplayComponent> |
|
<FormDisplayComponent Label="Army units built"> |
|
<Display> |
|
<div style="display: flex; width: 100%; gap: 12px; flex-wrap: wrap;"> |
|
@foreach (var unit in armyCount) |
|
{ |
|
<div style="width:90px; height: 60px; border: 1px solid gray; padding: 8px;"> |
|
<div>@unit.Value.ToString()x</div> |
|
<div>@unit.Key</div> |
|
</div> |
|
} |
|
</div> |
|
</Display> |
|
</FormDisplayComponent> |
|
|
|
</FormLayoutComponent> |
|
|
|
@code { |
|
|
|
|
|
private int lastInterval; |
|
|
|
readonly Dictionary<string, int> armyCount = new(); |
|
|
|
List<EntityModel> army = new(); |
|
|
|
protected override void OnInitialized() |
|
{ |
|
BuildOrder.Subscribe(OnBuildOrderChanged); |
|
} |
|
|
|
void IDisposable.Dispose() |
|
{ |
|
BuildOrder.Unsubscribe(OnBuildOrderChanged); |
|
} |
|
|
|
protected override bool ShouldRender() |
|
{ |
|
#if DEBUG |
|
jsRuntime.InvokeVoidAsync("console.time", "ArmyComponent"); |
|
#endif |
|
return true; |
|
} |
|
|
|
protected override void OnAfterRender(bool firstRender) |
|
{ |
|
#if DEBUG |
|
jsRuntime.InvokeVoidAsync("console.timeEnd", "ArmyComponent"); |
|
#endif |
|
} |
|
|
|
void OnBuildOrderChanged() |
|
{ |
|
int armyCountWas = 0; |
|
foreach (var army in armyCount) |
|
{ |
|
armyCountWas += army.Value; |
|
} |
|
|
|
armyCount.Clear(); |
|
|
|
lastInterval = 0; |
|
|
|
var entitiesOverTime = BuildOrder.GetOrders(); |
|
|
|
foreach (var entitiesAtTime in entitiesOverTime) |
|
{ |
|
foreach (var entity in entitiesAtTime.Value) |
|
{ |
|
if (entity.EntityType == EntityType.Army) |
|
{ |
|
if (!armyCount.TryAdd(entity.Info().Name, 1)) |
|
{ |
|
armyCount[entity.Info().Name]++; |
|
} |
|
|
|
if (entity.Production() != null && entity.Production().BuildTime + entitiesAtTime.Key > lastInterval) |
|
{ |
|
lastInterval = entity.Production().BuildTime + entitiesAtTime.Key; |
|
} |
|
} |
|
} |
|
} |
|
|
|
//TODO Better |
|
int armyCountIs = 0; |
|
foreach (var army in armyCount) |
|
{ |
|
armyCountIs += army.Value; |
|
} |
|
|
|
|
|
if (armyCountWas != armyCountIs) |
|
{ |
|
StateHasChanged(); |
|
} |
|
|
|
} |
|
|
|
} |