Skip to content

Commit

Permalink
Merge pull request inkle#532 from michael-badrobotgames/master
Browse files Browse the repository at this point in the history
Made observer param in RemoveVariableObserver optional
  • Loading branch information
joethephish authored Jun 25, 2019
2 parents 2012c86 + df06e50 commit 91bbf0b
Showing 1 changed file with 11 additions and 5 deletions.
16 changes: 11 additions & 5 deletions ink-engine-runtime/Story.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2040,11 +2040,12 @@ public void ObserveVariables(IList<string> variableNames, VariableObserver obser
/// Removes the variable observer, to stop getting variable change notifications.
/// If you pass a specific variable name, it will stop observing that particular one. If you
/// pass null (or leave it blank, since it's optional), then the observer will be removed
/// from all variables that it's subscribed to.
/// from all variables that it's subscribed to. If you pass in a specific variable name and
/// null for the the observer, all observers for that variable will be removed.
/// </summary>
/// <param name="observer">The observer to stop observing.</param>
/// <param name="observer">(Optional) The observer to stop observing.</param>
/// <param name="specificVariableName">(Optional) Specific variable name to stop observing.</param>
public void RemoveVariableObserver(VariableObserver observer, string specificVariableName = null)
public void RemoveVariableObserver(VariableObserver observer = null, string specificVariableName = null)
{
IfAsyncWeCant ("remove a variable observer");

Expand All @@ -2054,12 +2055,17 @@ public void RemoveVariableObserver(VariableObserver observer, string specificVar
// Remove observer for this specific variable
if (specificVariableName != null) {
if (_variableObservers.ContainsKey (specificVariableName)) {
_variableObservers [specificVariableName] -= observer;
if( observer != null) {
_variableObservers [specificVariableName] -= observer;
}
else {
_variableObservers.Remove(specificVariableName);
}
}
}

// Remove observer for all variables
else {
else if( observer != null) {
var keys = new List<string>(_variableObservers.Keys);
foreach (var varName in keys) {
_variableObservers[varName] -= observer;
Expand Down

0 comments on commit 91bbf0b

Please sign in to comment.