From 91652eb8fbaeb4b1582faa50ed943ad140bd11b7 Mon Sep 17 00:00:00 2001 From: Toastie <toastie@toastiet0ast.com> Date: Tue, 4 Feb 2025 20:07:37 +1300 Subject: [PATCH] Fix interview step being passed by reference instead of by value when getting them from the definitions, breaking selectors for instance --- Interviews/Interview.cs | 51 ++++++++++++++++++++++++++++++++++++++++- 1 file changed, 50 insertions(+), 1 deletion(-) diff --git a/Interviews/Interview.cs b/Interviews/Interview.cs index 99b13bc..0746f31 100644 --- a/Interviews/Interview.cs +++ b/Interviews/Interview.cs @@ -52,14 +52,30 @@ public class ReferencedInterviewStep [JsonProperty("after-reference-step")] public InterviewStep afterReferenceStep; + public ReferencedInterviewStep() { } + + public ReferencedInterviewStep(ReferencedInterviewStep other) + { + id = other.id; + buttonStyle = other.buttonStyle; + selectorDescription = other.selectorDescription; + + if (other.afterReferenceStep != null) + { + afterReferenceStep = new InterviewStep(other.afterReferenceStep); + } + } + public bool TryGetReferencedStep(Dictionary<string, InterviewStep> definitions, out InterviewStep step, bool ignoreReferenceParameters = false) { - if (!definitions.TryGetValue(id, out step)) + if (!definitions.TryGetValue(id, out InterviewStep tempStep)) { Logger.Error("Could not find referenced step '" + id + "' in interview."); + step = null; return false; } + step = new InterviewStep(tempStep); if (!ignoreReferenceParameters) { step.buttonStyle = buttonStyle; @@ -159,6 +175,39 @@ public class InterviewStep [JsonProperty("after-reference-step")] public InterviewStep afterReferenceStep = null; + public InterviewStep() { } + + public InterviewStep(InterviewStep other) + { + heading = other.heading; + message = other.message; + stepType = other.stepType; + color = other.color; + summaryField = other.summaryField; + buttonStyle = other.buttonStyle; + selectorPlaceholder = other.selectorPlaceholder; + selectorDescription = other.selectorDescription; + maxLength = other.maxLength; + minLength = other.minLength; + addSummary = other.addSummary; + answerDelimiter = other.answerDelimiter; + messageID = other.messageID; + answer = other.answer; + answerID = other.answerID; + relatedMessageIDs = other.relatedMessageIDs; + afterReferenceStep = other.afterReferenceStep; + + foreach (KeyValuePair<string, InterviewStep> childStep in other.steps ?? []) + { + steps.Add(childStep.Key, new InterviewStep(childStep.Value)); + } + + foreach (KeyValuePair<string, ReferencedInterviewStep> reference in other.references ?? []) + { + references.Add(reference.Key, new ReferencedInterviewStep(reference.Value)); + } + } + public bool TryGetCurrentStep(out InterviewStep currentStep) { bool result = TryGetTakenSteps(out List<InterviewStep> previousSteps);