fixed the encounter window
This commit is contained in:
@@ -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
|
||||
}
|
||||
}
|
||||
|
||||
@@ -8,7 +8,6 @@ namespace Jovian.EncounterSystem {
|
||||
EncounterProperties EncounterProperties { get; set; }
|
||||
EncounterVisuals EncounterVisuals { get; set; }
|
||||
EncounterDialogOptionSet EncounterDialogOptionSet { get; set; }
|
||||
IEncounterKind Kind { get; set; }
|
||||
}
|
||||
|
||||
/// <summary>Default concrete encounter. Extend via a new <see cref="IEncounterKind"/>, not by subclassing.</summary>
|
||||
@@ -18,9 +17,6 @@ namespace Jovian.EncounterSystem {
|
||||
[field: SerializeField] public EncounterProperties EncounterProperties { get; set; }
|
||||
[field: SerializeField] public EncounterVisuals EncounterVisuals { get; set; }
|
||||
[field: SerializeField] public EncounterDialogOptionSet EncounterDialogOptionSet { get; set; }
|
||||
|
||||
[field: SerializeReference, SubclassSelector]
|
||||
public IEncounterKind Kind { get; set; }
|
||||
}
|
||||
|
||||
[Serializable]
|
||||
@@ -32,6 +28,7 @@ namespace Jovian.EncounterSystem {
|
||||
public string id;
|
||||
public string name;
|
||||
public string description;
|
||||
[field: SerializeReference, SubclassSelector] public IEncounterKind Kind { get; set; }
|
||||
}
|
||||
|
||||
[Serializable]
|
||||
|
||||
@@ -35,7 +35,7 @@ namespace Jovian.EncounterSystem {
|
||||
}
|
||||
|
||||
public void OnEncounterTriggered(IEncounter encounter) {
|
||||
if(encounter?.Kind is not QuestKind questKind) {
|
||||
if(encounter?.EncounterDefinition.Kind is not QuestKind questKind) {
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -83,7 +83,7 @@ namespace Jovian.EncounterSystem {
|
||||
}
|
||||
|
||||
foreach(var encounter in table.encounters) {
|
||||
if(encounter?.Kind is not QuestKind questKind) {
|
||||
if(encounter?.EncounterDefinition.Kind is not QuestKind questKind) {
|
||||
continue;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user