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.0 KiB
C++
103 lines
3.0 KiB
C++
/*
|
|
* GDevelop Core
|
|
* Copyright 2008-2016 Florian Rival (Florian.Rival@gmail.com). All rights
|
|
* reserved. This project is released under the MIT License.
|
|
*/
|
|
#ifndef EventsContextAnalyzer_H
|
|
#define EventsContextAnalyzer_H
|
|
#include <map>
|
|
#include <memory>
|
|
#include <set>
|
|
#include <vector>
|
|
#include "GDCore/IDE/Events/ArbitraryEventsWorker.h"
|
|
#include "GDCore/String.h"
|
|
namespace gd {
|
|
class BaseEvent;
|
|
class Platform;
|
|
class ObjectsContainer;
|
|
class ObjectsContainersList;
|
|
class Project;
|
|
class Layout;
|
|
class EventsList;
|
|
class ParameterMetadata;
|
|
class Expression;
|
|
} // namespace gd
|
|
|
|
namespace gd {
|
|
|
|
/**
|
|
* \brief Store the results of a search done by EventsContextAnalyzer.
|
|
*/
|
|
class GD_CORE_API EventsContext {
|
|
public:
|
|
EventsContext(){};
|
|
virtual ~EventsContext(){};
|
|
|
|
void AddObjectName(const gd::ProjectScopedContainers& projectScopedContainers,
|
|
const gd::String& objectOrGroupName);
|
|
void AddBehaviorName(const gd::ProjectScopedContainers& projectScopedContainers,
|
|
const gd::String& objectOrGroupName,
|
|
const gd::String& behaviorName);
|
|
|
|
/**
|
|
* \brief Get object or group names being referenced in the events.
|
|
*/
|
|
const std::set<gd::String>& GetReferencedObjectOrGroupNames() {
|
|
return referencedObjectOrGroupNames;
|
|
}
|
|
|
|
/**
|
|
* \brief Get objects referenced in the events, without groups (all groups
|
|
* have been "expanded" to the real objects being referenced by the group).
|
|
*/
|
|
const std::set<gd::String>& GetObjectNames() { return objectNames; }
|
|
|
|
/**
|
|
* \brief Get behaviors referenced in the events for the given object (or
|
|
* group) name.
|
|
*/
|
|
const std::set<gd::String>& GetBehaviorNamesOfObjectOrGroup(const gd::String& objectOrGroupName) {
|
|
return objectOrGroupBehaviorNames[objectOrGroupName];
|
|
}
|
|
|
|
private:
|
|
std::set<gd::String> referencedObjectOrGroupNames;
|
|
std::set<gd::String> objectNames;
|
|
std::map<gd::String, std::set<gd::String>> objectOrGroupBehaviorNames;
|
|
};
|
|
|
|
/**
|
|
* \brief Analyze events to list all the objects being used in them.
|
|
*
|
|
* \ingroup IDE
|
|
*/
|
|
class GD_CORE_API EventsContextAnalyzer : public ArbitraryEventsWorkerWithContext {
|
|
public:
|
|
EventsContextAnalyzer(const gd::Platform& platform_)
|
|
: platform(platform_) {};
|
|
virtual ~EventsContextAnalyzer(){};
|
|
|
|
/**
|
|
* Get the context containing the objects that are used in the events.
|
|
*/
|
|
const EventsContext& GetEventsContext() { return context; }
|
|
|
|
static void AnalyzeParameter(const gd::Platform& platform,
|
|
const gd::ProjectScopedContainers& projectScopedContainers,
|
|
const gd::ParameterMetadata& metadata,
|
|
const gd::Expression& parameter,
|
|
EventsContext& context,
|
|
const gd::String& lastObjectName);
|
|
|
|
private:
|
|
virtual bool DoVisitInstruction(gd::Instruction& instruction,
|
|
bool isCondition);
|
|
|
|
const gd::Platform& platform;
|
|
EventsContext context;
|
|
};
|
|
|
|
} // namespace gd
|
|
|
|
#endif // EventsContextAnalyzer_H
|