Skip to content

Commit

Permalink
Fix automatic collision mask on multiple sprites addition (#5521)
Browse files Browse the repository at this point in the history
And on piskel edition
  • Loading branch information
ClementPasteau authored Jul 31, 2023
1 parent ca27a94 commit fa00337
Showing 1 changed file with 5 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -295,6 +295,7 @@ const SpritesList = ({
allDirectionSpritesHaveSameCollisionMasks,
allDirectionSpritesHaveSamePoints,
} = checkDirectionPointsAndCollisionsMasks(direction);
const spritesCountBeforeAdding = direction.getSpritesCount();

const resources = await resourceManagementProps.onChooseResource({
initialSourceName: resourceSource.name,
Expand Down Expand Up @@ -328,8 +329,8 @@ const SpritesList = ({
await resourceManagementProps.onFetchNewlyAddedResources();

if (resources.length && onSpriteUpdated) onSpriteUpdated();
if (direction.getSpritesCount() === 1 && onFirstSpriteUpdated) {
// If the sprites count is 1, we can assume the first sprite was added.
if (spritesCountBeforeAdding === 0 && onFirstSpriteUpdated) {
// If there was no sprites before, we can assume the first sprite was added.
onFirstSpriteUpdated();
}
},
Expand Down Expand Up @@ -408,6 +409,7 @@ const SpritesList = ({
copySpritePolygons(direction.getSprite(0), sprite);
}
}
onSpriteAdded(sprite); // Call the callback before `addSprite`, as `addSprite` will store a copy of it.
newDirection.addSprite(sprite);
sprite.delete();
});
Expand Down Expand Up @@ -449,6 +451,7 @@ const SpritesList = ({
objectName,
onReplaceByDirection,
onSpriteUpdated,
onSpriteAdded,
onFirstSpriteUpdated,
project,
resourceManagementProps,
Expand Down

0 comments on commit fa00337

Please sign in to comment.