mirror of
https://github.com/4ian/GDevelop.git
synced 2025-10-15 10:19:04 +00:00
Fix copying points & masks when editing sprite too (#5532)
Do not show in changeloc
This commit is contained in:
@@ -174,18 +174,8 @@ const checkObjectPointsAndCollisionsMasks = (
|
|||||||
) => {
|
) => {
|
||||||
let allObjectSpritesHaveSamePoints = false;
|
let allObjectSpritesHaveSamePoints = false;
|
||||||
let allObjectSpritesHaveSameCollisionMasks = false;
|
let allObjectSpritesHaveSameCollisionMasks = false;
|
||||||
const firstObjectSprite =
|
const firstObjectSprite = getCurrentElements(spriteConfiguration, 0, 0, 0)
|
||||||
spriteConfiguration.getAnimationsCount() > 0 &&
|
.sprite;
|
||||||
spriteConfiguration.getAnimation(0).getDirectionsCount() > 0 &&
|
|
||||||
spriteConfiguration
|
|
||||||
.getAnimation(0)
|
|
||||||
.getDirection(0)
|
|
||||||
.getSpritesCount() > 0
|
|
||||||
? spriteConfiguration
|
|
||||||
.getAnimation(0)
|
|
||||||
.getDirection(0)
|
|
||||||
.getSprite(0)
|
|
||||||
: null;
|
|
||||||
|
|
||||||
if (firstObjectSprite) {
|
if (firstObjectSprite) {
|
||||||
allObjectSpritesHaveSamePoints = allObjectSpritesHaveSamePointsAs(
|
allObjectSpritesHaveSamePoints = allObjectSpritesHaveSamePointsAs(
|
||||||
@@ -333,8 +323,8 @@ const SpritesList = ({
|
|||||||
]
|
]
|
||||||
);
|
);
|
||||||
|
|
||||||
const onAddSprite = React.useCallback(
|
const applyPointsAndMasksToSpriteIfNecessary = React.useCallback(
|
||||||
async (resourceSource: ResourceSource) => {
|
(sprite: gdSprite) => {
|
||||||
const {
|
const {
|
||||||
allDirectionSpritesHaveSameCollisionMasks,
|
allDirectionSpritesHaveSameCollisionMasks,
|
||||||
allDirectionSpritesHaveSamePoints,
|
allDirectionSpritesHaveSamePoints,
|
||||||
@@ -346,11 +336,42 @@ const SpritesList = ({
|
|||||||
const shouldUseFullImageCollisionMask = isFirstSpriteUsingFullImageCollisionMask(
|
const shouldUseFullImageCollisionMask = isFirstSpriteUsingFullImageCollisionMask(
|
||||||
spriteConfiguration
|
spriteConfiguration
|
||||||
);
|
);
|
||||||
const directionSpritesCountBeforeAdding = direction.getSpritesCount();
|
|
||||||
const firstObjectSprite = getCurrentElements(spriteConfiguration, 0, 0, 0)
|
const firstObjectSprite = getCurrentElements(spriteConfiguration, 0, 0, 0)
|
||||||
.sprite;
|
.sprite;
|
||||||
const firstDirectionSprite =
|
const firstDirectionSprite =
|
||||||
directionSpritesCountBeforeAdding > 0 ? direction.getSprite(0) : null;
|
direction.getSpritesCount() > 0 ? direction.getSprite(0) : null;
|
||||||
|
|
||||||
|
// Copy points if toggles were set before adding the sprite.
|
||||||
|
if (allObjectSpritesHaveSamePoints && firstObjectSprite) {
|
||||||
|
// Copy points from the first sprite of the object, if existing.
|
||||||
|
copySpritePoints(firstObjectSprite, sprite);
|
||||||
|
} else if (allDirectionSpritesHaveSamePoints && firstDirectionSprite) {
|
||||||
|
// Copy points from the first sprite of the direction, if this is not the first one we add.
|
||||||
|
copySpritePoints(firstDirectionSprite, sprite);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Copy collision masks if toggles were set before adding the sprite.
|
||||||
|
if (allObjectSpritesHaveSameCollisionMasks && firstObjectSprite) {
|
||||||
|
// Copy collision masks from the first sprite of the object, if existing.
|
||||||
|
copySpritePolygons(firstObjectSprite, sprite);
|
||||||
|
} else if (
|
||||||
|
allDirectionSpritesHaveSameCollisionMasks &&
|
||||||
|
firstDirectionSprite
|
||||||
|
) {
|
||||||
|
// Copy collision masks from the first sprite of the direction, if this is not the first one we add.
|
||||||
|
copySpritePolygons(firstDirectionSprite, sprite);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (shouldUseFullImageCollisionMask) {
|
||||||
|
sprite.setFullImageCollisionMask(true);
|
||||||
|
}
|
||||||
|
},
|
||||||
|
[direction, spriteConfiguration]
|
||||||
|
);
|
||||||
|
|
||||||
|
const onAddSprite = React.useCallback(
|
||||||
|
async (resourceSource: ResourceSource) => {
|
||||||
|
const directionSpritesCountBeforeAdding = direction.getSpritesCount();
|
||||||
|
|
||||||
const resources = await resourceManagementProps.onChooseResource({
|
const resources = await resourceManagementProps.onChooseResource({
|
||||||
initialSourceName: resourceSource.name,
|
initialSourceName: resourceSource.name,
|
||||||
@@ -365,30 +386,8 @@ const SpritesList = ({
|
|||||||
const sprite = new gd.Sprite();
|
const sprite = new gd.Sprite();
|
||||||
sprite.setImageName(resource.getName());
|
sprite.setImageName(resource.getName());
|
||||||
|
|
||||||
// Copy points if toggles were set before adding the sprite.
|
applyPointsAndMasksToSpriteIfNecessary(sprite);
|
||||||
if (allObjectSpritesHaveSamePoints && firstObjectSprite) {
|
|
||||||
// Copy points from the first sprite of the object, if existing.
|
|
||||||
copySpritePoints(firstObjectSprite, sprite);
|
|
||||||
} else if (allDirectionSpritesHaveSamePoints && firstDirectionSprite) {
|
|
||||||
// Copy points from the first sprite of the direction, if this is not the first one we add.
|
|
||||||
copySpritePoints(firstDirectionSprite, sprite);
|
|
||||||
}
|
|
||||||
|
|
||||||
// Copy collision masks if toggles were set before adding the sprite.
|
|
||||||
if (allObjectSpritesHaveSameCollisionMasks && firstObjectSprite) {
|
|
||||||
// Copy collision masks from the first sprite of the object, if existing.
|
|
||||||
copySpritePolygons(firstObjectSprite, sprite);
|
|
||||||
} else if (
|
|
||||||
allDirectionSpritesHaveSameCollisionMasks &&
|
|
||||||
firstDirectionSprite
|
|
||||||
) {
|
|
||||||
// Copy collision masks from the first sprite of the direction, if this is not the first one we add.
|
|
||||||
copySpritePolygons(firstDirectionSprite, sprite);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (shouldUseFullImageCollisionMask) {
|
|
||||||
sprite.setFullImageCollisionMask(true);
|
|
||||||
}
|
|
||||||
onSpriteAdded(sprite); // Call the callback before `addSprite`, as `addSprite` will store a copy of it.
|
onSpriteAdded(sprite); // Call the callback before `addSprite`, as `addSprite` will store a copy of it.
|
||||||
direction.addSprite(sprite);
|
direction.addSprite(sprite);
|
||||||
sprite.delete();
|
sprite.delete();
|
||||||
@@ -416,7 +415,7 @@ const SpritesList = ({
|
|||||||
onSpriteUpdated,
|
onSpriteUpdated,
|
||||||
onSpriteAdded,
|
onSpriteAdded,
|
||||||
onFirstSpriteUpdated,
|
onFirstSpriteUpdated,
|
||||||
spriteConfiguration,
|
applyPointsAndMasksToSpriteIfNecessary,
|
||||||
]
|
]
|
||||||
);
|
);
|
||||||
|
|
||||||
@@ -426,14 +425,6 @@ const SpritesList = ({
|
|||||||
return direction.getSprite(i).getImageName();
|
return direction.getSprite(i).getImageName();
|
||||||
});
|
});
|
||||||
|
|
||||||
const {
|
|
||||||
allDirectionSpritesHaveSameCollisionMasks,
|
|
||||||
allDirectionSpritesHaveSamePoints,
|
|
||||||
} = checkDirectionPointsAndCollisionsMasks(direction);
|
|
||||||
const shouldUseFullImageCollisionMask = isFirstSpriteUsingFullImageCollisionMask(
|
|
||||||
spriteConfiguration
|
|
||||||
);
|
|
||||||
|
|
||||||
try {
|
try {
|
||||||
setExternalEditorOpened(true);
|
setExternalEditorOpened(true);
|
||||||
const editResult: EditWithExternalEditorReturn | null = await externalEditor.edit(
|
const editResult: EditWithExternalEditorReturn | null = await externalEditor.edit(
|
||||||
@@ -476,19 +467,13 @@ const SpritesList = ({
|
|||||||
resource.originalIndex !== undefined &&
|
resource.originalIndex !== undefined &&
|
||||||
resource.originalIndex !== null
|
resource.originalIndex !== null
|
||||||
) {
|
) {
|
||||||
|
// The sprite existed before, so we can copy its points and collision masks.
|
||||||
const originalSprite = direction.getSprite(resource.originalIndex);
|
const originalSprite = direction.getSprite(resource.originalIndex);
|
||||||
copySpritePoints(originalSprite, sprite);
|
copySpritePoints(originalSprite, sprite);
|
||||||
copySpritePolygons(originalSprite, sprite);
|
copySpritePolygons(originalSprite, sprite);
|
||||||
} else {
|
} else {
|
||||||
if (allDirectionSpritesHaveSamePoints) {
|
// The sprite is new, apply points & collision masks if necessary.
|
||||||
copySpritePoints(direction.getSprite(0), sprite);
|
applyPointsAndMasksToSpriteIfNecessary(sprite);
|
||||||
}
|
|
||||||
if (allDirectionSpritesHaveSameCollisionMasks) {
|
|
||||||
copySpritePolygons(direction.getSprite(0), sprite);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if (shouldUseFullImageCollisionMask) {
|
|
||||||
sprite.setFullImageCollisionMask(true);
|
|
||||||
}
|
}
|
||||||
onSpriteAdded(sprite); // Call the callback before `addSprite`, as `addSprite` will store a copy of it.
|
onSpriteAdded(sprite); // Call the callback before `addSprite`, as `addSprite` will store a copy of it.
|
||||||
newDirection.addSprite(sprite);
|
newDirection.addSprite(sprite);
|
||||||
@@ -538,7 +523,7 @@ const SpritesList = ({
|
|||||||
resourceManagementProps,
|
resourceManagementProps,
|
||||||
resourcesLoader,
|
resourcesLoader,
|
||||||
onChangeName,
|
onChangeName,
|
||||||
spriteConfiguration,
|
applyPointsAndMasksToSpriteIfNecessary,
|
||||||
]
|
]
|
||||||
);
|
);
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user