feat(Navigation) Improved desktop navigation UI
This commit is contained in:
+2
-18
@@ -1,15 +1,8 @@
|
||||
|
||||
#if NO_SQL
|
||||
|
||||
#else
|
||||
using Contexts;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
#endif
|
||||
using Model.Doc;
|
||||
using Model.BuildOrders;
|
||||
using Model.Economy;
|
||||
using Model.Entity;
|
||||
using Model.Entity.Data;
|
||||
using Model.MemoryTester;
|
||||
using Model.Notes;
|
||||
using Model.Website;
|
||||
@@ -52,26 +45,15 @@ public interface IEntityDialogService
|
||||
}
|
||||
|
||||
public interface IWebsiteService {
|
||||
#if NO_SQL
|
||||
public List<WebPageModel> WebPageModels { 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 Unsubscribe(Action action);
|
||||
public void Update();
|
||||
|
||||
|
||||
#if NO_SQL
|
||||
public Task Load();
|
||||
#else
|
||||
|
||||
public Task Load(DatabaseContext database);
|
||||
#endif
|
||||
|
||||
|
||||
public bool IsLoaded();
|
||||
}
|
||||
@@ -146,6 +128,8 @@ public interface INavigationService {
|
||||
public void Subscribe(Action action);
|
||||
public void Unsubscribe(Action action);
|
||||
|
||||
public void ChangeNavigationSectionId(int newState);
|
||||
public int GetNavigationSectionId();
|
||||
public void ChangeNavigationState(string newState);
|
||||
public string GetNavigationState();
|
||||
|
||||
|
||||
@@ -9,29 +9,34 @@ using YamlDotNet.Serialization;
|
||||
|
||||
namespace Services.Immortal;
|
||||
|
||||
public class BuildOrderService : IBuildOrderService {
|
||||
private int HumanMicro = 2;
|
||||
|
||||
public class BuildOrderService : IBuildOrderService
|
||||
{
|
||||
private readonly BuildOrderModel buildOrder = new();
|
||||
private int lastInterval = 0;
|
||||
|
||||
public int GetLastRequestInterval() {
|
||||
private readonly int HumanMicro = 2;
|
||||
private int lastInterval;
|
||||
|
||||
public int GetLastRequestInterval()
|
||||
{
|
||||
return lastInterval;
|
||||
}
|
||||
|
||||
public Dictionary<int, List<EntityModel>> GetOrders() {
|
||||
public Dictionary<int, List<EntityModel>> GetOrders()
|
||||
{
|
||||
return buildOrder.Orders;
|
||||
}
|
||||
|
||||
public void Subscribe(Action action) {
|
||||
public void Subscribe(Action action)
|
||||
{
|
||||
OnChange += action;
|
||||
}
|
||||
|
||||
public void Unsubscribe(Action action) {
|
||||
public void Unsubscribe(Action action)
|
||||
{
|
||||
OnChange -= action;
|
||||
}
|
||||
|
||||
public void Add(EntityModel entity, int atInterval) {
|
||||
public void Add(EntityModel entity, int atInterval)
|
||||
{
|
||||
if (!buildOrder.Orders.ContainsKey(atInterval))
|
||||
buildOrder.Orders.Add(atInterval, new List<EntityModel> { entity.Clone() });
|
||||
else
|
||||
@@ -40,64 +45,76 @@ public class BuildOrderService : IBuildOrderService {
|
||||
if (atInterval > lastInterval) lastInterval = atInterval;
|
||||
}
|
||||
|
||||
public bool Add(EntityModel entity, IEconomyService withEconomy, IToastService withToasts) {
|
||||
if (entity != null) {
|
||||
var production = entity.Production();
|
||||
public bool Add(EntityModel entity, IEconomyService withEconomy, IToastService withToasts)
|
||||
{
|
||||
var production = entity.Production();
|
||||
|
||||
if (production != null) {
|
||||
for (var interval = lastInterval; interval < withEconomy.GetOverTime().Count; interval++) {
|
||||
var economyAtSecond = withEconomy.GetOverTime()[interval];
|
||||
if (economyAtSecond.Alloy >= production.Alloy && economyAtSecond.Ether >= production.Ether &&
|
||||
economyAtSecond.Pyre >= production.Pyre) {
|
||||
if (!MeetsSupply(entity)) {
|
||||
withToasts.AddToast(new ToastModel {Title = "Supply Cap Reached", Message = "Build more supply!", SeverityType = SeverityType.Error});
|
||||
return false;
|
||||
}
|
||||
|
||||
if (!MeetsRequirements(entity, interval)) continue;
|
||||
|
||||
//Account for human Micro delay
|
||||
interval += HumanMicro;
|
||||
|
||||
if (!buildOrder.Orders.ContainsKey(interval))
|
||||
buildOrder.Orders.Add(interval, new List<EntityModel> { entity.Clone() });
|
||||
else
|
||||
buildOrder.Orders[interval].Add(entity.Clone());
|
||||
|
||||
lastInterval = interval;
|
||||
|
||||
NotifyDataChanged();
|
||||
return true;
|
||||
}
|
||||
else if(interval + 1 == withEconomy.GetOverTime().Count)
|
||||
if (production != null)
|
||||
{
|
||||
for (var interval = lastInterval; interval < withEconomy.GetOverTime().Count; interval++)
|
||||
{
|
||||
var economyAtSecond = withEconomy.GetOverTime()[interval];
|
||||
if (economyAtSecond.Alloy >= production.Alloy && economyAtSecond.Ether >= production.Ether &&
|
||||
economyAtSecond.Pyre >= production.Pyre)
|
||||
{
|
||||
if (!MeetsSupply(entity))
|
||||
{
|
||||
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 = "Supply Cap Reached", Message = "Build more supply!",
|
||||
SeverityType = SeverityType.Error
|
||||
});
|
||||
return false;
|
||||
}
|
||||
|
||||
if (!MeetsRequirements(entity, interval)) continue;
|
||||
|
||||
//Account for human Micro delay
|
||||
interval += HumanMicro;
|
||||
|
||||
if (!buildOrder.Orders.ContainsKey(interval))
|
||||
buildOrder.Orders.Add(interval, new List<EntityModel> { entity.Clone() });
|
||||
else
|
||||
buildOrder.Orders[interval].Add(entity.Clone());
|
||||
|
||||
lastInterval = interval;
|
||||
|
||||
NotifyDataChanged();
|
||||
return true;
|
||||
}
|
||||
|
||||
if (interval + 1 == withEconomy.GetOverTime().Count)
|
||||
{
|
||||
if (economyAtSecond.Ether < production.Ether)
|
||||
withToasts.AddToast(new ToastModel
|
||||
{
|
||||
Title = "Not Enough Ether", Message = "Build more ether extractors!",
|
||||
SeverityType = SeverityType.Error
|
||||
});
|
||||
}
|
||||
}
|
||||
else {
|
||||
Add(entity, 0);
|
||||
NotifyDataChanged();
|
||||
return true;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
Add(entity, 0);
|
||||
NotifyDataChanged();
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
public void RemoveLast() {
|
||||
public void RemoveLast()
|
||||
{
|
||||
EntityModel entityRemoved = null!;
|
||||
|
||||
|
||||
if (buildOrder.Orders.Keys.Count > 1) {
|
||||
if (buildOrder.Orders.Keys.Count > 1)
|
||||
{
|
||||
var last = buildOrder.Orders.Keys.Last();
|
||||
|
||||
if (buildOrder.Orders[last].Count > 0) {
|
||||
if (buildOrder.Orders[last].Count > 0)
|
||||
{
|
||||
entityRemoved = buildOrder.Orders[last].Last();
|
||||
buildOrder.Orders[last].Remove(buildOrder.Orders[last].Last());
|
||||
}
|
||||
@@ -109,7 +126,8 @@ public class BuildOrderService : IBuildOrderService {
|
||||
else
|
||||
lastInterval = 1;
|
||||
|
||||
if (entityRemoved?.Info()?.Descriptive == DescriptiveType.Worker) {
|
||||
if (entityRemoved?.Info()?.Descriptive == DescriptiveType.Worker)
|
||||
{
|
||||
RemoveLast();
|
||||
return;
|
||||
}
|
||||
@@ -119,15 +137,18 @@ public class BuildOrderService : IBuildOrderService {
|
||||
}
|
||||
|
||||
|
||||
public string AsJson() {
|
||||
var options = new JsonSerializerOptions {
|
||||
public string AsJson()
|
||||
{
|
||||
var options = new JsonSerializerOptions
|
||||
{
|
||||
WriteIndented = true
|
||||
};
|
||||
options.Converters.Add(new JsonStringEnumConverter());
|
||||
return JsonSerializer.Serialize(buildOrder, options);
|
||||
}
|
||||
|
||||
public string BuildOrderAsYaml() {
|
||||
public string BuildOrderAsYaml()
|
||||
{
|
||||
var stringBuilder = new StringBuilder();
|
||||
var serializer = new Serializer();
|
||||
stringBuilder.AppendLine(serializer.Serialize(buildOrder));
|
||||
@@ -135,28 +156,32 @@ public class BuildOrderService : IBuildOrderService {
|
||||
return buildOrderText;
|
||||
}
|
||||
|
||||
public List<EntityModel> GetOrdersAt(int interval) {
|
||||
public List<EntityModel> GetOrdersAt(int interval)
|
||||
{
|
||||
return (from ordersAtTime in buildOrder.Orders
|
||||
from orders in ordersAtTime.Value
|
||||
where ordersAtTime.Key == interval
|
||||
select orders).ToList();
|
||||
}
|
||||
|
||||
public List<EntityModel> GetCompletedAt(int interval) {
|
||||
public List<EntityModel> GetCompletedAt(int interval)
|
||||
{
|
||||
return (from ordersAtTime in buildOrder.Orders
|
||||
from orders in ordersAtTime.Value
|
||||
where ordersAtTime.Key + (orders.Production() == null ? 0 : orders.Production().BuildTime) == interval
|
||||
select orders).ToList();
|
||||
}
|
||||
|
||||
public List<EntityModel> GetCompletedBefore(int interval) {
|
||||
public List<EntityModel> GetCompletedBefore(int interval)
|
||||
{
|
||||
return (from ordersAtTime in buildOrder.Orders
|
||||
from orders in ordersAtTime.Value
|
||||
where ordersAtTime.Key + (orders.Production() == null ? 0 : orders.Production().BuildTime) <= interval
|
||||
select orders).ToList();
|
||||
}
|
||||
|
||||
public List<EntityModel> GetHarvestersCompletedBefore(int interval) {
|
||||
public List<EntityModel> GetHarvestersCompletedBefore(int interval)
|
||||
{
|
||||
return (from ordersAtTime in buildOrder.Orders
|
||||
from orders in ordersAtTime.Value
|
||||
where ordersAtTime.Key + (orders.Production() == null ? 0 : orders.Production().BuildTime) <= interval
|
||||
@@ -164,12 +189,14 @@ public class BuildOrderService : IBuildOrderService {
|
||||
select orders).ToList();
|
||||
}
|
||||
|
||||
public bool MeetsRequirements(EntityModel entity, int requestedInterval) {
|
||||
public bool MeetsRequirements(EntityModel entity, int requestedInterval)
|
||||
{
|
||||
var requirements = entity.Requirements();
|
||||
if (requirements.Count == 0) return true;
|
||||
|
||||
foreach (var requirement in requirements)
|
||||
if (requirement.Requirement == RequirementType.Morph) {
|
||||
if (requirement.Requirement == RequirementType.Morph)
|
||||
{
|
||||
var entitiesNeeded = from entitiesAtInterval in buildOrder.Orders
|
||||
from requiredEntity in entitiesAtInterval.Value
|
||||
where requestedInterval > entitiesAtInterval.Key +
|
||||
@@ -185,7 +212,8 @@ public class BuildOrderService : IBuildOrderService {
|
||||
if (entitiesAlreadyMorphed.Count() >= entitiesNeeded.Count())
|
||||
return false;
|
||||
}
|
||||
else {
|
||||
else
|
||||
{
|
||||
var entitiesNeeded = from entitiesAtInterval in buildOrder.Orders
|
||||
from requiredEntity in entitiesAtInterval.Value
|
||||
where requestedInterval > entitiesAtInterval.Key +
|
||||
@@ -204,40 +232,48 @@ public class BuildOrderService : IBuildOrderService {
|
||||
return true;
|
||||
}
|
||||
|
||||
public void SetName(string Name) {
|
||||
public void SetName(string Name)
|
||||
{
|
||||
buildOrder.Name = Name;
|
||||
NotifyDataChanged();
|
||||
}
|
||||
|
||||
public string GetName() {
|
||||
public string GetName()
|
||||
{
|
||||
return buildOrder.Name;
|
||||
}
|
||||
|
||||
public void SetNotes(string Notes) {
|
||||
public void SetNotes(string Notes)
|
||||
{
|
||||
buildOrder.Notes = Notes;
|
||||
NotifyDataChanged();
|
||||
}
|
||||
|
||||
public string GetNotes() {
|
||||
public string GetNotes()
|
||||
{
|
||||
return buildOrder.Notes;
|
||||
}
|
||||
|
||||
public void SetColor(string color) {
|
||||
public void SetColor(string color)
|
||||
{
|
||||
buildOrder.Color = color;
|
||||
NotifyDataChanged();
|
||||
}
|
||||
|
||||
public string GetColor() {
|
||||
public string GetColor()
|
||||
{
|
||||
return buildOrder.Color;
|
||||
}
|
||||
|
||||
private event Action OnChange = null!;
|
||||
|
||||
private void NotifyDataChanged() {
|
||||
private void NotifyDataChanged()
|
||||
{
|
||||
OnChange?.Invoke();
|
||||
}
|
||||
|
||||
public bool MeetsSupply(EntityModel entity) {
|
||||
public bool MeetsSupply(EntityModel entity)
|
||||
{
|
||||
var supply = entity.Supply();
|
||||
if (supply == null || supply.Takes == 0) return true;
|
||||
|
||||
|
||||
@@ -5,10 +5,10 @@ using Model.Types;
|
||||
namespace Services.Immortal;
|
||||
|
||||
public class EconomyService : IEconomyService {
|
||||
private List<EconomyModel> _overTime = null!;
|
||||
private List<EconomyModel> _economyOverTime = null!;
|
||||
|
||||
public List<EconomyModel> GetOverTime() {
|
||||
return _overTime;
|
||||
return _economyOverTime;
|
||||
}
|
||||
|
||||
public void Subscribe(Action action) {
|
||||
@@ -20,28 +20,32 @@ public class EconomyService : IEconomyService {
|
||||
}
|
||||
|
||||
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++)
|
||||
_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());
|
||||
|
||||
|
||||
if (_economyOverTime.Count > timing.GetTiming())
|
||||
_economyOverTime.RemoveRange(timing.GetTiming(), _economyOverTime.Count - timing.GetTiming());
|
||||
|
||||
while (_overTime.Count < timing.GetTiming()) _overTime.Add(new EconomyModel { Interval = _overTime.Count - 1 });
|
||||
while (_economyOverTime.Count < timing.GetTiming()) _economyOverTime.Add(new EconomyModel { Interval = _economyOverTime.Count - 1 });
|
||||
|
||||
for (var interval = fromInterval; interval < timing.GetTiming(); interval++) {
|
||||
var economyAtSecond = _overTime[interval];
|
||||
var economyAtSecond = _economyOverTime[interval];
|
||||
if (interval > 0) {
|
||||
economyAtSecond.Alloy = _overTime[interval - 1].Alloy;
|
||||
economyAtSecond.Ether = _overTime[interval - 1].Ether;
|
||||
economyAtSecond.Pyre = _overTime[interval - 1].Pyre;
|
||||
economyAtSecond.WorkerCount = _overTime[interval - 1].WorkerCount;
|
||||
economyAtSecond.BusyWorkerCount = _overTime[interval - 1].BusyWorkerCount;
|
||||
economyAtSecond.CreatingWorkerCount = _overTime[interval - 1].CreatingWorkerCount;
|
||||
economyAtSecond.Harvesters = _overTime[interval - 1].Harvesters.ToList();
|
||||
economyAtSecond.CreatingWorkerDelays = _overTime[interval - 1].CreatingWorkerDelays.ToList();
|
||||
economyAtSecond.Alloy = _economyOverTime[interval - 1].Alloy;
|
||||
economyAtSecond.Ether = _economyOverTime[interval - 1].Ether;
|
||||
economyAtSecond.Pyre = _economyOverTime[interval - 1].Pyre;
|
||||
economyAtSecond.WorkerCount = _economyOverTime[interval - 1].WorkerCount;
|
||||
economyAtSecond.BusyWorkerCount = _economyOverTime[interval - 1].BusyWorkerCount;
|
||||
economyAtSecond.CreatingWorkerCount = _economyOverTime[interval - 1].CreatingWorkerCount;
|
||||
economyAtSecond.Harvesters = _economyOverTime[interval - 1].Harvesters.ToList();
|
||||
economyAtSecond.CreatingWorkerDelays = _economyOverTime[interval - 1].CreatingWorkerDelays.ToList();
|
||||
}
|
||||
|
||||
economyAtSecond.Interval = interval;
|
||||
@@ -134,7 +138,7 @@ public class EconomyService : IEconomyService {
|
||||
|
||||
|
||||
public EconomyModel GetEconomy(int atInterval) {
|
||||
return _overTime[atInterval];
|
||||
return _economyOverTime[atInterval];
|
||||
}
|
||||
|
||||
private event Action onChange = null!;
|
||||
|
||||
@@ -4,13 +4,18 @@ namespace Services.Website;
|
||||
|
||||
public class NavigationService : INavigationService {
|
||||
private string navigationStateType = NavigationStateType.Default;
|
||||
|
||||
private int navigationStateId = -1;
|
||||
|
||||
private NavSelectionType navSelectionType = NavSelectionType.None;
|
||||
|
||||
|
||||
|
||||
private Type renderType = null!;
|
||||
private int webPageType;
|
||||
private int webSectionType;
|
||||
|
||||
|
||||
|
||||
public void Subscribe(Action action) {
|
||||
OnChange += action;
|
||||
}
|
||||
@@ -19,6 +24,17 @@ public class NavigationService : INavigationService {
|
||||
OnChange += action;
|
||||
}
|
||||
|
||||
public void ChangeNavigationSectionId(int newState)
|
||||
{
|
||||
navigationStateId = newState;
|
||||
NotifyDataChanged();
|
||||
}
|
||||
|
||||
public int GetNavigationSectionId()
|
||||
{
|
||||
return navigationStateId;
|
||||
}
|
||||
|
||||
public void ChangeNavigationState(string newState) {
|
||||
if (newState.Equals(navigationStateType))
|
||||
return;
|
||||
|
||||
@@ -1,10 +1,5 @@
|
||||
using System.Net.Http.Json;
|
||||
|
||||
#if !NO_SQL
|
||||
using Contexts;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
#endif
|
||||
|
||||
using Model.Website;
|
||||
|
||||
namespace Services.Development;
|
||||
@@ -24,17 +19,8 @@ public class WebsiteService : IWebsiteService {
|
||||
|
||||
|
||||
|
||||
#if NO_SQL
|
||||
public List<WebSectionModel> WebSectionModels { 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) {
|
||||
@@ -49,39 +35,35 @@ public class WebsiteService : IWebsiteService {
|
||||
return isLoaded;
|
||||
}
|
||||
|
||||
#if NO_SQL
|
||||
|
||||
public async Task Load() {
|
||||
if (isLoaded) {return;}
|
||||
|
||||
|
||||
|
||||
WebPageModels = ((await httpClient.GetFromJsonAsync<WebPageModel[]>("generated/WebPageModels.json"))!).ToList();
|
||||
WebSectionModels =((await httpClient.GetFromJsonAsync<WebSectionModel[]>("generated/WebSectionModels.json"))!).ToList();
|
||||
|
||||
isLoaded = true;
|
||||
|
||||
SortSql();
|
||||
|
||||
NotifyDataChanged();
|
||||
}
|
||||
#else
|
||||
public async Task Load(DatabaseContext database) {
|
||||
Database = database;
|
||||
|
||||
if (isLoaded) {return;}
|
||||
|
||||
Database.WebPageModels.AddRange(await httpClient.GetFromJsonAsync<WebPageModel[]>("generated/WebPageModels.json"));
|
||||
Database.WebSectionModels.AddRange(
|
||||
await httpClient.GetFromJsonAsync<WebSectionModel[]>("generated/WebSectionModels.json"));
|
||||
|
||||
Database.SaveChanges();
|
||||
|
||||
isLoaded = true;
|
||||
|
||||
NotifyDataChanged();
|
||||
}
|
||||
#endif
|
||||
|
||||
void SortSql()
|
||||
{
|
||||
foreach (var page in WebPageModels)
|
||||
{
|
||||
|
||||
if (page.WebSectionModelId != null)
|
||||
{
|
||||
WebSectionModel webSection =
|
||||
WebSectionModels.Find(webSection => webSection.Id == page.WebSectionModelId);
|
||||
|
||||
webSection.WebPageModels.Add(page);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public void Update() {
|
||||
NotifyDataChanged();
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user