Repository: 4ian/GDevelop
File: Core/GDCore/Project/Layer.cpp (C++)

Code before:
  for (std::size_t c = 0; c < GetCameraCount(); ++c) {
    SerializerElement& cameraElement = camerasElement.AddChild("camera");
    cameraElement.SetAttribute("defaultSize", GetCamera(c).UseDefaultSize());
    cameraElement.SetAttribute("width", GetCamera(c).GetWidth());
    cameraElement.SetAttribute("height", GetCamera(c).GetHeight());

    cameraElement.SetAttribute("defaultViewport",
                               GetCamera(c).UseDefaultViewport());
    cameraElement.SetAttribute("viewportLeft", GetCamera(c).GetViewportX1());
    cameraElement.SetAttribute("viewportTop", GetCamera(c).GetViewportY1());
    cameraElement.SetAttribute("viewportRight", GetCamera(c).GetViewportX2());
    cameraElement.SetAttribute("viewportBottom", GetCamera(c).GetViewportY2());
  }

  SerializerElement& effectsElement = element.AddChild("effects");
  effectsContainer.SerializeTo(effectsElement);
}

/**
 * \brief Unserialize the layer.
 */
void Layer::UnserializeFrom(const SerializerElement& element) {
  SetName(element.GetStringAttribute("name", "", "Name"));
  SetRenderingType(element.GetStringAttribute("renderingType", ""));
  SetCameraType(element.GetStringAttribute("cameraType", "perspective"));
  SetDefaultCameraBehavior(element.GetStringAttribute("defaultCameraBehavior", "keep-top-left-fixed-if-never-moved"));
  SetVisibility(element.GetBoolAttribute("visibility", true, "Visibility"));
  SetLocked(element.GetBoolAttribute("isLocked", false));
  SetLightingLayer(element.GetBoolAttribute("isLightingLayer", false));
  SetFollowBaseLayerCamera(
      element.GetBoolAttribute("followBaseLayerCamera", false));
  SetAmbientLightColor(element.GetIntAttribute("ambientLightColorR", 200),
                       element.GetIntAttribute("ambientLightColorG", 200),
                       element.GetIntAttribute("ambientLightColorB", 200));
  SetCamera3DNearPlaneDistance(element.GetDoubleAttribute(
      "camera3DNearPlaneDistance", 0.1, "threeDNearPlaneDistance"));
  SetCamera3DFarPlaneDistance(element.GetDoubleAttribute(
      "camera3DFarPlaneDistance", 10000, "threeDFarPlaneDistance"));
  SetCamera3DFieldOfView(element.GetDoubleAttribute(
      "camera3DFieldOfView", 45, "threeDFieldOfView"));

  cameras.clear();
  SerializerElement& camerasElement = element.GetChild("cameras");
  camerasElement.ConsiderAsArrayOf("camera");
  for (std::size_t i = 0; i < camerasElement.GetChildrenCount(); ++i) {
    const SerializerElement& cameraElement = camerasElement.GetChild(i);

    Camera camera;
    camera.SetUseDefaultSize(
        cameraElement.GetBoolAttribute("defaultSize", true));
    camera.SetSize(cameraElement.GetDoubleAttribute("width"),

Review comment (suggestion):
to make it a bit shorter
```suggestion
  SetDefaultCameraBehavior(element.GetStringAttribute("defaultCameraBehavior", "top-left-anchored-if-never-moved"));

```

Code after:
  for (std::size_t c = 0; c < GetCameraCount(); ++c) {
    SerializerElement& cameraElement = camerasElement.AddChild("camera");
    cameraElement.SetAttribute("defaultSize", GetCamera(c).UseDefaultSize());
    cameraElement.SetAttribute("width", GetCamera(c).GetWidth());
    cameraElement.SetAttribute("height", GetCamera(c).GetHeight());

    cameraElement.SetAttribute("defaultViewport",
                               GetCamera(c).UseDefaultViewport());
    cameraElement.SetAttribute("viewportLeft", GetCamera(c).GetViewportX1());
    cameraElement.SetAttribute("viewportTop", GetCamera(c).GetViewportY1());
    cameraElement.SetAttribute("viewportRight", GetCamera(c).GetViewportX2());
    cameraElement.SetAttribute("viewportBottom", GetCamera(c).GetViewportY2());
  }

  SerializerElement& effectsElement = element.AddChild("effects");
  effectsContainer.SerializeTo(effectsElement);
}

/**
 * \brief Unserialize the layer.
 */
void Layer::UnserializeFrom(const SerializerElement& element) {
  SetName(element.GetStringAttribute("name", "", "Name"));
  SetRenderingType(element.GetStringAttribute("renderingType", ""));
  SetCameraType(element.GetStringAttribute("cameraType", "perspective"));
  SetDefaultCameraBehavior(element.GetStringAttribute("defaultCameraBehavior", "top-left-anchored-if-never-moved"));
  SetVisibility(element.GetBoolAttribute("visibility", true, "Visibility"));
  SetLocked(element.GetBoolAttribute("isLocked", false));
  SetLightingLayer(element.GetBoolAttribute("isLightingLayer", false));
  SetFollowBaseLayerCamera(
      element.GetBoolAttribute("followBaseLayerCamera", false));
  SetAmbientLightColor(element.GetIntAttribute("ambientLightColorR", 200),
                       element.GetIntAttribute("ambientLightColorG", 200),
                       element.GetIntAttribute("ambientLightColorB", 200));
  SetCamera3DNearPlaneDistance(element.GetDoubleAttribute(
      "camera3DNearPlaneDistance", 0.1, "threeDNearPlaneDistance"));
  SetCamera3DFarPlaneDistance(element.GetDoubleAttribute(
      "camera3DFarPlaneDistance", 10000, "threeDFarPlaneDistance"));
  SetCamera3DFieldOfView(element.GetDoubleAttribute(
      "camera3DFieldOfView", 45, "threeDFieldOfView"));

  cameras.clear();
  SerializerElement& camerasElement = element.GetChild("cameras");
  camerasElement.ConsiderAsArrayOf("camera");
  for (std::size_t i = 0; i < camerasElement.GetChildrenCount(); ++i) {
    const SerializerElement& cameraElement = camerasElement.GetChild(i);

    Camera camera;
    camera.SetUseDefaultSize(
        cameraElement.GetBoolAttribute("defaultSize", true));
    camera.SetSize(cameraElement.GetDoubleAttribute("width"),