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
39 changes: 23 additions & 16 deletions Core/GDCore/Events/CodeGeneration/EventsCodeGenerator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -898,22 +898,29 @@ gd::String EventsCodeGenerator::GenerateParameterCodes(
argOutput = GenerateGetBehaviorNameCode(parameter.GetPlainString());
} else if (metadata.GetType() == "key") {
argOutput = "\"" + ConvertToString(parameter.GetPlainString()) + "\"";
} else if (metadata.GetType() == "audioResource" ||
metadata.GetType() == "bitmapFontResource" ||
metadata.GetType() == "fontResource" ||
metadata.GetType() == "imageResource" ||
metadata.GetType() == "jsonResource" ||
metadata.GetType() == "tilemapResource" ||
metadata.GetType() == "tilesetResource" ||
metadata.GetType() == "videoResource" ||
metadata.GetType() == "model3DResource" ||
metadata.GetType() == "atlasResource" ||
metadata.GetType() == "spineResource" ||
// Deprecated, old parameter names:
metadata.GetType() == "password" ||
metadata.GetType() == "musicfile" ||
metadata.GetType() == "soundfile") {
argOutput = "\"" + ConvertToString(parameter.GetPlainString()) + "\"";
} else if (ParameterMetadata::IsExpression("resource", metadata.GetType())) {
const auto &resourceName = parameter.GetPlainString();
const auto &resourcesContainersList =
GetProjectScopedContainers().GetResourcesContainersList();
const auto sourceType =
resourcesContainersList.GetResourcesContainerSourceType(resourceName);
if (sourceType == ResourcesContainer::SourceType::Properties) {
const auto& propertiesContainersList =
GetProjectScopedContainers().GetPropertiesContainersList();
const auto& propertiesContainerAndProperty =
propertiesContainersList.Get(resourceName);
argOutput = GeneratePropertyGetterWithoutCasting(
propertiesContainerAndProperty.first,
propertiesContainerAndProperty.second);
} else if (sourceType == ResourcesContainer::SourceType::Parameters) {
const auto& parametersVectorsList =
GetProjectScopedContainers().GetParametersVectorsList();
const auto& parameter =
gd::ParameterMetadataTools::Get(parametersVectorsList, resourceName);
argOutput = GenerateParameterGetterWithoutCasting(parameter);
} else {
argOutput = "\"" + ConvertToString(resourceName) + "\"";
}
} else if (metadata.GetType() == "mouse") {
argOutput = "\"" + ConvertToString(parameter.GetPlainString()) + "\"";
} else if (metadata.GetType() == "yesorno") {
Expand Down
41 changes: 41 additions & 0 deletions Core/GDCore/Extensions/Metadata/ValueTypeMetadata.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@

#include "GDCore/CommonTools.h"
#include "GDCore/Serialization/SerializerElement.h"
#include "GDCore/Project/ResourcesContainer.h"

namespace gd {

Expand Down Expand Up @@ -72,6 +73,46 @@ ValueTypeMetadata::GetPrimitiveValueType(const gd::String &parameterType) {
return parameterType;
}

const gd::String &
ValueTypeMetadata::GetResourceType(const gd::String &parameterType) {
if (parameterType == "fontResource") {
return gd::Resource::fontType;
}
if (parameterType == "audioResource" ||
// Deprecated, old parameter types:
parameterType == "soundfile" || parameterType == "musicfile") {
return gd::Resource::audioType;
}
if (parameterType == "videoResource") {
return gd::Resource::videoType;
}
if (parameterType == "bitmapFontResource") {
return gd::Resource::bitmapType;
}
if (parameterType == "imageResource") {
return gd::Resource::imageType;
}
if (parameterType == "jsonResource") {
return gd::Resource::jsonType;
}
if (parameterType == "tilemapResource") {
return gd::Resource::tileMapType;
}
if (parameterType == "tilesetResource") {
return gd::Resource::tileSetType;
}
if (parameterType == "model3DResource") {
return gd::Resource::model3DType;
}
if (parameterType == "atlasResource") {
return gd::Resource::atlasType;
}
if (parameterType == "spineResource") {
return gd::Resource::spineType;
}
return parameterType;
}

const gd::String ValueTypeMetadata::numberValueType = "number";
const gd::String ValueTypeMetadata::booleanValueType = "boolean";
const gd::String ValueTypeMetadata::stringValueType = "string";
Expand Down
16 changes: 15 additions & 1 deletion Core/GDCore/Extensions/Metadata/ValueTypeMetadata.h
Original file line number Diff line number Diff line change
Expand Up @@ -197,6 +197,13 @@ class GD_CORE_API ValueTypeMetadata {
return parameterType == "behavior";
}

/**
* \brief Return true if the type is a resource.
*/
bool IsResource() const {
return gd::ValueTypeMetadata::IsTypeValue("resource", name);
}

/**
* \brief Return true if the type is an expression of the given type from the
* caller point of view.
Expand Down Expand Up @@ -253,7 +260,8 @@ class GD_CORE_API ValueTypeMetadata {
parameterType == "spineResource" ||
// Deprecated, old parameter types:
parameterType == "soundfile" ||
parameterType == "musicfile";
parameterType == "musicfile" ||
parameterType == "password";
}
return false;
}
Expand Down Expand Up @@ -306,6 +314,12 @@ class GD_CORE_API ValueTypeMetadata {
*/
static const gd::String &ConvertPropertyTypeToValueType(const gd::String &propertyType);

/**
* \brief Return the resource type for a parameter type.
* \see gd::Resource
*/
static const gd::String &GetResourceType(const gd::String &parameterType);

/** \name Serialization
*/
///@{
Expand Down
2 changes: 1 addition & 1 deletion Core/GDCore/IDE/Events/EventsParameterReplacer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -233,7 +233,7 @@ bool EventsParameterReplacer::DoVisitEventExpression(
bool EventsParameterReplacer::CanContainParameter(
const gd::ValueTypeMetadata &valueTypeMetadata) {
return valueTypeMetadata.IsVariable() || valueTypeMetadata.IsNumber() ||
valueTypeMetadata.IsString();
valueTypeMetadata.IsString() || valueTypeMetadata.IsResource();
}

EventsParameterReplacer::~EventsParameterReplacer() {}
Expand Down
2 changes: 1 addition & 1 deletion Core/GDCore/IDE/Events/EventsPropertyReplacer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -272,7 +272,7 @@ bool EventsPropertyReplacer::DoVisitEventExpression(
bool EventsPropertyReplacer::CanContainProperty(
const gd::ValueTypeMetadata &valueTypeMetadata) {
return valueTypeMetadata.IsVariable() || valueTypeMetadata.IsNumber() ||
valueTypeMetadata.IsString();
valueTypeMetadata.IsString() || valueTypeMetadata.IsResource();
}

EventsPropertyReplacer::~EventsPropertyReplacer() {}
Expand Down
53 changes: 53 additions & 0 deletions Core/GDCore/IDE/EventsFunctionTools.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
#include "GDCore/Project/ObjectsContainer.h"
#include "GDCore/Project/ParameterMetadataContainer.h"
#include "GDCore/Project/PropertiesContainer.h"
#include "GDCore/Project/ResourcesContainer.h"
#include "GDCore/Project/VariablesContainer.h"
#include "GDCore/Project/EventsFunction.h"
#include "GDCore/Project/Object.h"
Expand Down Expand Up @@ -171,4 +172,56 @@ void EventsFunctionTools::PropertiesToVariablesContainer(
}
}

void EventsFunctionTools::ParametersToResourcesContainer(
const ParameterMetadataContainer &parameters,
gd::ResourcesContainer &outputResourcesContainer) {
if (outputResourcesContainer.GetSourceType() !=
gd::ResourcesContainer::SourceType::Parameters) {
throw std::logic_error("Tried to generate a resources container from "
"parameters with the wrong source type.");
}
outputResourcesContainer.Clear();

gd::String lastObjectName;
for (std::size_t i = 0; i < parameters.GetParametersCount(); ++i) {
const auto &parameter = parameters.GetParameter(i);
if (parameter.GetName().empty())
continue;

auto &valueTypeMetadata = parameter.GetValueTypeMetadata();
if (valueTypeMetadata.IsResource()) {
outputResourcesContainer.AddResource(
parameter.GetName(), "",
gd::ValueTypeMetadata::GetResourceType(valueTypeMetadata.GetName()));
}
}
}

void EventsFunctionTools::PropertiesToResourcesContainer(
const PropertiesContainer &properties,
gd::ResourcesContainer &outputResourcesContainer) {
if (outputResourcesContainer.GetSourceType() !=
gd::ResourcesContainer::SourceType::Properties) {
throw std::logic_error("Tried to generate a resources container from "
"properties with the wrong source type.");
}
outputResourcesContainer.Clear();

gd::String lastObjectName;
for (std::size_t i = 0; i < properties.GetCount(); ++i) {
const auto &property = properties.Get(i);
if (property.GetName().empty()) {
continue;
}
auto &extraInfos = property.GetExtraInfo();
if (extraInfos.size() == 0) {
continue;
}
if (property.GetType() == "Resource") {
outputResourcesContainer.AddResource(property.GetName(), "",
extraInfos[0]);
}
}
}

} // namespace gd
9 changes: 9 additions & 0 deletions Core/GDCore/IDE/EventsFunctionTools.h
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ class EventsFunctionsContainer;
class ObjectsContainer;
class ParameterMetadataContainer;
class PropertiesContainer;
class ResourcesContainer;
class VariablesContainer;
class ParameterMetadata;
class EventsFunction;
Expand Down Expand Up @@ -79,5 +80,13 @@ class GD_CORE_API EventsFunctionTools {
static void PropertiesToVariablesContainer(
const PropertiesContainer &properties,
gd::VariablesContainer &outputVariablesContainer);

static void ParametersToResourcesContainer(
const ParameterMetadataContainer &parameters,
gd::ResourcesContainer &outputResourcesContainer);

static void PropertiesToResourcesContainer(
const PropertiesContainer &properties,
gd::ResourcesContainer &outputResourcesContainer);
};
} // namespace gd
2 changes: 1 addition & 1 deletion Core/GDCore/IDE/Project/ArbitraryResourceWorker.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
#include "GDCore/Extensions/Platform.h"
#include "GDCore/Extensions/PlatformExtension.h"
#include "GDCore/Project/Project.h"
#include "GDCore/Project/ResourcesManager.h"
#include "GDCore/Project/ResourcesContainer.h"
#include "GDCore/Project/Effect.h"
#include "GDCore/Tools/Log.h"
#include "GDCore/IDE/ResourceExposer.h"
Expand Down
6 changes: 3 additions & 3 deletions Core/GDCore/IDE/Project/ArbitraryResourceWorker.h
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ namespace gd {
class Resource;
}
namespace gd {
class ResourcesManager;
class ResourcesContainer;
}

namespace gd {
Expand All @@ -43,7 +43,7 @@ namespace gd {
*/
class GD_CORE_API ArbitraryResourceWorker {
public:
ArbitraryResourceWorker(gd::ResourcesManager &resourcesManager_)
ArbitraryResourceWorker(gd::ResourcesContainer &resourcesManager_)
: resourcesManager(&resourcesManager_){};
virtual ~ArbitraryResourceWorker();

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

protected:
gd::ResourcesManager * resourcesManager;
gd::ResourcesContainer * resourcesManager;

private:
/**
Expand Down
2 changes: 1 addition & 1 deletion Core/GDCore/IDE/Project/AssetResourcePathCleaner.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

#include "AssetResourcePathCleaner.h"
#include "GDCore/Project/Project.h"
#include "GDCore/Project/ResourcesManager.h"
#include "GDCore/Project/ResourcesContainer.h"
#include "GDCore/String.h"

namespace gd {
Expand Down
2 changes: 1 addition & 1 deletion Core/GDCore/IDE/Project/AssetResourcePathCleaner.h
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ namespace gd {
class GD_CORE_API AssetResourcePathCleaner : public ArbitraryResourceWorker {
public:
AssetResourcePathCleaner(
gd::ResourcesManager &resourcesManager,
gd::ResourcesContainer &resourcesManager,
std::map<gd::String, gd::String> &resourcesFileNameMap_,
std::map<gd::String, gd::String> &resourcesNameReverseMap_)
: ArbitraryResourceWorker(resourcesManager),
Expand Down
6 changes: 3 additions & 3 deletions Core/GDCore/IDE/Project/ObjectsUsingResourceCollector.h
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ namespace gd {
class GD_CORE_API ObjectsUsingResourceCollector
: public ArbitraryObjectsWorker {
public:
ObjectsUsingResourceCollector(gd::ResourcesManager &resourcesManager_,
ObjectsUsingResourceCollector(gd::ResourcesContainer &resourcesManager_,
const gd::String &resourceName_)
: resourcesManager(&resourcesManager_), resourceName(resourceName_){};
virtual ~ObjectsUsingResourceCollector();
Expand All @@ -33,12 +33,12 @@ class GD_CORE_API ObjectsUsingResourceCollector

std::vector<gd::String> objectNames;
gd::String resourceName;
gd::ResourcesManager *resourcesManager;
gd::ResourcesContainer *resourcesManager;
};

class GD_CORE_API ResourceNameMatcher : public ArbitraryResourceWorker {
public:
ResourceNameMatcher(gd::ResourcesManager &resourcesManager,
ResourceNameMatcher(gd::ResourcesContainer &resourcesManager,
const gd::String &resourceName_)
: resourceName(resourceName_),
matchesResourceName(false), gd::ArbitraryResourceWorker(
Expand Down
2 changes: 1 addition & 1 deletion Core/GDCore/IDE/Project/ResourcesAbsolutePathChecker.h
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ namespace gd {
class GD_CORE_API ResourcesAbsolutePathChecker
: public ArbitraryResourceWorker {
public:
ResourcesAbsolutePathChecker(gd::ResourcesManager &resourcesManager,
ResourcesAbsolutePathChecker(gd::ResourcesContainer &resourcesManager,
AbstractFileSystem &fileSystem)
: ArbitraryResourceWorker(resourcesManager), hasAbsoluteFilenames(false),
fs(fileSystem){};
Expand Down
2 changes: 1 addition & 1 deletion Core/GDCore/IDE/Project/ResourcesInUseHelper.h
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ std::set<gd::String> & usedImages = resourcesInUse.GetAllImages();
*/
class ResourcesInUseHelper : public gd::ArbitraryResourceWorker {
public:
ResourcesInUseHelper(gd::ResourcesManager &resourcesManager)
ResourcesInUseHelper(gd::ResourcesContainer &resourcesManager)
: gd::ArbitraryResourceWorker(resourcesManager){};
virtual ~ResourcesInUseHelper(){};

Expand Down
7 changes: 2 additions & 5 deletions Core/GDCore/IDE/Project/ResourcesMergingHelper.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 RESOURCESMERGINGHELPER_H
#define RESOURCESMERGINGHELPER_H
#pragma once

#include <map>
#include <memory>
Expand All @@ -29,7 +28,7 @@ namespace gd {
*/
class GD_CORE_API ResourcesMergingHelper : public ArbitraryResourceWorker {
public:
ResourcesMergingHelper(gd::ResourcesManager &resourcesManager,
ResourcesMergingHelper(gd::ResourcesContainer &resourcesManager,
gd::AbstractFileSystem &fileSystem)
: ArbitraryResourceWorker(resourcesManager),
preserveDirectoriesStructure(false), preserveAbsoluteFilenames(false),
Expand Down Expand Up @@ -98,5 +97,3 @@ class GD_CORE_API ResourcesMergingHelper : public ArbitraryResourceWorker {
};

} // namespace gd

#endif // RESOURCESMERGINGHELPER_H
2 changes: 1 addition & 1 deletion Core/GDCore/IDE/Project/ResourcesRenamer.h
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ class ResourcesRenamer : public gd::ArbitraryResourceWorker {
* @param oldToNewNames_ A map associating to a resource name the new name to
* use.
*/
ResourcesRenamer(gd::ResourcesManager &resourcesManager,
ResourcesRenamer(gd::ResourcesContainer &resourcesManager,
const std::map<gd::String, gd::String> &oldToNewNames_)
: gd::ArbitraryResourceWorker(resourcesManager),
oldToNewNames(oldToNewNames_){};
Expand Down
4 changes: 3 additions & 1 deletion Core/GDCore/IDE/Project/SceneResourcesFinder.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,9 @@ std::set<gd::String> SceneResourcesFinder::FindSceneResources(gd::Project &proje
}

void SceneResourcesFinder::AddUsedResource(gd::String &resourceName) {
if (resourceName.empty()) {
if (resourceName.empty() ||
// It avoids to list resource parameters and properties.
!resourcesManager->HasResource(resourceName)) {
return;
}
resourceNames.insert(resourceName);
Expand Down
2 changes: 1 addition & 1 deletion Core/GDCore/IDE/Project/SceneResourcesFinder.h
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ class SceneResourcesFinder : private gd::ArbitraryResourceWorker {
virtual ~SceneResourcesFinder(){};

private:
SceneResourcesFinder(gd::ResourcesManager &resourcesManager)
SceneResourcesFinder(gd::ResourcesContainer &resourcesManager)
: gd::ArbitraryResourceWorker(resourcesManager){};

void AddUsedResource(gd::String &resourceName);
Expand Down
Loading