mirror of
https://github.com/4ian/GDevelop.git
synced 2026-10-12 02:01:17 +00:00
Fix global object instances now have their layer reset after copied on a new scene if it does not exist (#9182)
This commit is contained in:
@@ -12,6 +12,7 @@ export const addSerializedInstances = ({
|
||||
serializedInstances,
|
||||
addInstancesInTheForeground = false,
|
||||
doesObjectExistInContext,
|
||||
doesLayerExistInContext,
|
||||
}: {|
|
||||
project: gdProject,
|
||||
instancesContainer: gdInitialInstancesContainer,
|
||||
@@ -19,6 +20,7 @@ export const addSerializedInstances = ({
|
||||
serializedInstances: Array<Object>,
|
||||
addInstancesInTheForeground?: boolean,
|
||||
doesObjectExistInContext: string => boolean,
|
||||
doesLayerExistInContext?: string => boolean,
|
||||
|}): Array<gdInitialInstance> => {
|
||||
const zOrderFinder = new gd.HighestZOrderFinder();
|
||||
zOrderFinder.reset();
|
||||
@@ -38,6 +40,12 @@ export const addSerializedInstances = ({
|
||||
project
|
||||
);
|
||||
if (!doesObjectExistInContext(instance.getObjectName())) return null;
|
||||
if (
|
||||
doesLayerExistInContext &&
|
||||
!doesLayerExistInContext(instance.getLayer())
|
||||
) {
|
||||
instance.setLayer('');
|
||||
}
|
||||
instance.setX(instance.getX() - copyReferential[0]);
|
||||
instance.setY(instance.getY() - copyReferential[1]);
|
||||
if (addInstancesInTheForeground) {
|
||||
|
||||
@@ -0,0 +1,42 @@
|
||||
// @flow
|
||||
import { addSerializedInstances } from './InstancesAdder';
|
||||
import { serializeToJSObject } from '../Utils/Serializer';
|
||||
const gd: libGDevelop = global.gd;
|
||||
|
||||
describe('addSerializedInstances', () => {
|
||||
it('keeps the layer of pasted instances if it exists, otherwise uses the base layer', () => {
|
||||
const project = gd.ProjectHelper.createNewGDJSProject();
|
||||
const sourceLayout = project.insertNewLayout('Source', 0);
|
||||
sourceLayout.getLayers().insertNewLayer('Foreground', 1);
|
||||
sourceLayout.getLayers().insertNewLayer('UI', 2);
|
||||
const targetLayout = project.insertNewLayout('Target', 1);
|
||||
targetLayout.getLayers().insertNewLayer('UI', 1);
|
||||
|
||||
const serializedInstances = ['UI', 'Foreground', ''].map(layerName => {
|
||||
const instance = sourceLayout
|
||||
.getInitialInstances()
|
||||
.insertNewInitialInstance();
|
||||
instance.setObjectName('MyGlobalObject');
|
||||
instance.setLayer(layerName);
|
||||
return serializeToJSObject(instance);
|
||||
});
|
||||
|
||||
const newInstances = addSerializedInstances({
|
||||
project,
|
||||
instancesContainer: targetLayout.getInitialInstances(),
|
||||
copyReferential: [0, 0],
|
||||
serializedInstances,
|
||||
doesObjectExistInContext: () => true,
|
||||
doesLayerExistInContext: layerName =>
|
||||
targetLayout.getLayers().hasLayerNamed(layerName),
|
||||
});
|
||||
|
||||
expect(newInstances.map(instance => instance.getLayer())).toEqual([
|
||||
'UI',
|
||||
'',
|
||||
'',
|
||||
]);
|
||||
|
||||
project.delete();
|
||||
});
|
||||
});
|
||||
@@ -2900,6 +2900,8 @@ export default class SceneEditor extends React.Component<Props, State> {
|
||||
.get()
|
||||
.getObjectsContainersList()
|
||||
.hasObjectNamed(objectName),
|
||||
doesLayerExistInContext: layerName =>
|
||||
this.props.layersContainer.hasLayerNamed(layerName),
|
||||
});
|
||||
|
||||
if (this.props.gameEditorMode === 'embedded-game') {
|
||||
|
||||
Reference in New Issue
Block a user