Expanded LocationControler implementation

This commit is contained in:
Chomp
2025-01-12 17:24:26 +00:00
parent 780591e923
commit c1b509e3a8
4 changed files with 80 additions and 9 deletions
@@ -1,4 +1,4 @@
using System.Text.Json.Serialization;
using System.Text.Json.Serialization;
namespace Core.Models.Eft.Common.Tables;
@@ -25,4 +25,4 @@ public class Path
public string? Destination { get; set; }
public bool? Event { get; set; }
}
}
@@ -1,12 +1,12 @@
using System.Text.Json.Serialization;
using System.Text.Json.Serialization;
namespace Core.Models.Eft.Common.Tables;
public class LocationsGenerateAllResponse
{
[JsonPropertyName("locations")]
public Locations? Locations { get; set; }
public Dictionary<string, LocationBase> Locations { get; set; }
[JsonPropertyName("paths")]
public List<Path>? Paths { get; set; }
}
}
+22 -2
View File
@@ -1,4 +1,5 @@
using System.Text.Json.Serialization;
using System.Reflection;
using System.Text.Json.Serialization;
using Core.Models.Eft.Common.Tables;
using Core.Models.Eft.Common;
@@ -81,4 +82,23 @@ public class Locations
.Invoke(this, [value]);
}
}
}
private Dictionary<string, Eft.Common.Location>? _locationDictionaryCache;
/// <summary>
/// Get map locations as a dictionary, keyed by its name e.g. factory4_day
/// </summary>
/// <returns></returns>
public Dictionary<string, Eft.Common.Location> GetDictionary()
{
if (_locationDictionaryCache is null)
{
var classProps = GetType()
.GetProperties();
_locationDictionaryCache = classProps
.ToDictionary(propertyInfo => propertyInfo.Name, propertyInfo => propertyInfo.GetValue(this, null) as Eft.Common.Location);
}
return _locationDictionaryCache;
}
}