Make main database properties immutable

This commit is contained in:
Archangel
2025-08-17 17:57:26 +02:00
parent aa4224081b
commit e4a80f1f42
10 changed files with 86 additions and 190 deletions
@@ -12,19 +12,19 @@ public record Globals
public Dictionary<string, object> ExtensionData { get; init; } = [];
[JsonPropertyName("config")]
public Config Configuration { get; set; }
public required Config Configuration { get; init; }
[JsonPropertyName("LocationInfection")]
public LocationInfection LocationInfection { get; set; }
public required LocationInfection LocationInfection { get; init; }
[JsonPropertyName("bot_presets")]
public IEnumerable<BotPreset> BotPresets { get; set; }
public required IEnumerable<BotPreset> BotPresets { get; init; }
[JsonPropertyName("BotWeaponScatterings")]
public IEnumerable<BotWeaponScattering> BotWeaponScatterings { get; set; }
public required IEnumerable<BotWeaponScattering> BotWeaponScatterings { get; init; }
[JsonPropertyName("ItemPresets")]
public Dictionary<MongoId, Preset> ItemPresets { get; set; }
public required Dictionary<MongoId, Preset> ItemPresets { get; init; }
}
public record PlayerSettings
@@ -12,16 +12,16 @@ public record Trader
public Dictionary<string, object> ExtensionData { get; init; } = [];
[JsonPropertyName("assort")]
public TraderAssort Assort { get; set; }
public required TraderAssort Assort { get; set; }
[JsonPropertyName("base")]
public TraderBase Base { get; set; }
public required TraderBase Base { get; init; }
[JsonPropertyName("dialogue")]
public Dictionary<string, List<string>?> Dialogue { get; set; }
public required Dictionary<string, List<string>?> Dialogue { get; init; }
[JsonPropertyName("questassort")]
public Dictionary<string, Dictionary<MongoId, MongoId>>? QuestAssort { get; set; }
public required Dictionary<string, Dictionary<MongoId, MongoId>> QuestAssort { get; init; }
[JsonPropertyName("suits")]
public List<Suit>? Suits { get; set; }
@@ -9,11 +9,11 @@ public record Bots
public Dictionary<string, object> ExtensionData { get; init; } = [];
[JsonPropertyName("types")]
public Dictionary<string, BotType?> Types { get; set; }
public required Dictionary<string, BotType?> Types { get; init; }
[JsonPropertyName("base")]
public BotBase Base { get; set; }
public required BotBase Base { get; init; }
[JsonPropertyName("core")]
public Dictionary<string, object> Core { get; set; }
public required Dictionary<string, object> Core { get; init; }
}
@@ -9,20 +9,20 @@ public record Hideout
public Dictionary<string, object> ExtensionData { get; init; } = [];
[JsonPropertyName("areas")]
public List<HideoutArea> Areas { get; set; }
public required List<HideoutArea> Areas { get; init; }
[JsonPropertyName("customAreas")]
public List<HideoutArea>? CustomAreas { get; set; }
public required List<HideoutArea>? CustomAreas { get; init; }
[JsonPropertyName("customisation")]
public HideoutCustomisation Customisation { get; set; }
public required HideoutCustomisation Customisation { get; init; }
[JsonPropertyName("production")]
public HideoutProductionData Production { get; set; }
public required HideoutProductionData Production { get; init; }
[JsonPropertyName("settings")]
public HideoutSettingsBase Settings { get; set; }
public required HideoutSettingsBase Settings { get; init; }
[JsonPropertyName("qte")]
public List<QteData> Qte { get; set; }
public required List<QteData> Qte { get; init; }
}
@@ -10,23 +10,23 @@ public record DatabaseTables
[JsonExtensionData]
public Dictionary<string, object> ExtensionData { get; init; } = [];
public required Bots.Bots Bots { get; set; }
public required Bots.Bots Bots { get; init; }
public required Hideout.Hideout Hideout { get; set; }
public required Hideout.Hideout Hideout { get; init; }
public required LocaleBase Locales { get; set; }
public required LocaleBase Locales { get; init; }
public required Locations Locations { get; set; }
public required Locations Locations { get; init; }
public required Match Match { get; set; }
public required Match Match { get; init; }
public required Templates.Templates Templates { get; set; }
public required Templates.Templates Templates { get; init; }
public required Dictionary<MongoId, Trader> Traders { get; set; }
public required Dictionary<MongoId, Trader> Traders { get; init; }
public required Globals Globals { get; set; }
public required Globals Globals { get; init; }
public required ServerBase Server { get; set; }
public required ServerBase Server { get; init; }
public required SettingsBase Settings { get; set; }
public required SettingsBase Settings { get; init; }
}
@@ -13,11 +13,11 @@ public record LocaleBase
/// THIS IS LAZY LOADED AND YOUR CHANGES WILL NOT BE SAVED
/// </summary>
[JsonPropertyName("global")]
public required Dictionary<string, LazyLoad<Dictionary<string, string>>> Global { get; set; }
public required Dictionary<string, LazyLoad<Dictionary<string, string>>> Global { get; init; }
[JsonPropertyName("menu")]
public required Dictionary<string, Dictionary<string, object>> Menu { get; set; }
public required Dictionary<string, Dictionary<string, object>> Menu { get; init; }
[JsonPropertyName("languages")]
public required Dictionary<string, string> Languages { get; set; }
public required Dictionary<string, string> Languages { get; init; }
}
@@ -58,67 +58,67 @@ public record Locations
private Dictionary<string, Eft.Common.Location>? _locationDictionaryCache;
[JsonPropertyName("bigmap")]
public Eft.Common.Location Bigmap { get; set; }
public required Eft.Common.Location Bigmap { get; init; }
[JsonPropertyName("develop")]
public Eft.Common.Location? Develop { get; set; }
public required Eft.Common.Location? Develop { get; init; }
[JsonPropertyName("factory4_day")]
public Eft.Common.Location Factory4Day { get; set; }
public required Eft.Common.Location Factory4Day { get; init; }
[JsonPropertyName("factory4_night")]
public Eft.Common.Location Factory4Night { get; set; }
public required Eft.Common.Location Factory4Night { get; init; }
[JsonPropertyName("hideout")]
public Eft.Common.Location? Hideout { get; set; }
public required Eft.Common.Location? Hideout { get; init; }
[JsonPropertyName("interchange")]
public Eft.Common.Location Interchange { get; set; }
public required Eft.Common.Location Interchange { get; init; }
[JsonPropertyName("laboratory")]
public Eft.Common.Location Laboratory { get; set; }
public required Eft.Common.Location Laboratory { get; init; }
[JsonPropertyName("lighthouse")]
public Eft.Common.Location Lighthouse { get; set; }
public required Eft.Common.Location Lighthouse { get; init; }
[JsonPropertyName("privatearea")]
public Eft.Common.Location? PrivateArea { get; set; }
public required Eft.Common.Location? PrivateArea { get; init; }
[JsonPropertyName("rezervbase")]
public Eft.Common.Location RezervBase { get; set; }
public required Eft.Common.Location RezervBase { get; init; }
[JsonPropertyName("shoreline")]
public Eft.Common.Location Shoreline { get; set; }
public required Eft.Common.Location Shoreline { get; init; }
[JsonPropertyName("suburbs")]
public Eft.Common.Location? Suburbs { get; set; }
public required Eft.Common.Location? Suburbs { get; init; }
[JsonPropertyName("tarkovstreets")]
public Eft.Common.Location TarkovStreets { get; set; }
public required Eft.Common.Location TarkovStreets { get; init; }
[JsonPropertyName("labyrinth")]
public Eft.Common.Location Labyrinth { get; set; }
public required Eft.Common.Location Labyrinth { get; init; }
[JsonPropertyName("terminal")]
public Eft.Common.Location? Terminal { get; set; }
public required Eft.Common.Location? Terminal { get; init; }
[JsonPropertyName("town")]
public Eft.Common.Location? Town { get; set; }
public required Eft.Common.Location? Town { get; init; }
[JsonPropertyName("woods")]
public Eft.Common.Location Woods { get; set; }
public required Eft.Common.Location Woods { get; init; }
[JsonPropertyName("sandbox")]
public Eft.Common.Location Sandbox { get; set; }
public required Eft.Common.Location Sandbox { get; init; }
[JsonPropertyName("sandbox_high")]
public Eft.Common.Location SandboxHigh { get; set; }
public required Eft.Common.Location SandboxHigh { get; init; }
/// <summary>
/// Holds a mapping of the linkages between locations on the UI
/// </summary>
[JsonPropertyName("base")]
public LocationsBase? Base { get; set; }
public required LocationsBase Base { get; init; }
/// <summary>
/// Get map locations as a dictionary, keyed by its name e.g. Factory4Day
@@ -9,7 +9,7 @@ public record SettingsBase
public Dictionary<string, object> ExtensionData { get; init; } = [];
[JsonPropertyName("config")]
public Config Configuration { get; set; }
public required Config Configuration { get; init; }
}
public record Config
@@ -11,62 +11,62 @@ public record Templates
public Dictionary<string, object> ExtensionData { get; init; } = [];
[JsonPropertyName("character")]
public List<string> Character { get; set; }
public required List<string> Character { get; init; }
[JsonPropertyName("customisationStorage")]
public List<CustomisationStorage> CustomisationStorage { get; set; }
public required List<CustomisationStorage> CustomisationStorage { get; init; }
[JsonPropertyName("items")]
public Dictionary<MongoId, TemplateItem> Items { get; set; }
public required Dictionary<MongoId, TemplateItem> Items { get; init; }
[JsonPropertyName("prestige")]
public Prestige? Prestige { get; set; }
public required Prestige Prestige { get; init; }
[JsonPropertyName("quests")]
public Dictionary<MongoId, Quest> Quests { get; set; }
public required Dictionary<MongoId, Quest> Quests { get; init; }
[JsonPropertyName("repeatableQuests")]
public RepeatableQuestDatabase RepeatableQuests { get; set; }
public required RepeatableQuestDatabase RepeatableQuests { get; init; }
[JsonPropertyName("handbook")]
public HandbookBase Handbook { get; set; }
public required HandbookBase Handbook { get; init; }
[JsonPropertyName("customization")]
public Dictionary<MongoId, CustomizationItem> Customization { get; set; }
public required Dictionary<MongoId, CustomizationItem> Customization { get; init; }
/// <summary>
/// The profile templates listed in the launcher on profile creation, split by account type (e.g. Standard) then side (e.g. bear/usec)
/// </summary>
[JsonPropertyName("profiles")]
public Dictionary<string, ProfileSides> Profiles { get; set; }
public required Dictionary<string, ProfileSides> Profiles { get; init; }
/// <summary>
/// Flea prices of items - gathered from online flea market dump
/// </summary>
[JsonPropertyName("prices")]
public Dictionary<MongoId, double> Prices { get; set; }
public required Dictionary<MongoId, double> Prices { get; init; }
/// <summary>
/// Default equipment loadouts that show on main inventory screen
/// </summary>
[JsonPropertyName("defaultEquipmentPresets")]
public List<DefaultEquipmentPreset> DefaultEquipmentPresets { get; set; }
public required List<DefaultEquipmentPreset> DefaultEquipmentPresets { get; init; }
/// <summary>
/// Achievements
/// </summary>
[JsonPropertyName("achievements")]
public List<Achievement> Achievements { get; set; }
public required List<Achievement> Achievements { get; init; }
/// <summary>
/// Achievements
/// </summary>
[JsonPropertyName("customAchievements")]
public List<Achievement> CustomAchievements { get; set; }
public required List<Achievement> CustomAchievements { get; init; }
/// <summary>
/// Location services data
/// </summary>
[JsonPropertyName("locationServices")]
public LocationServices LocationServices { get; set; }
public required LocationServices LocationServices { get; init; }
}
@@ -37,56 +37,31 @@ public class DatabaseService(
/// <returns> assets/database/bots/ </returns>
public Bots GetBots()
{
if (databaseServer.GetTables().Bots == null)
{
throw new Exception(serverLocalisationService.GetText("database-data_at_path_missing", "assets/database/bots"));
}
return databaseServer.GetTables().Bots!;
return databaseServer.GetTables().Bots;
}
/// <returns> assets/database/globals.json </returns>
public Globals GetGlobals()
{
if (databaseServer.GetTables().Globals == null)
{
throw new Exception(serverLocalisationService.GetText("database-data_at_path_missing", "assets/database/globals.json"));
}
return databaseServer.GetTables().Globals!;
return databaseServer.GetTables().Globals;
}
/// <returns> assets/database/hideout/ </returns>
public Hideout GetHideout()
{
if (databaseServer.GetTables().Hideout == null)
{
throw new Exception(serverLocalisationService.GetText("database-data_at_path_missing", "assets/database/hideout"));
}
return databaseServer.GetTables().Hideout!;
return databaseServer.GetTables().Hideout;
}
/// <returns> assets/database/locales/ </returns>
public LocaleBase GetLocales()
{
if (databaseServer.GetTables().Locales == null)
{
throw new Exception(serverLocalisationService.GetText("database-data_at_path_missing", "assets/database/locales"));
}
return databaseServer.GetTables().Locales!;
return databaseServer.GetTables().Locales;
}
/// <returns> assets/database/locations </returns>
public Locations GetLocations()
{
if (databaseServer.GetTables().Locations == null)
{
throw new Exception(serverLocalisationService.GetText("database-data_at_path_missing", "assets/database/locations"));
}
return databaseServer.GetTables().Locations!;
return databaseServer.GetTables().Locations;
}
/// <summary>
@@ -96,7 +71,7 @@ public class DatabaseService(
/// <returns> assets/database/locations/ </returns>
public Location? GetLocation(string locationId)
{
var desiredLocation = GetLocations()?.GetByJsonProp<Location>(locationId.ToLowerInvariant());
var desiredLocation = GetLocations().GetByJsonProp<Location>(locationId.ToLowerInvariant());
if (desiredLocation == null)
{
logger.Error(serverLocalisationService.GetText("database-no_location_found_with_id", locationId));
@@ -110,158 +85,79 @@ public class DatabaseService(
/// <returns> assets/database/match/ </returns>
public Match GetMatch()
{
if (databaseServer.GetTables().Match == null)
{
throw new Exception(serverLocalisationService.GetText("database-data_at_path_missing", "assets/database/locales"));
}
return databaseServer.GetTables().Match!;
return databaseServer.GetTables().Match;
}
/// <returns> assets/database/server.json </returns>
public ServerBase GetServer()
{
if (databaseServer.GetTables().Server == null)
{
throw new Exception(serverLocalisationService.GetText("database-data_at_path_missing", "assets/database/server.json"));
}
return databaseServer.GetTables().Server!;
return databaseServer.GetTables().Server;
}
/// <returns> assets/database/settings.json </returns>
public SettingsBase GetSettings()
{
if (databaseServer.GetTables().Settings == null)
{
throw new Exception(serverLocalisationService.GetText("database-data_at_path_missing", "assets/database/settings.json"));
}
return databaseServer.GetTables().Settings!;
return databaseServer.GetTables().Settings;
}
/// <returns> assets/database/templates/ </returns>
public Templates GetTemplates()
{
if (databaseServer.GetTables().Templates == null)
{
throw new Exception(serverLocalisationService.GetText("database-data_at_path_missing", "assets/database/templates"));
}
return databaseServer.GetTables().Templates!;
return databaseServer.GetTables().Templates;
}
/// <returns> assets/database/templates/achievements.json </returns>
public List<Achievement> GetAchievements()
{
if (databaseServer.GetTables().Templates?.Achievements == null)
{
throw new Exception(
serverLocalisationService.GetText("database-data_at_path_missing", "assets/database/templates/achievements.json")
);
}
return databaseServer.GetTables().Templates?.Achievements!;
return databaseServer.GetTables().Templates.Achievements;
}
/// <returns> assets/database/templates/customAchievements.json </returns>
public List<Achievement> GetCustomAchievements()
{
if (databaseServer.GetTables().Templates?.Achievements == null)
{
throw new Exception(
serverLocalisationService.GetText("database-data_at_path_missing", "assets/database/templates/customAchievements.json")
);
}
return databaseServer.GetTables().Templates?.CustomAchievements!;
return databaseServer.GetTables().Templates.CustomAchievements;
}
/// <returns> assets/database/templates/customisation.json </returns>
public Dictionary<MongoId, CustomizationItem?> GetCustomization()
public Dictionary<MongoId, CustomizationItem> GetCustomization()
{
if (databaseServer.GetTables().Templates?.Customization == null)
{
throw new Exception(
serverLocalisationService.GetText("database-data_at_path_missing", "assets/database/templates/customization.json")
);
}
return databaseServer.GetTables().Templates?.Customization!;
return databaseServer.GetTables().Templates.Customization;
}
/// <returns> assets/database/templates/handbook.json </returns>
public HandbookBase GetHandbook()
{
if (databaseServer.GetTables().Templates?.Handbook == null)
{
throw new Exception(
serverLocalisationService.GetText("database-data_at_path_missing", "assets/database/templates/handbook.json")
);
}
return databaseServer.GetTables().Templates?.Handbook!;
return databaseServer.GetTables().Templates.Handbook;
}
/// <returns> assets/database/templates/items.json </returns>
public Dictionary<MongoId, TemplateItem> GetItems()
{
if (databaseServer.GetTables().Templates?.Items == null)
{
throw new Exception(serverLocalisationService.GetText("database-data_at_path_missing", "assets/database/templates/items.json"));
}
return databaseServer.GetTables().Templates?.Items!;
return databaseServer.GetTables().Templates.Items;
}
/// <returns> assets/database/templates/prices.json </returns>
public Dictionary<MongoId, double> GetPrices()
{
if (databaseServer.GetTables().Templates?.Prices == null)
{
throw new Exception(
serverLocalisationService.GetText("database-data_at_path_missing", "assets/database/templates/prices.json")
);
}
return databaseServer.GetTables().Templates?.Prices!;
return databaseServer.GetTables().Templates.Prices;
}
/// <returns> assets/database/templates/profiles.json </returns>
public Dictionary<string, ProfileSides> GetProfileTemplates()
{
if (databaseServer.GetTables().Templates?.Profiles == null)
{
throw new Exception(
serverLocalisationService.GetText("database-data_at_path_missing", "assets/database/templates/profiles.json")
);
}
return databaseServer.GetTables().Templates?.Profiles!;
return databaseServer.GetTables().Templates.Profiles;
}
/// <returns> assets/database/templates/quests.json </returns>
public Dictionary<MongoId, Quest> GetQuests()
{
if (databaseServer.GetTables().Templates?.Quests == null)
{
throw new Exception(
serverLocalisationService.GetText("database-data_at_path_missing", "assets/database/templates/quests.json")
);
}
return databaseServer.GetTables().Templates?.Quests!;
return databaseServer.GetTables().Templates.Quests;
}
/// <returns> assets/database/traders/ </returns>
public Dictionary<MongoId, Trader> GetTraders()
{
if (databaseServer.GetTables().Traders == null)
{
throw new Exception(serverLocalisationService.GetText("database-data_at_path_missing", "assets/database/traders"));
}
return databaseServer.GetTables().Traders!;
return databaseServer.GetTables().Traders;
}
/// <summary>