Skip to content

Commit 30e8756

Browse files
committed
Allow to events use resources parameters and properties
1 parent 4d4b86a commit 30e8756

File tree

113 files changed

+2538
-1861
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

113 files changed

+2538
-1861
lines changed

Core/GDCore/Events/CodeGeneration/EventsCodeGenerator.cpp

Lines changed: 23 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -898,22 +898,29 @@ gd::String EventsCodeGenerator::GenerateParameterCodes(
898898
argOutput = GenerateGetBehaviorNameCode(parameter.GetPlainString());
899899
} else if (metadata.GetType() == "key") {
900900
argOutput = "\"" + ConvertToString(parameter.GetPlainString()) + "\"";
901-
} else if (metadata.GetType() == "audioResource" ||
902-
metadata.GetType() == "bitmapFontResource" ||
903-
metadata.GetType() == "fontResource" ||
904-
metadata.GetType() == "imageResource" ||
905-
metadata.GetType() == "jsonResource" ||
906-
metadata.GetType() == "tilemapResource" ||
907-
metadata.GetType() == "tilesetResource" ||
908-
metadata.GetType() == "videoResource" ||
909-
metadata.GetType() == "model3DResource" ||
910-
metadata.GetType() == "atlasResource" ||
911-
metadata.GetType() == "spineResource" ||
912-
// Deprecated, old parameter names:
913-
metadata.GetType() == "password" ||
914-
metadata.GetType() == "musicfile" ||
915-
metadata.GetType() == "soundfile") {
916-
argOutput = "\"" + ConvertToString(parameter.GetPlainString()) + "\"";
901+
} else if (ParameterMetadata::IsExpression("resource", metadata.GetType())) {
902+
const auto &resourceName = parameter.GetPlainString();
903+
const auto &resourcesContainersList =
904+
GetProjectScopedContainers().GetResourcesContainersList();
905+
const auto sourceType =
906+
resourcesContainersList.GetResourcesContainerSourceType(resourceName);
907+
if (sourceType == ResourcesContainer::SourceType::Properties) {
908+
const auto& propertiesContainersList =
909+
GetProjectScopedContainers().GetPropertiesContainersList();
910+
const auto& propertiesContainerAndProperty =
911+
propertiesContainersList.Get(resourceName);
912+
argOutput = GeneratePropertyGetterWithoutCasting(
913+
propertiesContainerAndProperty.first,
914+
propertiesContainerAndProperty.second);
915+
} else if (sourceType == ResourcesContainer::SourceType::Parameters) {
916+
const auto& parametersVectorsList =
917+
GetProjectScopedContainers().GetParametersVectorsList();
918+
const auto& parameter =
919+
gd::ParameterMetadataTools::Get(parametersVectorsList, resourceName);
920+
argOutput = GenerateParameterGetterWithoutCasting(parameter);
921+
} else {
922+
argOutput = "\"" + ConvertToString(resourceName) + "\"";
923+
}
917924
} else if (metadata.GetType() == "mouse") {
918925
argOutput = "\"" + ConvertToString(parameter.GetPlainString()) + "\"";
919926
} else if (metadata.GetType() == "yesorno") {

Core/GDCore/Extensions/Metadata/ValueTypeMetadata.cpp

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77

88
#include "GDCore/CommonTools.h"
99
#include "GDCore/Serialization/SerializerElement.h"
10+
#include "GDCore/Project/ResourcesContainer.h"
1011

1112
namespace gd {
1213

@@ -72,6 +73,46 @@ ValueTypeMetadata::GetPrimitiveValueType(const gd::String &parameterType) {
7273
return parameterType;
7374
}
7475

76+
const gd::String &
77+
ValueTypeMetadata::GetResourceType(const gd::String &parameterType) {
78+
if (parameterType == "fontResource") {
79+
return gd::Resource::fontType;
80+
}
81+
if (parameterType == "audioResource" ||
82+
// Deprecated, old parameter types:
83+
parameterType == "soundfile" || parameterType == "musicfile") {
84+
return gd::Resource::audioType;
85+
}
86+
if (parameterType == "videoResource") {
87+
return gd::Resource::videoType;
88+
}
89+
if (parameterType == "bitmapFontResource") {
90+
return gd::Resource::bitmapType;
91+
}
92+
if (parameterType == "imageResource") {
93+
return gd::Resource::imageType;
94+
}
95+
if (parameterType == "jsonResource") {
96+
return gd::Resource::jsonType;
97+
}
98+
if (parameterType == "tilemapResource") {
99+
return gd::Resource::tileMapType;
100+
}
101+
if (parameterType == "tilesetResource") {
102+
return gd::Resource::tileSetType;
103+
}
104+
if (parameterType == "model3DResource") {
105+
return gd::Resource::model3DType;
106+
}
107+
if (parameterType == "atlasResource") {
108+
return gd::Resource::atlasType;
109+
}
110+
if (parameterType == "spineResource") {
111+
return gd::Resource::spineType;
112+
}
113+
return parameterType;
114+
}
115+
75116
const gd::String ValueTypeMetadata::numberValueType = "number";
76117
const gd::String ValueTypeMetadata::booleanValueType = "boolean";
77118
const gd::String ValueTypeMetadata::stringValueType = "string";

Core/GDCore/Extensions/Metadata/ValueTypeMetadata.h

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -197,6 +197,13 @@ class GD_CORE_API ValueTypeMetadata {
197197
return parameterType == "behavior";
198198
}
199199

200+
/**
201+
* \brief Return true if the type is a resource.
202+
*/
203+
bool IsResource() const {
204+
return gd::ValueTypeMetadata::IsTypeValue("resource", name);
205+
}
206+
200207
/**
201208
* \brief Return true if the type is an expression of the given type from the
202209
* caller point of view.
@@ -253,7 +260,8 @@ class GD_CORE_API ValueTypeMetadata {
253260
parameterType == "spineResource" ||
254261
// Deprecated, old parameter types:
255262
parameterType == "soundfile" ||
256-
parameterType == "musicfile";
263+
parameterType == "musicfile" ||
264+
parameterType == "password";
257265
}
258266
return false;
259267
}
@@ -306,6 +314,12 @@ class GD_CORE_API ValueTypeMetadata {
306314
*/
307315
static const gd::String &ConvertPropertyTypeToValueType(const gd::String &propertyType);
308316

317+
/**
318+
* \brief Return the resource type for a parameter type.
319+
* \see gd::Resource
320+
*/
321+
static const gd::String &GetResourceType(const gd::String &parameterType);
322+
309323
/** \name Serialization
310324
*/
311325
///@{

Core/GDCore/IDE/Events/EventsParameterReplacer.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -233,7 +233,7 @@ bool EventsParameterReplacer::DoVisitEventExpression(
233233
bool EventsParameterReplacer::CanContainParameter(
234234
const gd::ValueTypeMetadata &valueTypeMetadata) {
235235
return valueTypeMetadata.IsVariable() || valueTypeMetadata.IsNumber() ||
236-
valueTypeMetadata.IsString();
236+
valueTypeMetadata.IsString() || valueTypeMetadata.IsResource();
237237
}
238238

239239
EventsParameterReplacer::~EventsParameterReplacer() {}

Core/GDCore/IDE/Events/EventsPropertyReplacer.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -272,7 +272,7 @@ bool EventsPropertyReplacer::DoVisitEventExpression(
272272
bool EventsPropertyReplacer::CanContainProperty(
273273
const gd::ValueTypeMetadata &valueTypeMetadata) {
274274
return valueTypeMetadata.IsVariable() || valueTypeMetadata.IsNumber() ||
275-
valueTypeMetadata.IsString();
275+
valueTypeMetadata.IsString() || valueTypeMetadata.IsResource();
276276
}
277277

278278
EventsPropertyReplacer::~EventsPropertyReplacer() {}

Core/GDCore/IDE/EventsFunctionTools.cpp

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
#include "GDCore/Project/ObjectsContainer.h"
1313
#include "GDCore/Project/ParameterMetadataContainer.h"
1414
#include "GDCore/Project/PropertiesContainer.h"
15+
#include "GDCore/Project/ResourcesContainer.h"
1516
#include "GDCore/Project/VariablesContainer.h"
1617
#include "GDCore/Project/EventsFunction.h"
1718
#include "GDCore/Project/Object.h"
@@ -171,4 +172,56 @@ void EventsFunctionTools::PropertiesToVariablesContainer(
171172
}
172173
}
173174

175+
void EventsFunctionTools::ParametersToResourcesContainer(
176+
const ParameterMetadataContainer &parameters,
177+
gd::ResourcesContainer &outputResourcesContainer) {
178+
if (outputResourcesContainer.GetSourceType() !=
179+
gd::ResourcesContainer::SourceType::Parameters) {
180+
throw std::logic_error("Tried to generate a resources container from "
181+
"parameters with the wrong source type.");
182+
}
183+
outputResourcesContainer.Clear();
184+
185+
gd::String lastObjectName;
186+
for (std::size_t i = 0; i < parameters.GetParametersCount(); ++i) {
187+
const auto &parameter = parameters.GetParameter(i);
188+
if (parameter.GetName().empty())
189+
continue;
190+
191+
auto &valueTypeMetadata = parameter.GetValueTypeMetadata();
192+
if (valueTypeMetadata.IsResource()) {
193+
outputResourcesContainer.AddResource(
194+
parameter.GetName(), "",
195+
gd::ValueTypeMetadata::GetResourceType(valueTypeMetadata.GetName()));
196+
}
197+
}
198+
}
199+
200+
void EventsFunctionTools::PropertiesToResourcesContainer(
201+
const PropertiesContainer &properties,
202+
gd::ResourcesContainer &outputResourcesContainer) {
203+
if (outputResourcesContainer.GetSourceType() !=
204+
gd::ResourcesContainer::SourceType::Properties) {
205+
throw std::logic_error("Tried to generate a resources container from "
206+
"properties with the wrong source type.");
207+
}
208+
outputResourcesContainer.Clear();
209+
210+
gd::String lastObjectName;
211+
for (std::size_t i = 0; i < properties.GetCount(); ++i) {
212+
const auto &property = properties.Get(i);
213+
if (property.GetName().empty()) {
214+
continue;
215+
}
216+
auto &extraInfos = property.GetExtraInfo();
217+
if (extraInfos.size() == 0) {
218+
continue;
219+
}
220+
if (property.GetType() == "Resource") {
221+
outputResourcesContainer.AddResource(property.GetName(), "",
222+
extraInfos[0]);
223+
}
224+
}
225+
}
226+
174227
} // namespace gd

Core/GDCore/IDE/EventsFunctionTools.h

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ class EventsFunctionsContainer;
1414
class ObjectsContainer;
1515
class ParameterMetadataContainer;
1616
class PropertiesContainer;
17+
class ResourcesContainer;
1718
class VariablesContainer;
1819
class ParameterMetadata;
1920
class EventsFunction;
@@ -79,5 +80,13 @@ class GD_CORE_API EventsFunctionTools {
7980
static void PropertiesToVariablesContainer(
8081
const PropertiesContainer &properties,
8182
gd::VariablesContainer &outputVariablesContainer);
83+
84+
static void ParametersToResourcesContainer(
85+
const ParameterMetadataContainer &parameters,
86+
gd::ResourcesContainer &outputResourcesContainer);
87+
88+
static void PropertiesToResourcesContainer(
89+
const PropertiesContainer &properties,
90+
gd::ResourcesContainer &outputResourcesContainer);
8291
};
8392
} // namespace gd

Core/GDCore/IDE/Project/ArbitraryResourceWorker.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818
#include "GDCore/Extensions/Platform.h"
1919
#include "GDCore/Extensions/PlatformExtension.h"
2020
#include "GDCore/Project/Project.h"
21-
#include "GDCore/Project/ResourcesManager.h"
21+
#include "GDCore/Project/ResourcesContainer.h"
2222
#include "GDCore/Project/Effect.h"
2323
#include "GDCore/Tools/Log.h"
2424
#include "GDCore/IDE/ResourceExposer.h"

Core/GDCore/IDE/Project/ArbitraryResourceWorker.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ namespace gd {
2525
class Resource;
2626
}
2727
namespace gd {
28-
class ResourcesManager;
28+
class ResourcesContainer;
2929
}
3030

3131
namespace gd {
@@ -43,7 +43,7 @@ namespace gd {
4343
*/
4444
class GD_CORE_API ArbitraryResourceWorker {
4545
public:
46-
ArbitraryResourceWorker(gd::ResourcesManager &resourcesManager_)
46+
ArbitraryResourceWorker(gd::ResourcesContainer &resourcesManager_)
4747
: resourcesManager(&resourcesManager_){};
4848
virtual ~ArbitraryResourceWorker();
4949

@@ -139,7 +139,7 @@ class GD_CORE_API ArbitraryResourceWorker {
139139
virtual void ExposeEmbeddeds(gd::String &resourceName);
140140

141141
protected:
142-
gd::ResourcesManager * resourcesManager;
142+
gd::ResourcesContainer * resourcesManager;
143143

144144
private:
145145
/**

Core/GDCore/IDE/Project/AssetResourcePathCleaner.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66

77
#include "AssetResourcePathCleaner.h"
88
#include "GDCore/Project/Project.h"
9-
#include "GDCore/Project/ResourcesManager.h"
9+
#include "GDCore/Project/ResourcesContainer.h"
1010
#include "GDCore/String.h"
1111

1212
namespace gd {

0 commit comments

Comments
 (0)