-
Notifications
You must be signed in to change notification settings - Fork 916
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add a button to export objects as assets
- Loading branch information
Showing
22 changed files
with
603 additions
and
47 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,110 @@ | ||
/* | ||
* GDevelop Core | ||
* Copyright 2008-2016 Florian Rival ([email protected]). All rights | ||
* reserved. This project is released under the MIT License. | ||
*/ | ||
#include "ObjectAssetSerializer.h" | ||
|
||
#include "GDCore/Extensions/Metadata/BehaviorMetadata.h" | ||
#include "GDCore/Extensions/Metadata/MetadataProvider.h" | ||
#include "GDCore/Extensions/Platform.h" | ||
#include "GDCore/Extensions/PlatformExtension.h" | ||
#include "GDCore/IDE/Project/ResourcesInUseHelper.h" | ||
#include "GDCore/Project/Behavior.h" | ||
#include "GDCore/Project/CustomBehavior.h" | ||
#include "GDCore/Project/EventsFunctionsExtension.h" | ||
#include "GDCore/Project/Layout.h" | ||
#include "GDCore/Project/Object.h" | ||
#include "GDCore/Project/Project.h" | ||
#include "GDCore/Project/PropertyDescriptor.h" | ||
#include "GDCore/Serialization/SerializerElement.h" | ||
#include "GDCore/Tools/Log.h" | ||
|
||
|
||
namespace gd { | ||
|
||
const std::vector<gd::String> ObjectAssetSerializer::resourceTypes = { | ||
"image", "audio", "font", "json", | ||
"tilemap", "tileset", "video", "bitmapFont"}; | ||
|
||
void ObjectAssetSerializer::SerializeTo(gd::Project &project, | ||
const gd::Object &object, | ||
SerializerElement &element) { | ||
auto cleanObject = object.Clone(); | ||
cleanObject->GetVariables().Clear(); | ||
cleanObject->GetEffects().Clear(); | ||
for (auto &&behaviorName : cleanObject->GetAllBehaviorNames()) { | ||
cleanObject->RemoveBehavior(behaviorName); | ||
} | ||
|
||
const gd::String &type = cleanObject->GetType(); | ||
const auto separatorIndex = | ||
type.find(PlatformExtension::GetNamespaceSeparator()); | ||
gd::String extensionName = | ||
separatorIndex != std::string::npos ? type.substr(0, separatorIndex) : ""; | ||
|
||
element.SetAttribute("id", ""); | ||
element.SetAttribute("name", ""); | ||
element.SetAttribute("license", ""); | ||
if (project.HasEventsFunctionsExtensionNamed(extensionName)) { | ||
auto &extension = project.GetEventsFunctionsExtension(extensionName); | ||
element.SetAttribute("description", extension.GetShortDescription()); | ||
} | ||
element.SetAttribute("gdevelopVersion", ""); | ||
element.SetAttribute("version", ""); | ||
element.SetIntAttribute("animationsCount", 1); | ||
element.SetIntAttribute("maxFramesCount", 1); | ||
// TODO Find the right object dimensions. | ||
element.SetIntAttribute("width", 0); | ||
element.SetIntAttribute("height", 0); | ||
SerializerElement &authorsElement = element.AddChild("authors"); | ||
authorsElement.ConsiderAsArrayOf("author"); | ||
SerializerElement &tagsElement = element.AddChild("tags"); | ||
tagsElement.ConsiderAsArrayOf("tag"); | ||
|
||
SerializerElement &objectAssetsElement = element.AddChild("objectAssets"); | ||
objectAssetsElement.ConsiderAsArrayOf("objectAsset"); | ||
SerializerElement &objectAssetElement = | ||
objectAssetsElement.AddChild("objectAsset"); | ||
|
||
cleanObject->SerializeTo(objectAssetElement.AddChild("object")); | ||
|
||
SerializerElement &resourcesElement = | ||
objectAssetElement.AddChild("resources"); | ||
resourcesElement.ConsiderAsArrayOf("resource"); | ||
auto &resourcesManager = project.GetResourcesManager(); | ||
gd::ResourcesInUseHelper resourcesInUse(resourcesManager); | ||
cleanObject->GetConfiguration().ExposeResources(resourcesInUse); | ||
for (auto &&resourceType : resourceTypes) { | ||
for (auto &&resourceName : resourcesInUse.GetAll(resourceType)) { | ||
if (resourceName.length() == 0) { | ||
continue; | ||
} | ||
auto &resource = resourcesManager.GetResource(resourceName); | ||
SerializerElement &resourceElement = | ||
resourcesElement.AddChild("resource"); | ||
resourceElement.SetAttribute("name", resourceName); | ||
resourceElement.SetAttribute("file", resource.GetFile()); | ||
resourceElement.SetAttribute("kind", resource.GetKind()); | ||
resourceElement.SetBoolAttribute("alwaysLoaded", false); | ||
resourceElement.SetAttribute("metadata", resource.GetMetadata()); | ||
} | ||
} | ||
|
||
SerializerElement &requiredExtensionsElement = | ||
objectAssetElement.AddChild("requiredExtensions"); | ||
requiredExtensionsElement.ConsiderAsArrayOf("requiredExtension"); | ||
if (project.HasEventsFunctionsExtensionNamed(extensionName)) { | ||
SerializerElement &requiredExtensionElement = | ||
requiredExtensionsElement.AddChild("requiredExtension"); | ||
requiredExtensionElement.SetAttribute("extensionName", extensionName); | ||
requiredExtensionElement.SetAttribute("extensionVersion", "1.0.0"); | ||
} | ||
|
||
// TODO This can be removed when the asset script no longer require it. | ||
SerializerElement &customizationElement = | ||
objectAssetElement.AddChild("customization"); | ||
customizationElement.ConsiderAsArrayOf("empty"); | ||
} | ||
|
||
} // namespace gd |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
/* | ||
* GDevelop Core | ||
* Copyright 2008-2016 Florian Rival ([email protected]). All rights | ||
* reserved. This project is released under the MIT License. | ||
*/ | ||
#pragma once | ||
#include <vector> | ||
|
||
#include "GDCore/String.h" | ||
|
||
namespace gd { | ||
class Object; | ||
class ExtensionDependency; | ||
class PropertyDescriptor; | ||
class Project; | ||
class Layout; | ||
class ArbitraryResourceWorker; | ||
class InitialInstance; | ||
class SerializerElement; | ||
class EffectsContainer; | ||
} // namespace gd | ||
|
||
namespace gd { | ||
|
||
/** | ||
* \brief Serialize objects into an asset for the store. | ||
* | ||
* \ingroup IDE | ||
*/ | ||
class GD_CORE_API ObjectAssetSerializer { | ||
public: | ||
/** | ||
* \brief Serialize the object into an asset. | ||
*/ | ||
static void SerializeTo(gd::Project &project, const gd::Object &object, | ||
SerializerElement &element); | ||
|
||
~ObjectAssetSerializer(){}; | ||
|
||
private: | ||
ObjectAssetSerializer(){}; | ||
|
||
static const std::vector<gd::String> resourceTypes; | ||
}; | ||
|
||
} // namespace gd |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
/* | ||
* GDevelop Core | ||
* Copyright 2008-2016 Florian Rival ([email protected]). All rights | ||
* reserved. This project is released under the MIT License. | ||
*/ | ||
|
||
#include "AssetResourcesMergingHelper.h" | ||
#include "GDCore/Project/Project.h" | ||
#include "GDCore/Project/ResourcesManager.h" | ||
#include "GDCore/String.h" | ||
|
||
|
||
namespace gd { | ||
|
||
void AssetResourcesMergingHelper::ExposeImage(gd::String &imageName) { | ||
ExposeResourceAsFile(imageName); | ||
} | ||
|
||
void AssetResourcesMergingHelper::ExposeAudio(gd::String &audioName) { | ||
ExposeResourceAsFile(audioName); | ||
} | ||
|
||
void AssetResourcesMergingHelper::ExposeFont(gd::String &fontName) { | ||
ExposeResourceAsFile(fontName); | ||
} | ||
|
||
void AssetResourcesMergingHelper::ExposeJson(gd::String &jsonName) { | ||
ExposeResourceAsFile(jsonName); | ||
} | ||
|
||
void AssetResourcesMergingHelper::ExposeTilemap(gd::String &tilemapName) { | ||
ExposeResourceAsFile(tilemapName); | ||
} | ||
|
||
void AssetResourcesMergingHelper::ExposeTileset(gd::String &tilesetName) { | ||
ExposeResourceAsFile(tilesetName); | ||
} | ||
|
||
void AssetResourcesMergingHelper::ExposeVideo(gd::String &videoName) { | ||
ExposeResourceAsFile(videoName); | ||
} | ||
|
||
void AssetResourcesMergingHelper::ExposeBitmapFont(gd::String &bitmapFontName) { | ||
ExposeResourceAsFile(bitmapFontName); | ||
} | ||
|
||
void AssetResourcesMergingHelper::ExposeResourceAsFile( | ||
gd::String &resourceName) { | ||
|
||
auto &resource = project.GetResourcesManager().GetResource(resourceName); | ||
gd::String file = resource.GetFile(); | ||
ExposeFile(file); | ||
resourceName = file; | ||
} | ||
|
||
} // namespace gd |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
/* | ||
* GDevelop Core | ||
* Copyright 2008-2016 Florian Rival ([email protected]). All rights | ||
* reserved. This project is released under the MIT License. | ||
*/ | ||
#pragma once | ||
|
||
#include "GDCore/IDE/Project/ArbitraryResourceWorker.h" | ||
#include "GDCore/IDE/Project/ResourcesMergingHelper.h" | ||
#include "GDCore/String.h" | ||
#include <map> | ||
#include <memory> | ||
#include <vector> | ||
|
||
namespace gd { | ||
class AbstractFileSystem; | ||
class Project; | ||
} // namespace gd | ||
|
||
namespace gd { | ||
|
||
/** | ||
* \brief ResourcesMergingHelper is used (mainly during export) | ||
* to list resources and generate new filenames, to allow them to be all copied | ||
* in a single directory (potentially changing the filename to avoid conflicts, | ||
* but preserving extensions). | ||
* | ||
* \see ArbitraryResourceWorker | ||
* | ||
* \ingroup IDE | ||
*/ | ||
class GD_CORE_API AssetResourcesMergingHelper : public ResourcesMergingHelper { | ||
public: | ||
AssetResourcesMergingHelper(gd::Project &project_, | ||
gd::AbstractFileSystem &fileSystem) | ||
: ResourcesMergingHelper(project_.GetResourcesManager(), fileSystem), project(project_){}; | ||
virtual ~AssetResourcesMergingHelper(){}; | ||
|
||
void ExposeImage(gd::String &imageName) override; | ||
void ExposeAudio(gd::String &audioName) override; | ||
void ExposeFont(gd::String &fontName) override; | ||
void ExposeJson(gd::String &jsonName) override; | ||
void ExposeTilemap(gd::String &tilemapName) override; | ||
void ExposeTileset(gd::String &tilesetName) override; | ||
void ExposeVideo(gd::String &videoName) override; | ||
void ExposeBitmapFont(gd::String &bitmapFontName) override; | ||
|
||
protected: | ||
void ExposeResourceAsFile(gd::String &resourceName); | ||
|
||
gd::Project &project; | ||
}; | ||
|
||
} // namespace gd |
Oops, something went wrong.