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

Code before:
          return makeGenericFailure(
            `Object with name "${object_name}" already exists in scene "${scene_name}" but with a different type ("${object_type}").`
          );
        }

        // /!\ Tell the editor that some objects have potentially been modified (and even removed).
        // This will force the objects panel to refresh.
        onObjectsModifiedOutsideEditor({
          scene: layout,
        });
        return makeGenericSuccess(
          `Object with name "${object_name}" already exists, no need to re-create it.`
        );
      }

      return createNewObject();
    }
  },
};

/**
 * Retrieves the properties of a specific object (global or in a scene)
 */
const inspectObjectProperties: EditorFunction = {
  renderForEditor: ({ args, editorCallbacks }) => {
    const scope = extractRequiredString(args, 'scope');
    const scene_name = extractRequiredString(args, 'scene_name');
    const object_name = extractRequiredString(args, 'object_name');

    const isGlobalObject = scope === 'global';

    return {
      text: isGlobalObject ? (
        <Trans>
          Inspecting properties of global object <b>{object_name}</b>.
        </Trans>
      ) : (
        <Trans>
          Inspecting properties of object <b>{object_name}</b> in scene{' '}
          <Link
            href="#"
            onClick={() =>
              editorCallbacks.onOpenLayout(scene_name, {
                openEventsEditor: true,
                openSceneEditor: true,
                focusWhenOpened: 'scene',
              })
            }
          >
            {scene_name}
          </Link>

Review comment (suggestion):
For me, this scope should not be needed here: the function itself should do the work of searching the object wherever it is. 

This is similar to events btw, you search in scene then in global objects.

Code after:

      if (!existingObject) {
        // No existing object to duplicate, create a new one.
        return createNewObject();
      }

      const objectsContainerWhereObjectWasFound = isGlobalObject
        ? globalObjects
        : layoutObjects;
      const targetObjectsContainer =
        target_object_scope === 'global'
          ? globalObjects
          : objectsContainerWhereObjectWasFound;

      const serializedObject = serializeToJSObject(existingObject);
      const newObject = targetObjectsContainer.insertNewObject(
        project,
        existingObject.getType(),
        object_name,
        targetObjectsContainer.getObjectsCount()
      );
      unserializeFromJSObject(
        newObject,
        serializedObject,
        'unserializeFrom',
        project
      );
      newObject.setName(object_name); // Unserialization has overwritten the name.

      // /!\ Tell the editor that some objects have potentially been modified (and even removed).
      // This will force the objects panel to refresh.
      onObjectsModifiedOutsideEditor({
        scene: layout,
      });
      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) {
      return replaceExistingObject();
    } else if (duplicatedObjectName) {
      return duplicateExistingObject(duplicatedObjectName);
    } else {
      return createNewObject();
    }
  },
};

/**
 * Retrieves the properties of a specific object (global or in a scene)