using System;
using System.Collections.Generic;
using UnityEngine;
namespace DanroJump.Settings
{
///
/// ScriptableObject-база всех операторских настроек проекта.
///
[CreateAssetMenu(
fileName = "ServiceSettingsDatabase",
menuName = "Danro Jump/Settings/Service Settings Database")]
public sealed class ServiceSettingsDatabase : ScriptableObject
{
[SerializeField] private List entries = new();
///
/// Все описания сервисных настроек в порядке отображения.
///
public IReadOnlyList Entries => entries;
///
/// Находит описание настройки по ключу.
///
public ServiceSettingDefinition Find(string key)
{
return entries.Find(entry =>
entry != null &&
string.Equals(entry.Key, key, StringComparison.Ordinal));
}
///
/// Безопасно пытается найти настройку по ключу.
///
public bool TryFind(string key, out ServiceSettingDefinition definition)
{
definition = Find(key);
return definition != null;
}
///
/// Проверяет пустые и дублирующиеся ключи в редакторе.
///
private void OnValidate()
{
var keys = new HashSet();
foreach (var entry in entries)
{
if (entry == null)
{
continue;
}
if (string.IsNullOrWhiteSpace(entry.Key))
{
Debug.LogWarning($"[{nameof(ServiceSettingsDatabase)}] Empty key in {name}.", this);
continue;
}
if (!keys.Add(entry.Key))
{
Debug.LogWarning($"[{nameof(ServiceSettingsDatabase)}] Duplicate key '{entry.Key}' in {name}.", this);
}
}
}
}
}