mirror of
https://github.com/4ian/GDevelop.git
synced 2025-10-15 10:19:04 +00:00
Add a command to generate an action and an expression for a property (#4565)
This commit is contained in:
@@ -46,4 +46,25 @@ const gd::String &ValueTypeMetadata::GetPrimitiveValueType(const gd::String &par
|
||||
return parameterType;
|
||||
}
|
||||
|
||||
const gd::String ValueTypeMetadata::numberValueType = "number";
|
||||
const gd::String ValueTypeMetadata::booleanValueType = "boolean";
|
||||
const gd::String ValueTypeMetadata::colorValueType = "color";
|
||||
const gd::String ValueTypeMetadata::choiceValueType = "stringWithSelector";
|
||||
const gd::String ValueTypeMetadata::stringValueType = "string";
|
||||
|
||||
const gd::String &ValueTypeMetadata::ConvertPropertyTypeToValueType(
|
||||
const gd::String &propertyType) {
|
||||
if (propertyType == "Number") {
|
||||
return numberValueType;
|
||||
} else if (propertyType == "Boolean") {
|
||||
return booleanValueType;
|
||||
} else if (propertyType == "Color") {
|
||||
return colorValueType;
|
||||
} else if (propertyType == "Choice") {
|
||||
return choiceValueType;
|
||||
}
|
||||
// For "String" or default
|
||||
return stringValueType;
|
||||
};
|
||||
|
||||
} // namespace gd
|
||||
|
@@ -192,6 +192,12 @@ class GD_CORE_API ValueTypeMetadata {
|
||||
static const gd::String numberType;
|
||||
static const gd::String stringType;
|
||||
|
||||
/**
|
||||
* \brief Return the ValueTypeMetadata name for a property type.
|
||||
* \see gd::PropertyDescriptor
|
||||
*/
|
||||
static const gd::String &ConvertPropertyTypeToValueType(const gd::String &propertyType);
|
||||
|
||||
/** \name Serialization
|
||||
*/
|
||||
///@{
|
||||
@@ -212,6 +218,12 @@ class GD_CORE_API ValueTypeMetadata {
|
||||
bool optional; ///< True if the parameter is optional
|
||||
gd::String defaultValue; ///< Used as a default value in editor or if an
|
||||
///< optional parameter is empty.
|
||||
|
||||
static const gd::String numberValueType;
|
||||
static const gd::String booleanValueType;
|
||||
static const gd::String colorValueType;
|
||||
static const gd::String choiceValueType;
|
||||
static const gd::String stringValueType;
|
||||
};
|
||||
|
||||
} // namespace gd
|
||||
|
245
Core/GDCore/IDE/PropertyFunctionGenerator.cpp
Normal file
245
Core/GDCore/IDE/PropertyFunctionGenerator.cpp
Normal file
@@ -0,0 +1,245 @@
|
||||
/*
|
||||
* GDevelop Core
|
||||
* Copyright 2008-2022 Florian Rival (Florian.Rival@gmail.com). All rights
|
||||
* reserved. This project is released under the MIT License.
|
||||
*/
|
||||
#include "PropertyFunctionGenerator.h"
|
||||
|
||||
#include "GDCore/Events/Builtin/StandardEvent.h"
|
||||
#include "GDCore/Events/Event.h"
|
||||
#include "GDCore/Extensions/Metadata/ValueTypeMetadata.h"
|
||||
#include "GDCore/Project/EventsBasedBehavior.h"
|
||||
#include "GDCore/Project/EventsFunctionsExtension.h"
|
||||
#include "GDCore/Project/Project.h"
|
||||
#include "GDCore/Project/PropertyDescriptor.h"
|
||||
#include "GDCore/String.h"
|
||||
|
||||
namespace gd {
|
||||
|
||||
void PropertyFunctionGenerator::GenerateGetterAndSetter(
|
||||
gd::Project &project, gd::EventsFunctionsExtension &extension,
|
||||
gd::EventsBasedBehavior &eventsBasedBehavior,
|
||||
const gd::NamedPropertyDescriptor &property, bool isSharedProperties) {
|
||||
auto &propertyName = property.GetName();
|
||||
auto &functionsContainer = eventsBasedBehavior.GetEventsFunctions();
|
||||
gd::String capitalizedName = CapitalizeFirstLetter(property.GetName());
|
||||
gd::String setterName = "Set" + capitalizedName;
|
||||
|
||||
gd::String functionGroupName =
|
||||
(eventsBasedBehavior.GetFullName().empty()
|
||||
? eventsBasedBehavior.GetName()
|
||||
: eventsBasedBehavior.GetFullName()) +
|
||||
(property.GetGroup().empty()
|
||||
? ""
|
||||
: " " + UnCapitalizeFirstLetter(property.GetGroup())) +
|
||||
" configuration";
|
||||
|
||||
gd::String propertyLabel =
|
||||
property.GetLabel().empty() ? property.GetName() : property.GetLabel();
|
||||
|
||||
gd::String descriptionSubject =
|
||||
(property.GetType() == "Boolean" ? "if " : "the ") +
|
||||
UnCapitalizeFirstLetter(propertyLabel) +
|
||||
(isSharedProperties || property.GetType() == "Boolean"
|
||||
? "."
|
||||
: " of the object.") +
|
||||
(property.GetDescription().empty() ? ""
|
||||
: " " + property.GetDescription()) +
|
||||
(isSharedProperties ? " While an object is needed, this will apply to all "
|
||||
"objects using the behavior."
|
||||
: "");
|
||||
|
||||
gd::String behaviorNamespace =
|
||||
extension.GetName() + "::" + eventsBasedBehavior.GetName() + "::";
|
||||
gd::String propertyGetterName =
|
||||
(isSharedProperties ? "SharedProperty" : "Property") + property.GetName();
|
||||
gd::String getterType = behaviorNamespace + propertyGetterName;
|
||||
gd::String setterType = behaviorNamespace + "Set" + propertyGetterName;
|
||||
|
||||
gd::String getterName = capitalizedName;
|
||||
gd::String numberOrString =
|
||||
property.GetType() == "Number" ? "Number" : "String";
|
||||
|
||||
if (!functionsContainer.HasEventsFunctionNamed(getterName)) {
|
||||
auto &getter = functionsContainer.InsertNewEventsFunction(
|
||||
getterName, functionsContainer.GetEventsFunctionsCount());
|
||||
auto &expressionType =
|
||||
gd::ValueTypeMetadata::ConvertPropertyTypeToValueType(
|
||||
property.GetType());
|
||||
// TODO Stop replacing number by expression when it"s handled by the UI
|
||||
// and released.
|
||||
auto &legacyExpressionType =
|
||||
expressionType == "number" ? "expression" : expressionType;
|
||||
getter.GetExpressionType()
|
||||
.SetName(legacyExpressionType)
|
||||
.SetExtraInfo(GetStringifiedExtraInfo(property));
|
||||
getter.SetFullName(propertyLabel).SetGroup(functionGroupName);
|
||||
if (property.GetType() == "Boolean") {
|
||||
getter.SetFunctionType(gd::EventsFunction::Condition)
|
||||
.SetDescription("Check " + descriptionSubject)
|
||||
.SetSentence("_PARAM0_ " + UnCapitalizeFirstLetter(propertyLabel));
|
||||
} else {
|
||||
getter.SetFunctionType(gd::EventsFunction::ExpressionAndCondition)
|
||||
.SetDescription(descriptionSubject)
|
||||
.SetSentence("the " + UnCapitalizeFirstLetter(propertyLabel));
|
||||
}
|
||||
|
||||
auto &event =
|
||||
dynamic_cast<gd::StandardEvent &>(getter.GetEvents().InsertNewEvent(
|
||||
project, "BuiltinCommonInstructions::Standard", 0));
|
||||
if (property.GetType() == "Boolean") {
|
||||
gd::Instruction condition;
|
||||
condition.SetType(getterType);
|
||||
condition.SetParametersCount(2);
|
||||
condition.SetParameter(0, "Object");
|
||||
condition.SetParameter(1, "Behavior");
|
||||
event.GetConditions().Insert(condition, 0);
|
||||
|
||||
gd::Instruction action;
|
||||
action.SetType("SetReturnBoolean");
|
||||
action.SetParametersCount(1);
|
||||
action.SetParameter(0, "True");
|
||||
event.GetActions().Insert(action, 0);
|
||||
} else {
|
||||
gd::Instruction action;
|
||||
action.SetType("SetReturn" + numberOrString);
|
||||
action.SetParametersCount(1);
|
||||
gd::String propertyPrefix =
|
||||
(isSharedProperties ? "SharedProperty" : "Property");
|
||||
action.SetParameter(0, "Object.Behavior::" + propertyPrefix +
|
||||
property.GetName() + "()");
|
||||
event.GetActions().Insert(action, 0);
|
||||
}
|
||||
}
|
||||
|
||||
if (!functionsContainer.HasEventsFunctionNamed(setterName)) {
|
||||
auto &setter = functionsContainer.InsertNewEventsFunction(
|
||||
setterName, functionsContainer.GetEventsFunctionsCount());
|
||||
if (property.GetType() == "Boolean") {
|
||||
setter.SetFunctionType(gd::EventsFunction::Action)
|
||||
.SetFullName(propertyLabel)
|
||||
.SetGroup(functionGroupName)
|
||||
.SetDescription("Change " + descriptionSubject)
|
||||
.SetSentence("_PARAM0_ " + UnCapitalizeFirstLetter(propertyLabel) +
|
||||
": _PARAM2_");
|
||||
gd::ParameterMetadata parameter;
|
||||
parameter.SetType("yesorno")
|
||||
.SetName("Value")
|
||||
.SetDescription(capitalizedName)
|
||||
.SetOptional(true)
|
||||
.SetDefaultValue("yes");
|
||||
setter.GetParameters().push_back(parameter);
|
||||
} else {
|
||||
setter.SetFunctionType(gd::EventsFunction::ActionWithOperator);
|
||||
setter.SetGetterName(getterName);
|
||||
}
|
||||
|
||||
if (property.GetType() == "Boolean") {
|
||||
{
|
||||
auto &event =
|
||||
dynamic_cast<gd::StandardEvent &>(setter.GetEvents().InsertNewEvent(
|
||||
project, "BuiltinCommonInstructions::Standard", 0));
|
||||
|
||||
gd::Instruction condition;
|
||||
condition.SetType("GetArgumentAsBoolean");
|
||||
condition.SetParametersCount(1);
|
||||
condition.SetParameter(0, "\"Value\"");
|
||||
event.GetConditions().Insert(condition, 0);
|
||||
|
||||
gd::Instruction action;
|
||||
action.SetType(setterType);
|
||||
action.SetParametersCount(3);
|
||||
action.SetParameter(0, "Object");
|
||||
action.SetParameter(1, "Behavior");
|
||||
action.SetParameter(2, "yes");
|
||||
event.GetActions().Insert(action, 0);
|
||||
}
|
||||
{
|
||||
auto &event =
|
||||
dynamic_cast<gd::StandardEvent &>(setter.GetEvents().InsertNewEvent(
|
||||
project, "BuiltinCommonInstructions::Standard", 0));
|
||||
|
||||
gd::Instruction condition;
|
||||
condition.SetType("GetArgumentAsBoolean");
|
||||
condition.SetParametersCount(1);
|
||||
condition.SetParameter(0, "\"Value\"");
|
||||
condition.SetInverted(true);
|
||||
event.GetConditions().Insert(condition, 0);
|
||||
|
||||
gd::Instruction action;
|
||||
action.SetType(setterType);
|
||||
action.SetParametersCount(3);
|
||||
action.SetParameter(0, "Object");
|
||||
action.SetParameter(1, "Behavior");
|
||||
action.SetParameter(2, "no");
|
||||
event.GetActions().Insert(action, 0);
|
||||
}
|
||||
} else {
|
||||
auto &event =
|
||||
dynamic_cast<gd::StandardEvent &>(setter.GetEvents().InsertNewEvent(
|
||||
project, "BuiltinCommonInstructions::Standard", 0));
|
||||
|
||||
gd::Instruction action;
|
||||
action.SetType(setterType);
|
||||
action.SetParametersCount(4);
|
||||
action.SetParameter(0, "Object");
|
||||
action.SetParameter(1, "Behavior");
|
||||
action.SetParameter(2, "=");
|
||||
action.SetParameter(3, "GetArgumentAs" + numberOrString + "(\"Value\")");
|
||||
event.GetActions().Insert(action, 0);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
bool PropertyFunctionGenerator::CanGenerateGetterAndSetter(
|
||||
const gd::EventsBasedBehavior &eventsBasedBehavior,
|
||||
const gd::NamedPropertyDescriptor &property) {
|
||||
auto &type = property.GetType();
|
||||
if (type != "Boolean" && type != "Number" && type != "String" &&
|
||||
type != "Choice" && type != "Color") {
|
||||
return false;
|
||||
}
|
||||
|
||||
auto &functionsContainer = eventsBasedBehavior.GetEventsFunctions();
|
||||
auto getterName = CapitalizeFirstLetter(property.GetName());
|
||||
auto setterName = "Set" + getterName;
|
||||
return !functionsContainer.HasEventsFunctionNamed(setterName) &&
|
||||
!functionsContainer.HasEventsFunctionNamed(getterName);
|
||||
};
|
||||
|
||||
gd::String PropertyFunctionGenerator::GetStringifiedExtraInfo(
|
||||
const gd::PropertyDescriptor &property) {
|
||||
if (property.GetType() == "Choice") {
|
||||
gd::String arrayString;
|
||||
arrayString += "[";
|
||||
bool isFirst = true;
|
||||
for (const gd::String &choice : property.GetExtraInfo()) {
|
||||
if (!isFirst) {
|
||||
arrayString += ",";
|
||||
}
|
||||
isFirst = false;
|
||||
arrayString += "\"" + choice + "\"";
|
||||
}
|
||||
arrayString += "]";
|
||||
return arrayString;
|
||||
}
|
||||
return "";
|
||||
}
|
||||
|
||||
gd::String
|
||||
PropertyFunctionGenerator::CapitalizeFirstLetter(const gd::String &string) {
|
||||
if (string.empty()) {
|
||||
return string;
|
||||
}
|
||||
return string.substr(0, 1).UpperCase() + string.substr(1);
|
||||
}
|
||||
|
||||
gd::String
|
||||
PropertyFunctionGenerator::UnCapitalizeFirstLetter(const gd::String &string) {
|
||||
if (string.empty()) {
|
||||
return string;
|
||||
}
|
||||
return string.substr(0, 1).LowerCase() + string.substr(1);
|
||||
}
|
||||
|
||||
} // namespace gd
|
49
Core/GDCore/IDE/PropertyFunctionGenerator.h
Normal file
49
Core/GDCore/IDE/PropertyFunctionGenerator.h
Normal file
@@ -0,0 +1,49 @@
|
||||
/*
|
||||
* GDevelop Core
|
||||
* Copyright 2008-2022 Florian Rival (Florian.Rival@gmail.com). All rights
|
||||
* reserved. This project is released under the MIT License.
|
||||
*/
|
||||
#ifndef GDCORE_PROPERTYFUNCTIONGENERATOR_H
|
||||
#define GDCORE_PROPERTYFUNCTIONGENERATOR_H
|
||||
|
||||
namespace gd {
|
||||
class String;
|
||||
class Project;
|
||||
class EventsFunctionsExtension;
|
||||
class EventsBasedBehavior;
|
||||
class PropertyDescriptor;
|
||||
class NamedPropertyDescriptor;
|
||||
} // namespace gd
|
||||
|
||||
namespace gd {
|
||||
|
||||
/**
|
||||
* \brief Generate a getter and a setter functions for properties.
|
||||
*/
|
||||
class GD_CORE_API PropertyFunctionGenerator {
|
||||
public:
|
||||
/**
|
||||
* \brief Generate a getter and a setter for the given property.
|
||||
*/
|
||||
static void GenerateGetterAndSetter(
|
||||
gd::Project &project, gd::EventsFunctionsExtension &extension,
|
||||
gd::EventsBasedBehavior &eventsBasedBehavior,
|
||||
const gd::NamedPropertyDescriptor &property, bool isSharedProperties);
|
||||
static bool
|
||||
CanGenerateGetterAndSetter(const gd::EventsBasedBehavior &eventsBasedBehavior,
|
||||
const gd::NamedPropertyDescriptor &property);
|
||||
|
||||
~PropertyFunctionGenerator();
|
||||
|
||||
private:
|
||||
static gd::String CapitalizeFirstLetter(const gd::String &string);
|
||||
static gd::String UnCapitalizeFirstLetter(const gd::String &string);
|
||||
static gd::String
|
||||
GetStringifiedExtraInfo(const gd::PropertyDescriptor &property);
|
||||
|
||||
PropertyFunctionGenerator();
|
||||
};
|
||||
|
||||
} // namespace gd
|
||||
|
||||
#endif // GDCORE_PROPERTYFUNCTIONGENERATOR_H
|
@@ -145,6 +145,11 @@ class GD_CORE_API EventsFunction {
|
||||
*/
|
||||
const gd::ValueTypeMetadata& GetExpressionType() const { return expressionType; }
|
||||
|
||||
/**
|
||||
* \brief Get the type of the expression
|
||||
*/
|
||||
gd::ValueTypeMetadata& GetExpressionType() { return expressionType; }
|
||||
|
||||
enum FunctionType {
|
||||
Action,
|
||||
Condition,
|
||||
|
@@ -12,6 +12,7 @@
|
||||
#include "GDCore/Project/Layout.h"
|
||||
#include "GDCore/Project/Project.h"
|
||||
#include "GDCore/Tools/Localization.h"
|
||||
#include "GDCore/Events/Builtin/StandardEvent.h"
|
||||
#include "catch.hpp"
|
||||
|
||||
// TODO Remove these 2 classes and write the test with events based behaviors.
|
||||
@@ -94,6 +95,13 @@ void SetupProjectWithDummyPlatform(gd::Project& project,
|
||||
// Don't show extension loading logs for tests (too verbose).
|
||||
platform.EnableExtensionLoadingLogs(false);
|
||||
|
||||
// Required for tests on event generation.
|
||||
std::shared_ptr<gd::PlatformExtension> commonInstructionsExtension =
|
||||
std::shared_ptr<gd::PlatformExtension>(new gd::PlatformExtension);
|
||||
commonInstructionsExtension->SetExtensionInformation(
|
||||
"BuiltinCommonInstructions", "instruction extension", "", "", "");
|
||||
commonInstructionsExtension->AddEvent("Standard", "Standard event", "", "", "", std::make_shared<gd::StandardEvent>());
|
||||
|
||||
std::shared_ptr<gd::PlatformExtension> baseObjectExtension =
|
||||
std::shared_ptr<gd::PlatformExtension>(new gd::PlatformExtension);
|
||||
|
||||
@@ -373,6 +381,7 @@ void SetupProjectWithDummyPlatform(gd::Project& project,
|
||||
.AddUnsupportedBaseObjectCapability("effect");
|
||||
}
|
||||
|
||||
platform.AddExtension(commonInstructionsExtension);
|
||||
platform.AddExtension(baseObjectExtension);
|
||||
platform.AddExtension(extension);
|
||||
project.AddPlatform(platform);
|
||||
|
477
Core/tests/PropertyFunctionGenerator.cpp
Normal file
477
Core/tests/PropertyFunctionGenerator.cpp
Normal file
@@ -0,0 +1,477 @@
|
||||
/*
|
||||
* 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/PropertyFunctionGenerator.h"
|
||||
#include "DummyPlatform.h"
|
||||
#include "GDCore/Events/Builtin/StandardEvent.h"
|
||||
#include "GDCore/Extensions/Metadata/ValueTypeMetadata.h"
|
||||
#include "GDCore/Extensions/Platform.h"
|
||||
#include "GDCore/Project/EventsBasedBehavior.h"
|
||||
#include "GDCore/Project/EventsFunctionsExtension.h"
|
||||
#include "GDCore/Project/Project.h"
|
||||
#include "GDCore/String.h"
|
||||
#include "catch.hpp"
|
||||
|
||||
namespace {
|
||||
|
||||
gd::EventsBasedBehavior &
|
||||
CreateBehavior(gd::EventsFunctionsExtension &eventsExtension) {
|
||||
auto &eventsBasedBehavior =
|
||||
eventsExtension.GetEventsBasedBehaviors().InsertNew(
|
||||
"MyEventsBasedBehavior", 0);
|
||||
eventsBasedBehavior.SetFullName("My events based behavior");
|
||||
eventsBasedBehavior.SetDescription("An events based behavior for test");
|
||||
eventsBasedBehavior.SetObjectType("");
|
||||
return eventsBasedBehavior;
|
||||
};
|
||||
} // namespace
|
||||
|
||||
TEST_CASE("PropertyFunctionGenerator", "[common]") {
|
||||
SECTION("Can generate functions for a number property") {
|
||||
gd::Platform platform;
|
||||
gd::Project project;
|
||||
SetupProjectWithDummyPlatform(project, platform);
|
||||
auto &extension =
|
||||
project.InsertNewEventsFunctionsExtension("MyEventsExtension", 0);
|
||||
auto &behavior = CreateBehavior(extension);
|
||||
|
||||
auto &property =
|
||||
behavior.GetPropertyDescriptors().InsertNew("MovementAngle", 0);
|
||||
property.SetType("Number")
|
||||
.SetLabel("Movement angle")
|
||||
.SetDescription("The angle of the trajectory direction.")
|
||||
.SetGroup("Movement");
|
||||
|
||||
gd::PropertyFunctionGenerator::GenerateGetterAndSetter(
|
||||
project, extension, behavior, property, false);
|
||||
|
||||
REQUIRE(
|
||||
behavior.GetEventsFunctions().HasEventsFunctionNamed("MovementAngle"));
|
||||
REQUIRE(behavior.GetEventsFunctions().HasEventsFunctionNamed(
|
||||
"SetMovementAngle"));
|
||||
{
|
||||
auto &getter =
|
||||
behavior.GetEventsFunctions().GetEventsFunction("MovementAngle");
|
||||
|
||||
REQUIRE(getter.GetFunctionType() ==
|
||||
gd::EventsFunction::ExpressionAndCondition);
|
||||
REQUIRE(getter.GetExpressionType().GetName() == "expression");
|
||||
REQUIRE(getter.GetFullName() == "Movement angle");
|
||||
REQUIRE(getter.GetGroup() ==
|
||||
"My events based behavior movement configuration");
|
||||
REQUIRE(getter.GetDescription() ==
|
||||
"the movement angle of the object. The "
|
||||
"angle of the trajectory direction.");
|
||||
REQUIRE(getter.GetSentence() == "the movement angle");
|
||||
// Object and behavior parameters are added automatically.
|
||||
REQUIRE(getter.GetParameters().size() == 0);
|
||||
|
||||
REQUIRE(getter.GetEvents().GetEventsCount() == 1);
|
||||
REQUIRE(getter.GetEvents().GetEvent(0).GetType() ==
|
||||
"BuiltinCommonInstructions::Standard");
|
||||
auto &getterEvent =
|
||||
dynamic_cast<gd::StandardEvent &>(getter.GetEvents().GetEvent(0));
|
||||
REQUIRE(getterEvent.GetConditions().size() == 0);
|
||||
REQUIRE(getterEvent.GetActions().size() == 1);
|
||||
auto &getterAction = getterEvent.GetActions().at(0);
|
||||
REQUIRE(getterAction.GetType() == "SetReturnNumber");
|
||||
REQUIRE(getterAction.GetParametersCount() == 1);
|
||||
REQUIRE(getterAction.GetParameter(0).GetPlainString() ==
|
||||
"Object.Behavior::PropertyMovementAngle()");
|
||||
}
|
||||
{
|
||||
auto &setter =
|
||||
behavior.GetEventsFunctions().GetEventsFunction("SetMovementAngle");
|
||||
|
||||
REQUIRE(setter.GetFunctionType() ==
|
||||
gd::EventsFunction::ActionWithOperator);
|
||||
REQUIRE(setter.GetGetterName() == "MovementAngle");
|
||||
// These fields are deducted from the getter.
|
||||
REQUIRE(setter.GetFullName() == "");
|
||||
REQUIRE(setter.GetGroup() == "");
|
||||
REQUIRE(setter.GetDescription() == "");
|
||||
REQUIRE(setter.GetSentence() == "");
|
||||
// Object and behavior parameters are added automatically.
|
||||
REQUIRE(setter.GetParameters().size() == 0);
|
||||
|
||||
REQUIRE(setter.GetEvents().GetEventsCount() == 1);
|
||||
REQUIRE(setter.GetEvents().GetEvent(0).GetType() ==
|
||||
"BuiltinCommonInstructions::Standard");
|
||||
auto &setterEvent =
|
||||
dynamic_cast<gd::StandardEvent &>(setter.GetEvents().GetEvent(0));
|
||||
REQUIRE(setterEvent.GetConditions().size() == 0);
|
||||
REQUIRE(setterEvent.GetActions().size() == 1);
|
||||
auto &setterAction = setterEvent.GetActions().at(0);
|
||||
REQUIRE(
|
||||
setterAction.GetType() ==
|
||||
"MyEventsExtension::MyEventsBasedBehavior::SetPropertyMovementAngle");
|
||||
REQUIRE(setterAction.GetParametersCount() == 4);
|
||||
REQUIRE(setterAction.GetParameter(0).GetPlainString() == "Object");
|
||||
REQUIRE(setterAction.GetParameter(1).GetPlainString() == "Behavior");
|
||||
REQUIRE(setterAction.GetParameter(2).GetPlainString() == "=");
|
||||
REQUIRE(setterAction.GetParameter(3).GetPlainString() ==
|
||||
"GetArgumentAsNumber(\"Value\")");
|
||||
}
|
||||
}
|
||||
|
||||
SECTION("Can generate functions for a choice property") {
|
||||
gd::Platform platform;
|
||||
gd::Project project;
|
||||
SetupProjectWithDummyPlatform(project, platform);
|
||||
auto &extension =
|
||||
project.InsertNewEventsFunctionsExtension("MyEventsExtension", 0);
|
||||
auto &behavior = CreateBehavior(extension);
|
||||
|
||||
auto &property =
|
||||
behavior.GetPropertyDescriptors().InsertNew("CollisionShape", 0);
|
||||
property.SetType("Choice")
|
||||
.SetLabel("Collision shape")
|
||||
.SetLabel("Dot shape")
|
||||
.SetDescription("The shape is used for collision.")
|
||||
.SetGroup("Movement");
|
||||
property.GetExtraInfo().push_back("Dot shape");
|
||||
property.GetExtraInfo().push_back("Bounding disk");
|
||||
|
||||
gd::PropertyFunctionGenerator::GenerateGetterAndSetter(
|
||||
project, extension, behavior, property, false);
|
||||
|
||||
REQUIRE(
|
||||
behavior.GetEventsFunctions().HasEventsFunctionNamed("CollisionShape"));
|
||||
REQUIRE(behavior.GetEventsFunctions().HasEventsFunctionNamed(
|
||||
"SetCollisionShape"));
|
||||
|
||||
auto &getter =
|
||||
behavior.GetEventsFunctions().GetEventsFunction("CollisionShape");
|
||||
|
||||
REQUIRE(getter.GetFunctionType() ==
|
||||
gd::EventsFunction::ExpressionAndCondition);
|
||||
REQUIRE(getter.GetExpressionType().GetName() == "stringWithSelector");
|
||||
REQUIRE(getter.GetExpressionType().GetExtraInfo() ==
|
||||
"[\"Dot shape\",\"Bounding disk\"]");
|
||||
}
|
||||
|
||||
SECTION("Can generate functions for a boolean property") {
|
||||
gd::Platform platform;
|
||||
gd::Project project;
|
||||
SetupProjectWithDummyPlatform(project, platform);
|
||||
auto &extension =
|
||||
project.InsertNewEventsFunctionsExtension("MyEventsExtension", 0);
|
||||
auto &behavior = CreateBehavior(extension);
|
||||
|
||||
auto &property = behavior.GetPropertyDescriptors().InsertNew("Rotate", 0);
|
||||
property.SetType("Boolean")
|
||||
.SetLabel("Rotate object")
|
||||
.SetDescription(
|
||||
"The rotation follows movements done by this behavior only.")
|
||||
.SetGroup("Movement");
|
||||
|
||||
gd::PropertyFunctionGenerator::GenerateGetterAndSetter(
|
||||
project, extension, behavior, property, false);
|
||||
|
||||
REQUIRE(behavior.GetEventsFunctions().HasEventsFunctionNamed("Rotate"));
|
||||
REQUIRE(behavior.GetEventsFunctions().HasEventsFunctionNamed("SetRotate"));
|
||||
{
|
||||
auto &getter = behavior.GetEventsFunctions().GetEventsFunction("Rotate");
|
||||
REQUIRE(getter.GetFunctionType() == gd::EventsFunction::Condition);
|
||||
REQUIRE(getter.GetExpressionType().GetName() == "boolean");
|
||||
REQUIRE(getter.GetFullName() == "Rotate object");
|
||||
REQUIRE(getter.GetGroup() ==
|
||||
"My events based behavior movement configuration");
|
||||
REQUIRE(getter.GetDescription() ==
|
||||
"Check if rotate object. The rotation follows movements done by "
|
||||
"this behavior only.");
|
||||
REQUIRE(getter.GetSentence() == "_PARAM0_ rotate object");
|
||||
// Object and behavior parameters are added automatically.
|
||||
REQUIRE(getter.GetParameters().size() == 0);
|
||||
|
||||
REQUIRE(getter.GetEvents().GetEventsCount() == 1);
|
||||
REQUIRE(getter.GetEvents().GetEvent(0).GetType() ==
|
||||
"BuiltinCommonInstructions::Standard");
|
||||
auto &getterEvent =
|
||||
dynamic_cast<gd::StandardEvent &>(getter.GetEvents().GetEvent(0));
|
||||
REQUIRE(getterEvent.GetConditions().size() == 1);
|
||||
REQUIRE(getterEvent.GetActions().size() == 1);
|
||||
|
||||
auto &getterCondition = getterEvent.GetConditions().at(0);
|
||||
REQUIRE(getterCondition.GetType() ==
|
||||
"MyEventsExtension::MyEventsBasedBehavior::PropertyRotate");
|
||||
REQUIRE(!getterCondition.IsInverted());
|
||||
REQUIRE(getterCondition.GetParametersCount() == 2);
|
||||
REQUIRE(getterCondition.GetParameter(0).GetPlainString() == "Object");
|
||||
REQUIRE(getterCondition.GetParameter(1).GetPlainString() == "Behavior");
|
||||
|
||||
auto &getterAction = getterEvent.GetActions().at(0);
|
||||
REQUIRE(getterAction.GetType() == "SetReturnBoolean");
|
||||
REQUIRE(getterAction.GetParametersCount() == 1);
|
||||
REQUIRE(getterAction.GetParameter(0).GetPlainString() == "True");
|
||||
}
|
||||
{
|
||||
auto &setter =
|
||||
behavior.GetEventsFunctions().GetEventsFunction("SetRotate");
|
||||
|
||||
REQUIRE(setter.GetFunctionType() == gd::EventsFunction::Action);
|
||||
REQUIRE(setter.GetFullName() == "Rotate object");
|
||||
REQUIRE(setter.GetGroup() ==
|
||||
"My events based behavior movement configuration");
|
||||
REQUIRE(setter.GetDescription() ==
|
||||
"Change if rotate object. The rotation follows movements done by "
|
||||
"this behavior only.");
|
||||
REQUIRE(setter.GetSentence() == "_PARAM0_ rotate object: _PARAM2_");
|
||||
// Object and behavior parameters are added automatically.
|
||||
REQUIRE(setter.GetParameters().size() == 1);
|
||||
auto &valueParameter = setter.GetParameters().at(0);
|
||||
REQUIRE(valueParameter.GetName() == "Value");
|
||||
REQUIRE(valueParameter.GetType() == "yesorno");
|
||||
|
||||
REQUIRE(setter.GetEvents().GetEventsCount() == 2);
|
||||
REQUIRE(setter.GetEvents().GetEvent(0).GetType() ==
|
||||
"BuiltinCommonInstructions::Standard");
|
||||
REQUIRE(setter.GetEvents().GetEvent(1).GetType() ==
|
||||
"BuiltinCommonInstructions::Standard");
|
||||
|
||||
auto &setterNoEvent =
|
||||
dynamic_cast<gd::StandardEvent &>(setter.GetEvents().GetEvent(0));
|
||||
REQUIRE(setterNoEvent.GetConditions().size() == 1);
|
||||
REQUIRE(setterNoEvent.GetActions().size() == 1);
|
||||
|
||||
auto &setterNoCondition = setterNoEvent.GetConditions().at(0);
|
||||
REQUIRE(setterNoCondition.GetType() == "GetArgumentAsBoolean");
|
||||
REQUIRE(setterNoCondition.IsInverted());
|
||||
REQUIRE(setterNoCondition.GetParametersCount() == 1);
|
||||
REQUIRE(setterNoCondition.GetParameter(0).GetPlainString() ==
|
||||
"\"Value\"");
|
||||
|
||||
auto &setterNoAction = setterNoEvent.GetActions().at(0);
|
||||
REQUIRE(setterNoAction.GetType() ==
|
||||
"MyEventsExtension::MyEventsBasedBehavior::SetPropertyRotate");
|
||||
REQUIRE(setterNoAction.GetParametersCount() == 3);
|
||||
REQUIRE(setterNoAction.GetParameter(0).GetPlainString() == "Object");
|
||||
REQUIRE(setterNoAction.GetParameter(1).GetPlainString() == "Behavior");
|
||||
REQUIRE(setterNoAction.GetParameter(2).GetPlainString() == "no");
|
||||
|
||||
auto &setterYesEvent =
|
||||
dynamic_cast<gd::StandardEvent &>(setter.GetEvents().GetEvent(1));
|
||||
REQUIRE(setterYesEvent.GetConditions().size() == 1);
|
||||
REQUIRE(setterYesEvent.GetActions().size() == 1);
|
||||
|
||||
auto &setterYesCondition = setterYesEvent.GetConditions().at(0);
|
||||
REQUIRE(setterYesCondition.GetType() == "GetArgumentAsBoolean");
|
||||
REQUIRE(!setterYesCondition.IsInverted());
|
||||
REQUIRE(setterYesCondition.GetParametersCount() == 1);
|
||||
REQUIRE(setterYesCondition.GetParameter(0).GetPlainString() ==
|
||||
"\"Value\"");
|
||||
|
||||
auto &setterYesAction = setterYesEvent.GetActions().at(0);
|
||||
REQUIRE(setterYesAction.GetType() ==
|
||||
"MyEventsExtension::MyEventsBasedBehavior::SetPropertyRotate");
|
||||
REQUIRE(setterYesAction.GetParametersCount() == 3);
|
||||
REQUIRE(setterYesAction.GetParameter(0).GetPlainString() == "Object");
|
||||
REQUIRE(setterYesAction.GetParameter(1).GetPlainString() == "Behavior");
|
||||
REQUIRE(setterYesAction.GetParameter(2).GetPlainString() == "yes");
|
||||
}
|
||||
}
|
||||
|
||||
SECTION("Can generate functions for a shared property") {
|
||||
gd::Platform platform;
|
||||
gd::Project project;
|
||||
SetupProjectWithDummyPlatform(project, platform);
|
||||
auto &extension =
|
||||
project.InsertNewEventsFunctionsExtension("MyEventsExtension", 0);
|
||||
auto &behavior = CreateBehavior(extension);
|
||||
|
||||
auto &property =
|
||||
behavior.GetSharedPropertyDescriptors().InsertNew("MovementAngle", 0);
|
||||
property.SetType("Number")
|
||||
.SetLabel("Movement angle")
|
||||
.SetDescription("The angle of the trajectory direction.")
|
||||
.SetGroup("Movement");
|
||||
|
||||
gd::PropertyFunctionGenerator::GenerateGetterAndSetter(
|
||||
project, extension, behavior, property, true);
|
||||
|
||||
REQUIRE(
|
||||
behavior.GetEventsFunctions().HasEventsFunctionNamed("MovementAngle"));
|
||||
REQUIRE(behavior.GetEventsFunctions().HasEventsFunctionNamed(
|
||||
"SetMovementAngle"));
|
||||
{
|
||||
auto &getter =
|
||||
behavior.GetEventsFunctions().GetEventsFunction("MovementAngle");
|
||||
REQUIRE(getter.GetDescription() ==
|
||||
"the movement angle. The angle of the trajectory direction. "
|
||||
"While an object is needed, this will apply to all objects using "
|
||||
"the behavior.");
|
||||
|
||||
REQUIRE(getter.GetEvents().GetEventsCount() == 1);
|
||||
REQUIRE(getter.GetEvents().GetEvent(0).GetType() ==
|
||||
"BuiltinCommonInstructions::Standard");
|
||||
auto &getterEvent =
|
||||
dynamic_cast<gd::StandardEvent &>(getter.GetEvents().GetEvent(0));
|
||||
REQUIRE(getterEvent.GetConditions().size() == 0);
|
||||
REQUIRE(getterEvent.GetActions().size() == 1);
|
||||
auto &getterAction = getterEvent.GetActions().at(0);
|
||||
REQUIRE(getterAction.GetType() == "SetReturnNumber");
|
||||
REQUIRE(getterAction.GetParametersCount() == 1);
|
||||
REQUIRE(getterAction.GetParameter(0).GetPlainString() ==
|
||||
"Object.Behavior::SharedPropertyMovementAngle()");
|
||||
}
|
||||
{
|
||||
auto &setter =
|
||||
behavior.GetEventsFunctions().GetEventsFunction("SetMovementAngle");
|
||||
|
||||
REQUIRE(setter.GetEvents().GetEventsCount() == 1);
|
||||
REQUIRE(setter.GetEvents().GetEvent(0).GetType() ==
|
||||
"BuiltinCommonInstructions::Standard");
|
||||
auto &setterEvent =
|
||||
dynamic_cast<gd::StandardEvent &>(setter.GetEvents().GetEvent(0));
|
||||
REQUIRE(setterEvent.GetConditions().size() == 0);
|
||||
REQUIRE(setterEvent.GetActions().size() == 1);
|
||||
auto &setterAction = setterEvent.GetActions().at(0);
|
||||
REQUIRE(setterAction.GetType() ==
|
||||
"MyEventsExtension::MyEventsBasedBehavior::"
|
||||
"SetSharedPropertyMovementAngle");
|
||||
}
|
||||
}
|
||||
|
||||
SECTION("Allow functions generation when there is no setter") {
|
||||
gd::Platform platform;
|
||||
gd::Project project;
|
||||
SetupProjectWithDummyPlatform(project, platform);
|
||||
auto &extension =
|
||||
project.InsertNewEventsFunctionsExtension("MyEventsExtension", 0);
|
||||
auto &behavior = CreateBehavior(extension);
|
||||
|
||||
auto &property =
|
||||
behavior.GetPropertyDescriptors().InsertNew("MovementAngle", 0);
|
||||
property.SetType("Number")
|
||||
.SetLabel("Movement angle")
|
||||
.SetDescription("The angle of the trajectory direction.")
|
||||
.SetGroup("Movement");
|
||||
|
||||
REQUIRE(gd::PropertyFunctionGenerator::CanGenerateGetterAndSetter(
|
||||
behavior, property));
|
||||
}
|
||||
|
||||
SECTION("Forbid functions generation when a getter exists") {
|
||||
gd::Platform platform;
|
||||
gd::Project project;
|
||||
SetupProjectWithDummyPlatform(project, platform);
|
||||
auto &extension =
|
||||
project.InsertNewEventsFunctionsExtension("MyEventsExtension", 0);
|
||||
auto &behavior = CreateBehavior(extension);
|
||||
|
||||
auto &property =
|
||||
behavior.GetPropertyDescriptors().InsertNew("MovementAngle", 0);
|
||||
property.SetType("Number")
|
||||
.SetLabel("Movement angle")
|
||||
.SetDescription("The angle of the trajectory direction.")
|
||||
.SetGroup("Movement");
|
||||
|
||||
behavior.GetEventsFunctions().InsertNewEventsFunction("MovementAngle", 0);
|
||||
|
||||
REQUIRE(!gd::PropertyFunctionGenerator::CanGenerateGetterAndSetter(
|
||||
behavior, property));
|
||||
}
|
||||
|
||||
SECTION("Forbid functions generation when a setter exists") {
|
||||
gd::Platform platform;
|
||||
gd::Project project;
|
||||
SetupProjectWithDummyPlatform(project, platform);
|
||||
auto &extension =
|
||||
project.InsertNewEventsFunctionsExtension("MyEventsExtension", 0);
|
||||
auto &behavior = CreateBehavior(extension);
|
||||
|
||||
auto &property =
|
||||
behavior.GetPropertyDescriptors().InsertNew("MovementAngle", 0);
|
||||
property.SetType("Number")
|
||||
.SetLabel("Movement angle")
|
||||
.SetDescription("The angle of the trajectory direction.")
|
||||
.SetGroup("Movement");
|
||||
|
||||
behavior.GetEventsFunctions().InsertNewEventsFunction("SetMovementAngle",
|
||||
0);
|
||||
|
||||
REQUIRE(!gd::PropertyFunctionGenerator::CanGenerateGetterAndSetter(
|
||||
behavior, property));
|
||||
}
|
||||
|
||||
SECTION("Forbid functions generation when both setter and getter exist") {
|
||||
gd::Platform platform;
|
||||
gd::Project project;
|
||||
SetupProjectWithDummyPlatform(project, platform);
|
||||
auto &extension =
|
||||
project.InsertNewEventsFunctionsExtension("MyEventsExtension", 0);
|
||||
auto &behavior = CreateBehavior(extension);
|
||||
|
||||
auto &property =
|
||||
behavior.GetPropertyDescriptors().InsertNew("MovementAngle", 0);
|
||||
property.SetType("Number")
|
||||
.SetLabel("Movement angle")
|
||||
.SetDescription("The angle of the trajectory direction.")
|
||||
.SetGroup("Movement");
|
||||
|
||||
behavior.GetEventsFunctions().InsertNewEventsFunction("MovementAngle", 0);
|
||||
behavior.GetEventsFunctions().InsertNewEventsFunction("SetMovementAngle",
|
||||
0);
|
||||
|
||||
REQUIRE(!gd::PropertyFunctionGenerator::CanGenerateGetterAndSetter(
|
||||
behavior, property));
|
||||
}
|
||||
|
||||
SECTION("Forbid functions generation for required behavior properties") {
|
||||
gd::Platform platform;
|
||||
gd::Project project;
|
||||
SetupProjectWithDummyPlatform(project, platform);
|
||||
auto &extension =
|
||||
project.InsertNewEventsFunctionsExtension("MyEventsExtension", 0);
|
||||
auto &behavior = CreateBehavior(extension);
|
||||
|
||||
auto &property =
|
||||
behavior.GetPropertyDescriptors().InsertNew("MovementAngle", 0);
|
||||
property.SetType("Behavior")
|
||||
.SetLabel("Pathfinding behavior")
|
||||
.SetDescription("A required behavior.")
|
||||
.SetGroup("Movement")
|
||||
.GetExtraInfo()
|
||||
.push_back("PlatformBehavior::PlatformerObjectBehavior");
|
||||
|
||||
REQUIRE(!gd::PropertyFunctionGenerator::CanGenerateGetterAndSetter(
|
||||
behavior, property));
|
||||
}
|
||||
|
||||
SECTION("Can generate functions when only the property name is filled") {
|
||||
gd::Platform platform;
|
||||
gd::Project project;
|
||||
SetupProjectWithDummyPlatform(project, platform);
|
||||
auto &extension =
|
||||
project.InsertNewEventsFunctionsExtension("MyEventsExtension", 0);
|
||||
auto &behavior = CreateBehavior(extension);
|
||||
|
||||
auto &property =
|
||||
behavior.GetPropertyDescriptors().InsertNew("MovementAngle", 0);
|
||||
property.SetType("Number");
|
||||
|
||||
gd::PropertyFunctionGenerator::GenerateGetterAndSetter(
|
||||
project, extension, behavior, property, false);
|
||||
|
||||
REQUIRE(
|
||||
behavior.GetEventsFunctions().HasEventsFunctionNamed("MovementAngle"));
|
||||
REQUIRE(behavior.GetEventsFunctions().HasEventsFunctionNamed(
|
||||
"SetMovementAngle"));
|
||||
|
||||
auto &getter =
|
||||
behavior.GetEventsFunctions().GetEventsFunction("MovementAngle");
|
||||
|
||||
REQUIRE(getter.GetFunctionType() ==
|
||||
gd::EventsFunction::ExpressionAndCondition);
|
||||
REQUIRE(getter.GetExpressionType().GetName() == "expression");
|
||||
REQUIRE(getter.GetFullName() == "MovementAngle");
|
||||
REQUIRE(getter.GetGroup() == "My events based behavior configuration");
|
||||
REQUIRE(getter.GetDescription() == "the movementAngle of the object.");
|
||||
REQUIRE(getter.GetSentence() == "the movementAngle");
|
||||
}
|
||||
}
|
@@ -1367,6 +1367,7 @@ interface ValueTypeMetadata {
|
||||
boolean STATIC_IsTypeBehavior([Const] DOMString parameterType);
|
||||
boolean STATIC_IsTypeExpression([Const] DOMString type, [Const] DOMString parameterType);
|
||||
[Const, Ref] DOMString STATIC_GetPrimitiveValueType([Const] DOMString parameterType);
|
||||
[Const, Ref] DOMString STATIC_ConvertPropertyTypeToValueType([Const] DOMString propertyType);
|
||||
|
||||
void SerializeTo([Ref] SerializerElement element);
|
||||
void UnserializeFrom([Const, Ref] SerializerElement element);
|
||||
@@ -2158,6 +2159,11 @@ interface WholeProjectRefactorer {
|
||||
boolean STATIC_FixInvalidRequiredBehaviorProperties([Ref] Project project);
|
||||
};
|
||||
|
||||
interface PropertyFunctionGenerator {
|
||||
void STATIC_GenerateGetterAndSetter([Ref] Project project, [Ref] EventsFunctionsExtension extension, [Ref] EventsBasedBehavior eventsBasedBehavior, [Const, Ref] NamedPropertyDescriptor property, boolean isSharedProperties);
|
||||
boolean STATIC_CanGenerateGetterAndSetter([Const, Ref] EventsBasedBehavior eventsBasedBehavior, [Const, Ref] NamedPropertyDescriptor property);
|
||||
};
|
||||
|
||||
interface UsedExtensionsFinder {
|
||||
[Value] SetString STATIC_ScanProject([Ref] Project project);
|
||||
};
|
||||
|
@@ -48,6 +48,7 @@
|
||||
#include <GDCore/IDE/Project/ResourcesInUseHelper.h>
|
||||
#include <GDCore/IDE/Project/ResourcesMergingHelper.h>
|
||||
#include <GDCore/IDE/Project/ResourcesRenamer.h>
|
||||
#include <GDCore/IDE/PropertyFunctionGenerator.h>
|
||||
#include <GDCore/IDE/WholeProjectRefactorer.h>
|
||||
#include <GDCore/IDE/UnfilledRequiredBehaviorPropertyProblem.h>
|
||||
#include <GDCore/Project/Behavior.h>
|
||||
@@ -516,6 +517,7 @@ typedef ExtensionAndMetadata<ExpressionMetadata> ExtensionAndExpressionMetadata;
|
||||
#define STATIC_IsTypeExpression IsTypeExpression
|
||||
#define STATIC_GetExpressionValueType GetExpressionValueType
|
||||
#define STATIC_GetPrimitiveValueType GetPrimitiveValueType
|
||||
#define STATIC_ConvertPropertyTypeToValueType ConvertPropertyTypeToValueType
|
||||
#define STATIC_Get Get
|
||||
#define STATIC_GetAllUseless GetAllUseless
|
||||
#define STATIC_RemoveAllUseless RemoveAllUseless
|
||||
@@ -595,6 +597,8 @@ typedef ExtensionAndMetadata<ExpressionMetadata> ExtensionAndExpressionMetadata;
|
||||
GetBehaviorsWithType
|
||||
#define STATIC_FixInvalidRequiredBehaviorProperties \
|
||||
FixInvalidRequiredBehaviorProperties
|
||||
#define STATIC_GenerateGetterAndSetter GenerateGetterAndSetter
|
||||
#define STATIC_CanGenerateGetterAndSetter CanGenerateGetterAndSetter
|
||||
#define STATIC_CreateRectangle CreateRectangle
|
||||
#define STATIC_SanityCheckBehaviorProperty SanityCheckBehaviorProperty
|
||||
#define STATIC_SanityCheckObjectProperty SanityCheckObjectProperty
|
||||
|
7
GDevelop.js/types/gdpropertyfunctiongenerator.js
Normal file
7
GDevelop.js/types/gdpropertyfunctiongenerator.js
Normal file
@@ -0,0 +1,7 @@
|
||||
// Automatically generated by GDevelop.js/scripts/generate-types.js
|
||||
declare class gdPropertyFunctionGenerator {
|
||||
static generateGetterAndSetter(project: gdProject, extension: gdEventsFunctionsExtension, eventsBasedBehavior: gdEventsBasedBehavior, property: gdNamedPropertyDescriptor, isSharedProperties: boolean): void;
|
||||
static canGenerateGetterAndSetter(eventsBasedBehavior: gdEventsBasedBehavior, property: gdNamedPropertyDescriptor): boolean;
|
||||
delete(): void;
|
||||
ptr: number;
|
||||
};
|
@@ -18,6 +18,7 @@ declare class gdValueTypeMetadata {
|
||||
static isTypeBehavior(parameterType: string): boolean;
|
||||
static isTypeExpression(type: string, parameterType: string): boolean;
|
||||
static getPrimitiveValueType(parameterType: string): string;
|
||||
static convertPropertyTypeToValueType(propertyType: string): string;
|
||||
serializeTo(element: gdSerializerElement): void;
|
||||
unserializeFrom(element: gdSerializerElement): void;
|
||||
delete(): void;
|
||||
|
@@ -146,6 +146,7 @@ declare class libGDevelop {
|
||||
UnfilledRequiredBehaviorPropertyProblem: Class<gdUnfilledRequiredBehaviorPropertyProblem>;
|
||||
VectorUnfilledRequiredBehaviorPropertyProblem: Class<gdVectorUnfilledRequiredBehaviorPropertyProblem>;
|
||||
WholeProjectRefactorer: Class<gdWholeProjectRefactorer>;
|
||||
PropertyFunctionGenerator: Class<gdPropertyFunctionGenerator>;
|
||||
UsedExtensionsFinder: Class<gdUsedExtensionsFinder>;
|
||||
ExtensionAndBehaviorMetadata: Class<gdExtensionAndBehaviorMetadata>;
|
||||
ExtensionAndObjectMetadata: Class<gdExtensionAndObjectMetadata>;
|
||||
|
@@ -80,8 +80,9 @@ export default function EventsBasedBehaviorEditorDialog({
|
||||
)}
|
||||
{currentTab === 'behavior-properties' && (
|
||||
<EventsBasedBehaviorPropertiesEditor
|
||||
allowRequiredBehavior
|
||||
project={project}
|
||||
extension={eventsFunctionsExtension}
|
||||
eventsBasedBehavior={eventsBasedBehavior}
|
||||
properties={eventsBasedBehavior.getPropertyDescriptors()}
|
||||
onRenameProperty={onRenameProperty}
|
||||
behaviorObjectType={eventsBasedBehavior.getObjectType()}
|
||||
@@ -89,7 +90,10 @@ export default function EventsBasedBehaviorEditorDialog({
|
||||
)}
|
||||
{currentTab === 'scene-properties' && (
|
||||
<EventsBasedBehaviorPropertiesEditor
|
||||
isSceneProperties
|
||||
project={project}
|
||||
extension={eventsFunctionsExtension}
|
||||
eventsBasedBehavior={eventsBasedBehavior}
|
||||
properties={eventsBasedBehavior.getSharedPropertyDescriptors()}
|
||||
onRenameProperty={onRenameSharedProperty}
|
||||
/>
|
||||
|
@@ -32,8 +32,10 @@ const gd: libGDevelop = global.gd;
|
||||
|
||||
type Props = {|
|
||||
project: gdProject,
|
||||
extension: gdEventsFunctionsExtension,
|
||||
eventsBasedBehavior: gdEventsBasedBehavior,
|
||||
properties: gdNamedPropertyDescriptorsList,
|
||||
allowRequiredBehavior?: boolean,
|
||||
isSceneProperties?: boolean,
|
||||
onPropertiesUpdated?: () => void,
|
||||
onRenameProperty: (oldName: string, newName: string) => void,
|
||||
behaviorObjectType?: string,
|
||||
@@ -225,6 +227,21 @@ export default class EventsBasedBehaviorPropertiesEditor extends React.Component
|
||||
click: () => this._moveProperty(i, i + 1),
|
||||
enabled: i + 1 < properties.getCount(),
|
||||
},
|
||||
{
|
||||
label: i18n._(t`Generate expression and action`),
|
||||
click: () =>
|
||||
gd.PropertyFunctionGenerator.generateGetterAndSetter(
|
||||
this.props.project,
|
||||
this.props.extension,
|
||||
this.props.eventsBasedBehavior,
|
||||
property,
|
||||
!!this.props.isSceneProperties
|
||||
),
|
||||
enabled: gd.PropertyFunctionGenerator.canGenerateGetterAndSetter(
|
||||
this.props.eventsBasedBehavior,
|
||||
property
|
||||
),
|
||||
},
|
||||
]}
|
||||
/>
|
||||
</MiniToolbar>
|
||||
@@ -265,7 +282,7 @@ export default class EventsBasedBehaviorPropertiesEditor extends React.Component
|
||||
value="Color"
|
||||
primaryText={t`Color (text)`}
|
||||
/>
|
||||
{this.props.allowRequiredBehavior && (
|
||||
{!this.props.isSceneProperties && (
|
||||
<SelectOption
|
||||
value="Behavior"
|
||||
primaryText={t`Required behavior`}
|
||||
|
@@ -362,9 +362,7 @@ export default class EventsBasedObjectPropertiesEditor extends React.Component<
|
||||
<ResponsiveLineStackLayout noMargin>
|
||||
<SemiControlledTextField
|
||||
commitOnBlur
|
||||
floatingLabelText={
|
||||
<Trans>Label, shown in the editor</Trans>
|
||||
}
|
||||
floatingLabelText={<Trans>Short label</Trans>}
|
||||
translatableHintText={t`Make the purpose of the property easy to understand`}
|
||||
floatingLabelFixed
|
||||
value={property.getLabel()}
|
||||
|
@@ -699,22 +699,6 @@ type gdInstructionOrExpressionMetadata =
|
||||
| gdExpressionMetadata
|
||||
| gdMultipleInstructionMetadata;
|
||||
|
||||
const convertPropertyTypeToValueType = (propertyType: string): string => {
|
||||
switch (propertyType) {
|
||||
case 'Number':
|
||||
return 'number';
|
||||
case 'Boolean':
|
||||
return 'boolean';
|
||||
case 'Color':
|
||||
return 'color';
|
||||
case 'Choice':
|
||||
return 'stringWithSelector';
|
||||
case 'String':
|
||||
default:
|
||||
return 'string';
|
||||
}
|
||||
};
|
||||
|
||||
const getStringifiedExtraInfo = (property: gdPropertyDescriptor) => {
|
||||
return property.getType() === 'Choice'
|
||||
? JSON.stringify(property.getExtraInfo().toJSArray())
|
||||
@@ -778,7 +762,7 @@ export const declareBehaviorPropertiesInstructionAndExpressions = (
|
||||
|
||||
addObjectAndBehaviorParameters(
|
||||
behaviorMetadata.addExpressionAndConditionAndAction(
|
||||
convertPropertyTypeToValueType(propertyType),
|
||||
gd.ValueTypeMetadata.convertPropertyTypeToValueType(propertyType),
|
||||
gd.EventsBasedBehavior.getPropertyExpressionName(propertyName),
|
||||
propertyLabel,
|
||||
i18n._(t`the value of ${propertyLabel}`),
|
||||
@@ -788,7 +772,7 @@ export const declareBehaviorPropertiesInstructionAndExpressions = (
|
||||
)
|
||||
)
|
||||
.useStandardParameters(
|
||||
convertPropertyTypeToValueType(propertyType),
|
||||
gd.ValueTypeMetadata.convertPropertyTypeToValueType(propertyType),
|
||||
getStringifiedExtraInfo(property)
|
||||
)
|
||||
.setFunctionName(
|
||||
@@ -808,7 +792,7 @@ export const declareBehaviorPropertiesInstructionAndExpressions = (
|
||||
|
||||
addObjectAndBehaviorParameters(
|
||||
behaviorMetadata.addExpressionAndConditionAndAction(
|
||||
convertPropertyTypeToValueType(propertyType),
|
||||
gd.ValueTypeMetadata.convertPropertyTypeToValueType(propertyType),
|
||||
gd.EventsBasedBehavior.getSharedPropertyExpressionName(propertyName),
|
||||
propertyLabel,
|
||||
i18n._(t`the value of ${propertyLabel}`),
|
||||
@@ -818,7 +802,7 @@ export const declareBehaviorPropertiesInstructionAndExpressions = (
|
||||
)
|
||||
)
|
||||
.useStandardParameters(
|
||||
convertPropertyTypeToValueType(propertyType),
|
||||
gd.ValueTypeMetadata.convertPropertyTypeToValueType(propertyType),
|
||||
getStringifiedExtraInfo(property)
|
||||
)
|
||||
.setFunctionName(
|
||||
@@ -873,7 +857,7 @@ export const declareObjectPropertiesInstructionAndExpressions = (
|
||||
|
||||
addObjectParameter(
|
||||
objectMetadata.addExpressionAndConditionAndAction(
|
||||
convertPropertyTypeToValueType(propertyType),
|
||||
gd.ValueTypeMetadata.convertPropertyTypeToValueType(propertyType),
|
||||
gd.EventsBasedObject.getPropertyExpressionName(propertyName),
|
||||
propertyLabel,
|
||||
i18n._(t`the value of ${propertyLabel}`),
|
||||
@@ -883,7 +867,7 @@ export const declareObjectPropertiesInstructionAndExpressions = (
|
||||
)
|
||||
)
|
||||
.useStandardParameters(
|
||||
convertPropertyTypeToValueType(propertyType),
|
||||
gd.ValueTypeMetadata.convertPropertyTypeToValueType(propertyType),
|
||||
getStringifiedExtraInfo(property)
|
||||
)
|
||||
.setFunctionName(
|
||||
|
Reference in New Issue
Block a user