Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 5 additions & 5 deletions Core/GDCore/Project/Behavior.h
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,11 @@
* Copyright 2008-2016 Florian Rival (Florian.Rival@gmail.com). All rights
* reserved. This project is released under the MIT License.
*/
#ifndef GDCORE_BEHAVIOR_H
#define GDCORE_BEHAVIOR_H
#pragma once

#include "GDCore/String.h"
#include "GDCore/Project/BehaviorConfigurationContainer.h"
#include "GDCore/Tools/MakeUnique.h"

namespace gd {

Expand All @@ -28,7 +28,9 @@ class GD_CORE_API Behavior: public BehaviorConfigurationContainer {
: BehaviorConfigurationContainer(name_, type_),
isDefaultBehavior(false) {};
virtual ~Behavior();
virtual Behavior* Clone() const override { return new Behavior(*this); }
virtual std::unique_ptr<gd::Behavior> Clone() const {
return gd::make_unique<gd::Behavior>(*this);
}

bool IsDefaultBehavior() const {
return isDefaultBehavior;
Expand All @@ -43,5 +45,3 @@ class GD_CORE_API Behavior: public BehaviorConfigurationContainer {
};

} // namespace gd

#endif // GDCORE_BEHAVIOR_H
3 changes: 0 additions & 3 deletions Core/GDCore/Project/BehaviorConfigurationContainer.h
Original file line number Diff line number Diff line change
Expand Up @@ -46,9 +46,6 @@ class GD_CORE_API BehaviorConfigurationContainer {
quickCustomizationVisibility(QuickCustomization::Visibility::Default),
propertiesQuickCustomizationVisibilities() {};
virtual ~BehaviorConfigurationContainer();
virtual BehaviorConfigurationContainer* Clone() const {
return new BehaviorConfigurationContainer(*this);
}

/**
* \brief Return the name identifying the behavior
Expand Down
7 changes: 2 additions & 5 deletions Core/GDCore/Project/BehaviorsSharedData.h
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,7 @@
* reserved. This project is released under the MIT License.
*/

#ifndef GDCORE_BEHAVIORSSHAREDDATA_H
#define GDCORE_BEHAVIORSSHAREDDATA_H
#pragma once

#include "GDCore/String.h"
#include "GDCore/Project/BehaviorConfigurationContainer.h"
Expand All @@ -27,9 +26,7 @@ class GD_CORE_API BehaviorsSharedData: public BehaviorConfigurationContainer {
BehaviorsSharedData(const gd::String& name_, const gd::String& type_)
: BehaviorConfigurationContainer(name_, type_) {};
virtual ~BehaviorsSharedData();
virtual BehaviorsSharedData* Clone() const override { return new BehaviorsSharedData(*this); }
virtual BehaviorsSharedData* Clone() const { return new BehaviorsSharedData(*this); }
};

} // namespace gd

#endif // GDCORE_BEHAVIORSSHAREDDATA_H
5 changes: 2 additions & 3 deletions Core/GDCore/Project/CustomBehavior.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,8 @@

using namespace gd;

CustomBehavior *CustomBehavior::Clone() const {
CustomBehavior *clone = new CustomBehavior(*this);
return clone;
std::unique_ptr<gd::Behavior> CustomBehavior::Clone() const {
return gd::make_unique<gd::CustomBehavior>(*this);
}

void CustomBehavior::InitializeContent(gd::SerializerElement &behaviorContent) {
Expand Down
7 changes: 2 additions & 5 deletions Core/GDCore/Project/CustomBehavior.h
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,7 @@
* Copyright 2008-2016 Florian Rival (Florian.Rival@gmail.com). All rights
* reserved. This project is released under the MIT License.
*/
#ifndef GDCORE_CUSTOMBEHAVIOR_H
#define GDCORE_CUSTOMBEHAVIOR_H
#pragma once

#include "GDCore/Project/Behavior.h"
#include "GDCore/Project/EventsBasedBehavior.h"
Expand All @@ -26,7 +25,7 @@ class CustomBehavior : public gd::Behavior {
const gd::String &fullType)
: Behavior(name, fullType),
project(project_) {}
CustomBehavior *Clone() const override;
std::unique_ptr<gd::Behavior> Clone() const override;

using Behavior::GetProperties;
using Behavior::InitializeContent;
Expand All @@ -44,5 +43,3 @@ class CustomBehavior : public gd::Behavior {
///< EventBasedBehavior from the fullType.
};
} // namespace gd

#endif // GDCORE_CUSTOMBEHAVIOR_H
6 changes: 1 addition & 5 deletions Core/GDCore/Project/Object.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -51,11 +51,7 @@ void Object::CopyWithoutConfiguration(const gd::Object& object) {
assetStoreId = object.assetStoreId;
objectVariables = object.objectVariables;
effectsContainer = object.effectsContainer;

behaviors.clear();
for (auto& it : object.behaviors) {
behaviors[it.first] = gd::make_unique<gd::Behavior>(*it.second);
}
behaviors = gd::Clone(object.behaviors);
}

gd::ObjectConfiguration& Object::GetConfiguration() { return *configuration; }
Expand Down
16 changes: 12 additions & 4 deletions Core/GDCore/Tools/PolymorphicClone.h
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
#ifndef GD_CORE_POLYMORPHICCLONE_H
#define GD_CORE_POLYMORPHICCLONE_H
#pragma once

#include <memory>
#include <vector>
Expand All @@ -20,6 +19,15 @@ std::vector<std::unique_ptr<T>> Clone(
return copy;
}

} // namespace gd
template <class T>
std::map<gd::String, std::unique_ptr<T>>
Clone(const std::map<gd::String, std::unique_ptr<T>> &map) {
std::map<gd::String, std::unique_ptr<T>> copy;

for (const auto &it : map) {
copy[it.first] = gd::Clone(it.second);
}
return copy;
}

#endif
} // namespace gd
11 changes: 11 additions & 0 deletions Core/tests/BehaviorSerialization.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -140,6 +140,17 @@ TEST_CASE("BehaviorSerialization", "[common]") {
CheckBehaviorProperty(readProject.GetLayout("Scene").GetObjects());
}

SECTION("Copy constructor of Behavior") {
gd::Platform platform;
gd::Project originalProject;
SetupProject(originalProject, platform);
CheckBehaviorProperty(originalProject.GetLayout("Scene").GetObjects());

auto clonedProject = originalProject;

CheckBehaviorProperty(clonedProject.GetLayout("Scene").GetObjects());
}

SECTION("Load a project with a property value on a custom behavior that no longer exists") {
gd::Platform platform;
gd::Project writtenProject;
Expand Down
8 changes: 4 additions & 4 deletions Core/tests/DummyPlatform.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,8 @@ class BehaviorWithRequiredBehaviorProperty : public gd::Behavior {
const gd::String& name, const gd::String& type)
: Behavior(name, type) {};
virtual ~BehaviorWithRequiredBehaviorProperty(){};
virtual Behavior* Clone() const override {
return new BehaviorWithRequiredBehaviorProperty(*this);
virtual std::unique_ptr<gd::Behavior> Clone() const override {
return gd::make_unique<BehaviorWithRequiredBehaviorProperty>(*this);
}

virtual std::map<gd::String, gd::PropertyDescriptor> GetProperties(
Expand Down Expand Up @@ -74,8 +74,8 @@ class BehaviorWithRequiredBehaviorPropertyRequiringAnotherBehavior
const gd::String& name, const gd::String& type)
: Behavior(name, type) {};
virtual ~BehaviorWithRequiredBehaviorPropertyRequiringAnotherBehavior(){};
virtual Behavior* Clone() const override {
return new BehaviorWithRequiredBehaviorPropertyRequiringAnotherBehavior(
virtual std::unique_ptr<gd::Behavior> Clone() const override {
return gd::make_unique<BehaviorWithRequiredBehaviorPropertyRequiringAnotherBehavior>(
*this);
}

Expand Down
6 changes: 3 additions & 3 deletions Extensions/AnchorBehavior/AnchorBehavior.h
Original file line number Diff line number Diff line change
Expand Up @@ -36,15 +36,15 @@ class GD_EXTENSION_API AnchorBehavior : public gd::Behavior {

AnchorBehavior() {};
virtual ~AnchorBehavior(){};
virtual Behavior* Clone() const override { return new AnchorBehavior(*this); }
virtual std::unique_ptr<gd::Behavior> Clone() const override {
return gd::make_unique<AnchorBehavior>(*this);
}

#if defined(GD_IDE_ONLY)
virtual std::map<gd::String, gd::PropertyDescriptor> GetProperties(
const gd::SerializerElement& behaviorContent) const override;
virtual bool UpdateProperty(gd::SerializerElement& behaviorContent,
const gd::String& name,
const gd::String& value) override;
#endif

virtual void InitializeContent(
gd::SerializerElement& behaviorContent) override;
Expand Down
13 changes: 6 additions & 7 deletions Extensions/DestroyOutsideBehavior/DestroyOutsideBehavior.h
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,11 @@ Copyright (c) 2013-2016 Florian Rival (Florian.Rival@gmail.com)
This project is released under the MIT License.
*/

#ifndef DESTROYOUTSIDEBEHAVIOR_H
#define DESTROYOUTSIDEBEHAVIOR_H
#pragma once

#include "GDCore/Project/Behavior.h"
#include "GDCore/Project/Object.h"

class RuntimeScene;
namespace gd {
class SerializerElement;
Expand All @@ -21,18 +22,16 @@ class GD_EXTENSION_API DestroyOutsideBehavior : public gd::Behavior {
public:
DestroyOutsideBehavior(){};
virtual ~DestroyOutsideBehavior(){};
virtual Behavior* Clone() const override { return new DestroyOutsideBehavior(*this); }
virtual std::unique_ptr<gd::Behavior> Clone() const override {
return gd::make_unique<DestroyOutsideBehavior>(*this);
}

#if defined(GD_IDE_ONLY)
virtual std::map<gd::String, gd::PropertyDescriptor> GetProperties(
const gd::SerializerElement& behaviorContent) const override;
virtual bool UpdateProperty(gd::SerializerElement& behaviorContent,
const gd::String& name,
const gd::String& value) override;
#endif

virtual void InitializeContent(
gd::SerializerElement& behaviorContent) override;
};

#endif // DESTROYOUTSIDEBEHAVIOR_H
11 changes: 5 additions & 6 deletions Extensions/DraggableBehavior/DraggableBehavior.h
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,13 @@ Copyright (c) 2013-2016 Florian Rival (Florian.Rival@gmail.com)
This project is released under the MIT License.
*/

#ifndef DRAGGABLEBEHAVIOR_H
#define DRAGGABLEBEHAVIOR_H
#pragma once

#include "GDCore/Vector2.h"
#include <map>
#include "GDCore/Project/Behavior.h"
#include "GDCore/Project/Object.h"

class RuntimeScene;
namespace gd {
class SerializerElement;
Expand All @@ -24,8 +25,8 @@ class GD_EXTENSION_API DraggableBehavior : public gd::Behavior {
public:
DraggableBehavior();
virtual ~DraggableBehavior(){};
virtual Behavior* Clone() const override {
return new DraggableBehavior(*this);
virtual std::unique_ptr<gd::Behavior> Clone() const override {
return gd::make_unique<DraggableBehavior>(*this);
}

virtual std::map<gd::String, gd::PropertyDescriptor> GetProperties(
Expand All @@ -37,5 +38,3 @@ class GD_EXTENSION_API DraggableBehavior : public gd::Behavior {
virtual void InitializeContent(
gd::SerializerElement& behaviorContent) override;
};

#endif // DRAGGABLEBEHAVIOR_H
12 changes: 5 additions & 7 deletions Extensions/PathfindingBehavior/PathfindingBehavior.h
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,13 @@ Copyright (c) 2010-2016 Florian Rival (Florian.Rival@gmail.com)
This project is released under the MIT License.
*/

#ifndef PATHFINDINGBEHAVIOR_H
#define PATHFINDINGBEHAVIOR_H
#pragma once

#include "GDCore/Vector2.h"
#include <vector>
#include "GDCore/Project/Behavior.h"
#include "GDCore/Project/Object.h"

namespace gd {
class Layout;
}
Expand All @@ -29,17 +30,15 @@ class GD_EXTENSION_API PathfindingBehavior : public gd::Behavior {
public:
PathfindingBehavior(){};
virtual ~PathfindingBehavior(){};
virtual Behavior* Clone() const override {
return new PathfindingBehavior(*this);
virtual std::unique_ptr<gd::Behavior> Clone() const override {
return gd::make_unique<PathfindingBehavior>(*this);
}

#if defined(GD_IDE_ONLY)
virtual std::map<gd::String, gd::PropertyDescriptor> GetProperties(
const gd::SerializerElement& behaviorContent) const override;
virtual bool UpdateProperty(gd::SerializerElement& behaviorContent,
const gd::String& name,
const gd::String& value) override;
#endif

/**
* \brief Serialize the behavior
Expand All @@ -49,4 +48,3 @@ class GD_EXTENSION_API PathfindingBehavior : public gd::Behavior {

private:
};
#endif // PATHFINDINGBEHAVIOR_H
10 changes: 4 additions & 6 deletions Extensions/PathfindingBehavior/PathfindingObstacleBehavior.h
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@ Copyright (c) 2010-2016 Florian Rival (Florian.Rival@gmail.com)
This project is released under the MIT License.
*/

#ifndef PATHFINDINGOBSTACLEBEHAVIOR_H
#define PATHFINDINGOBSTACLEBEHAVIOR_H
#pragma once

#include <map>

#include "GDCore/Project/Behavior.h"
Expand All @@ -25,8 +25,8 @@ class GD_EXTENSION_API PathfindingObstacleBehavior : public gd::Behavior {
public:
PathfindingObstacleBehavior(){};
virtual ~PathfindingObstacleBehavior(){};
virtual Behavior* Clone() const override {
return new PathfindingObstacleBehavior(*this);
virtual std::unique_ptr<gd::Behavior> Clone() const override {
return gd::make_unique<PathfindingObstacleBehavior>(*this);
}

virtual std::map<gd::String, gd::PropertyDescriptor> GetProperties(
Expand All @@ -40,5 +40,3 @@ class GD_EXTENSION_API PathfindingObstacleBehavior : public gd::Behavior {

private:
};

#endif // PATHFINDINGOBSTACLEBEHAVIOR_H
13 changes: 5 additions & 8 deletions Extensions/PhysicsBehavior/PhysicsBehavior.h
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,15 @@ Copyright (c) 2010-2016 Florian Rival (Florian.Rival@gmail.com)
This project is released under the MIT License.
*/

#ifndef PHYSICBEHAVIOR_H
#define PHYSICBEHAVIOR_H
#pragma once

#include <map>
#include <set>
#include <vector>
#include "GDCore/Project/Behavior.h"
#include "GDCore/Project/Object.h"
#include "GDCore/Vector2.h"

namespace gd {
class Project;
class SerializerElement;
Expand All @@ -23,19 +23,18 @@ class GD_EXTENSION_API PhysicsBehavior : public gd::Behavior {
public:
PhysicsBehavior(){};
virtual ~PhysicsBehavior(){};
virtual Behavior *Clone() const override {
return new PhysicsBehavior(*this);
virtual std::unique_ptr<gd::Behavior> Clone() const override {
return gd::make_unique<PhysicsBehavior>(*this);
}

enum Positioning { OnOrigin = 0, OnCenter = 2 };

#if defined(GD_IDE_ONLY)
virtual std::map<gd::String, gd::PropertyDescriptor> GetProperties(
const gd::SerializerElement &behaviorContent) const override;
virtual bool UpdateProperty(gd::SerializerElement &behaviorContent,
const gd::String &name,
const gd::String &value) override;
#endif

/**
* Serialize the behavior
*/
Expand All @@ -52,5 +51,3 @@ class GD_EXTENSION_API PhysicsBehavior : public gd::Behavior {
CustomPolygon
} shapeType; ///< the kind of hitbox -> Box, Circle or CustomPolygon
};

#endif // PHYSICBEHAVIOR_H
Loading