Skip to content

Commit

Permalink
Support custom actions for blackboard tracker.
Browse files Browse the repository at this point in the history
  • Loading branch information
isadorasophia committed Jan 19, 2025
1 parent 78d703d commit 4d8a0bf
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 6 deletions.
2 changes: 1 addition & 1 deletion gum
20 changes: 15 additions & 5 deletions src/Murder/Core/Dialogs/CharacterRuntime.cs
Original file line number Diff line number Diff line change
Expand Up @@ -473,7 +473,7 @@ private bool DoActionsForActiveDialog(World? world, Entity? target)
}
}

DoAction(actionEntity, tracker, action);
DoAction(world, actionEntity, tracker, action);
}

// If an entity has been created, trigger it immediately.
Expand Down Expand Up @@ -517,7 +517,7 @@ private bool DoLineEvents(Entity? target, Line line)
return true;
}

private void DoAction(Entity? actionEntity, BlackboardTracker tracker, DialogAction action)
private void DoAction(World? world, Entity? actionEntity, BlackboardTracker tracker, DialogAction action)
{
if (action.ComponentValue is IComponent component)
{
Expand All @@ -532,21 +532,31 @@ private void DoAction(Entity? actionEntity, BlackboardTracker tracker, DialogAct
switch (fact.Kind)
{
case FactKind.Bool:
tracker.SetBool(fact.Blackboard, fact.Name, action.Kind, action.BoolValue!.Value);
bool @bool = action.BoolValue!.Value;

tracker.SetBool(fact.Blackboard, fact.Name, action.Kind, @bool);
tracker.OnFieldModifiedByDialogue(world, fact.Blackboard, fact.Name, action.Kind, @bool);
break;

case FactKind.Int:
tracker.SetInt(fact.Blackboard, fact.Name, action.Kind, action.IntValue!.Value);
int @int = action.IntValue!.Value;

tracker.SetInt(fact.Blackboard, fact.Name, action.Kind, @int);
tracker.OnFieldModifiedByDialogue(world, fact.Blackboard, fact.Name, action.Kind, @int);
break;

case FactKind.Float:
tracker.SetFloat(fact.Blackboard, fact.Name, action.Kind, action.FloatValue!.Value);
float @float = action.FloatValue!.Value;

tracker.SetFloat(fact.Blackboard, fact.Name, action.Kind, @float);
tracker.OnFieldModifiedByDialogue(world, fact.Blackboard, fact.Name, action.Kind, @float);
break;

case FactKind.String:
tracker.SetString(fact.Blackboard, fact.Name, action.StrValue!);
break;
}

}

/// <summary>
Expand Down
9 changes: 9 additions & 0 deletions src/Murder/Data/Save/BlackboardTracker.cs
Original file line number Diff line number Diff line change
Expand Up @@ -500,6 +500,15 @@ private T GetValue<T>(string name) where T : notnull
// Implemented by third-party
}

/// <summary>
/// This provides custom proessing when a field is modified because of a dialogue action.
/// This can do custom behaviors to post-process the field.
/// </summary>
public virtual void OnFieldModifiedByDialogue<T>(World? world, string? blackboardName, string fieldName, BlackboardActionKind kind, T value) where T : notnull
{
// Implemented by third-party
}

/// <summary>
/// Set a variable value that is not available in any blackboard.
/// </summary>
Expand Down

0 comments on commit 4d8a0bf

Please sign in to comment.