feat(BuildCalc) Optimized the build calculator
This commit is contained in:
@@ -1,7 +1,4 @@
|
||||
@using Microsoft.Extensions.Localization
|
||||
@implements IDisposable
|
||||
|
||||
@layout PageLayout
|
||||
@layout PageLayout
|
||||
|
||||
@inject IStringLocalizer<Localizations> locale
|
||||
|
||||
@@ -13,6 +10,9 @@
|
||||
@inject ITimingService timingService
|
||||
|
||||
@page "/build-calculator"
|
||||
@using Microsoft.Extensions.Localization
|
||||
|
||||
@implements IDisposable
|
||||
|
||||
<LayoutLargeContentComponent>
|
||||
<WebsiteTitleComponent>Build Calculator</WebsiteTitleComponent>
|
||||
@@ -30,7 +30,7 @@
|
||||
<div class="calculatorGrid">
|
||||
|
||||
<div style="grid-area: timing;" class="gridItem">
|
||||
<InfoTooltipComponent InfoText="@locale["Tooltip Timing Info"]" >
|
||||
<InfoTooltipComponent InfoText="@locale["Tooltip Timing Info"]">
|
||||
|
||||
<TimingComponent></TimingComponent>
|
||||
</InfoTooltipComponent>
|
||||
@@ -52,27 +52,32 @@
|
||||
</InfoTooltipComponent>
|
||||
</div>
|
||||
|
||||
@if (true)
|
||||
{
|
||||
<div style="grid-area: view;" class="gridItem">
|
||||
<InfoTooltipComponent InfoText="@locale["Tooltip Entity Info"]">
|
||||
<EntityClickViewComponent/>
|
||||
</InfoTooltipComponent>
|
||||
</div>
|
||||
}
|
||||
|
||||
<div style="grid-area: view;" class="gridItem">
|
||||
<InfoTooltipComponent InfoText="@locale["Tooltip Entity Info"]">
|
||||
<EntityClickViewComponent/>
|
||||
</InfoTooltipComponent>
|
||||
</div>
|
||||
|
||||
|
||||
<div style="grid-area: bank;" class="gridItem">
|
||||
<InfoTooltipComponent InfoText="@locale["Tooltip Bank Info"]">
|
||||
<BankComponent></BankComponent>
|
||||
</InfoTooltipComponent>
|
||||
</div>
|
||||
|
||||
|
||||
<div style="grid-area: army;" class="gridItem">
|
||||
<InfoTooltipComponent InfoText="@locale["Tooltip Army Info"]">
|
||||
<ArmyComponent></ArmyComponent>
|
||||
</InfoTooltipComponent>
|
||||
</div>
|
||||
@if (true)
|
||||
{
|
||||
<div style="grid-area: bank;" class="gridItem">
|
||||
<InfoTooltipComponent InfoText="@locale["Tooltip Bank Info"]">
|
||||
<BankComponent></BankComponent>
|
||||
</InfoTooltipComponent>
|
||||
</div>
|
||||
}
|
||||
|
||||
@if (true)
|
||||
{
|
||||
<div style="grid-area: army;" class="gridItem">
|
||||
<InfoTooltipComponent InfoText="@locale["Tooltip Army Info"]">
|
||||
<ArmyComponent></ArmyComponent>
|
||||
</InfoTooltipComponent>
|
||||
</div>
|
||||
}
|
||||
|
||||
<div class="gridItem gridKeys">
|
||||
|
||||
@@ -82,25 +87,22 @@
|
||||
</InfoTooltipComponent>
|
||||
</div>
|
||||
|
||||
|
||||
@if (false)
|
||||
@if (true)
|
||||
{
|
||||
<div style="grid-area: timeline;" class="gridItem">
|
||||
<TimelineComponent></TimelineComponent>
|
||||
<div style="grid-area: highlights;" class="gridItem">
|
||||
<InfoTooltipComponent InfoText="@locale["Tooltip Highlights Info"]">
|
||||
<HighlightsComponent></HighlightsComponent>
|
||||
</InfoTooltipComponent>
|
||||
</div>
|
||||
}
|
||||
@if (true)
|
||||
{
|
||||
<div style="grid-area: buildorder;" class="gridItem">
|
||||
<InfoTooltipComponent InfoText="@locale["Tooltip BuildOrder Info"]">
|
||||
<BuildOrderComponent></BuildOrderComponent>
|
||||
</InfoTooltipComponent>
|
||||
</div>
|
||||
}
|
||||
|
||||
<div style="grid-area: highlights;" class="gridItem">
|
||||
<InfoTooltipComponent InfoText="@locale["Tooltip Highlights Info"]">
|
||||
<HighlightsComponent></HighlightsComponent>
|
||||
</InfoTooltipComponent>
|
||||
</div>
|
||||
|
||||
<div style="grid-area: buildorder;" class="gridItem">
|
||||
<InfoTooltipComponent InfoText="@locale["Tooltip BuildOrder Info"]">
|
||||
<BuildOrderComponent></BuildOrderComponent>
|
||||
</InfoTooltipComponent>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<ContentDividerComponent></ContentDividerComponent>
|
||||
@@ -218,29 +220,19 @@
|
||||
|
||||
|
||||
@code {
|
||||
|
||||
protected override void OnInitialized()
|
||||
{
|
||||
keyService.Subscribe(HandleClick);
|
||||
filterService.Subscribe(StateHasChanged);
|
||||
economyService.Subscribe(StateHasChanged);
|
||||
timingService.Subscribe(HandleTimingChanged);
|
||||
economyService.Calculate(buildOrderService, timingService, 0);
|
||||
|
||||
keyService.Subscribe(HandleClick);
|
||||
}
|
||||
|
||||
|
||||
void IDisposable.Dispose()
|
||||
{
|
||||
keyService.Unsubscribe(HandleClick);
|
||||
filterService.Unsubscribe(StateHasChanged);
|
||||
timingService.Unsubscribe(StateHasChanged);
|
||||
economyService.Unsubscribe(StateHasChanged);
|
||||
}
|
||||
|
||||
private void HandleTimingChanged()
|
||||
{
|
||||
economyService.Calculate(buildOrderService, timingService, buildOrderService.GetLastRequestInterval());
|
||||
}
|
||||
|
||||
|
||||
private void HandleClick()
|
||||
{
|
||||
var hotkey = keyService.GetHotkey();
|
||||
@@ -254,7 +246,6 @@
|
||||
{
|
||||
buildOrderService.RemoveLast();
|
||||
economyService.Calculate(buildOrderService, timingService, buildOrderService.GetLastRequestInterval());
|
||||
StateHasChanged();
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -275,5 +266,4 @@
|
||||
economyService.Calculate(buildOrderService, timingService, buildOrderService.GetLastRequestInterval());
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,4 +1,8 @@
|
||||
@implements IDisposable
|
||||
@inject IJSRuntime jsRuntime;
|
||||
|
||||
@inject IBuildOrderService BuildOrder
|
||||
|
||||
@implements IDisposable
|
||||
|
||||
<FormLayoutComponent>
|
||||
<FormDisplayComponent Label="Army ready at">
|
||||
@@ -22,8 +26,6 @@
|
||||
|
||||
@code {
|
||||
|
||||
[Inject]
|
||||
public IBuildOrderService BuildOrder { get; set; } = default!;
|
||||
|
||||
private int lastInterval;
|
||||
|
||||
@@ -41,8 +43,29 @@
|
||||
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;
|
||||
@@ -68,7 +91,19 @@
|
||||
}
|
||||
}
|
||||
|
||||
StateHasChanged();
|
||||
//TODO Better
|
||||
int armyCountIs = 0;
|
||||
foreach (var army in armyCount)
|
||||
{
|
||||
armyCountIs += army.Value;
|
||||
}
|
||||
|
||||
|
||||
if (armyCountWas != armyCountIs)
|
||||
{
|
||||
StateHasChanged();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,4 +1,9 @@
|
||||
@implements IDisposable
|
||||
@inject IJSRuntime jsRuntime;
|
||||
|
||||
@inject IEconomyService economyService
|
||||
|
||||
|
||||
@implements IDisposable
|
||||
|
||||
<FormLayoutComponent>
|
||||
<FormDisplayComponent Label="Time">
|
||||
@@ -10,11 +15,6 @@
|
||||
<FormDisplayComponent Label="Ether">
|
||||
<Display>@economy.Ether</Display>
|
||||
</FormDisplayComponent>
|
||||
<DevOnlyComponent>
|
||||
<FormDisplayComponent Label="Pyre">
|
||||
<Display>@economy.Pyre</Display>
|
||||
</FormDisplayComponent>
|
||||
</DevOnlyComponent>
|
||||
<FormDisplayComponent Label="Supply">
|
||||
<Display>@supplyTaken / @supplyGranted (@(supplyGranted / 16)@(extraBuildings > 0 ? "+" + extraBuildings : ""))</Display>
|
||||
</FormDisplayComponent>
|
||||
@@ -36,13 +36,27 @@
|
||||
protected override void OnInitialized()
|
||||
{
|
||||
BuildOrderService.Subscribe(OnBuildOrderChanged);
|
||||
EconomyService.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);
|
||||
EconomyService.Subscribe(OnBuildOrderChanged);
|
||||
}
|
||||
|
||||
void OnBuildOrderChanged()
|
||||
|
||||
@@ -1,4 +1,7 @@
|
||||
@inject IBuildOrderService buildOrderService
|
||||
@inject IJSRuntime jsRuntime;
|
||||
|
||||
|
||||
@inject IBuildOrderService buildOrderService
|
||||
|
||||
@implements IDisposable
|
||||
|
||||
@@ -21,4 +24,19 @@
|
||||
buildOrderService.Unsubscribe(StateHasChanged);
|
||||
}
|
||||
|
||||
protected override bool ShouldRender()
|
||||
{
|
||||
#if DEBUG
|
||||
jsRuntime.InvokeVoidAsync("console.time", "BuildOrderComponent");
|
||||
#endif
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
protected override void OnAfterRender(bool firstRender)
|
||||
{
|
||||
#if DEBUG
|
||||
jsRuntime.InvokeVoidAsync("console.timeEnd", "BuildOrderComponent");
|
||||
#endif
|
||||
}
|
||||
}
|
||||
@@ -1,27 +1,38 @@
|
||||
@implements IDisposable
|
||||
@inject IEconomyService economyService
|
||||
@inject IBuildOrderService buildOrderService
|
||||
@inject IJSRuntime jsRuntime;
|
||||
@implements IDisposable
|
||||
|
||||
<div class="chartsContainer">
|
||||
@foreach (var chart in charts)
|
||||
{
|
||||
<div style="width: @chart.IntervalDisplayMax.ToString()px; height: @chart.ValueDisplayMax.ToString()px">
|
||||
<div style="position: relative; border: 2px solid gray; border-radius:2px; width: @chart.IntervalDisplayMax.ToString()px; height: @chart.ValueDisplayMax.ToString()px">
|
||||
@foreach (var point in chart.Points)
|
||||
{
|
||||
<div style="position: absolute;
|
||||
@if (lastRequestedRefreshIndex != requestedRefreshIndex)
|
||||
{
|
||||
<LoadingComponent/>
|
||||
|
||||
}
|
||||
else
|
||||
{
|
||||
<div class="chartsContainer">
|
||||
@foreach (var chart in charts)
|
||||
{
|
||||
<div style="width: @chart.IntervalDisplayMax.ToString()px; height: @chart.ValueDisplayMax.ToString()px">
|
||||
<div style="position: relative; border: 2px solid gray; border-radius:2px; width: @chart.IntervalDisplayMax.ToString()px; height: @chart.ValueDisplayMax.ToString()px">
|
||||
@foreach (var point in chart.Points)
|
||||
{
|
||||
<div style="position: absolute;
|
||||
bottom:@point.GetValue(chart.HighestValuePoint, chart.ValueDisplayMax)px;
|
||||
left:@point.GetInterval(chart.HighestIntervalPoint, chart.IntervalDisplayMax)px;
|
||||
width: 0px;
|
||||
height: 0px;">
|
||||
<div style="width:1px; height: 1px; border-top-right-radius:10px; border-top-left-radius:10px; border: 2px solid @chart.ChartColor; background-color:@chart.ChartColor">
|
||||
<div style="width:1px; height: 1px; border-top-right-radius:10px; border-top-left-radius:10px; border: 2px solid @chart.ChartColor; background-color:@chart.ChartColor">
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
}
|
||||
}
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
}
|
||||
</div>
|
||||
|
||||
<style>
|
||||
}
|
||||
</div>
|
||||
|
||||
|
||||
<style>
|
||||
.chartsContainer {
|
||||
position: relative;
|
||||
display: flex;
|
||||
@@ -30,34 +41,31 @@
|
||||
justify-content: center;
|
||||
margin-bottom: 20px;
|
||||
}
|
||||
|
||||
</style>
|
||||
|
||||
<FormLayoutComponent>
|
||||
<FormDisplayComponent Label="Highest Alloy">
|
||||
<Display>@highestAlloyPoint</Display>
|
||||
</FormDisplayComponent>
|
||||
<FormDisplayComponent Label="Highest Ether">
|
||||
<Display>@highestEtherPoint</Display>
|
||||
</FormDisplayComponent>
|
||||
<DevOnlyComponent>
|
||||
<FormDisplayComponent Label="Highest Pyre">
|
||||
<FormLayoutComponent>
|
||||
<FormDisplayComponent Label="Highest Alloy">
|
||||
<Display>@highestAlloyPoint</Display>
|
||||
</FormDisplayComponent>
|
||||
<FormDisplayComponent Label="Highest Ether">
|
||||
<Display>@highestEtherPoint</Display>
|
||||
</FormDisplayComponent>
|
||||
</DevOnlyComponent>
|
||||
<FormDisplayComponent Label="Highest Army">
|
||||
<Display>@highestArmyPoint</Display>
|
||||
</FormDisplayComponent>
|
||||
</FormLayoutComponent>
|
||||
<DevOnlyComponent>
|
||||
<FormDisplayComponent Label="Highest Pyre">
|
||||
<Display>@highestEtherPoint</Display>
|
||||
</FormDisplayComponent>
|
||||
</DevOnlyComponent>
|
||||
<FormDisplayComponent Label="Highest Army">
|
||||
<Display>@highestArmyPoint</Display>
|
||||
</FormDisplayComponent>
|
||||
</FormLayoutComponent>
|
||||
|
||||
|
||||
}
|
||||
|
||||
@code {
|
||||
|
||||
[Inject]
|
||||
IEconomyService EconomyService { get; set; } = default!;
|
||||
|
||||
[Inject]
|
||||
IBuildOrderService BuildOrderService { get; set; } = default!;
|
||||
|
||||
private readonly int width = 250;
|
||||
|
||||
List<int> valueList = new();
|
||||
@@ -70,23 +78,75 @@
|
||||
float highestPyrePoint;
|
||||
float highestArmyPoint;
|
||||
|
||||
private Timer ageTimer = null!;
|
||||
|
||||
|
||||
protected override void OnInitialized()
|
||||
{
|
||||
EconomyService.Subscribe(GenerateChart);
|
||||
BuildOrderService.Subscribe(GenerateChart);
|
||||
buildOrderService.Subscribe(OnBuilderOrderChanged);
|
||||
|
||||
ageTimer = new Timer(3000);
|
||||
ageTimer.Elapsed += OnAge!;
|
||||
ageTimer.Enabled = true;
|
||||
|
||||
|
||||
GenerateChart();
|
||||
}
|
||||
|
||||
|
||||
int lastRequestedRefreshIndex = 0;
|
||||
void OnAge(object? sender, ElapsedEventArgs elapsedEventArgs)
|
||||
{
|
||||
if (requestedRefreshIndex > 0)
|
||||
{
|
||||
if (requestedRefreshIndex == lastRequestedRefreshIndex)
|
||||
{
|
||||
GenerateChart();
|
||||
requestedRefreshIndex = 0;
|
||||
lastRequestedRefreshIndex = 0;
|
||||
}
|
||||
|
||||
lastRequestedRefreshIndex = requestedRefreshIndex;
|
||||
}
|
||||
|
||||
ageTimer.Enabled = true;
|
||||
}
|
||||
|
||||
|
||||
|
||||
void IDisposable.Dispose()
|
||||
{
|
||||
EconomyService.Unsubscribe(GenerateChart);
|
||||
BuildOrderService.Unsubscribe(GenerateChart);
|
||||
buildOrderService.Unsubscribe(OnBuilderOrderChanged);
|
||||
}
|
||||
|
||||
|
||||
int requestedRefreshIndex = 0;
|
||||
void OnBuilderOrderChanged()
|
||||
{
|
||||
requestedRefreshIndex++;
|
||||
StateHasChanged();
|
||||
}
|
||||
|
||||
|
||||
protected override bool ShouldRender()
|
||||
{
|
||||
#if DEBUG
|
||||
jsRuntime.InvokeVoidAsync("console.time", "ChartComponent");
|
||||
#endif
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
protected override void OnAfterRender(bool firstRender)
|
||||
{
|
||||
#if DEBUG
|
||||
jsRuntime.InvokeVoidAsync("console.timeEnd", "ChartComponent");
|
||||
#endif
|
||||
}
|
||||
|
||||
void GenerateChart()
|
||||
{
|
||||
var economyOverTime = EconomyService.GetOverTime();
|
||||
var economyOverTime = economyService.GetOverTime();
|
||||
|
||||
charts.Clear();
|
||||
|
||||
@@ -127,7 +187,7 @@
|
||||
|
||||
for (var interval = 0; interval < economyOverTime.Count(); interval++)
|
||||
{
|
||||
var army = from unit in BuildOrderService.GetCompletedBefore(interval)
|
||||
var army = from unit in buildOrderService.GetCompletedBefore(interval)
|
||||
where unit.EntityType == EntityType.Army
|
||||
select unit;
|
||||
|
||||
|
||||
@@ -1,4 +1,11 @@
|
||||
@implements IDisposable
|
||||
@inject IJSRuntime jsRuntime;
|
||||
|
||||
|
||||
@inject IKeyService keyService
|
||||
@inject IImmortalSelectionService filterService
|
||||
@inject IBuildOrderService buildOrderService
|
||||
|
||||
@implements IDisposable
|
||||
|
||||
@if (entity != null)
|
||||
{
|
||||
@@ -20,48 +27,45 @@
|
||||
private EntityModel? entity = default!;
|
||||
private string viewType = "Detailed";
|
||||
|
||||
[Inject]
|
||||
IKeyService KeyService { get; set; } = default!;
|
||||
|
||||
[Inject]
|
||||
IImmortalSelectionService FilterService { get; set; } = default!;
|
||||
|
||||
[Inject]
|
||||
IBuildOrderService BuildOrderService { get; set; } = default!;
|
||||
|
||||
protected override void OnInitialized()
|
||||
{
|
||||
KeyService.Subscribe(HandleClick);
|
||||
BuildOrderService.Subscribe(OnBuildOrderChanged);
|
||||
keyService.Subscribe(HandleClick);
|
||||
}
|
||||
|
||||
void IDisposable.Dispose()
|
||||
{
|
||||
KeyService.Unsubscribe(HandleClick);
|
||||
BuildOrderService.Unsubscribe(OnBuildOrderChanged);
|
||||
keyService.Unsubscribe(HandleClick);
|
||||
}
|
||||
|
||||
|
||||
protected void HandleClick()
|
||||
protected override bool ShouldRender()
|
||||
{
|
||||
var hotkey = KeyService.GetHotkey();
|
||||
var hotkeyGroup = KeyService.GetHotkeyGroup();
|
||||
var isHoldSpace = KeyService.IsHoldingSpace();
|
||||
var faction = FilterService.GetFactionType();
|
||||
var immortal = FilterService.GetImmortalType();
|
||||
#if DEBUG
|
||||
jsRuntime.InvokeVoidAsync("console.time", "EntityClickViewComponent");
|
||||
#endif
|
||||
return true;
|
||||
}
|
||||
|
||||
protected override void OnAfterRender(bool firstRender)
|
||||
{
|
||||
#if DEBUG
|
||||
jsRuntime.InvokeVoidAsync("console.timeEnd", "EntityClickViewComponent");
|
||||
#endif
|
||||
}
|
||||
|
||||
private void HandleClick()
|
||||
{
|
||||
var hotkey = keyService.GetHotkey();
|
||||
var hotkeyGroup = keyService.GetHotkeyGroup();
|
||||
var isHoldSpace = keyService.IsHoldingSpace();
|
||||
var faction = filterService.GetFactionType();
|
||||
var immortal = filterService.GetImmortalType();
|
||||
|
||||
var foundEntity = EntityModel.GetFrom(hotkey!, hotkeyGroup, isHoldSpace, faction, immortal);
|
||||
|
||||
if (foundEntity != null)
|
||||
if (foundEntity != null && entity != foundEntity)
|
||||
{
|
||||
entity = foundEntity;
|
||||
StateHasChanged();
|
||||
}
|
||||
}
|
||||
|
||||
void OnBuildOrderChanged()
|
||||
{
|
||||
StateHasChanged();
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,4 +1,6 @@
|
||||
<FormLayoutComponent>
|
||||
@inject IJSRuntime jsRuntime;
|
||||
|
||||
<FormLayoutComponent>
|
||||
<FormSelectComponent OnChange="@OnFactionChanged">
|
||||
<FormLabelComponent>Faction</FormLabelComponent>
|
||||
<ChildContent>
|
||||
@@ -39,4 +41,19 @@
|
||||
FilterService.SelectImmortalType(e.Value!.ToString()!);
|
||||
}
|
||||
|
||||
protected override bool ShouldRender()
|
||||
{
|
||||
#if DEBUG
|
||||
jsRuntime.InvokeVoidAsync("console.time", "FilterComponent");
|
||||
#endif
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
protected override void OnAfterRender(bool firstRender)
|
||||
{
|
||||
#if DEBUG
|
||||
jsRuntime.InvokeVoidAsync("console.timeEnd", "FilterComponent");
|
||||
#endif
|
||||
}
|
||||
}
|
||||
@@ -1,40 +1,37 @@
|
||||
@implements IDisposable
|
||||
@inject IJSRuntime jsRuntime;
|
||||
|
||||
|
||||
@implements IDisposable
|
||||
|
||||
<div class="highlightsContainer">
|
||||
<div>
|
||||
<div>Requested</div>
|
||||
|
||||
@for (var i = TimingService.GetTiming() - 1; i >= 0; i--)
|
||||
{
|
||||
@foreach (var order in BuildOrderService.GetOrdersAt(i))
|
||||
{
|
||||
if (order.EntityType == EntityType.Worker)
|
||||
{
|
||||
continue;
|
||||
|
||||
@foreach (var ordersAtTime in BuildOrderService.StartedOrders.Reverse()) {
|
||||
foreach (var order in ordersAtTime.Value)
|
||||
{
|
||||
<div>
|
||||
|
||||
@ordersAtTime.Key | T @Interval.ToTime(ordersAtTime.Key)
|
||||
</div>
|
||||
<div>
|
||||
@order.Info().Name
|
||||
</div>
|
||||
<br/>
|
||||
}
|
||||
}
|
||||
<div>
|
||||
@i | T @Interval.ToTime(i)
|
||||
</div>
|
||||
<div>
|
||||
@order.Info().Name
|
||||
</div>
|
||||
<br/>
|
||||
}
|
||||
}
|
||||
|
||||
</div>
|
||||
<div>
|
||||
<div>Finished</div>
|
||||
|
||||
@for (var i = TimingService.GetTiming() - 1; i >= 0; i--)
|
||||
|
||||
@foreach (var ordersAtTime in BuildOrderService.CompletedOrders.Reverse())
|
||||
{
|
||||
@foreach (var order in BuildOrderService.GetCompletedAt(i))
|
||||
foreach (var order in ordersAtTime.Value)
|
||||
{
|
||||
if (order.EntityType == EntityType.Worker)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
<div>
|
||||
@i | T @Interval.ToTime(i)
|
||||
|
||||
@ordersAtTime.Key | T @Interval.ToTime(ordersAtTime.Key)
|
||||
</div>
|
||||
<div>
|
||||
@order.Info().Name
|
||||
@@ -79,5 +76,21 @@
|
||||
EconomyService.Unsubscribe(StateHasChanged);
|
||||
BuildOrderService.Unsubscribe(StateHasChanged);
|
||||
}
|
||||
|
||||
protected override bool ShouldRender()
|
||||
{
|
||||
#if DEBUG
|
||||
jsRuntime.InvokeVoidAsync("console.time", "HighlightsComponent");
|
||||
#endif
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
protected override void OnAfterRender(bool firstRender)
|
||||
{
|
||||
#if DEBUG
|
||||
jsRuntime.InvokeVoidAsync("console.timeEnd", "HighlightsComponent");
|
||||
#endif
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,4 +1,14 @@
|
||||
@implements IDisposable
|
||||
@inject IJSRuntime jsRuntime;
|
||||
|
||||
@implements IDisposable
|
||||
@inject IKeyService keyService
|
||||
@inject IBuildOrderService buildOrderService
|
||||
@inject IImmortalSelectionService filterService
|
||||
|
||||
@inject IEconomyService economyService
|
||||
@inject ITimingService timingService
|
||||
@inject IToastService toastService
|
||||
|
||||
|
||||
<InputPanelComponent>
|
||||
<div class="keyContainer">
|
||||
@@ -9,7 +19,7 @@
|
||||
continue;
|
||||
}
|
||||
|
||||
var color = hotkey.KeyText.Equals("SPACE") && KeyService.IsHoldingSpace() || KeyService.GetAllPressedKeys().Contains(hotkey.KeyText)
|
||||
var color = hotkey.KeyText.Equals("SPACE") && keyService.IsHoldingSpace() || keyService.GetAllPressedKeys().Contains(hotkey.KeyText)
|
||||
? "#0a0f12" : hotkey.GetColor();
|
||||
|
||||
var x = hotkey.PositionX * Size;
|
||||
@@ -25,7 +35,7 @@
|
||||
border = "5px solid green";
|
||||
}
|
||||
|
||||
if (hotkey.KeyText.Equals("SPACE") && KeyService.IsHoldingSpace())
|
||||
if (hotkey.KeyText.Equals("SPACE") && keyService.IsHoldingSpace())
|
||||
{
|
||||
border = "5px solid green";
|
||||
}
|
||||
@@ -37,7 +47,7 @@
|
||||
width: 0px;
|
||||
height: 0px;">
|
||||
|
||||
<div @onclick="x => { if (hotkey.KeyText.Equals(HotKeyType.SPACE.ToString())) { if (KeyService.IsHoldingSpace()) { KeyService.RemovePressedKey(hotkey.KeyText); } else { KeyService.AddPressedKey(hotkey.KeyText); } } else { KeyService.AddPressedKey(hotkey.KeyText); KeyService.RemovePressedKey(hotkey.KeyText); }}" style="background-color:@color;
|
||||
<div @onclick="x => { if (hotkey.KeyText.Equals(HotKeyType.SPACE.ToString())) { if (keyService.IsHoldingSpace()) { keyService.RemovePressedKey(hotkey.KeyText); } else { keyService.AddPressedKey(hotkey.KeyText); } } else { keyService.AddPressedKey(hotkey.KeyText); keyService.RemovePressedKey(hotkey.KeyText); }}" style="background-color:@color;
|
||||
border: @border;
|
||||
width: @Size.ToString()px;
|
||||
height: @Size.ToString()px;
|
||||
@@ -46,7 +56,7 @@
|
||||
@hotkey.KeyText
|
||||
@foreach (var entity in data.Values)
|
||||
{
|
||||
if (!BuildOrderService.MeetsRequirements(entity, 9000))
|
||||
if (buildOrderService.WillMeetRequirements(entity) == null)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
@@ -97,15 +107,6 @@
|
||||
[Parameter]
|
||||
public int Size { get; set; } = 100;
|
||||
|
||||
[Inject]
|
||||
public IKeyService KeyService { get; set; } = default!;
|
||||
|
||||
[Inject]
|
||||
public IBuildOrderService BuildOrderService { get; set; } = default!;
|
||||
|
||||
[Inject]
|
||||
public IImmortalSelectionService FilterService { get; set; } = default!;
|
||||
|
||||
readonly Dictionary<string, EntityModel> data = EntityModel.GetDictionary();
|
||||
readonly List<HotkeyModel> hotkeys = HotkeyModel.GetAll();
|
||||
|
||||
@@ -116,20 +117,48 @@
|
||||
{
|
||||
base.OnInitialized();
|
||||
|
||||
KeyService.Subscribe(OnKeyPressed);
|
||||
FilterService.Subscribe(StateHasChanged);
|
||||
keyService.Subscribe(OnKeyPressed);
|
||||
filterService.Subscribe(StateHasChanged);
|
||||
buildOrderService.Subscribe(OnBuilderOrderChanged);
|
||||
}
|
||||
|
||||
void IDisposable.Dispose()
|
||||
{
|
||||
KeyService.Unsubscribe(OnKeyPressed);
|
||||
FilterService.Unsubscribe(StateHasChanged);
|
||||
keyService.Unsubscribe(OnKeyPressed);
|
||||
filterService.Unsubscribe(StateHasChanged);
|
||||
buildOrderService.Unsubscribe(OnBuilderOrderChanged);
|
||||
}
|
||||
|
||||
int completedTimeCount = 0;
|
||||
void OnBuilderOrderChanged()
|
||||
{
|
||||
if (buildOrderService.UniqueCompletedTimes.Count != completedTimeCount)
|
||||
{
|
||||
completedTimeCount = buildOrderService.UniqueCompletedTimes.Count;
|
||||
StateHasChanged();
|
||||
}
|
||||
}
|
||||
|
||||
protected override bool ShouldRender()
|
||||
{
|
||||
#if DEBUG
|
||||
jsRuntime.InvokeVoidAsync("console.time", "HotKeyViewerComponent");
|
||||
#endif
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
protected override void OnAfterRender(bool firstRender)
|
||||
{
|
||||
#if DEBUG
|
||||
jsRuntime.InvokeVoidAsync("console.timeEnd", "HotKeyViewerComponent");
|
||||
#endif
|
||||
}
|
||||
|
||||
// Move to Filter Service
|
||||
bool InvalidFaction(EntityModel entity)
|
||||
{
|
||||
if (entity.Faction() != null && entity.Faction()?.Faction != FilterService.GetFactionType() && FilterService.GetFactionType() != FactionType.Any)
|
||||
if (entity.Faction() != null && entity.Faction()?.Faction != filterService.GetFactionType() && filterService.GetFactionType() != FactionType.Any)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
@@ -140,7 +169,7 @@
|
||||
// Move to Filter Service
|
||||
bool InvalidVanguard(EntityModel entity)
|
||||
{
|
||||
if (entity.VanguardAdded() != null && entity.VanguardAdded()?.ImmortalId != FilterService.GetImmortalType() && FilterService.GetImmortalType() != ImmortalType.Any)
|
||||
if (entity.VanguardAdded() != null && entity.VanguardAdded()?.ImmortalId != filterService.GetImmortalType() && filterService.GetImmortalType() != ImmortalType.Any)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
@@ -156,7 +185,7 @@
|
||||
var isReplaced = false;
|
||||
foreach (var replaced in entity.Replaceds())
|
||||
{
|
||||
if (FilterService.GetImmortalType() == replaced.ImmortalId)
|
||||
if (filterService.GetImmortalType() == replaced.ImmortalId)
|
||||
{
|
||||
isReplaced = true;
|
||||
break;
|
||||
@@ -171,11 +200,6 @@
|
||||
return false;
|
||||
}
|
||||
|
||||
bool InvalidRequirements(EntityModel entity)
|
||||
{
|
||||
return !BuildOrderService.MeetsRequirements(entity, 9000);
|
||||
}
|
||||
|
||||
bool InvalidKey(EntityModel entity, HotkeyModel key)
|
||||
{
|
||||
if (entity.Hotkey()?.Hotkey == key.KeyText)
|
||||
@@ -215,7 +239,7 @@
|
||||
|
||||
bool InvalidHoldSpace(EntityModel entity)
|
||||
{
|
||||
if (entity.Hotkey()?.HoldSpace == KeyService.IsHoldingSpace())
|
||||
if (entity.Hotkey()?.HoldSpace == keyService.IsHoldingSpace())
|
||||
{
|
||||
return false;
|
||||
}
|
||||
@@ -224,47 +248,93 @@
|
||||
|
||||
void OnKeyPressed()
|
||||
{
|
||||
if (KeyService.GetAllPressedKeys().Contains("Z"))
|
||||
|
||||
string controlGroupWas = _controlGroup;
|
||||
string keyWas = _key;
|
||||
|
||||
|
||||
if (keyService.GetAllPressedKeys().Contains("Z"))
|
||||
{
|
||||
_controlGroup = "Z";
|
||||
}
|
||||
if (KeyService.GetAllPressedKeys().Contains("TAB"))
|
||||
if (keyService.GetAllPressedKeys().Contains("TAB"))
|
||||
{
|
||||
_controlGroup = "TAB";
|
||||
}
|
||||
if (KeyService.GetAllPressedKeys().Contains("C"))
|
||||
if (keyService.GetAllPressedKeys().Contains("C"))
|
||||
{
|
||||
_controlGroup = "C";
|
||||
}
|
||||
if (KeyService.GetAllPressedKeys().Contains("D"))
|
||||
if (keyService.GetAllPressedKeys().Contains("D"))
|
||||
{
|
||||
_controlGroup = "D";
|
||||
}
|
||||
if (KeyService.GetAllPressedKeys().Contains("1"))
|
||||
if (keyService.GetAllPressedKeys().Contains("1"))
|
||||
{
|
||||
_controlGroup = "1";
|
||||
}
|
||||
//TODO This could be better. Duplicated code
|
||||
if (KeyService.GetAllPressedKeys().Contains("2"))
|
||||
if (keyService.GetAllPressedKeys().Contains("2"))
|
||||
{
|
||||
_controlGroup = "2";
|
||||
}
|
||||
if (KeyService.GetAllPressedKeys().Contains("SHIFT"))
|
||||
if (keyService.GetAllPressedKeys().Contains("SHIFT"))
|
||||
{
|
||||
_controlGroup = "SHIFT";
|
||||
}
|
||||
|
||||
if (KeyService.GetAllPressedKeys().Contains("CONTROL"))
|
||||
if (keyService.GetAllPressedKeys().Contains("CONTROL"))
|
||||
{
|
||||
_controlGroup = "CONTROL";
|
||||
}
|
||||
|
||||
if (KeyService.GetAllPressedKeys().Count > 0)
|
||||
if (keyService.GetAllPressedKeys().Count > 0)
|
||||
{
|
||||
_key = KeyService.GetAllPressedKeys().First();
|
||||
_key = keyService.GetAllPressedKeys().First();
|
||||
}
|
||||
|
||||
StateHasChanged();
|
||||
}
|
||||
// HandleClick();
|
||||
|
||||
if (controlGroupWas != _controlGroup || keyWas != _key)
|
||||
{
|
||||
|
||||
StateHasChanged();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
private void HandleClick()
|
||||
{
|
||||
var hotkey = keyService.GetHotkey();
|
||||
|
||||
if (hotkey == "")
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
if (hotkey == "`")
|
||||
{
|
||||
buildOrderService.RemoveLast();
|
||||
economyService.Calculate(buildOrderService, timingService, buildOrderService.GetLastRequestInterval());
|
||||
return;
|
||||
}
|
||||
|
||||
var hotkeyGroup = keyService.GetHotkeyGroup();
|
||||
var isHoldSpace = keyService.IsHoldingSpace();
|
||||
var faction = filterService.GetFactionType();
|
||||
var immortal = filterService.GetImmortalType();
|
||||
|
||||
EntityModel? entity = EntityModel.GetFrom(hotkey!, hotkeyGroup, isHoldSpace, faction, immortal);
|
||||
|
||||
if (entity == null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
if (buildOrderService.Add(entity, economyService, toastService))
|
||||
{
|
||||
economyService.Calculate(buildOrderService, timingService, buildOrderService.GetLastRequestInterval());
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,4 +1,9 @@
|
||||
<div tabindex="0"
|
||||
@inject IKeyService keyService
|
||||
|
||||
@inject IJSRuntime jsRuntime;
|
||||
|
||||
|
||||
<div tabindex="0"
|
||||
style="margin: auto;"
|
||||
@onkeydown="HandleKeyDown"
|
||||
@onkeyup="HandleKeyUp"
|
||||
@@ -8,21 +13,32 @@
|
||||
</div>
|
||||
|
||||
@code {
|
||||
|
||||
[Parameter]
|
||||
public RenderFragment ChildContent { get; set; } = default!;
|
||||
|
||||
[Inject]
|
||||
public IKeyService KeyService { get; set; } = default!;
|
||||
|
||||
|
||||
private void HandleKeyDown(KeyboardEventArgs e)
|
||||
{
|
||||
KeyService.AddPressedKey(e.Key);
|
||||
keyService.AddPressedKey(e.Key);
|
||||
}
|
||||
|
||||
private void HandleKeyUp(KeyboardEventArgs e)
|
||||
{
|
||||
KeyService.RemovePressedKey(e.Key);
|
||||
keyService.RemovePressedKey(e.Key);
|
||||
}
|
||||
|
||||
protected override bool ShouldRender()
|
||||
{
|
||||
#if DEBUG
|
||||
jsRuntime.InvokeVoidAsync("console.time", "InputPanelComponent");
|
||||
#endif
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
protected override void OnAfterRender(bool firstRender)
|
||||
{
|
||||
#if DEBUG
|
||||
jsRuntime.InvokeVoidAsync("console.timeEnd", "InputPanelComponent");
|
||||
#endif
|
||||
}
|
||||
}
|
||||
@@ -1,4 +1,7 @@
|
||||
@implements IDisposable
|
||||
@inject IJSRuntime jsRuntime;
|
||||
|
||||
|
||||
@implements IDisposable
|
||||
|
||||
<Virtualize Items="@EconomyService.GetOverTime()" Context="economyAtSecond" ItemSize="400" OverscanCount="4">
|
||||
<div style="display: grid; gap: 8px; grid-template-columns: 1fr 1fr;">
|
||||
@@ -24,17 +27,26 @@
|
||||
<br/>
|
||||
</div>
|
||||
<div>
|
||||
@foreach (var order in BuildOrderService.GetOrdersAt(economyAtSecond.Interval))
|
||||
|
||||
@if (BuildOrderService.StartedOrders.TryGetValue(economyAtSecond.Interval, out var ordersAtTime))
|
||||
{
|
||||
<div>
|
||||
Requested: @order.Info().Name
|
||||
</div>
|
||||
@foreach (var order in ordersAtTime)
|
||||
{
|
||||
<div>
|
||||
Requested: @order.Info().Name
|
||||
</div>
|
||||
}
|
||||
}
|
||||
@foreach (var order in BuildOrderService.GetCompletedAt(economyAtSecond.Interval))
|
||||
|
||||
|
||||
@if (BuildOrderService.CompletedOrders.TryGetValue(economyAtSecond.Interval, out var ordersCompletedAtTime))
|
||||
{
|
||||
<div>
|
||||
New: @order.Info().Name
|
||||
</div>
|
||||
@foreach (var order in ordersCompletedAtTime)
|
||||
{
|
||||
<div>
|
||||
New: @order.Info().Name
|
||||
</div>
|
||||
}
|
||||
}
|
||||
</div>
|
||||
</div>
|
||||
@@ -60,5 +72,21 @@
|
||||
EconomyService.Unsubscribe(StateHasChanged);
|
||||
BuildOrderService.Unsubscribe(StateHasChanged);
|
||||
}
|
||||
|
||||
protected override bool ShouldRender()
|
||||
{
|
||||
#if DEBUG
|
||||
jsRuntime.InvokeVoidAsync("console.time", "TimelineComponent");
|
||||
#endif
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
protected override void OnAfterRender(bool firstRender)
|
||||
{
|
||||
#if DEBUG
|
||||
jsRuntime.InvokeVoidAsync("console.timeEnd", "TimelineComponent");
|
||||
#endif
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,55 +1,69 @@
|
||||
<FormLayoutComponent>
|
||||
@inject IJSRuntime jsRuntime;
|
||||
|
||||
@inject IBuildOrderService buildOrderService
|
||||
@inject IEconomyService economyService
|
||||
@inject IToastService toastService
|
||||
@inject ITimingService timingService
|
||||
|
||||
|
||||
|
||||
<FormLayoutComponent>
|
||||
<FormNumberComponent ReadOnly="true"
|
||||
Max="600"
|
||||
Min="0"
|
||||
Value="@TimingService.GetTiming()"
|
||||
Value="@timingService.GetTiming()"
|
||||
OnChange="@OnTimingChanged">
|
||||
<FormLabelComponent>Timing interval</FormLabelComponent>
|
||||
<FormInfoComponent>Altering the time interval is currently disabled.</FormInfoComponent>
|
||||
</FormNumberComponent>
|
||||
|
||||
<FormTextComponent Label="Name" Placeholder="Fast Thrones..." Value="@BuildOrderService.GetName()" OnChange="OnNameChanged"/>
|
||||
<FormTextComponent Label="Name" Placeholder="Fast Thrones..." Value="@buildOrderService.GetName()" OnChange="OnNameChanged"/>
|
||||
|
||||
<FormTextAreaComponent Label="Notes"
|
||||
Value="@BuildOrderService.GetNotes()"
|
||||
Value="@buildOrderService.GetNotes()"
|
||||
OnChange="@OnNotesChanged">
|
||||
</FormTextAreaComponent>
|
||||
<FormTextComponent Label="Color" Placeholder="red..." Value="@BuildOrderService.GetColor()" OnChange="OnColorChanged"/>
|
||||
<FormTextComponent Label="Color" Placeholder="red..." Value="@buildOrderService.GetColor()" OnChange="OnColorChanged"/>
|
||||
</FormLayoutComponent>
|
||||
|
||||
@code {
|
||||
|
||||
[Inject]
|
||||
public ITimingService TimingService { get; set; } = default!;
|
||||
|
||||
[Inject]
|
||||
public IBuildOrderService BuildOrderService { get; set; } = default!;
|
||||
|
||||
|
||||
void OnTimingChanged(ChangeEventArgs changeEventArgs)
|
||||
{
|
||||
TimingService.SetTiming(int.Parse(changeEventArgs.Value!.ToString()!));
|
||||
}
|
||||
|
||||
void OnTimingChanged(int value)
|
||||
{
|
||||
TimingService.SetTiming(value);
|
||||
timingService.SetTiming(int.Parse(changeEventArgs.Value!.ToString()!));
|
||||
economyService.Calculate(buildOrderService, timingService, buildOrderService.GetLastRequestInterval());
|
||||
}
|
||||
|
||||
void OnNameChanged(ChangeEventArgs changeEventArgs)
|
||||
{
|
||||
BuildOrderService.SetName(changeEventArgs.Value!.ToString()!);
|
||||
buildOrderService.SetName(changeEventArgs.Value!.ToString()!);
|
||||
}
|
||||
|
||||
void OnColorChanged(ChangeEventArgs changeEventArgs)
|
||||
{
|
||||
BuildOrderService.SetColor(changeEventArgs.Value!.ToString()!);
|
||||
buildOrderService.SetColor(changeEventArgs.Value!.ToString()!);
|
||||
}
|
||||
|
||||
|
||||
void OnNotesChanged(ChangeEventArgs changeEventArgs)
|
||||
{
|
||||
BuildOrderService.SetNotes(changeEventArgs.Value!.ToString()!);
|
||||
buildOrderService.SetNotes(changeEventArgs.Value!.ToString()!);
|
||||
}
|
||||
|
||||
protected override bool ShouldRender()
|
||||
{
|
||||
#if DEBUG
|
||||
jsRuntime.InvokeVoidAsync("console.time", "TimingComponent");
|
||||
#endif
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
protected override void OnAfterRender(bool firstRender)
|
||||
{
|
||||
#if DEBUG
|
||||
jsRuntime.InvokeVoidAsync("console.timeEnd", "TimingComponent");
|
||||
#endif
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user