Restructured for new direction.

This commit is contained in:
2026-05-12 12:01:09 +01:00
parent 0439b6c1d2
commit c203f836b1
1134 changed files with 125569 additions and 213519 deletions

View File

@@ -1,5 +1,4 @@
using System.Collections.Generic;
using System.Linq;
using BriarQueen.Data.Identifiers;
using BriarQueen.Framework.Managers.Achievements.Data;
using UnityEngine;
@@ -19,8 +18,22 @@ namespace BriarQueen.Framework.Registries
if (_achievementDictionary != null)
return;
_achievementDictionary = _achievementSos.ToDictionary(achievement => achievement.Achievement,
achievement => achievement);
RebuildLookup();
}
private void RebuildLookup()
{
_achievementDictionary = new Dictionary<AchievementID, AchievementSo>();
RegistryLookupBuilder.AddEntries(
_achievementDictionary,
_achievementSos,
this,
nameof(AchievementRegistry),
"Achievements",
nameof(AchievementSo.Achievement),
entry => entry.Achievement,
entry => entry);
}
public bool TryGetAchievement(AchievementID identifier, out AchievementSo achievement)
@@ -35,4 +48,4 @@ namespace BriarQueen.Framework.Registries
return _achievementDictionary.Values;
}
}
}
}

View File

@@ -45,47 +45,57 @@ namespace BriarQueen.Framework.Registries
{
_assetDictionary = new Dictionary<string, AssetReference>();
AddEntries(_sceneReferences, "Scenes");
AddEntries(_levelReferences, "Levels");
AddEntries(_itemReferences, "Items");
AddEntries(_uiReferences, "UI");
}
RegistryLookupBuilder.AddEntries(
_assetDictionary,
_sceneReferences,
this,
nameof(AssetRegistry),
"Scenes",
"AssetKey",
entry => entry.AssetKey,
entry => entry.Asset,
entry => RegistryLookupBuilder.HasNonEmptyKey(entry.AssetKey),
entry => entry.Asset != null,
"AssetReference is null");
private void AddEntries(List<AssetEntry> entries, string category)
{
if (entries == null)
return;
RegistryLookupBuilder.AddEntries(
_assetDictionary,
_levelReferences,
this,
nameof(AssetRegistry),
"Levels",
"AssetKey",
entry => entry.AssetKey,
entry => entry.Asset,
entry => RegistryLookupBuilder.HasNonEmptyKey(entry.AssetKey),
entry => entry.Asset != null,
"AssetReference is null");
foreach (var entry in entries)
{
if (entry == null)
continue;
RegistryLookupBuilder.AddEntries(
_assetDictionary,
_itemReferences,
this,
nameof(AssetRegistry),
"Items",
"AssetKey",
entry => entry.AssetKey,
entry => entry.Asset,
entry => RegistryLookupBuilder.HasNonEmptyKey(entry.AssetKey),
entry => entry.Asset != null,
"AssetReference is null");
if (string.IsNullOrWhiteSpace(entry.AssetKey))
{
Debug.LogWarning(
$"[AssetRegistry] Skipping {category} entry '{entry.name}' because AssetKey is empty.", this);
continue;
}
if (entry.Asset == null)
{
Debug.LogWarning(
$"[AssetRegistry] Skipping {category} entry '{entry.name}' because AssetReference is null.",
this);
continue;
}
if (_assetDictionary.ContainsKey(entry.AssetKey))
{
Debug.LogError(
$"[AssetRegistry] Duplicate AssetKey detected: '{entry.AssetKey}' from entry '{entry.name}'.",
this);
continue;
}
_assetDictionary.Add(entry.AssetKey, entry.Asset);
}
RegistryLookupBuilder.AddEntries(
_assetDictionary,
_uiReferences,
this,
nameof(AssetRegistry),
"UI",
"AssetKey",
entry => entry.AssetKey,
entry => entry.Asset,
entry => RegistryLookupBuilder.HasNonEmptyKey(entry.AssetKey),
entry => entry.Asset != null,
"AssetReference is null");
}
public bool TryGetReference(string key, out AssetReference reference)
@@ -116,4 +126,4 @@ namespace BriarQueen.Framework.Registries
}
#endif
}
}
}

View File

@@ -1,5 +1,4 @@
using System.Collections.Generic;
using System.Linq;
using BriarQueen.Framework.Managers.Audio.Data;
using NaughtyAttributes;
using UnityEngine;
@@ -17,15 +16,32 @@ namespace BriarQueen.Framework.Registries
private void EnsureInitialized()
{
if (_audioFileDict == null)
_audioFileDict = _audioFiles.ToDictionary(entry => entry.UniqueID, entry => entry);
if (_audioFileDict != null)
return;
RebuildLookup();
}
private void RebuildLookup()
{
_audioFileDict = new Dictionary<string, AudioFileSo>();
RegistryLookupBuilder.AddEntries(
_audioFileDict,
_audioFiles,
this,
nameof(AudioRegistry),
"Audio Files",
"UniqueID",
entry => entry.UniqueID,
entry => entry,
entry => RegistryLookupBuilder.HasNonEmptyKey(entry.UniqueID));
}
public bool TryGetAudio(string audioName, out AudioFileSo audioFile)
{
if (_audioFileDict == null) EnsureInitialized();
return _audioFileDict!.TryGetValue(audioName, out audioFile);
EnsureInitialized();
return _audioFileDict.TryGetValue(audioName, out audioFile);
}
}
}
}

View File

@@ -35,39 +35,38 @@ namespace BriarQueen.Framework.Registries
{
_entryLookup = new Dictionary<string, CodexEntrySo>();
AddEntries(_bookEntries, "Book Entries");
AddEntries(_puzzleClues, "Puzzle Clues");
AddEntries(_photoEntries, "Photo Entries");
}
RegistryLookupBuilder.AddEntries(
_entryLookup,
_bookEntries,
this,
nameof(CodexRegistry),
"Book Entries",
"UniqueID",
entry => entry.UniqueID,
entry => entry,
entry => RegistryLookupBuilder.HasNonEmptyKey(entry.UniqueID));
private void AddEntries(List<CodexEntrySo> entries, string category)
{
if (entries == null)
return;
RegistryLookupBuilder.AddEntries(
_entryLookup,
_puzzleClues,
this,
nameof(CodexRegistry),
"Puzzle Clues",
"UniqueID",
entry => entry.UniqueID,
entry => entry,
entry => RegistryLookupBuilder.HasNonEmptyKey(entry.UniqueID));
foreach (var entry in entries)
{
if (entry == null)
continue;
if (string.IsNullOrWhiteSpace(entry.UniqueID))
{
Debug.LogWarning(
$"[CodexRegistry] Skipping {category} entry '{entry.name}' because UniqueID is empty.",
this);
continue;
}
if (_entryLookup.ContainsKey(entry.UniqueID))
{
Debug.LogError(
$"[CodexRegistry] Duplicate UniqueID detected: '{entry.UniqueID}' from entry '{entry.name}'.",
this);
continue;
}
_entryLookup.Add(entry.UniqueID, entry);
}
RegistryLookupBuilder.AddEntries(
_entryLookup,
_photoEntries,
this,
nameof(CodexRegistry),
"Photo Entries",
"UniqueID",
entry => entry.UniqueID,
entry => entry,
entry => RegistryLookupBuilder.HasNonEmptyKey(entry.UniqueID));
}
public bool TryGetEntry(string entryID, out CodexEntrySo entry)
@@ -130,4 +129,4 @@ namespace BriarQueen.Framework.Registries
}
#endif
}
}
}

View File

@@ -35,39 +35,38 @@ namespace BriarQueen.Framework.Registries
{
_entryLookup = new Dictionary<string, ItemDataSo>();
AddEntries(_puzzleSlots, "Puzzle Slots");
AddEntries(_pickupItems, "Pickup Items");
AddEntries(_environmentInteractables, "Environment Interactables");
}
RegistryLookupBuilder.AddEntries(
_entryLookup,
_puzzleSlots,
this,
nameof(ItemRegistry),
"Puzzle Slots",
"UniqueID",
entry => entry.UniqueID,
entry => entry,
entry => RegistryLookupBuilder.HasNonEmptyKey(entry.UniqueID));
private void AddEntries(List<ItemDataSo> entries, string category)
{
if (entries == null)
return;
RegistryLookupBuilder.AddEntries(
_entryLookup,
_pickupItems,
this,
nameof(ItemRegistry),
"Pickup Items",
"UniqueID",
entry => entry.UniqueID,
entry => entry,
entry => RegistryLookupBuilder.HasNonEmptyKey(entry.UniqueID));
foreach (var entry in entries)
{
if (entry == null)
continue;
if (string.IsNullOrWhiteSpace(entry.UniqueID))
{
Debug.LogWarning(
$"[ItemRegistry] Skipping {category} entry '{entry.name}' because UniqueID is empty.",
this);
continue;
}
if (_entryLookup.ContainsKey(entry.UniqueID))
{
Debug.LogError(
$"[ItemRegistry] Duplicate UniqueID detected: '{entry.UniqueID}' from entry '{entry.name}'.",
this);
continue;
}
_entryLookup.Add(entry.UniqueID, entry);
}
RegistryLookupBuilder.AddEntries(
_entryLookup,
_environmentInteractables,
this,
nameof(ItemRegistry),
"Environment Interactables",
"UniqueID",
entry => entry.UniqueID,
entry => entry,
entry => RegistryLookupBuilder.HasNonEmptyKey(entry.UniqueID));
}
public bool TryGetEntry(string itemID, out ItemDataSo entry)
@@ -130,4 +129,4 @@ namespace BriarQueen.Framework.Registries
}
#endif
}
}
}

View File

@@ -0,0 +1,69 @@
using System;
using System.Collections.Generic;
using UnityEngine;
namespace BriarQueen.Framework.Registries
{
internal static class RegistryLookupBuilder
{
public static void AddEntries<TKey, TEntry, TValue>(
Dictionary<TKey, TValue> lookup,
IEnumerable<TEntry> entries,
UnityEngine.Object context,
string registryName,
string category,
string keyLabel,
Func<TEntry, TKey> keySelector,
Func<TEntry, TValue> valueSelector,
Func<TEntry, bool> isKeyValid = null,
Func<TEntry, bool> 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);
}
}
}

View File

@@ -0,0 +1,2 @@
fileFormatVersion: 2
guid: be2d54c81fb1f49eb974c7b2b0a91f47