@inject IJSRuntime jsRuntime @inject IBuildOrderService buildOrder @inject ITimingService timingService @implements IDisposable
@lastInterval | T @Interval.ToTime(lastInterval) @(lastInterval + timingService.GetTravelTime()) | T @Interval.ToTime(lastInterval + timingService.GetTravelTime())
@foreach (var unit in armyCount) {
@unit.Value.ToString()x
@unit.Key
}
@code { private int lastInterval; readonly Dictionary armyCount = new(); List army = new(); protected override void OnInitialized() { buildOrder.Subscribe(OnBuildOrderChanged); timingService.Subscribe(StateHasChanged); } void IDisposable.Dispose() { buildOrder.Unsubscribe(OnBuildOrderChanged); timingService.Unsubscribe(StateHasChanged); } 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() { var 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 var armyCountIs = 0; foreach (var army in armyCount) { armyCountIs += army.Value; } if (armyCountWas != armyCountIs) { StateHasChanged(); } } }