feature(BuildCalc) Added reset button, can change micro delay, and can alter timing interval again

This commit is contained in:
2022-04-14 22:28:14 -04:00
parent 4cef578cd0
commit 04c1718259
115 changed files with 1561 additions and 1308 deletions
+4 -13
View File
@@ -22,7 +22,6 @@ public class DocumentationService : IDocumentationService
public List<DocConnectionModel> DocConnectionModels { get; set; } = new();
public void Subscribe(Action? action)
{
OnChange += action;
@@ -54,7 +53,7 @@ public class DocumentationService : IDocumentationService
DocSectionModels =
(await httpClient.GetFromJsonAsync<DocSectionModel[]>("generated/DocSectionModels.json") ??
Array.Empty<DocSectionModel>()).ToList();
SortSql();
isLoaded = true;
@@ -88,28 +87,20 @@ public class DocumentationService : IDocumentationService
}
foreach (var content in DocContentModels)
{
if (content.DocSectionModelId != null)
{
foreach (var section in DocSectionModels)
{
if (section.Id == content.DocSectionModelId)
{
section.DocumentationModels.Add(content);
}
}
}
}
ByPageOrder();
}
private void ByPageOrder()
{
DocContentModelsByPageOrder = new List<DocContentModel>();
int order = 1;
var order = 1;
foreach (var documentation in DocContentModels)
{
if (documentation.Parent != null) continue;
+24 -19
View File
@@ -10,15 +10,17 @@ using Microsoft.EntityFrameworkCore;
namespace Services.Development;
public class GitService : IGitService {
public class GitService : IGitService
{
private readonly HttpClient httpClient;
private bool isLoaded;
private event Action OnChange = default!;
public GitService(HttpClient httpClient) {
public GitService(HttpClient httpClient)
{
this.httpClient = httpClient;
}
@@ -32,30 +34,32 @@ public class GitService : IGitService {
#endif
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 bool IsLoaded() {
public bool IsLoaded()
{
return isLoaded;
}
#if NO_SQL
public async Task Load() {
public async Task Load()
{
if (isLoaded) return;
if (isLoaded) {
return;
}
GitChangeModels = (await httpClient.GetFromJsonAsync<GitChangeModel[]>("generated/GitChangeModels.json") ?? Array.Empty<GitChangeModel>()).ToList();
GitPatchModels = (await httpClient.GetFromJsonAsync<GitPatchModel[]>("generated/GitPatchModels.json") ?? Array.Empty<GitPatchModel>()).ToList();
GitChangeModels = (await httpClient.GetFromJsonAsync<GitChangeModel[]>("generated/GitChangeModels.json") ??
Array.Empty<GitChangeModel>()).ToList();
GitPatchModels = (await httpClient.GetFromJsonAsync<GitPatchModel[]>("generated/GitPatchModels.json") ??
Array.Empty<GitPatchModel>()).ToList();
isLoaded = true;
@@ -64,7 +68,6 @@ public class GitService : IGitService {
}
#else
public async Task Load(DatabaseContext database) {
Database = database;
@@ -84,12 +87,14 @@ public class GitService : IGitService {
#endif
public void Update() {
public void Update()
{
NotifyDataChanged();
}
private void NotifyDataChanged() {
private void NotifyDataChanged()
{
OnChange?.Invoke();
}
}
+47 -42
View File
@@ -10,57 +10,73 @@ using Microsoft.EntityFrameworkCore;
namespace Services.Development;
public class NoteService : INoteService {
public class NoteService : INoteService
{
private readonly HttpClient httpClient;
private bool isLoaded;
private event Action OnChange = default!;
private void NotifyDataChanged() {
OnChange?.Invoke();
}
public NoteService(HttpClient httpClient) {
public NoteService(HttpClient httpClient)
{
this.httpClient = httpClient;
}
public List<NoteContentModel> NoteContentModelsByPageOrder { get; set; } = new();
public List<NoteContentModel> NoteContentModels { get; set; } = default!;
public List<NoteConnectionModel> NoteConnectionModels { get; set; } = null!;
public List<NoteSectionModel> NoteSectionModels { get; set; } = null!;
public List<NoteContentModel> NoteContentModelsByPageOrder { get; set; } = new();
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 bool IsLoaded() {
public bool IsLoaded()
{
return isLoaded;
}
public async Task Load() {
if (isLoaded) {
return;
}
NoteContentModels = (await httpClient.GetFromJsonAsync<NoteContentModel[]>("generated/NoteContentModels.json") ?? Array.Empty<NoteContentModel>()).ToList();
NoteConnectionModels = (await httpClient.GetFromJsonAsync<NoteConnectionModel[]>("generated/NoteConnectionModels.json") ?? Array.Empty<NoteConnectionModel>()).ToList();
NoteSectionModels = (await httpClient.GetFromJsonAsync<NoteSectionModel[]>("generated/NoteSectionModels.json") ?? Array.Empty<NoteSectionModel>()).ToList();
public async Task Load()
{
if (isLoaded) return;
NoteContentModels =
(await httpClient.GetFromJsonAsync<NoteContentModel[]>("generated/NoteContentModels.json") ??
Array.Empty<NoteContentModel>()).ToList();
NoteConnectionModels =
(await httpClient.GetFromJsonAsync<NoteConnectionModel[]>("generated/NoteConnectionModels.json") ??
Array.Empty<NoteConnectionModel>()).ToList();
NoteSectionModels =
(await httpClient.GetFromJsonAsync<NoteSectionModel[]>("generated/NoteSectionModels.json") ??
Array.Empty<NoteSectionModel>()).ToList();
isLoaded = true;
SortSQL();
NotifyDataChanged();
}
public void Update()
{
NotifyDataChanged();
}
private event Action OnChange = default!;
private void NotifyDataChanged()
{
OnChange?.Invoke();
}
private NoteContentModel? ContentById(int id)
{
foreach (var data in NoteContentModels!)
@@ -69,7 +85,7 @@ public class NoteService : INoteService {
return null;
}
private void SortSQL()
{
foreach (var connection in NoteConnectionModels)
@@ -79,27 +95,19 @@ public class NoteService : INoteService {
}
foreach (var content in NoteContentModels)
{
if (content.NoteSectionModelId != null)
{
foreach (var section in NoteSectionModels)
{
if (section.Id == content.NoteSectionModelId)
{
section.NoteContentModels.Add(content);
}
}
}
}
ByPageOrder();
}
private void ByPageOrder()
{
NoteContentModelsByPageOrder = new List<NoteContentModel>();
int order = 1;
var order = 1;
foreach (var note in NoteContentModels)
{
if (note.Parent != null) continue;
@@ -121,10 +129,7 @@ public class NoteService : INoteService {
GetAllChildren(note);
}
NoteContentModelsByPageOrder = NoteContentModelsByPageOrder.OrderBy(noteContent => noteContent.PageOrder).ToList();
}
public void Update() {
NotifyDataChanged();
NoteContentModelsByPageOrder =
NoteContentModelsByPageOrder.OrderBy(noteContent => noteContent.PageOrder).ToList();
}
}
+42 -36
View File
@@ -1,20 +1,18 @@
using Model.BuildOrders;
using Model.Doc;
using Model.BuildOrders;
using Model.Economy;
using Model.Entity;
using Model.Feedback;
using Model.Git;
using Model.MemoryTester;
using Model.Notes;
using Model.Website;
using Model.Website.Enums;
using Model.Git;
using Model.Feedback;
using Model.Work.Tasks;
using Services.Immortal;
namespace Services;
public interface IToastService
{
public void Subscribe(Action action);
@@ -27,15 +25,14 @@ public interface IToastService
void ClearAllToasts();
}
public interface IEntityDialogService
{
public void Subscribe(Action action);
public void Unsubscribe(Action action);
public void AddDialog(string entityId);
public void CloseDialog();
public void BackDialog();
public string? GetEntityId();
@@ -44,22 +41,23 @@ public interface IEntityDialogService
public bool HasHistory();
}
public interface IWebsiteService {
public interface IWebsiteService
{
public List<WebPageModel> WebPageModels { get; set; }
public List<WebSectionModel> WebSectionModels { get; set; }
public void Subscribe(Action action);
public void Unsubscribe(Action action);
public void Update();
public Task Load();
public bool IsLoaded();
}
public interface IAgileService {
public interface IAgileService
{
#if NO_SQL
public List<AgileSprintModel>? AgileSprintModels { get; set; }
public List<AgileTaskModel>? AgileTaskModels { get; set; }
@@ -71,12 +69,13 @@ public interface IAgileService {
public void Subscribe(Action? action);
public void Unsubscribe(Action? action);
public void Update();
public Task Load();
public bool IsLoaded();
}
public interface INoteService {
public interface INoteService
{
public List<NoteContentModel> NoteContentModels { get; set; }
public List<NoteConnectionModel> NoteConnectionModels { get; set; }
public List<NoteSectionModel> NoteSectionModels { get; set; }
@@ -101,9 +100,8 @@ public interface IDocumentationService
public bool IsLoaded();
}
public interface IGitService {
public interface IGitService
{
#if NO_SQL
public List<GitChangeModel> GitChangeModels { get; set; }
public List<GitPatchModel> GitPatchModels { get; set; }
@@ -124,7 +122,8 @@ public interface IGitService {
public bool IsLoaded();
}
public interface INavigationService {
public interface INavigationService
{
public void Subscribe(Action action);
public void Unsubscribe(Action action);
@@ -143,7 +142,8 @@ public interface INavigationService {
public Type GetRenderType();
}
public interface IBuildComparisonService {
public interface IBuildComparisonService
{
public void SetBuilds(BuildComparisonModel buildComparisonModel);
public BuildComparisonModel Get();
public string BuildOrderAsYaml();
@@ -153,14 +153,16 @@ public interface IBuildComparisonService {
public void Unsubscribe(Action action);
}
public interface ITimingService {
public interface ITimingService
{
public int GetTiming();
public void SetTiming(int timing);
public void Subscribe(Action? action);
public void Unsubscribe(Action? action);
}
public interface IEconomyService {
public interface IEconomyService
{
public List<EconomyModel> GetOverTime();
public EconomyModel GetEconomy(int atInterval);
public void Calculate(IBuildOrderService buildOrder, ITimingService timing, int fromInterval);
@@ -168,7 +170,8 @@ public interface IEconomyService {
public void Unsubscribe(Action action);
}
public interface IEntityFilterService {
public interface IEntityFilterService
{
public delegate void EntityFilterAction(EntityFilterEvent entityFilterEvent);
public string GetFactionType();
@@ -191,24 +194,23 @@ public interface IEntityFilterService {
public void Unsubscribe(EntityFilterAction action);
}
public interface IEntityService {
public interface IEntityService
{
public List<EntityModel> GetEntities();
}
public interface IEntityDisplayService
{
public List<string> DefaultChoices();
public string GetDisplayType();
public void SetDisplayType(string displayType);
public void Subscribe(Action action);
public void Unsubscribe(Action action);
}
public interface IImmortalSelectionService {
public interface IImmortalSelectionService
{
public string GetFactionType();
public string GetImmortalType();
public bool SelectFactionType(string factionType);
@@ -217,7 +219,8 @@ public interface IImmortalSelectionService {
public void Unsubscribe(Action action);
}
public interface IKeyService {
public interface IKeyService
{
public List<string> GetAllPressedKeys();
public string? GetHotkey();
public string GetHotkeyGroup();
@@ -228,7 +231,8 @@ public interface IKeyService {
public void Unsubscribe(Action? action);
}
public interface IMemoryTesterService {
public interface IMemoryTesterService
{
public delegate void MemoryAction(MemoryTesterEvent memoryEvent);
public List<MemoryEntityModel> GetEntities();
@@ -244,15 +248,16 @@ public interface IMemoryTesterService {
public void Unsubscribe(MemoryAction memoryAction);
}
public interface IBuildOrderService {
public interface IBuildOrderService
{
public int BuildingInputDelay { get; set; }
public Dictionary<int, List<EntityModel>> StartedOrders { get; }
public Dictionary<int, List<EntityModel>> CompletedOrders { get; }
public Dictionary<string, int> UniqueCompletedTimes { get; }
public Dictionary<int, int> SupplyCountTimes { get; }
public bool Add(EntityModel entity, IEconomyService withEconomy, IToastService toastService);
public void Add(EntityModel entity, int atInterval);
@@ -272,6 +277,7 @@ public interface IBuildOrderService {
public List<EntityModel> GetHarvestersCompletedBefore(int interval);
public void RemoveLast();
public void Reset();
public int GetLastRequestInterval();
public string BuildOrderAsYaml();
+33 -20
View File
@@ -3,48 +3,51 @@ using System.Text.Json;
using System.Text.Json.Serialization;
using Model.BuildOrders;
using Model.Entity;
using Model.Entity.Data;
using YamlDotNet.Serialization;
namespace Services.Immortal;
public class BuildComparisionService : IBuildComparisonService {
private event Action OnChange = default!;
public class BuildComparisionService : IBuildComparisonService
{
private BuildComparisonModel buildComparison = new();
public void Subscribe(Action action) {
public void Subscribe(Action action)
{
OnChange += action;
}
public void Unsubscribe(Action action) {
public void Unsubscribe(Action action)
{
OnChange -= action;
}
private void NotifyDataChanged() {
OnChange?.Invoke();
}
public void SetBuilds(BuildComparisonModel buildComparisonModel) {
public void SetBuilds(BuildComparisonModel buildComparisonModel)
{
buildComparison = buildComparisonModel;
NotifyDataChanged();
}
public BuildComparisonModel Get() {
public BuildComparisonModel Get()
{
return buildComparison;
}
public string AsJson() {
var options = new JsonSerializerOptions {
public string AsJson()
{
var options = new JsonSerializerOptions
{
WriteIndented = true
};
options.Converters.Add(new JsonStringEnumConverter());
return JsonSerializer.Serialize(buildComparison, options);
}
public bool LoadJson(string data) {
try {
var options = new JsonSerializerOptions {
public bool LoadJson(string data)
{
try
{
var options = new JsonSerializerOptions
{
WriteIndented = true
};
options.Converters.Add(new JsonStringEnumConverter());
@@ -56,12 +59,14 @@ public class BuildComparisionService : IBuildComparisonService {
NotifyDataChanged();
return true;
}
catch {
catch
{
return false;
}
}
public string BuildOrderAsYaml() {
public string BuildOrderAsYaml()
{
var stringBuilder = new StringBuilder();
var serializer = new Serializer();
stringBuilder.AppendLine(serializer.Serialize(buildComparison));
@@ -69,8 +74,16 @@ public class BuildComparisionService : IBuildComparisonService {
return buildOrderText;
}
private event Action OnChange = default!;
public void HydratedLoadedJson() {
private void NotifyDataChanged()
{
OnChange?.Invoke();
}
public void HydratedLoadedJson()
{
foreach (var build in buildComparison.Builds)
foreach (var orders in build.StartedOrders.Values)
foreach (var order in orders)
+72 -17
View File
@@ -12,11 +12,14 @@ namespace Services.Immortal;
public class BuildOrderService : IBuildOrderService
{
private readonly BuildOrderModel buildOrder = new();
private readonly int HumanMicro = 2;
private int lastInterval;
private BuildOrderModel buildOrder = new();
public int BuildingInputDelay { get; set; } = 2;
private int lastInterval = 0;
private event Action OnChange = null!;
public BuildOrderService()
{
Reset();
}
public Dictionary<int, List<EntityModel>> StartedOrders => buildOrder.StartedOrders;
public Dictionary<int, List<EntityModel>> CompletedOrders => buildOrder.CompletedOrders;
@@ -92,7 +95,6 @@ public class BuildOrderService : IBuildOrderService
var metTime = 0;
foreach (var requiredEntity in requirements)
{
if (buildOrder.UniqueCompletedTimes.TryGetValue(requiredEntity.Id, out var completedTime))
{
if (completedTime > metTime) metTime = completedTime;
@@ -101,7 +103,6 @@ public class BuildOrderService : IBuildOrderService
{
return null;
}
}
return metTime;
}
@@ -135,7 +136,6 @@ public class BuildOrderService : IBuildOrderService
public void RemoveLast()
{
if (buildOrder.StartedOrders.Keys.Count > 1)
{
var lastStarted = buildOrder.StartedOrders.Keys.Last();
@@ -160,16 +160,15 @@ public class BuildOrderService : IBuildOrderService
if (entityRemoved.Supply()?.Grants > 0)
SupplyCountTimes.Remove(SupplyCountTimes.Last().Key);
if (entityRemoved.Supply()?.Takes > 0)
buildOrder.CurrentSupplyUsed -= entityRemoved.Supply()!.Takes;
buildOrder.UniqueCompletedCount[entityRemoved!.DataType]--;
if (buildOrder.UniqueCompletedCount[entityRemoved!.DataType] == 0) {
if (buildOrder.UniqueCompletedCount[entityRemoved!.DataType] == 0)
UniqueCompletedTimes.Remove(entityRemoved.DataType);
}
if (entityRemoved.Info().Descriptive == DescriptiveType.Worker)
{
RemoveLast();
@@ -252,6 +251,65 @@ public class BuildOrderService : IBuildOrderService
return buildOrder.Color;
}
public void Reset()
{
lastInterval = 0;
buildOrder = new BuildOrderModel
{
StartedOrders = new Dictionary<int, List<EntityModel>>
{
{
0,
new List<EntityModel>
{
EntityModel.Get(DataType.STARTING_Bastion),
EntityModel.Get(DataType.STARTING_TownHall_Aru)
}
}
},
CompletedOrders = new Dictionary<int, List<EntityModel>>
{
{
0,
new List<EntityModel>
{
EntityModel.Get(DataType.STARTING_Bastion),
EntityModel.Get(DataType.STARTING_TownHall_Aru)
}
}
},
UniqueCompletedTimes = new Dictionary<string, int>
{
{
DataType.STARTING_Bastion, 0
},
{
DataType.STARTING_TownHall_Aru, 0
}
},
UniqueCompletedCount = new Dictionary<string, int>
{
{
DataType.STARTING_Bastion, 1
},
{
DataType.STARTING_TownHall_Aru, 1
}
},
SupplyCountTimes = new Dictionary<int, int>
{
{
0, 0
}
}
};
NotifyDataChanged();
}
private event Action OnChange = null!;
private bool HandleEconomy(EntityModel entity, IEconomyService withEconomy, IToastService withToasts,
ref int atInterval)
{
@@ -266,12 +324,9 @@ public class BuildOrderService : IBuildOrderService
economyAtSecond.Pyre >= production.Pyre)
{
atInterval = interval;
if (entity.EntityType != EntityType.Army)
{
atInterval += HumanMicro;
}
if (entity.EntityType != EntityType.Army) atInterval += BuildingInputDelay;
return true;
}
+35 -26
View File
@@ -1,43 +1,47 @@
using Model.Economy;
using Model.Entity;
using Model.Feedback;
using Model.Types;
using Services.Website;
namespace Services.Immortal;
public class EconomyService : IEconomyService {
public class EconomyService : IEconomyService
{
private List<EconomyModel> _economyOverTime = null!;
private event Action OnChange = null!;
public List<EconomyModel> GetOverTime() {
public List<EconomyModel> GetOverTime()
{
return _economyOverTime;
}
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 Calculate(IBuildOrderService buildOrder, ITimingService timing, int fromInterval) {
public void Calculate(IBuildOrderService buildOrder, ITimingService timing, int fromInterval)
{
//TODO Break all this up
if (_economyOverTime == null) {
if (_economyOverTime == null)
{
_economyOverTime = new List<EconomyModel>();
for (var interval = 0; interval < timing.GetTiming(); interval++)
_economyOverTime.Add(new EconomyModel { Interval = interval });
}
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 });
while (_economyOverTime.Count < timing.GetTiming())
_economyOverTime.Add(new EconomyModel { Interval = _economyOverTime.Count - 1 });
for (var interval = fromInterval; interval < timing.GetTiming(); interval++)
{
@@ -119,8 +123,6 @@ public class EconomyService : IEconomyService {
// Remove Funds from Build Order
if (buildOrder.StartedOrders.TryGetValue(interval, out var ordersAtTime))
{
foreach (var order in ordersAtTime)
{
var foundEntity = EntityModel.GetDictionary()[order.DataType];
@@ -138,31 +140,38 @@ public class EconomyService : IEconomyService {
if (production.ConsumesWorker) economyAtSecond.WorkerCount -= 1;
}
}
}
// Handle new entities
if (buildOrder.CompletedOrders.TryGetValue(interval, out var completedAtInterval))
{
foreach (var newEntity in completedAtInterval)
{
var harvest = newEntity;
if (harvest != null) economyAtSecond.Harvesters.Add(harvest);
{
var harvest = newEntity;
if (harvest != null) economyAtSecond.Harvesters.Add(harvest);
var production = newEntity.Production();
if (production != null && production.RequiresWorker) economyAtSecond.BusyWorkerCount -= 1;
}
var production = newEntity.Production();
if (production != null && production.RequiresWorker) economyAtSecond.BusyWorkerCount -= 1;
}
}
}
NotifyDataChanged();
}
public EconomyModel GetEconomy(int atInterval) {
public EconomyModel GetEconomy(int atInterval)
{
if (atInterval >= _economyOverTime.Count)
{
return _economyOverTime.Last();
}
return _economyOverTime[atInterval];
}
private void NotifyDataChanged() {
private event Action OnChange = null!;
private void NotifyDataChanged()
{
OnChange?.Invoke();
}
}
+14 -12
View File
@@ -1,28 +1,24 @@
using Model.Types;
namespace Services.Immortal;
namespace Services.Immortal;
public class EntityDisplayService : IEntityDisplayService {
public class EntityDisplayService : IEntityDisplayService
{
private string displayType = "Detailed";
private event Action OnChange = null!;
public List<string> DefaultChoices()
{
return new List<string>() { "Detailed", "Plain" };
return new List<string> { "Detailed", "Plain" };
}
public void Subscribe(Action action) {
public void Subscribe(Action action)
{
OnChange += action;
}
public void Unsubscribe(Action action) {
public void Unsubscribe(Action action)
{
OnChange -= action;
}
private void NotifyDataChanged() {
OnChange?.Invoke();
}
public string GetDisplayType()
{
return displayType;
@@ -34,4 +30,10 @@ public class EntityDisplayService : IEntityDisplayService {
NotifyDataChanged();
}
private event Action OnChange = null!;
private void NotifyDataChanged()
{
OnChange?.Invoke();
}
}
+58 -33
View File
@@ -4,14 +4,16 @@ using static Services.IEntityFilterService;
namespace Services.Immortal;
public enum EntityFilterEvent {
public enum EntityFilterEvent
{
OnRefreshFaction,
OnRefreshImmortal,
OnRefreshEntity,
OnRefreshSearch
}
public class EntityFilterService : IEntityFilterService {
public class EntityFilterService : IEntityFilterService
{
private readonly List<string> _entityChoices = new();
private readonly List<string> _factionChoices = new() { FactionType.Any, FactionType.QRath, FactionType.Aru };
@@ -20,37 +22,43 @@ public class EntityFilterService : IEntityFilterService {
private string _searchText = "";
private string _selectedFaction = FactionType.Any;
private string _selectedImmortal = ImmortalType.Any;
private event EntityFilterAction OnChange = null!;
public EntityFilterService() {
public EntityFilterService()
{
RefreshImmortalChoices();
RefreshEntityChoices();
}
public void Subscribe(EntityFilterAction action) {
public void Subscribe(EntityFilterAction action)
{
OnChange += action;
}
public void Unsubscribe(EntityFilterAction action) {
public void Unsubscribe(EntityFilterAction action)
{
OnChange -= action;
}
public string GetEntityType() {
public string GetEntityType()
{
return _entityType;
}
public string GetFactionType() {
public string GetFactionType()
{
return _selectedFaction;
}
public string GetImmortalType() {
public string GetImmortalType()
{
return _selectedImmortal;
}
public bool SelectFactionType(string factionType) {
if (_selectedFaction == factionType) {
public bool SelectFactionType(string factionType)
{
if (_selectedFaction == factionType)
{
_selectedFaction = FactionType.None;
_selectedImmortal = ImmortalType.None;
@@ -72,8 +80,10 @@ public class EntityFilterService : IEntityFilterService {
return true;
}
public bool SelectImmortalType(string immortalType) {
if (_selectedImmortal == immortalType) {
public bool SelectImmortalType(string immortalType)
{
if (_selectedImmortal == immortalType)
{
_selectedImmortal = ImmortalType.None;
NotifyDataChanged(EntityFilterEvent.OnRefreshImmortal);
return true;
@@ -84,14 +94,16 @@ public class EntityFilterService : IEntityFilterService {
return true;
}
public bool SelectEntityType(string entityType) {
public bool SelectEntityType(string entityType)
{
if (_entityType == entityType) return false;
_entityType = entityType;
NotifyDataChanged(EntityFilterEvent.OnRefreshEntity);
return true;
}
public bool EnterSearchText(string searchText) {
public bool EnterSearchText(string searchText)
{
if (_searchText.Equals(searchText))
return false;
_searchText = searchText;
@@ -99,23 +111,30 @@ public class EntityFilterService : IEntityFilterService {
return true;
}
public List<string> GetFactionChoices() {
public List<string> GetFactionChoices()
{
return _factionChoices;
}
public List<string> GetImmortalChoices() {
public List<string> GetImmortalChoices()
{
return _immortalChoices;
}
public List<string> GetEntityChoices() {
public List<string> GetEntityChoices()
{
return _entityChoices;
}
public string GetSearchText() {
public string GetSearchText()
{
return _searchText;
}
private void RefreshImmortalChoices() {
private event EntityFilterAction OnChange = null!;
private void RefreshImmortalChoices()
{
_immortalChoices.Clear();
//TODO Consider getting these values from the database
@@ -128,22 +147,27 @@ public class EntityFilterService : IEntityFilterService {
_immortalChoices.Add(ImmortalType.Mala);
_immortalChoices.Add(ImmortalType.Xol);
}*/
if (_selectedFaction == FactionType.QRath || _selectedFaction == FactionType.Any) {
if (_selectedFaction == FactionType.QRath || _selectedFaction == FactionType.Any)
{
_immortalChoices.Add(DataType.IMMORTAL_Orzum);
_immortalChoices.Add(DataType.IMMORTAL_Ajari);
}
if (_selectedFaction == FactionType.Aru || _selectedFaction == FactionType.Any) {
if (_selectedFaction == FactionType.Aru || _selectedFaction == FactionType.Any)
{
_immortalChoices.Add(DataType.IMMORTAL_Mala);
_immortalChoices.Add(DataType.IMMORTAL_Xol);
}
}
private void RefreshEntityChoices() {
private void RefreshEntityChoices()
{
_entityChoices.Clear();
if (_selectedFaction == FactionType.QRath || _selectedFaction == FactionType.Aru || _selectedFaction == FactionType.Any) {
if (_selectedFaction == FactionType.QRath || _selectedFaction == FactionType.Aru ||
_selectedFaction == FactionType.Any)
{
_entityChoices.Add(EntityType.Army);
_entityChoices.Add(EntityType.Immortal);
_entityChoices.Add(EntityType.Passive);
@@ -154,21 +178,22 @@ public class EntityFilterService : IEntityFilterService {
_entityChoices.Add(EntityType.Worker);
}
if (_selectedFaction == FactionType.Any) {
_entityChoices.Add(EntityType.Any);
}
if (_selectedFaction == FactionType.Any) _entityChoices.Add(EntityType.Any);
}
private void NotifyDataChanged(EntityFilterEvent entityFilterEvent) {
private void NotifyDataChanged(EntityFilterEvent entityFilterEvent)
{
OnChange?.Invoke(entityFilterEvent);
}
public void Subscribe(Action action) {
public void Subscribe(Action action)
{
throw new NotImplementedException();
}
public void Unsubscribe(Action action) {
public void Unsubscribe(Action action)
{
throw new NotImplementedException();
}
}
+4 -2
View File
@@ -2,8 +2,10 @@
namespace Services.Immortal;
public class EntityService : IEntityService {
public List<EntityModel> GetEntities() {
public class EntityService : IEntityService
{
public List<EntityModel> GetEntities()
{
throw new NotImplementedException();
}
}
+16 -9
View File
@@ -3,27 +3,33 @@ using Model.Types;
namespace Services.Immortal;
public class ImmortalSelectionService : IImmortalSelectionService {
public class ImmortalSelectionService : IImmortalSelectionService
{
private string _selectedFaction = FactionType.QRath;
private string _selectedImmortal = DataType.IMMORTAL_Orzum;
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 string GetFactionType() {
public string GetFactionType()
{
return _selectedFaction;
}
public string GetImmortalType() {
public string GetImmortalType()
{
return _selectedImmortal;
}
public bool SelectFactionType(string factionType) {
public bool SelectFactionType(string factionType)
{
if (_selectedFaction == factionType) return false;
_selectedFaction = factionType;
@@ -35,7 +41,8 @@ public class ImmortalSelectionService : IImmortalSelectionService {
return true;
}
public bool SelectImmortalType(string immortalType) {
public bool SelectImmortalType(string immortalType)
{
if (_selectedImmortal == immortalType) return false;
_selectedImmortal = immortalType;
NotifyDataChanged();
@@ -44,8 +51,8 @@ public class ImmortalSelectionService : IImmortalSelectionService {
private event Action OnChange = null!;
private void NotifyDataChanged() {
private void NotifyDataChanged()
{
OnChange?.Invoke();
}
}
+34 -19
View File
@@ -2,31 +2,35 @@
namespace Services.Immortal;
public class KeyService : IKeyService {
public class KeyService : IKeyService
{
private static readonly List<string> PressedKeys = new();
private string? _hotkey;
private string _hotkeyGroup = "C";
private bool _isHoldingSpace;
private event Action? OnChange;
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 bool AddPressedKey(string key) {
public bool AddPressedKey(string key)
{
_hotkey = null;
if (PressedKeys.Count > 0) return false;
var pressedKey = key.ToUpper();
if (pressedKey.Equals(" ") || pressedKey.Equals("SPACE")) {
if (!_isHoldingSpace) {
if (pressedKey.Equals(" ") || pressedKey.Equals("SPACE"))
{
if (!_isHoldingSpace)
{
_isHoldingSpace = true;
NotifyDataChanged();
}
@@ -34,7 +38,8 @@ public class KeyService : IKeyService {
return false;
}
if (!PressedKeys.Contains(pressedKey)) {
if (!PressedKeys.Contains(pressedKey))
{
if (HotkeyModel.KeyGroups.Contains(pressedKey)) _hotkeyGroup = pressedKey;
if (HotkeyModel.HotKeys.Contains(pressedKey)) _hotkey = pressedKey;
@@ -47,16 +52,20 @@ public class KeyService : IKeyService {
return false;
}
public List<string> GetAllPressedKeys() {
public List<string> GetAllPressedKeys()
{
return PressedKeys;
}
public bool RemovePressedKey(string key) {
public bool RemovePressedKey(string key)
{
_hotkey = null;
var pressedKey = key.ToUpper();
if (pressedKey.Equals(" ") || pressedKey.Equals("SPACE")) {
if (_isHoldingSpace || true) {
if (pressedKey.Equals(" ") || pressedKey.Equals("SPACE"))
{
if (_isHoldingSpace || true)
{
_isHoldingSpace = false;
NotifyDataChanged();
}
@@ -64,7 +73,8 @@ public class KeyService : IKeyService {
return false;
}
if (PressedKeys.Contains(pressedKey)) {
if (PressedKeys.Contains(pressedKey))
{
PressedKeys.Remove(pressedKey);
NotifyDataChanged();
return true;
@@ -73,20 +83,25 @@ public class KeyService : IKeyService {
return false;
}
public bool IsHoldingSpace() {
public bool IsHoldingSpace()
{
return _isHoldingSpace;
}
public string? GetHotkey() {
public string? GetHotkey()
{
return _hotkey;
}
public string GetHotkeyGroup() {
public string GetHotkeyGroup()
{
return _hotkeyGroup;
}
private void NotifyDataChanged() {
private event Action? OnChange;
private void NotifyDataChanged()
{
OnChange?.Invoke();
}
}
+33 -19
View File
@@ -5,31 +5,33 @@ using static Services.IMemoryTesterService;
namespace Services.Immortal;
public enum MemoryTesterEvent {
public enum MemoryTesterEvent
{
OnVerify,
OnRefresh
}
public class MemoryTesterService : IMemoryTesterService {
public class MemoryTesterService : IMemoryTesterService
{
private readonly List<MemoryEntityModel> memoryEntities = MemoryEntityModel.TestData;
private readonly List<MemoryQuestionModel> memoryQuestions = MemoryQuestionModel.TestData;
private readonly Random random = new();
private event MemoryAction OnChange = null!;
public void Subscribe(MemoryAction action) {
public void Subscribe(MemoryAction action)
{
OnChange += action;
}
public void Unsubscribe(MemoryAction action) {
public void Unsubscribe(MemoryAction action)
{
OnChange -= action;
}
public void GenerateQuiz() {
public void GenerateQuiz()
{
memoryEntities.Clear();
memoryQuestions.Clear();
@@ -42,17 +44,21 @@ public class MemoryTesterService : IMemoryTesterService {
var entityIndex = 0;
var questionIndex = 0;
foreach (var unit in units) {
memoryEntities.Add(new MemoryEntityModel {
foreach (var unit in units)
{
memoryEntities.Add(new MemoryEntityModel
{
Id = ++entityIndex,
Name = unit.Info().Name
});
var weaponIndex = 0;
foreach (var weapon in unit.Weapons()) {
foreach (var weapon in unit.Weapons())
{
weaponIndex++;
memoryQuestions.Add(new MemoryQuestionModel {
memoryQuestions.Add(new MemoryQuestionModel
{
Id = ++questionIndex,
MemoryEntityModelId = entityIndex,
Name = $"Range (Weapon {weaponIndex})",
@@ -61,7 +67,8 @@ public class MemoryTesterService : IMemoryTesterService {
});
}
memoryQuestions.Add(new MemoryQuestionModel {
memoryQuestions.Add(new MemoryQuestionModel
{
Id = ++questionIndex,
MemoryEntityModelId = entityIndex,
Name = "Speed",
@@ -73,27 +80,34 @@ public class MemoryTesterService : IMemoryTesterService {
NotifyDataChanged(MemoryTesterEvent.OnRefresh);
}
public List<MemoryEntityModel> GetEntities() {
public List<MemoryEntityModel> GetEntities()
{
return memoryEntities;
}
public List<MemoryQuestionModel> GetQuestions() {
public List<MemoryQuestionModel> GetQuestions()
{
return memoryQuestions;
}
public void Update(MemoryQuestionModel memoryQuestion) {
public void Update(MemoryQuestionModel memoryQuestion)
{
memoryQuestions[memoryQuestion.Id - 1].Guess = memoryQuestion.Guess;
}
public void Verify() {
public void Verify()
{
NotifyDataChanged(MemoryTesterEvent.OnVerify);
}
private event MemoryAction OnChange = null!;
//public delegate void MemoryAction(MemoryTesterActions memoryAction);
private void NotifyDataChanged(MemoryTesterEvent memoryAction) {
private void NotifyDataChanged(MemoryTesterEvent memoryAction)
{
OnChange?.Invoke(memoryAction);
}
}
+16 -10
View File
@@ -1,31 +1,37 @@
namespace Services.Immortal;
public class TimingService : ITimingService {
public class TimingService : ITimingService
{
private int _timing = 1500;
private event Action? OnChange;
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 int GetTiming() {
public int GetTiming()
{
return _timing;
}
public void SetTiming(int timing) {
if (_timing != timing) {
public void SetTiming(int timing)
{
if (_timing != timing)
{
_timing = timing;
NotifyDataChanged();
}
}
private void NotifyDataChanged() {
private event Action? OnChange;
private void NotifyDataChanged()
{
OnChange?.Invoke();
}
}
+5 -5
View File
@@ -7,20 +7,20 @@
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)' == 'Debug' ">
<DefineConstants>TRACE;NO_SQL</DefineConstants>
<DefineConstants>TRACE;NO_SQL</DefineConstants>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)' == 'Release' ">
<DefineConstants>TRACE;NO_SQL;</DefineConstants>
<DefineConstants>TRACE;NO_SQL;</DefineConstants>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="YamlDotNet" Version="11.2.1" />
<PackageReference Include="YamlDotNet" Version="11.2.1"/>
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\Contexts\Contexts.csproj" />
<ProjectReference Include="..\Model\Model.csproj" />
<ProjectReference Include="..\Contexts\Contexts.csproj"/>
<ProjectReference Include="..\Model\Model.csproj"/>
</ItemGroup>
</Project>
+19 -21
View File
@@ -1,29 +1,22 @@
using System.ComponentModel.DataAnnotations;
using DataType = Model.Entity.Data.DataType;
namespace Services.Website;
namespace Services.Website;
//TODO Move to a database folder, with EntityService, EntityFilterService
public class EntityDialogService : IEntityDialogService
{
private string? entityId = null;
private string? entityId;
private List<string> history = new List<string>();
private event Action OnChange = null!;
private readonly List<string> history = new();
private void NotifyDataChanged() {
OnChange?.Invoke();
}
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 AddDialog(string id)
{
entityId = id;
@@ -36,7 +29,7 @@ public class EntityDialogService : IEntityDialogService
{
entityId = null;
history.Clear();
NotifyDataChanged();
}
@@ -45,20 +38,20 @@ public class EntityDialogService : IEntityDialogService
if (history.Count > 1)
{
history.RemoveAt(history.Count - 1);
if (history.Count == 0)
{
entityId = null;
NotifyDataChanged();
return;
}
entityId = history.Last();
NotifyDataChanged();
}
}
public bool HasDialog()
{
@@ -74,6 +67,11 @@ public class EntityDialogService : IEntityDialogService
{
return entityId;
}
}
private event Action OnChange = null!;
private void NotifyDataChanged()
{
OnChange?.Invoke();
}
}
+37 -23
View File
@@ -2,27 +2,26 @@
namespace Services.Website;
public class NavigationService : INavigationService {
private string navigationStateType = NavigationStateType.Default;
public class NavigationService : INavigationService
{
private int navigationStateId = -1;
private string navigationStateType = NavigationStateType.Default;
private NavSelectionType navSelectionType = NavSelectionType.None;
private Type renderType = null!;
private int webPageType;
private int webSectionType;
private event Action OnChange = null!;
public void Subscribe(Action action) {
public void Subscribe(Action action)
{
OnChange += action;
}
public void Unsubscribe(Action action) {
public void Unsubscribe(Action action)
{
OnChange += action;
}
@@ -37,7 +36,8 @@ public class NavigationService : INavigationService {
return navigationStateId;
}
public void ChangeNavigationState(string newState) {
public void ChangeNavigationState(string newState)
{
if (newState.Equals(navigationStateType))
return;
@@ -46,12 +46,15 @@ public class NavigationService : INavigationService {
NotifyDataChanged();
}
public string GetNavigationState() {
public string GetNavigationState()
{
return navigationStateType;
}
public void SelectPage(int pageType, Type page) {
if (renderType != page) {
public void SelectPage(int pageType, Type page)
{
if (renderType != page)
{
renderType = page;
webPageType = pageType;
navSelectionType = NavSelectionType.Page;
@@ -60,7 +63,8 @@ public class NavigationService : INavigationService {
}
public void SelectSection(int section) {
public void SelectSection(int section)
{
if (section == webSectionType) return;
webSectionType = section;
navSelectionType = NavSelectionType.Section;
@@ -68,15 +72,18 @@ public class NavigationService : INavigationService {
NotifyDataChanged();
}
public void Back() {
if (navSelectionType == NavSelectionType.Page) {
public void Back()
{
if (navSelectionType == NavSelectionType.Page)
{
navSelectionType = NavSelectionType.Section;
webPageType = 0;
NotifyDataChanged();
return;
}
if (navSelectionType == NavSelectionType.Section) {
if (navSelectionType == NavSelectionType.Section)
{
navSelectionType = NavSelectionType.None;
webSectionType = 0;
webPageType = 0;
@@ -84,23 +91,30 @@ public class NavigationService : INavigationService {
}
}
public NavSelectionType GetNavSelectionType() {
public NavSelectionType GetNavSelectionType()
{
return navSelectionType;
}
public int GetWebPageId() {
public int GetWebPageId()
{
return webPageType;
}
public int GetWebSectionId() {
public int GetWebSectionId()
{
return webSectionType;
}
public Type GetRenderType() {
public Type GetRenderType()
{
return renderType;
}
private void NotifyDataChanged() {
private event Action OnChange = null!;
private void NotifyDataChanged()
{
OnChange?.Invoke();
}
}
+12 -26
View File
@@ -5,36 +5,21 @@ namespace Services.Website;
public class ToastService : IToastService
{
private readonly List<ToastModel> toasts = new();
private event Action OnChange = null!;
#if DEBUG
public ToastService()
public void Subscribe(Action action)
{
toasts.Add(new ToastModel(){Message = "Example message", SeverityType = SeverityType.Error, Title = "Example Error"});
toasts.Add(new ToastModel(){Message = "Example message", SeverityType = SeverityType.Information, Title = "Example Information"});
toasts.Add(new ToastModel(){Message = "Example message", SeverityType = SeverityType.Success, Title = "Example Success"});
toasts.Add(new ToastModel(){Message = "Example message", SeverityType = SeverityType.Warning, Title = "Example Warning"});
}
#endif
private void NotifyDataChanged() {
OnChange();
}
public void Subscribe(Action action) {
OnChange += action;
}
public void Unsubscribe(Action action) {
public void Unsubscribe(Action action)
{
OnChange += action;
}
public void AddToast(ToastModel toast)
{
toasts.Insert(0, toast);
NotifyDataChanged();
}
@@ -55,11 +40,8 @@ public class ToastService : IToastService
public void AgeToasts()
{
foreach (var toast in toasts)
{
toast.Age++;
}
foreach (var toast in toasts) toast.Age++;
NotifyDataChanged();
}
@@ -69,6 +51,10 @@ public class ToastService : IToastService
NotifyDataChanged();
}
}
private event Action OnChange = null!;
private void NotifyDataChanged()
{
OnChange();
}
}
+36 -33
View File
@@ -1,45 +1,47 @@
using System.Net.Http.Json;
using Model.Website;
namespace Services.Development;
public class WebsiteService : IWebsiteService {
public class WebsiteService : IWebsiteService
{
private readonly HttpClient httpClient;
private bool isLoaded;
private event Action OnChange = default!;
public WebsiteService(HttpClient httpClient) {
public WebsiteService(HttpClient httpClient)
{
this.httpClient = httpClient;
}
public List<WebSectionModel> WebSectionModels { get; set; } = default!;
public List<WebPageModel> WebPageModels { get; set; } = default!;
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 bool IsLoaded() {
public bool IsLoaded()
{
return isLoaded;
}
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();
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;
@@ -48,27 +50,28 @@ public class WebsiteService : IWebsiteService {
NotifyDataChanged();
}
void SortSql()
public void Update()
{
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();
}
private void NotifyDataChanged() {
private event Action OnChange = default!;
private void SortSql()
{
foreach (var page in WebPageModels)
if (page.WebSectionModelId != null)
{
var webSection =
WebSectionModels.Find(webSection => webSection.Id == page.WebSectionModelId);
webSection.WebPageModels.Add(page);
}
}
private void NotifyDataChanged()
{
OnChange?.Invoke();
}
}