Some encounter testing and working

This commit is contained in:
Sebastian Bularca
2026-04-19 18:34:22 +02:00
parent 8861bdc5eb
commit f055250ca6
11 changed files with 485 additions and 88 deletions

View File

@@ -42,5 +42,34 @@ namespace Jovian.EncounterSystem {
return pool[UnityEngine.Random.Range(0, pool.Count)];
}
#if UNITY_EDITOR
// Unity's inspector "+" duplicates the previous list element, including nested internalId
// GUIDs. Regenerate any duplicates so every encounter carries a unique internalId.
private void OnValidate() {
if(encounters == null) {
return;
}
var seen = new HashSet<string>();
var changed = false;
foreach(var encounter in encounters) {
if(encounter?.EncounterDefinition == null) {
continue;
}
var id = encounter.EncounterDefinition.internalId;
if(string.IsNullOrEmpty(id) || !seen.Add(id)) {
encounter.EncounterDefinition.internalId = Guid.NewGuid().ToString();
seen.Add(encounter.EncounterDefinition.internalId);
changed = true;
}
}
if(changed) {
UnityEditor.EditorUtility.SetDirty(this);
}
}
#endif
}
}