mirror of
https://github.com/Heretek-AI/GDevelop.git
synced 2026-07-22 18:15:27 -04:00
77320ce12e
* Tilemaps made with [LDtk](https://ldtk.io/), a modern 2D level editor, can be now used directly. Make sure to save your map made in LDtk as a JSON file, create a new Tilemap object in GDevelop and in the Tilemap field, choose the LDtk file. * Tilesets used by the LDtk Tilemap are automatically imported in your game - you don't need to import them separately. * For more information, read about the [Tilemap object on the wiki](https://wiki.gdevelop.io/gdevelop5/objects/tilemap). Co-authored-by: Davy Hélard <davy.helard@gmail.com> Co-authored-by: Florian Rival <Florian.Rival@gmail.com>
96 lines
3.5 KiB
C++
96 lines
3.5 KiB
C++
/*
|
|
* GDevelop Core
|
|
* Copyright 2008-2016 Florian Rival (Florian.Rival@gmail.com). All rights
|
|
* reserved. This project is released under the MIT License.
|
|
*/
|
|
/**
|
|
* @file Tests covering common features of GDevelop Core.
|
|
*/
|
|
#include "GDCore/IDE/Project/ResourcesRenamer.h"
|
|
|
|
#include "GDCore/CommonTools.h"
|
|
#include "GDCore/Project/Project.h"
|
|
#include "catch.hpp"
|
|
|
|
TEST_CASE("ResourcesRenamer", "[common]") {
|
|
SECTION("It renames resources that are exposed") {
|
|
std::map<gd::String, gd::String> renamings = {
|
|
{"Resource1", "RenamedResource1"}};
|
|
gd::ResourcesRenamer resourcesRenamer(renamings);
|
|
|
|
gd::Project project;
|
|
|
|
// Add "classic", plain resources.
|
|
gd::ImageResource resource1;
|
|
resource1.SetName("Resource1");
|
|
project.GetResourcesManager().AddResource(resource1);
|
|
gd::ImageResource resource2;
|
|
resource2.SetName("Resource2");
|
|
project.GetResourcesManager().AddResource(resource2);
|
|
|
|
// Add usage of some resources.
|
|
project.GetPlatformSpecificAssets().Set(
|
|
"android", "some-icon", "Resource1");
|
|
project.GetPlatformSpecificAssets().Set(
|
|
"android", "some-other-icon", "Resource2");
|
|
|
|
project.ExposeResources(resourcesRenamer);
|
|
|
|
// Check that resources were renamed were used.
|
|
REQUIRE(project.GetPlatformSpecificAssets().Get("android", "some-icon") ==
|
|
"RenamedResource1");
|
|
REQUIRE(project.GetPlatformSpecificAssets().Get(
|
|
"android", "some-other-icon") == "Resource2");
|
|
}
|
|
|
|
SECTION("It renames embedded resources") {
|
|
std::map<gd::String, gd::String> renamings = {
|
|
{"Resource1", "RenamedResource1"}};
|
|
gd::ResourcesRenamer resourcesRenamer(renamings);
|
|
|
|
gd::Project project;
|
|
|
|
// Add "classic", plain resources.
|
|
gd::ImageResource resource1;
|
|
resource1.SetName("Resource1");
|
|
project.GetResourcesManager().AddResource(resource1);
|
|
gd::ImageResource resource2;
|
|
resource2.SetName("Resource2");
|
|
project.GetResourcesManager().AddResource(resource2);
|
|
|
|
// Add a resource containing a mapping to other resources.
|
|
gd::JsonResource jsonResourceWithEmbeddeds;
|
|
jsonResourceWithEmbeddeds.SetName("Resource3");
|
|
jsonResourceWithEmbeddeds.SetMetadata(
|
|
"{ \"embeddedResourcesMapping\": {\"some-resource-name\": "
|
|
"\"Resource1\", \"some-other-resource-name\": \"Resource2\"} }");
|
|
project.GetResourcesManager().AddResource(jsonResourceWithEmbeddeds);
|
|
|
|
// Add usage of some resources.
|
|
project.GetPlatformSpecificAssets().Set(
|
|
"android", "some-icon", "Resource1");
|
|
project.GetPlatformSpecificAssets().Set(
|
|
"android", "some-other-icon", "Resource2");
|
|
|
|
project.ExposeResources(resourcesRenamer);
|
|
|
|
// TODO: This should not be necessary, but for now not all resources support embeddeds,
|
|
// so we must call it manually:
|
|
gd::String resource3Name = "Resource3";
|
|
resourcesRenamer.ExposeEmbeddeds(resource3Name);
|
|
|
|
// Check that resources were renamed were used.
|
|
REQUIRE(project.GetPlatformSpecificAssets().Get("android", "some-icon") ==
|
|
"RenamedResource1");
|
|
REQUIRE(project.GetPlatformSpecificAssets().Get(
|
|
"android", "some-other-icon") == "Resource2");
|
|
|
|
// Check that the names were also updated in the embedded resources mapping.
|
|
REQUIRE(project.GetResourcesManager().HasResource("Resource3") == true);
|
|
REQUIRE(
|
|
project.GetResourcesManager().GetResource("Resource3").GetMetadata() ==
|
|
"{\"embeddedResourcesMapping\":{\"some-resource-name\":"
|
|
"\"RenamedResource1\",\"some-other-resource-name\":\"Resource2\"}}");
|
|
}
|
|
}
|