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.
57 lines
1.7 KiB
C++
57 lines
1.7 KiB
C++
/*
|
|
* GDevelop Core
|
|
* Copyright 2008-2016 Florian Rival (Florian.Rival@gmail.com). All rights
|
|
* reserved. This project is released under the MIT License.
|
|
*/
|
|
#pragma once
|
|
#include <map>
|
|
#include <memory>
|
|
#include <unordered_map>
|
|
#include <unordered_set>
|
|
#include <vector>
|
|
|
|
#include "GDCore/IDE/Events/ArbitraryEventsWorker.h"
|
|
#include "GDCore/String.h"
|
|
namespace gd {
|
|
class BaseEvent;
|
|
class PropertiesContainer;
|
|
class EventsList;
|
|
class Platform;
|
|
} // namespace gd
|
|
|
|
namespace gd {
|
|
|
|
/**
|
|
* \brief Replace in expressions and in parameters of actions or conditions,
|
|
* references to the name of a property by another.
|
|
*
|
|
* \ingroup IDE
|
|
*/
|
|
class GD_CORE_API EventsPropertyReplacer
|
|
: public ArbitraryEventsWorkerWithContext {
|
|
public:
|
|
EventsPropertyReplacer(
|
|
const gd::Platform &platform_,
|
|
const gd::PropertiesContainer &targetPropertiesContainer_,
|
|
const std::unordered_map<gd::String, gd::String> &oldToNewPropertyNames_,
|
|
const std::unordered_set<gd::String> &removedPropertyNames_)
|
|
: platform(platform_),
|
|
targetPropertiesContainer(targetPropertiesContainer_),
|
|
oldToNewPropertyNames(oldToNewPropertyNames_),
|
|
removedPropertyNames(removedPropertyNames_){};
|
|
virtual ~EventsPropertyReplacer();
|
|
|
|
private:
|
|
bool DoVisitInstruction(gd::Instruction &instruction,
|
|
bool isCondition) override;
|
|
bool DoVisitEventExpression(gd::Expression &expression,
|
|
const gd::ParameterMetadata &metadata) override;
|
|
|
|
const gd::Platform &platform;
|
|
const gd::PropertiesContainer &targetPropertiesContainer;
|
|
const std::unordered_map<gd::String, gd::String> &oldToNewPropertyNames;
|
|
const std::unordered_set<gd::String> &removedPropertyNames;
|
|
};
|
|
|
|
} // namespace gd
|