Repository: 4ian/GDevelop
File: newIDE/app/src/EditorFunctions/index.js (JavaScript)

Code before:
      }

      return makeGenericFailure(
        `Could not find an object in the asset store to replace "${object_name}" in scene "${scene_name}". Instead, inspect properties of the object and modify it until it matches what you want it to be.`
      );
    };

    const duplicateExistingObject = (duplicatedObjectName: string) => {
      const object = objectsContainer.getObject(duplicatedObjectName);
      const serializedObject = serializeToJSObject(object);
      const newObject = objectsContainer.insertNewObject(
        project,
        object.getType(),
        object_name,
        objectsContainer.getObjectsCount()
      );
      unserializeFromJSObject(
        newObject,
        serializedObject,
        'unserializeFrom',
        project
      );
      newObject.setName(object_name); // Unserialization has overwritten the name.

      return makeGenericSuccess(
        `Duplicated object "${duplicatedObjectName}" as "${newObject.getName()}".`
      );
    };

    if (shouldReplaceExistingObject) {
      // Replace an existing object, if there is one existing.
      if (!objectsContainer.hasObjectNamed(object_name)) {
        return createNewObject();
      }

      return replaceExistingObject();
    } else if (duplicatedObjectName) {
      // Duplicate an existing object, if there is one existing.
      if (!objectsContainer.hasObjectNamed(duplicatedObjectName)) {
        return makeGenericFailure(
          `Object with name "${duplicatedObjectName}" does not exist in scene "${scene_name}", cannot duplicate it into ${object_name}.`
        );
      }

      return duplicateExistingObject(duplicatedObjectName);
    } else {
      // Add a new object.
      if (objectsContainer.hasObjectNamed(object_name)) {
        if (objectsContainer.getObject(object_name).getType() !== object_type) {
          return makeGenericFailure(
            `Object with name "${object_name}" already exists in scene "${scene_name}" but with a different type ("${object_type}").`

Review comment (refactor):
```suggestion
        `Duplicated object "${duplicatedObjectName}" as "${newObject.getName()}". The new object "{newObject.getName()}" has the same type, behaviors, properties and effects as the one it was duplicated from.`
```

Code after:
      }

      return makeGenericFailure(
        `Could not find an object in the asset store to replace "${object_name}" in scene "${scene_name}". Instead, inspect properties of the object and modify it until it matches what you want it to be.`
      );
    };

    const duplicateExistingObject = (duplicatedObjectName: string) => {
      const object = objectsContainer.getObject(duplicatedObjectName);
      const serializedObject = serializeToJSObject(object);
      const newObject = objectsContainer.insertNewObject(
        project,
        object.getType(),
        object_name,
        objectsContainer.getObjectsCount()
      );
      unserializeFromJSObject(
        newObject,
        serializedObject,
        'unserializeFrom',
        project
      );
      newObject.setName(object_name); // Unserialization has overwritten the name.

      return makeGenericSuccess(
        `Duplicated object "${duplicatedObjectName}" as "${newObject.getName()}". The new object "${newObject.getName()}" has the same type, behaviors, properties and effects as the one it was duplicated from.`
      );
    };

    if (shouldReplaceExistingObject) {
      // Replace an existing object, if there is one existing.
      if (!objectsContainer.hasObjectNamed(object_name)) {
        return createNewObject();
      }

      return replaceExistingObject();
    } else if (duplicatedObjectName) {
      // Duplicate an existing object, if there is one existing.
      if (!objectsContainer.hasObjectNamed(duplicatedObjectName)) {
        return makeGenericFailure(
          `Object with name "${duplicatedObjectName}" does not exist in scene "${scene_name}", cannot duplicate it into ${object_name}.`
        );
      }

      return duplicateExistingObject(duplicatedObjectName);
    } else {
      // Add a new object.
      if (objectsContainer.hasObjectNamed(object_name)) {
        if (objectsContainer.getObject(object_name).getType() !== object_type) {
          return makeGenericFailure(
            `Object with name "${object_name}" already exists in scene "${scene_name}" but with a different type ("${object_type}").`