mirror of
https://github.com/4ian/GDevelop.git
synced 2025-10-15 10:19:04 +00:00

* 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.
103 lines
3.4 KiB
C++
103 lines
3.4 KiB
C++
/*
|
|
* GDevelop Core
|
|
* Copyright 2008-2016 Florian Rival (Florian.Rival@gmail.com). All rights
|
|
* reserved. This project is released under the MIT License.
|
|
*/
|
|
|
|
#include "RepeatEvent.h"
|
|
#include "GDCore/Events/Serialization.h"
|
|
#include "GDCore/Serialization/SerializerElement.h"
|
|
|
|
using namespace std;
|
|
|
|
namespace gd {
|
|
|
|
RepeatEvent::RepeatEvent()
|
|
: BaseEvent(),
|
|
repeatNumberExpression(""),
|
|
repeatNumberExpressionSelected(false) {}
|
|
|
|
vector<gd::InstructionsList*> RepeatEvent::GetAllConditionsVectors() {
|
|
vector<gd::InstructionsList*> allConditions;
|
|
allConditions.push_back(&conditions);
|
|
|
|
return allConditions;
|
|
}
|
|
|
|
vector<gd::InstructionsList*> RepeatEvent::GetAllActionsVectors() {
|
|
vector<gd::InstructionsList*> allActions;
|
|
allActions.push_back(&actions);
|
|
|
|
return allActions;
|
|
}
|
|
|
|
vector<pair<gd::Expression*, gd::ParameterMetadata> >
|
|
RepeatEvent::GetAllExpressionsWithMetadata() {
|
|
vector<pair<gd::Expression*, gd::ParameterMetadata> >
|
|
allExpressionsWithMetadata;
|
|
auto metadata = gd::ParameterMetadata().SetType("number");
|
|
allExpressionsWithMetadata.push_back(
|
|
std::make_pair(&repeatNumberExpression, metadata));
|
|
|
|
return allExpressionsWithMetadata;
|
|
}
|
|
|
|
vector<const gd::InstructionsList*> RepeatEvent::GetAllConditionsVectors()
|
|
const {
|
|
vector<const gd::InstructionsList*> allConditions;
|
|
allConditions.push_back(&conditions);
|
|
|
|
return allConditions;
|
|
}
|
|
|
|
vector<const gd::InstructionsList*> RepeatEvent::GetAllActionsVectors() const {
|
|
vector<const gd::InstructionsList*> allActions;
|
|
allActions.push_back(&actions);
|
|
|
|
return allActions;
|
|
}
|
|
|
|
vector<pair<const gd::Expression*, const gd::ParameterMetadata> >
|
|
RepeatEvent::GetAllExpressionsWithMetadata() const {
|
|
vector<pair<const gd::Expression*, const gd::ParameterMetadata> >
|
|
allExpressionsWithMetadata;
|
|
auto metadata = gd::ParameterMetadata().SetType("number");
|
|
allExpressionsWithMetadata.push_back(
|
|
std::make_pair(&repeatNumberExpression, metadata));
|
|
|
|
return allExpressionsWithMetadata;
|
|
}
|
|
|
|
void RepeatEvent::SerializeTo(SerializerElement& element) const {
|
|
element.AddChild("repeatExpression")
|
|
.SetValue(repeatNumberExpression.GetPlainString());
|
|
gd::EventsListSerialization::SerializeInstructionsTo(
|
|
conditions, element.AddChild("conditions"));
|
|
gd::EventsListSerialization::SerializeInstructionsTo(
|
|
actions, element.AddChild("actions"));
|
|
|
|
if (!events.IsEmpty())
|
|
gd::EventsListSerialization::SerializeEventsTo(events,
|
|
element.AddChild("events"));
|
|
}
|
|
|
|
void RepeatEvent::UnserializeFrom(gd::Project& project,
|
|
const SerializerElement& element) {
|
|
repeatNumberExpression =
|
|
gd::Expression(element.GetChild("repeatExpression", 0, "RepeatExpression")
|
|
.GetValue()
|
|
.GetString());
|
|
gd::EventsListSerialization::UnserializeInstructionsFrom(
|
|
project, conditions, element.GetChild("conditions", 0, "Conditions"));
|
|
gd::EventsListSerialization::UnserializeInstructionsFrom(
|
|
project, actions, element.GetChild("actions", 0, "Actions"));
|
|
|
|
events.Clear();
|
|
if (element.HasChild("events", "Events")) {
|
|
gd::EventsListSerialization::UnserializeEventsFrom(
|
|
project, events, element.GetChild("events", 0, "Events"));
|
|
}
|
|
}
|
|
|
|
} // namespace gd
|