using System; using System.Collections.Generic; using UnityEngine; namespace BriarQueen.Framework.Registries { internal static class RegistryLookupBuilder { public static void AddEntries( Dictionary lookup, IEnumerable entries, UnityEngine.Object context, string registryName, string category, string keyLabel, Func keySelector, Func valueSelector, Func isKeyValid = null, Func isEntryValid = null, string invalidEntryReason = null) where TEntry : UnityEngine.Object { if (lookup == null) throw new ArgumentNullException(nameof(lookup)); if (entries == null) return; foreach (var entry in entries) { if (!entry) continue; if (isKeyValid != null && !isKeyValid(entry)) { Debug.LogWarning( $"[{registryName}] Skipping {category} entry '{entry.name}' because {keyLabel} is invalid.", context); continue; } if (isEntryValid != null && !isEntryValid(entry)) { Debug.LogWarning( $"[{registryName}] Skipping {category} entry '{entry.name}' because {invalidEntryReason}.", context); continue; } var key = keySelector(entry); if (lookup.ContainsKey(key)) { Debug.LogError( $"[{registryName}] Duplicate {keyLabel} detected: '{key}' from entry '{entry.name}'.", context); continue; } lookup.Add(key, valueSelector(entry)); } } public static bool HasNonEmptyKey(string key) { return !string.IsNullOrWhiteSpace(key); } } }