Skip to content

Commit

Permalink
Merge pull request #24 from chickensoft-games/feat/overwrite
Browse files Browse the repository at this point in the history
feat: allow blackboard data to be overwritten from inside a logic block
  • Loading branch information
jolexxa authored Dec 21, 2023
2 parents 96627f9 + c57f737 commit cbeb42d
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -183,7 +183,7 @@ CancellationToken token
return null;
}

// if stateSubtype is an interface, we want to find the first subtype that
// if stateBaseType is an interface, we want to find the first subtype that
// implements it and StateLogic. this is a shallow search in the
// logic block.
var primaryState = symbol.GetTypeMembers().FirstOrDefault(
Expand Down
12 changes: 11 additions & 1 deletion Chickensoft.LogicBlocks/src/Logic.cs
Original file line number Diff line number Diff line change
Expand Up @@ -288,7 +288,7 @@ public TData Get<TData>() where TData : notnull {
/// Adds data to the blackboard. Data is retrieved by its type, so do not add
/// more than one piece of data with the same type.
/// </summary>
/// <param name="data">Closure which returns the data.</param>
/// <param name="data">Data to write to the blackboard.</param>
/// <typeparam name="TData">Type of the data to add.</typeparam>
/// <exception cref="ArgumentException">Thrown if data of the provided type
/// has already been added.</exception>
Expand All @@ -301,4 +301,14 @@ protected void Set<TData>(TData data) where TData : notnull {
}
_blackboard.Add(type, data);
}

/// <summary>
/// Adds new data or overwrites existing data in the blackboard. Data is
/// retrieved by its type, so this will overwrite any existing data of the
/// given type, unlike <see cref="Set{TData}(TData)" />.
/// </summary>
/// <param name="data">Data to write to the blackboard.</param>
/// <typeparam name="TData">Type of the data to add or overwrite.</typeparam>
protected void Overwrite<TData>(TData data) where TData : notnull =>
_blackboard[typeof(TData)] = data;
}

0 comments on commit cbeb42d

Please sign in to comment.