Skip to content

Commit 1358126

Browse files
authored
Fix resources used in behavior configurations were not exported (#7941)
1 parent ac70684 commit 1358126

24 files changed

+90
-99
lines changed

Core/GDCore/Project/Behavior.h

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,11 @@
33
* Copyright 2008-2016 Florian Rival ([email protected]). All rights
44
* reserved. This project is released under the MIT License.
55
*/
6-
#ifndef GDCORE_BEHAVIOR_H
7-
#define GDCORE_BEHAVIOR_H
6+
#pragma once
87

98
#include "GDCore/String.h"
109
#include "GDCore/Project/BehaviorConfigurationContainer.h"
10+
#include "GDCore/Tools/MakeUnique.h"
1111

1212
namespace gd {
1313

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

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

4547
} // namespace gd
46-
47-
#endif // GDCORE_BEHAVIOR_H

Core/GDCore/Project/BehaviorConfigurationContainer.h

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -46,9 +46,6 @@ class GD_CORE_API BehaviorConfigurationContainer {
4646
quickCustomizationVisibility(QuickCustomization::Visibility::Default),
4747
propertiesQuickCustomizationVisibilities() {};
4848
virtual ~BehaviorConfigurationContainer();
49-
virtual BehaviorConfigurationContainer* Clone() const {
50-
return new BehaviorConfigurationContainer(*this);
51-
}
5249

5350
/**
5451
* \brief Return the name identifying the behavior

Core/GDCore/Project/BehaviorsSharedData.h

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,7 @@
44
* reserved. This project is released under the MIT License.
55
*/
66

7-
#ifndef GDCORE_BEHAVIORSSHAREDDATA_H
8-
#define GDCORE_BEHAVIORSSHAREDDATA_H
7+
#pragma once
98

109
#include "GDCore/String.h"
1110
#include "GDCore/Project/BehaviorConfigurationContainer.h"
@@ -27,9 +26,7 @@ class GD_CORE_API BehaviorsSharedData: public BehaviorConfigurationContainer {
2726
BehaviorsSharedData(const gd::String& name_, const gd::String& type_)
2827
: BehaviorConfigurationContainer(name_, type_) {};
2928
virtual ~BehaviorsSharedData();
30-
virtual BehaviorsSharedData* Clone() const override { return new BehaviorsSharedData(*this); }
29+
virtual BehaviorsSharedData* Clone() const { return new BehaviorsSharedData(*this); }
3130
};
3231

3332
} // namespace gd
34-
35-
#endif // GDCORE_BEHAVIORSSHAREDDATA_H

Core/GDCore/Project/CustomBehavior.cpp

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,9 +17,8 @@
1717

1818
using namespace gd;
1919

20-
CustomBehavior *CustomBehavior::Clone() const {
21-
CustomBehavior *clone = new CustomBehavior(*this);
22-
return clone;
20+
std::unique_ptr<gd::Behavior> CustomBehavior::Clone() const {
21+
return gd::make_unique<gd::CustomBehavior>(*this);
2322
}
2423

2524
void CustomBehavior::InitializeContent(gd::SerializerElement &behaviorContent) {

Core/GDCore/Project/CustomBehavior.h

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,7 @@
33
* Copyright 2008-2016 Florian Rival ([email protected]). All rights
44
* reserved. This project is released under the MIT License.
55
*/
6-
#ifndef GDCORE_CUSTOMBEHAVIOR_H
7-
#define GDCORE_CUSTOMBEHAVIOR_H
6+
#pragma once
87

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

3130
using Behavior::GetProperties;
3231
using Behavior::InitializeContent;
@@ -44,5 +43,3 @@ class CustomBehavior : public gd::Behavior {
4443
///< EventBasedBehavior from the fullType.
4544
};
4645
} // namespace gd
47-
48-
#endif // GDCORE_CUSTOMBEHAVIOR_H

Core/GDCore/Project/Object.cpp

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -51,11 +51,7 @@ void Object::CopyWithoutConfiguration(const gd::Object& object) {
5151
assetStoreId = object.assetStoreId;
5252
objectVariables = object.objectVariables;
5353
effectsContainer = object.effectsContainer;
54-
55-
behaviors.clear();
56-
for (auto& it : object.behaviors) {
57-
behaviors[it.first] = gd::make_unique<gd::Behavior>(*it.second);
58-
}
54+
behaviors = gd::Clone(object.behaviors);
5955
}
6056

6157
gd::ObjectConfiguration& Object::GetConfiguration() { return *configuration; }

Core/GDCore/Tools/PolymorphicClone.h

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
1-
#ifndef GD_CORE_POLYMORPHICCLONE_H
2-
#define GD_CORE_POLYMORPHICCLONE_H
1+
#pragma once
32

43
#include <memory>
54
#include <vector>
@@ -20,6 +19,15 @@ std::vector<std::unique_ptr<T>> Clone(
2019
return copy;
2120
}
2221

23-
} // namespace gd
22+
template <class T>
23+
std::map<gd::String, std::unique_ptr<T>>
24+
Clone(const std::map<gd::String, std::unique_ptr<T>> &map) {
25+
std::map<gd::String, std::unique_ptr<T>> copy;
26+
27+
for (const auto &it : map) {
28+
copy[it.first] = gd::Clone(it.second);
29+
}
30+
return copy;
31+
}
2432

25-
#endif
33+
} // namespace gd

Core/tests/BehaviorSerialization.cpp

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -140,6 +140,17 @@ TEST_CASE("BehaviorSerialization", "[common]") {
140140
CheckBehaviorProperty(readProject.GetLayout("Scene").GetObjects());
141141
}
142142

143+
SECTION("Copy constructor of Behavior") {
144+
gd::Platform platform;
145+
gd::Project originalProject;
146+
SetupProject(originalProject, platform);
147+
CheckBehaviorProperty(originalProject.GetLayout("Scene").GetObjects());
148+
149+
auto clonedProject = originalProject;
150+
151+
CheckBehaviorProperty(clonedProject.GetLayout("Scene").GetObjects());
152+
}
153+
143154
SECTION("Load a project with a property value on a custom behavior that no longer exists") {
144155
gd::Platform platform;
145156
gd::Project writtenProject;

Core/tests/DummyPlatform.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -26,8 +26,8 @@ class BehaviorWithRequiredBehaviorProperty : public gd::Behavior {
2626
const gd::String& name, const gd::String& type)
2727
: Behavior(name, type) {};
2828
virtual ~BehaviorWithRequiredBehaviorProperty(){};
29-
virtual Behavior* Clone() const override {
30-
return new BehaviorWithRequiredBehaviorProperty(*this);
29+
virtual std::unique_ptr<gd::Behavior> Clone() const override {
30+
return gd::make_unique<BehaviorWithRequiredBehaviorProperty>(*this);
3131
}
3232

3333
virtual std::map<gd::String, gd::PropertyDescriptor> GetProperties(
@@ -74,8 +74,8 @@ class BehaviorWithRequiredBehaviorPropertyRequiringAnotherBehavior
7474
const gd::String& name, const gd::String& type)
7575
: Behavior(name, type) {};
7676
virtual ~BehaviorWithRequiredBehaviorPropertyRequiringAnotherBehavior(){};
77-
virtual Behavior* Clone() const override {
78-
return new BehaviorWithRequiredBehaviorPropertyRequiringAnotherBehavior(
77+
virtual std::unique_ptr<gd::Behavior> Clone() const override {
78+
return gd::make_unique<BehaviorWithRequiredBehaviorPropertyRequiringAnotherBehavior>(
7979
*this);
8080
}
8181

Extensions/AnchorBehavior/AnchorBehavior.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -36,15 +36,15 @@ class GD_EXTENSION_API AnchorBehavior : public gd::Behavior {
3636

3737
AnchorBehavior() {};
3838
virtual ~AnchorBehavior(){};
39-
virtual Behavior* Clone() const override { return new AnchorBehavior(*this); }
39+
virtual std::unique_ptr<gd::Behavior> Clone() const override {
40+
return gd::make_unique<AnchorBehavior>(*this);
41+
}
4042

41-
#if defined(GD_IDE_ONLY)
4243
virtual std::map<gd::String, gd::PropertyDescriptor> GetProperties(
4344
const gd::SerializerElement& behaviorContent) const override;
4445
virtual bool UpdateProperty(gd::SerializerElement& behaviorContent,
4546
const gd::String& name,
4647
const gd::String& value) override;
47-
#endif
4848

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

0 commit comments

Comments
 (0)