Browse Source

feat(Navigation) Improved desktop navigation UI

main
Jonathan McCaffrey 4 years ago
parent
commit
16223cd010
  1. 105
      Components/Navigation/DesktopNavComponent.razor
  2. 38
      Components/Navigation/DesktopNavLinkComponent.razor
  3. 30
      Components/Navigation/DesktopNavSectionComponent.razor
  4. 59
      Components/Navigation/NavSectionComponent.razor
  5. 14
      Components/Navigation/TabletNavComponent.razor
  6. BIN
      IGP/Database.db
  7. 4
      IGP/PageLayout.razor
  8. 2
      IGP/wwwroot/generated/AgileTaskModels.json
  9. 2
      IGP/wwwroot/generated/WebSectionModels.json
  10. 2
      Model/Entity/EntityModel.cs
  11. 2
      Model/Website/WebPageModel.cs
  12. 7
      Model/Website/WebSectionModel.cs
  13. 20
      Services/IServices.cs
  14. 126
      Services/Immortal/BuildOrderService.cs
  15. 40
      Services/Immortal/EconomyService.cs
  16. 16
      Services/Website/NavigationService.cs
  17. 44
      Services/Website/WebsiteService.cs

105
Components/Navigation/DesktopNavComponent.razor

@ -2,33 +2,53 @@
@inject INavigationService navigationService @inject INavigationService navigationService
@implements IDisposable @implements IDisposable
<div onmouseleave="@HoverOut" class="desktopNavContainer"> @{
<div class="menuHeader" @onmouseover="() => navigationService.ChangeNavigationState(NavigationStateType.Hovering_Menu)"> var visibleStyle = navigationService.GetNavigationSectionId() > 0 ? "clickOffVisible" : "";
}
<div onclick="@MenuClosed" class="clickOffBackground @visibleStyle">
</div>
<div class="desktopNavContainer">
<div class="menuHeader">
<NavLink href="/" class="websiteTitle"> <NavLink href="/" class="websiteTitle">
IGP Fan Reference IGP Fan Reference
</NavLink> </NavLink>
@foreach (var webSection in WebSections) { @foreach (var webSection in WebSections)
<div class="sectionButton">@webSection.Name</div> {
} <div>
</div> <button onclick="@(() => MenuClicked(webSection.Id))" class="sectionButton">@webSection.Name</button>
@{
var hoveredStyle = NavigationStateType.Hovering_Menu.Equals(navigationService.GetNavigationState()) ?
"navMenuContainerShow" : "";
}
<div class="navMenuContainer @hoveredStyle">
@foreach (var section in WebSections) {
var pages = (from page in WebPages
where page.WebSectionModelId == section.Id
select page).ToList();
<NavSectionComponent Section=section Children=pages/> @if (webSection.Id.Equals(navigationService.GetNavigationSectionId()))
{
<div class="navMenuPosition">
<div class="navMenuContainer">
<DesktopNavSectionComponent Section=webSection/>
</div>
</div>
}
</div>
} }
</div> </div>
</div> </div>
<style> <style>
.clickOffBackground {
top: 0;
left: 0;
position: fixed;
width: 100vw;
height: 100vh;
visibility: hidden;
}
.clickOffBackground.clickOffVisible {
visibility:visible;
}
.sectionButton { .sectionButton {
cursor: pointer; cursor: pointer;
} }
@ -60,27 +80,32 @@
color: white; color: white;
} }
.navMenuPosition {
position: relative;
top: calc(100% - 18px);
left: -64px;
width: 0;
height: 0;
}
.navMenuContainer { .navMenuContainer {
display: none; width: 330px;
position: fixed;
top: 50px;
flex-direction: row; flex-direction: row;
gap: 20px; gap: 20px;
width: 100%;
align-items: flex-start; align-items: flex-start;
justify-content: center; justify-content: center;
flex-wrap: wrap; flex-wrap: wrap;
border-bottom: 4px solid black; padding-top: 4px;
padding-top: 20px; padding-bottom: 4px;
padding-bottom: 20px; padding-left: 4px;
padding-right: 4px;
background-color: rgba(22, 22, 24, 0.95); background-color: rgba(22, 22, 24, 0.95);
} border: 1px solid black;
border-radius: 4px;
.navMenuContainerShow {
display: flex; display: flex;
} }
@@media only screen and (max-width: 1025px) { @@media only screen and (max-width: 1025px) {
.desktopNavContainer { .desktopNavContainer {
display: none; display: none;
@ -97,20 +122,36 @@
@code { @code {
[Parameter] public List<WebSectionModel> WebSections { get; set; } = default!; [Parameter]
public List<WebSectionModel> WebSections { get; set; } = default!;
[Parameter] public List<WebPageModel> WebPages { get; set; } = default!; [Parameter]
public List<WebPageModel> WebPages { get; set; } = default!;
protected override void OnInitialized() { protected override void OnInitialized()
{
navigationService.Subscribe(StateHasChanged); navigationService.Subscribe(StateHasChanged);
} }
void IDisposable.Dispose() { void IDisposable.Dispose()
{
navigationService.Unsubscribe(StateHasChanged); navigationService.Unsubscribe(StateHasChanged);
} }
void HoverOut(MouseEventArgs mouseEventArgs) { void MenuClicked(int menuName)
{
Console.WriteLine($"MenuClicked {menuName}");
navigationService.ChangeNavigationSectionId(menuName);
}
void MenuClosed()
{
navigationService.ChangeNavigationSectionId(-1);
}
void HoverOut(MouseEventArgs mouseEventArgs)
{
Console.WriteLine(NavigationStateType.Default); Console.WriteLine(NavigationStateType.Default);
navigationService.ChangeNavigationState(NavigationStateType.Default); navigationService.ChangeNavigationState(NavigationStateType.Default);
} }

38
Components/Navigation/NavLinkComponent.razor → Components/Navigation/DesktopNavLinkComponent.razor

@ -1,18 +1,15 @@
@using Services @inject INavigationService navigationService;
@using Model.Website
@using Model.Website.Enums
@inject INavigationService navigationService;
@inject NavigationManager navigationManager; @inject NavigationManager navigationManager;
@if (isOnPage) { @if (isOnPage) {
<NavLink href="@Page.Href" class="navContainer navLink navSelected"> <NavLink href="@Page.Href" class="desktopNavLink navSelected">
<div class="navName"> <div class="navName">
@Page.Name @Page.Name
</div> </div>
</NavLink> </NavLink>
} }
else { else {
<NavLink @onclick="() => navigationService.ChangeNavigationState(NavigationStateType.Default)" href="@Page.Href" class="navContainer navLink"> <NavLink @onclick="() => navigationService.ChangeNavigationState(NavigationStateType.Default)" href="@Page.Href" class="desktopNavLink">
<div class="navName"> <div class="navName">
@Page.Name @Page.Name
</div> </div>
@ -20,16 +17,6 @@ else {
} }
<style> <style>
.navContainer {
cursor: pointer;
border: 2px solid black;
border: none;
height: 60px;
width: 100%;
display: block;
display: flex;
border: none;
}
.navName { .navName {
margin: auto; margin: auto;
@ -40,12 +27,27 @@ else {
} }
.navLink { .desktopNavLink {
cursor: pointer;
height: 60px;
width: 100%;
display: flex;
background-color: var(--primary); background-color: var(--primary);
border: 1px solid var(--primary); border: 1px solid var(--primary);
} }
.navLink:hover { .desktopNavLink:first-of-type {
border-top-left-radius: 4px;
border-top-right-radius: 4px;
}
.desktopNavLink:last-of-type {
border-bottom-left-radius: 4px;
border-bottom-right-radius: 4px;
}
.desktopNavLink:hover {
color: #8EC3FF; color: #8EC3FF;
background-color: var(--primary-hover); background-color: var(--primary-hover);
border-color: var(--primary-border-hover); border-color: var(--primary-border-hover);

30
Components/Navigation/DesktopNavSectionComponent.razor

@ -0,0 +1,30 @@
@using Model.Website
<div class="sectionContainer">
@foreach (var childPage in Section.WebPageModels) {
if (childPage.IsPrivate.Equals("True")) {
continue;
}
<DesktopNavLinkComponent Page=childPage></DesktopNavLinkComponent>
}
</div>
<style>
.sectionContainer {
display: flex;
flex-direction: column;
gap: 4px;
justify-content: flex-start;
position: relative;
width: 100%;
}
</style>
@code {
[Parameter]
public WebSectionModel Section { get; set; } = default!;
}

59
Components/Navigation/NavSectionComponent.razor

@ -1,59 +0,0 @@
@using Model.Website
<div class="sectionContainer">
<div class="sectionHeader">
<div class="sectionTitle">
@Section.Name
</div>
</div>
@foreach (var childPage in Children) {
if (childPage.IsPrivate.Equals("True")) {
continue;
}
<NavLinkComponent Page=childPage></NavLinkComponent>
}
</div>
<style>
.sectionContainer {
display: flex;
flex-direction: column;
gap: 4px;
justify-content: flex-start;
position: relative;
margin-top: 12px;
padding: 18px;
width: 300px;
margin-left: 4px;
}
.sectionHeader {
bottom: 100%;
position: absolute;
top: 0px;
left: -8px;
padding-right: 12px;
padding-left: 4px;
width: 100%;
display: flex;
line-height: 0px;
}
.sectionTitle {
font-weight: bold;
padding-right: 8px;
margin-top: -2px;
white-space: pre;
}
</style>
@code {
[Parameter]
public WebSectionModel Section { get; set; } = default!;
[Parameter]
public List<WebPageModel> Children { get; set; } = default!;
}

14
Components/Navigation/TabletNavComponent.razor

@ -19,23 +19,23 @@
<div class="tabletNav @navOpen"> <div class="tabletNav @navOpen">
@foreach (var _section in WebSections) { @foreach (var webSection in WebSections) {
var pages = (from page in WebPages var pages = (from page in WebPages
where page.WebSectionModelId == _section.Id where page.WebSectionModelId == webSection.Id
select page).ToList(); select page).ToList();
<div> <div>
<div> <div>
@_section.Name @webSection.Name
</div> </div>
<div class="tabletNavItems"> <div class="tabletNavItems">
@foreach (var _page in pages) { @foreach (var webPage in pages) {
if (_page.IsPrivate.Equals("True")) { if (webPage.IsPrivate.Equals("True")) {
continue; continue;
} }
<NavLink href="@_page.Href" class="tabletNavItem" @onclick="OnPageClicked"> <NavLink href="@webPage.Href" class="tabletNavItem" @onclick="OnPageClicked">
@_page.Name @webPage.Name
</NavLink> </NavLink>
} }
</div> </div>

BIN
IGP/Database.db

Binary file not shown.

4
IGP/PageLayout.razor

@ -41,11 +41,7 @@
protected override async Task OnInitializedAsync() protected override async Task OnInitializedAsync()
{ {
#if NO_SQL
await webService.Load(); await webService.Load();
#else
await WebService.Load(Database);
#endif
} }
void IDisposable.Dispose() void IDisposable.Dispose()

2
IGP/wwwroot/generated/AgileTaskModels.json

File diff suppressed because one or more lines are too long

2
IGP/wwwroot/generated/WebSectionModels.json

@ -1 +1 @@
[{"Id":1,"Name":"Tools","Description":"Tools Stuff","Href":null,"Order":1,"IsPrivate":"False"},{"Id":2,"Name":"Resources","Description":"Resources Stuff","Href":null,"Order":2,"IsPrivate":"False"},{"Id":3,"Name":"General","Description":"About Stuff","Href":null,"Order":3,"IsPrivate":"False"},{"Id":4,"Name":"Development","Description":"Development Stuff","Href":null,"Order":4,"IsPrivate":"False"}] [{"Id":1,"Name":"Tools","Description":"Tools Stuff","Href":null,"Order":1,"IsPrivate":"False","WebPageModels":[]},{"Id":2,"Name":"Resources","Description":"Resources Stuff","Href":null,"Order":2,"IsPrivate":"False","WebPageModels":[]},{"Id":3,"Name":"General","Description":"About Stuff","Href":null,"Order":3,"IsPrivate":"False","WebPageModels":[]},{"Id":4,"Name":"Development","Description":"Development Stuff","Href":null,"Order":4,"IsPrivate":"False","WebPageModels":[]}]

2
Model/Entity/EntityModel.cs

@ -177,7 +177,7 @@ public class EntityModel
} }
public EntityProductionModel Production() public EntityProductionModel? Production()
{ {
return ((EntityProductionModel)EntityParts.Find(x => x.GetType() == typeof(EntityProductionModel))!)!; return ((EntityProductionModel)EntityParts.Find(x => x.GetType() == typeof(EntityProductionModel))!)!;
} }

2
Model/Website/WebPageModel.cs

@ -3,7 +3,7 @@
public class WebPageModel public class WebPageModel
{ {
public int Id { get; set; } public int Id { get; set; }
public int WebSectionModelId { get; set; } public int? WebSectionModelId { get; set; }
public string Name { get; set; } = "Add name"; public string Name { get; set; } = "Add name";
public string Description { get; set; } = "Add description"; public string Description { get; set; } = "Add description";
public string Href { get; set; } = null; public string Href { get; set; } = null;

7
Model/Website/WebSectionModel.cs

@ -1,4 +1,7 @@
namespace Model.Website; using System.Collections.Generic;
using System.ComponentModel.DataAnnotations.Schema;
namespace Model.Website;
public class WebSectionModel public class WebSectionModel
{ {
@ -8,4 +11,6 @@ public class WebSectionModel
public string Href { get; set; } = null; public string Href { get; set; } = null;
public int Order { get; set; } = 0; public int Order { get; set; } = 0;
public string IsPrivate { get; set; } = "True"; public string IsPrivate { get; set; } = "True";
[NotMapped] public List<WebPageModel> WebPageModels { get; set; } = new List<WebPageModel>();
} }

20
Services/IServices.cs

@ -1,15 +1,8 @@
 
#if NO_SQL
#else
using Contexts;
using Microsoft.EntityFrameworkCore;
#endif
using Model.Doc; using Model.Doc;
using Model.BuildOrders; using Model.BuildOrders;
using Model.Economy; using Model.Economy;
using Model.Entity; using Model.Entity;
using Model.Entity.Data;
using Model.MemoryTester; using Model.MemoryTester;
using Model.Notes; using Model.Notes;
using Model.Website; using Model.Website;
@ -52,26 +45,15 @@ public interface IEntityDialogService
} }
public interface IWebsiteService { public interface IWebsiteService {
#if NO_SQL
public List<WebPageModel> WebPageModels { get; set; } public List<WebPageModel> WebPageModels { get; set; }
public List<WebSectionModel> WebSectionModels { get; set; } public List<WebSectionModel> WebSectionModels { get; set; }
#else
public DbSet<WebPageModel> WebPageModels { get; }
public DbSet<WebSectionModel> WebSectionModels { get; }
#endif
public void Subscribe(Action action); public void Subscribe(Action action);
public void Unsubscribe(Action action); public void Unsubscribe(Action action);
public void Update(); public void Update();
#if NO_SQL
public Task Load(); public Task Load();
#else
public Task Load(DatabaseContext database);
#endif
public bool IsLoaded(); public bool IsLoaded();
} }
@ -146,6 +128,8 @@ public interface INavigationService {
public void Subscribe(Action action); public void Subscribe(Action action);
public void Unsubscribe(Action action); public void Unsubscribe(Action action);
public void ChangeNavigationSectionId(int newState);
public int GetNavigationSectionId();
public void ChangeNavigationState(string newState); public void ChangeNavigationState(string newState);
public string GetNavigationState(); public string GetNavigationState();

126
Services/Immortal/BuildOrderService.cs

@ -9,29 +9,34 @@ using YamlDotNet.Serialization;
namespace Services.Immortal; namespace Services.Immortal;
public class BuildOrderService : IBuildOrderService { public class BuildOrderService : IBuildOrderService
private int HumanMicro = 2; {
private readonly BuildOrderModel buildOrder = new(); private readonly BuildOrderModel buildOrder = new();
private int lastInterval = 0; private readonly int HumanMicro = 2;
private int lastInterval;
public int GetLastRequestInterval() { public int GetLastRequestInterval()
{
return lastInterval; return lastInterval;
} }
public Dictionary<int, List<EntityModel>> GetOrders() { public Dictionary<int, List<EntityModel>> GetOrders()
{
return buildOrder.Orders; return buildOrder.Orders;
} }
public void Subscribe(Action action) { public void Subscribe(Action action)
{
OnChange += action; OnChange += action;
} }
public void Unsubscribe(Action action) { public void Unsubscribe(Action action)
{
OnChange -= action; OnChange -= action;
} }
public void Add(EntityModel entity, int atInterval) { public void Add(EntityModel entity, int atInterval)
{
if (!buildOrder.Orders.ContainsKey(atInterval)) if (!buildOrder.Orders.ContainsKey(atInterval))
buildOrder.Orders.Add(atInterval, new List<EntityModel> { entity.Clone() }); buildOrder.Orders.Add(atInterval, new List<EntityModel> { entity.Clone() });
else else
@ -40,17 +45,25 @@ public class BuildOrderService : IBuildOrderService {
if (atInterval > lastInterval) lastInterval = atInterval; if (atInterval > lastInterval) lastInterval = atInterval;
} }
public bool Add(EntityModel entity, IEconomyService withEconomy, IToastService withToasts) { public bool Add(EntityModel entity, IEconomyService withEconomy, IToastService withToasts)
if (entity != null) { {
var production = entity.Production(); var production = entity.Production();
if (production != null) { if (production != null)
for (var interval = lastInterval; interval < withEconomy.GetOverTime().Count; interval++) { {
for (var interval = lastInterval; interval < withEconomy.GetOverTime().Count; interval++)
{
var economyAtSecond = withEconomy.GetOverTime()[interval]; var economyAtSecond = withEconomy.GetOverTime()[interval];
if (economyAtSecond.Alloy >= production.Alloy && economyAtSecond.Ether >= production.Ether && if (economyAtSecond.Alloy >= production.Alloy && economyAtSecond.Ether >= production.Ether &&
economyAtSecond.Pyre >= production.Pyre) { economyAtSecond.Pyre >= production.Pyre)
if (!MeetsSupply(entity)) { {
withToasts.AddToast(new ToastModel {Title = "Supply Cap Reached", Message = "Build more supply!", SeverityType = SeverityType.Error}); if (!MeetsSupply(entity))
{
withToasts.AddToast(new ToastModel
{
Title = "Supply Cap Reached", Message = "Build more supply!",
SeverityType = SeverityType.Error
});
return false; return false;
} }
@ -69,35 +82,39 @@ public class BuildOrderService : IBuildOrderService {
NotifyDataChanged(); NotifyDataChanged();
return true; return true;
} }
else if(interval + 1 == withEconomy.GetOverTime().Count)
if (interval + 1 == withEconomy.GetOverTime().Count)
{ {
if (economyAtSecond.Ether < production.Ether) if (economyAtSecond.Ether < production.Ether)
withToasts.AddToast(new ToastModel
{ {
withToasts.AddToast(new ToastModel {Title = "Not Enough Ether", Message = "Build more ether extractors!", SeverityType = SeverityType.Error}); Title = "Not Enough Ether", Message = "Build more ether extractors!",
SeverityType = SeverityType.Error
} });
} }
} }
} }
else { else
{
Add(entity, 0); Add(entity, 0);
NotifyDataChanged(); NotifyDataChanged();
return true; return true;
} }
}
return false; return false;
} }
public void RemoveLast() { public void RemoveLast()
{
EntityModel entityRemoved = null!; EntityModel entityRemoved = null!;
if (buildOrder.Orders.Keys.Count > 1) { if (buildOrder.Orders.Keys.Count > 1)
{
var last = buildOrder.Orders.Keys.Last(); var last = buildOrder.Orders.Keys.Last();
if (buildOrder.Orders[last].Count > 0) { if (buildOrder.Orders[last].Count > 0)
{
entityRemoved = buildOrder.Orders[last].Last(); entityRemoved = buildOrder.Orders[last].Last();
buildOrder.Orders[last].Remove(buildOrder.Orders[last].Last()); buildOrder.Orders[last].Remove(buildOrder.Orders[last].Last());
} }
@ -109,7 +126,8 @@ public class BuildOrderService : IBuildOrderService {
else else
lastInterval = 1; lastInterval = 1;
if (entityRemoved?.Info()?.Descriptive == DescriptiveType.Worker) { if (entityRemoved?.Info()?.Descriptive == DescriptiveType.Worker)
{
RemoveLast(); RemoveLast();
return; return;
} }
@ -119,15 +137,18 @@ public class BuildOrderService : IBuildOrderService {
} }
public string AsJson() { public string AsJson()
var options = new JsonSerializerOptions { {
var options = new JsonSerializerOptions
{
WriteIndented = true WriteIndented = true
}; };
options.Converters.Add(new JsonStringEnumConverter()); options.Converters.Add(new JsonStringEnumConverter());
return JsonSerializer.Serialize(buildOrder, options); return JsonSerializer.Serialize(buildOrder, options);
} }
public string BuildOrderAsYaml() { public string BuildOrderAsYaml()
{
var stringBuilder = new StringBuilder(); var stringBuilder = new StringBuilder();
var serializer = new Serializer(); var serializer = new Serializer();
stringBuilder.AppendLine(serializer.Serialize(buildOrder)); stringBuilder.AppendLine(serializer.Serialize(buildOrder));
@ -135,28 +156,32 @@ public class BuildOrderService : IBuildOrderService {
return buildOrderText; return buildOrderText;
} }
public List<EntityModel> GetOrdersAt(int interval) { public List<EntityModel> GetOrdersAt(int interval)
{
return (from ordersAtTime in buildOrder.Orders return (from ordersAtTime in buildOrder.Orders
from orders in ordersAtTime.Value from orders in ordersAtTime.Value
where ordersAtTime.Key == interval where ordersAtTime.Key == interval
select orders).ToList(); select orders).ToList();
} }
public List<EntityModel> GetCompletedAt(int interval) { public List<EntityModel> GetCompletedAt(int interval)
{
return (from ordersAtTime in buildOrder.Orders return (from ordersAtTime in buildOrder.Orders
from orders in ordersAtTime.Value from orders in ordersAtTime.Value
where ordersAtTime.Key + (orders.Production() == null ? 0 : orders.Production().BuildTime) == interval where ordersAtTime.Key + (orders.Production() == null ? 0 : orders.Production().BuildTime) == interval
select orders).ToList(); select orders).ToList();
} }
public List<EntityModel> GetCompletedBefore(int interval) { public List<EntityModel> GetCompletedBefore(int interval)
{
return (from ordersAtTime in buildOrder.Orders return (from ordersAtTime in buildOrder.Orders
from orders in ordersAtTime.Value from orders in ordersAtTime.Value
where ordersAtTime.Key + (orders.Production() == null ? 0 : orders.Production().BuildTime) <= interval where ordersAtTime.Key + (orders.Production() == null ? 0 : orders.Production().BuildTime) <= interval
select orders).ToList(); select orders).ToList();
} }
public List<EntityModel> GetHarvestersCompletedBefore(int interval) { public List<EntityModel> GetHarvestersCompletedBefore(int interval)
{
return (from ordersAtTime in buildOrder.Orders return (from ordersAtTime in buildOrder.Orders
from orders in ordersAtTime.Value from orders in ordersAtTime.Value
where ordersAtTime.Key + (orders.Production() == null ? 0 : orders.Production().BuildTime) <= interval where ordersAtTime.Key + (orders.Production() == null ? 0 : orders.Production().BuildTime) <= interval
@ -164,12 +189,14 @@ public class BuildOrderService : IBuildOrderService {
select orders).ToList(); select orders).ToList();
} }
public bool MeetsRequirements(EntityModel entity, int requestedInterval) { public bool MeetsRequirements(EntityModel entity, int requestedInterval)
{
var requirements = entity.Requirements(); var requirements = entity.Requirements();
if (requirements.Count == 0) return true; if (requirements.Count == 0) return true;
foreach (var requirement in requirements) foreach (var requirement in requirements)
if (requirement.Requirement == RequirementType.Morph) { if (requirement.Requirement == RequirementType.Morph)
{
var entitiesNeeded = from entitiesAtInterval in buildOrder.Orders var entitiesNeeded = from entitiesAtInterval in buildOrder.Orders
from requiredEntity in entitiesAtInterval.Value from requiredEntity in entitiesAtInterval.Value
where requestedInterval > entitiesAtInterval.Key + where requestedInterval > entitiesAtInterval.Key +
@ -185,7 +212,8 @@ public class BuildOrderService : IBuildOrderService {
if (entitiesAlreadyMorphed.Count() >= entitiesNeeded.Count()) if (entitiesAlreadyMorphed.Count() >= entitiesNeeded.Count())
return false; return false;
} }
else { else
{
var entitiesNeeded = from entitiesAtInterval in buildOrder.Orders var entitiesNeeded = from entitiesAtInterval in buildOrder.Orders
from requiredEntity in entitiesAtInterval.Value from requiredEntity in entitiesAtInterval.Value
where requestedInterval > entitiesAtInterval.Key + where requestedInterval > entitiesAtInterval.Key +
@ -204,40 +232,48 @@ public class BuildOrderService : IBuildOrderService {
return true; return true;
} }
public void SetName(string Name) { public void SetName(string Name)
{
buildOrder.Name = Name; buildOrder.Name = Name;
NotifyDataChanged(); NotifyDataChanged();
} }
public string GetName() { public string GetName()
{
return buildOrder.Name; return buildOrder.Name;
} }
public void SetNotes(string Notes) { public void SetNotes(string Notes)
{
buildOrder.Notes = Notes; buildOrder.Notes = Notes;
NotifyDataChanged(); NotifyDataChanged();
} }
public string GetNotes() { public string GetNotes()
{
return buildOrder.Notes; return buildOrder.Notes;
} }
public void SetColor(string color) { public void SetColor(string color)
{
buildOrder.Color = color; buildOrder.Color = color;
NotifyDataChanged(); NotifyDataChanged();
} }
public string GetColor() { public string GetColor()
{
return buildOrder.Color; return buildOrder.Color;
} }
private event Action OnChange = null!; private event Action OnChange = null!;
private void NotifyDataChanged() { private void NotifyDataChanged()
{
OnChange?.Invoke(); OnChange?.Invoke();
} }
public bool MeetsSupply(EntityModel entity) { public bool MeetsSupply(EntityModel entity)
{
var supply = entity.Supply(); var supply = entity.Supply();
if (supply == null || supply.Takes == 0) return true; if (supply == null || supply.Takes == 0) return true;

40
Services/Immortal/EconomyService.cs

@ -5,10 +5,10 @@ using Model.Types;
namespace Services.Immortal; namespace Services.Immortal;
public class EconomyService : IEconomyService { public class EconomyService : IEconomyService {
private List<EconomyModel> _overTime = null!; private List<EconomyModel> _economyOverTime = null!;
public List<EconomyModel> GetOverTime() { public List<EconomyModel> GetOverTime() {
return _overTime; return _economyOverTime;
} }
public void Subscribe(Action action) { public void Subscribe(Action action) {
@ -20,28 +20,32 @@ public class EconomyService : IEconomyService {
} }
public void Calculate(IBuildOrderService buildOrder, ITimingService timing, int fromInterval) { public void Calculate(IBuildOrderService buildOrder, ITimingService timing, int fromInterval) {
if (_overTime == null) {
_overTime = new List<EconomyModel>(); //TODO Break all this up
if (_economyOverTime == null) {
_economyOverTime = new List<EconomyModel>();
for (var interval = 0; interval < timing.GetTiming(); interval++) for (var interval = 0; interval < timing.GetTiming(); interval++)
_overTime.Add(new EconomyModel { Interval = interval }); _economyOverTime.Add(new EconomyModel { Interval = interval });
} }
if (_overTime.Count > timing.GetTiming())
_overTime.RemoveRange(timing.GetTiming(), _overTime.Count - timing.GetTiming());
while (_overTime.Count < timing.GetTiming()) _overTime.Add(new EconomyModel { Interval = _overTime.Count - 1 });
if (_economyOverTime.Count > timing.GetTiming())
_economyOverTime.RemoveRange(timing.GetTiming(), _economyOverTime.Count - timing.GetTiming());
while (_economyOverTime.Count < timing.GetTiming()) _economyOverTime.Add(new EconomyModel { Interval = _economyOverTime.Count - 1 });
for (var interval = fromInterval; interval < timing.GetTiming(); interval++) { for (var interval = fromInterval; interval < timing.GetTiming(); interval++) {
var economyAtSecond = _overTime[interval]; var economyAtSecond = _economyOverTime[interval];
if (interval > 0) { if (interval > 0) {
economyAtSecond.Alloy = _overTime[interval - 1].Alloy; economyAtSecond.Alloy = _economyOverTime[interval - 1].Alloy;
economyAtSecond.Ether = _overTime[interval - 1].Ether; economyAtSecond.Ether = _economyOverTime[interval - 1].Ether;
economyAtSecond.Pyre = _overTime[interval - 1].Pyre; economyAtSecond.Pyre = _economyOverTime[interval - 1].Pyre;
economyAtSecond.WorkerCount = _overTime[interval - 1].WorkerCount; economyAtSecond.WorkerCount = _economyOverTime[interval - 1].WorkerCount;
economyAtSecond.BusyWorkerCount = _overTime[interval - 1].BusyWorkerCount; economyAtSecond.BusyWorkerCount = _economyOverTime[interval - 1].BusyWorkerCount;
economyAtSecond.CreatingWorkerCount = _overTime[interval - 1].CreatingWorkerCount; economyAtSecond.CreatingWorkerCount = _economyOverTime[interval - 1].CreatingWorkerCount;
economyAtSecond.Harvesters = _overTime[interval - 1].Harvesters.ToList(); economyAtSecond.Harvesters = _economyOverTime[interval - 1].Harvesters.ToList();
economyAtSecond.CreatingWorkerDelays = _overTime[interval - 1].CreatingWorkerDelays.ToList(); economyAtSecond.CreatingWorkerDelays = _economyOverTime[interval - 1].CreatingWorkerDelays.ToList();
} }
economyAtSecond.Interval = interval; economyAtSecond.Interval = interval;
@ -134,7 +138,7 @@ public class EconomyService : IEconomyService {
public EconomyModel GetEconomy(int atInterval) { public EconomyModel GetEconomy(int atInterval) {
return _overTime[atInterval]; return _economyOverTime[atInterval];
} }
private event Action onChange = null!; private event Action onChange = null!;

16
Services/Website/NavigationService.cs

@ -4,13 +4,18 @@ namespace Services.Website;
public class NavigationService : INavigationService { public class NavigationService : INavigationService {
private string navigationStateType = NavigationStateType.Default; private string navigationStateType = NavigationStateType.Default;
private int navigationStateId = -1;
private NavSelectionType navSelectionType = NavSelectionType.None; private NavSelectionType navSelectionType = NavSelectionType.None;
private Type renderType = null!; private Type renderType = null!;
private int webPageType; private int webPageType;
private int webSectionType; private int webSectionType;
public void Subscribe(Action action) { public void Subscribe(Action action) {
OnChange += action; OnChange += action;
} }
@ -19,6 +24,17 @@ public class NavigationService : INavigationService {
OnChange += action; OnChange += action;
} }
public void ChangeNavigationSectionId(int newState)
{
navigationStateId = newState;
NotifyDataChanged();
}
public int GetNavigationSectionId()
{
return navigationStateId;
}
public void ChangeNavigationState(string newState) { public void ChangeNavigationState(string newState) {
if (newState.Equals(navigationStateType)) if (newState.Equals(navigationStateType))
return; return;

44
Services/Website/WebsiteService.cs

@ -1,10 +1,5 @@
using System.Net.Http.Json; using System.Net.Http.Json;
#if !NO_SQL
using Contexts;
using Microsoft.EntityFrameworkCore;
#endif
using Model.Website; using Model.Website;
namespace Services.Development; namespace Services.Development;
@ -24,17 +19,8 @@ public class WebsiteService : IWebsiteService {
#if NO_SQL
public List<WebSectionModel> WebSectionModels { get; set; } = default!; public List<WebSectionModel> WebSectionModels { get; set; } = default!;
public List<WebPageModel> WebPageModels { get; set; } = default!; public List<WebPageModel> WebPageModels { get; set; } = default!;
#else
private DatabaseContext Database { get; set; }
public DbSet<WebSectionModel> WebSectionModels => Database.WebSectionModels;
public DbSet<WebPageModel> WebPageModels => Database.WebPageModels;
#endif
public void Subscribe(Action action) { public void Subscribe(Action action) {
@ -49,38 +35,34 @@ public class WebsiteService : IWebsiteService {
return isLoaded; return isLoaded;
} }
#if NO_SQL
public async Task Load() { public async Task Load() {
if (isLoaded) {return;} if (isLoaded) {return;}
WebPageModels = ((await httpClient.GetFromJsonAsync<WebPageModel[]>("generated/WebPageModels.json"))!).ToList(); WebPageModels = ((await httpClient.GetFromJsonAsync<WebPageModel[]>("generated/WebPageModels.json"))!).ToList();
WebSectionModels =((await httpClient.GetFromJsonAsync<WebSectionModel[]>("generated/WebSectionModels.json"))!).ToList(); WebSectionModels =((await httpClient.GetFromJsonAsync<WebSectionModel[]>("generated/WebSectionModels.json"))!).ToList();
isLoaded = true; isLoaded = true;
SortSql();
NotifyDataChanged(); NotifyDataChanged();
} }
#else
public async Task Load(DatabaseContext database) {
Database = database;
if (isLoaded) {return;} void SortSql()
{
Database.WebPageModels.AddRange(await httpClient.GetFromJsonAsync<WebPageModel[]>("generated/WebPageModels.json")); foreach (var page in WebPageModels)
Database.WebSectionModels.AddRange( {
await httpClient.GetFromJsonAsync<WebSectionModel[]>("generated/WebSectionModels.json"));
Database.SaveChanges(); if (page.WebSectionModelId != null)
{
isLoaded = true; WebSectionModel webSection =
WebSectionModels.Find(webSection => webSection.Id == page.WebSectionModelId);
NotifyDataChanged(); webSection.WebPageModels.Add(page);
}
} }
#endif
}
public void Update() { public void Update() {
NotifyDataChanged(); NotifyDataChanged();

Loading…
Cancel
Save