DF Chat Enhancements: Merge chat message data flags instead of overwriting #486
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
When writing the WorldTime into the chat message data flags structure, DF Chat Enhancement would straight out overwrite the whole flags structure, wiping away all previously written flags. Since DF Chat Enhancement is often very late in the Hooks chain, this would mean most flags are destroyed.
This poses a problem when other modules would want to read from the flags, for example data written by the system. One such example is the Pathfinder 1e integration for https://github.com/otigon/automated-jb2a-animations . It would read the flags added by the system to determine when an attack (or spell cast) has taken place and use the attached source item name to match again a list of animations to play, as well as the attacker and attacke. So it can, for example, see that an attack with a crossbow has taken place and animate a crossbow bolt flying towards the target.
If, however, the system flags are wiped away by DF Chat Enhancements, Automated Animations fails to play any animations for any attacks, because it can't determine anything about the attack (or that, in fact, an attack has taken place). See https://github.com/otigon/automated-jb2a-animations/issues/669 .
This PR fixes the situation by using
foundry.utils.mergeObject()
to merge the DF Chat Enhancements flags into the existing chat message data object instead.This also fixes #387, if I understand it correctly.