mirror of
https://github.com/Heretek-AI/GDevelop.git
synced 2026-07-22 18:15:27 -04:00
a0925c79c3
* You can now simply write the name of the scene or global variable in an expression to use it: `1 + MyVariable` (instead of `1 + Variable(MyVariable)`). * Objects can also have their variables accessed like this: `MyObject.MyVariable` (instead of `MyObject.Variable(MyVariable)`. * This also works for properties inside functions of behaviors or custom objects. For example, you can write `Speed` instead of `Object.Behavior::PropertySpeed()`. * This syntax will also handle all types of variables without the need to write ToString. For example, you can now write "Score: " + CoinsEarned instead of "Score: " + ToString(Variable(CoinsEarned)). * This syntax will only work (and autocompletions will be shown) if you add the variable in the variables editor of the scene, the project or in the variables of the object. It's a good practice to always declare your variables here and give them a default value - do it to benefit from this new simplified syntax, which will make your formulas and expressions much more readable. * When you rename a variable in an editor, it will now rename the variables everywhere in the events of the project. This makes it much easier to change the name of a variable if you find a better one. Note that this works for "rootæ variables, but not variables inside structures or arrays.
126 lines
4.8 KiB
C++
126 lines
4.8 KiB
C++
/*
|
|
* GDevelop Core
|
|
* Copyright 2008-2023 Florian Rival (Florian.Rival@gmail.com). All rights
|
|
* reserved. This project is released under the MIT License.
|
|
*/
|
|
/**
|
|
* @file Tests covering layout content helper methods.
|
|
*/
|
|
#include "GDCore/Project/Layout.h"
|
|
#include "DummyPlatform.h"
|
|
#include "GDCore/CommonTools.h"
|
|
#include "GDCore/Extensions/Platform.h"
|
|
#include "GDCore/Project/Object.h"
|
|
#include "GDCore/Project/ObjectsContainer.h"
|
|
#include "GDCore/Project/Project.h"
|
|
#include "catch.hpp"
|
|
|
|
using namespace gd;
|
|
|
|
TEST_CASE("Layout", "[common]") {
|
|
|
|
SECTION("Find the type of a behavior in a object") {
|
|
gd::Platform platform;
|
|
gd::Project project;
|
|
SetupProjectWithDummyPlatform(project, platform);
|
|
|
|
gd::Layout &layout = project.InsertNewLayout("Scene", 0);
|
|
gd::Object &object =
|
|
layout.InsertNewObject(project, "MyExtension::Sprite", "MyObject", 0);
|
|
object.AddNewBehavior(project, "MyExtension::MyBehavior", "MyBehavior");
|
|
|
|
REQUIRE(GetTypeOfBehaviorInObjectOrGroup(project, layout, "MyObject",
|
|
"MyBehavior", true) ==
|
|
"MyExtension::MyBehavior");
|
|
}
|
|
|
|
SECTION("Give an empty type for an object that doesn't have the behavior") {
|
|
gd::Platform platform;
|
|
gd::Project project;
|
|
SetupProjectWithDummyPlatform(project, platform);
|
|
|
|
gd::Layout &layout = project.InsertNewLayout("Scene", 0);
|
|
gd::Object &object =
|
|
layout.InsertNewObject(project, "MyExtension::Sprite", "MyObject", 0);
|
|
|
|
REQUIRE(GetTypeOfBehaviorInObjectOrGroup(project, layout, "MyObject",
|
|
"MyBehavior", true) == "");
|
|
}
|
|
|
|
SECTION("Find the type of a behavior in a group") {
|
|
gd::Platform platform;
|
|
gd::Project project;
|
|
SetupProjectWithDummyPlatform(project, platform);
|
|
|
|
gd::Layout &layout = project.InsertNewLayout("Scene", 0);
|
|
gd::Object &object1 =
|
|
layout.InsertNewObject(project, "MyExtension::Sprite", "MyObject1", 0);
|
|
object1.AddNewBehavior(project, "MyExtension::MyBehavior", "MyBehavior");
|
|
gd::Object &object2 =
|
|
layout.InsertNewObject(project, "MyExtension::Sprite", "MyObject2", 0);
|
|
object2.AddNewBehavior(project, "MyExtension::MyBehavior", "MyBehavior");
|
|
|
|
auto &group = layout.GetObjectGroups().InsertNew("MyGroup", 0);
|
|
group.AddObject(object1.GetName());
|
|
group.AddObject(object2.GetName());
|
|
|
|
REQUIRE(GetTypeOfBehaviorInObjectOrGroup(project, layout, "MyGroup",
|
|
"MyBehavior", true) ==
|
|
"MyExtension::MyBehavior");
|
|
}
|
|
|
|
SECTION("Give an empty type for a group with an object missing the behavior") {
|
|
gd::Platform platform;
|
|
gd::Project project;
|
|
SetupProjectWithDummyPlatform(project, platform);
|
|
|
|
gd::Layout &layout = project.InsertNewLayout("Scene", 0);
|
|
gd::Object &object1 =
|
|
layout.InsertNewObject(project, "MyExtension::Sprite", "MyObject1", 0);
|
|
object1.AddNewBehavior(project, "MyExtension::MyBehavior", "MyBehavior");
|
|
gd::Object &object2 =
|
|
layout.InsertNewObject(project, "MyExtension::Sprite", "MyObject2", 0);
|
|
// object2 doesn't have the behavior.
|
|
|
|
auto &group = layout.GetObjectGroups().InsertNew("MyGroup", 0);
|
|
group.AddObject(object1.GetName());
|
|
group.AddObject(object2.GetName());
|
|
|
|
REQUIRE(GetTypeOfBehaviorInObjectOrGroup(project, layout, "MyGroup",
|
|
"MyBehavior", true) == "");
|
|
}
|
|
|
|
SECTION("Give an empty type for a group with behaviors of same name but different types") {
|
|
gd::Platform platform;
|
|
gd::Project project;
|
|
SetupProjectWithDummyPlatform(project, platform);
|
|
|
|
gd::Layout &layout = project.InsertNewLayout("Scene", 0);
|
|
gd::Object &object1 =
|
|
layout.InsertNewObject(project, "MyExtension::Sprite", "MyObject1", 0);
|
|
object1.AddNewBehavior(project, "MyExtension::MyBehavior", "MyBehavior");
|
|
gd::Object &object2 =
|
|
layout.InsertNewObject(project, "MyExtension::Sprite", "MyObject2", 0);
|
|
object2.AddNewBehavior(project, "MyExtension::MyOtherBehavior",
|
|
"MyBehavior");
|
|
|
|
auto &group = layout.GetObjectGroups().InsertNew("MyGroup", 0);
|
|
group.AddObject(object1.GetName());
|
|
group.AddObject(object2.GetName());
|
|
|
|
REQUIRE(GetTypeOfBehaviorInObjectOrGroup(project, layout, "MyGroup",
|
|
"MyBehavior", true) == "");
|
|
}
|
|
|
|
SECTION("Give an empty type for an empty group") {
|
|
gd::Platform platform;
|
|
gd::Project project;
|
|
SetupProjectWithDummyPlatform(project, platform);
|
|
|
|
gd::Layout &layout = project.InsertNewLayout("Scene", 0);
|
|
auto &group = layout.GetObjectGroups().InsertNew("MyGroup", 0);
|
|
|
|
REQUIRE(GetTypeOfBehaviorInObjectOrGroup(project, layout, "MyGroup",
|
|
"MyBehavior", true) == "");
|
|
}
|
|
} |