GDevelop Core
Core library for developing platforms and tools compatible with GDevelop.
Event.h
1 /*
2  * GDevelop Core
3  * Copyright 2008-2016 Florian Rival ([email protected]). All rights
4  * reserved. This project is released under the MIT License.
5  */
6 #if defined(GD_IDE_ONLY)
7 #ifndef GDCORE_EVENT_H
8 #define GDCORE_EVENT_H
9 
10 #include <iostream>
11 #include <memory>
12 #include <vector>
13 
14 #include "GDCore/Events/Instruction.h"
15 #include "GDCore/Events/InstructionsList.h"
16 #include "GDCore/Extensions/Metadata/InstructionMetadata.h"
17 #include "GDCore/String.h"
18 namespace gd {
19 class EventsList;
20 class Project;
21 class Layout;
22 class EventsCodeGenerator;
23 class EventsCodeGenerationContext;
24 class Platform;
25 class SerializerElement;
26 class Instruction;
27 class EventVisitor;
28 class ReadOnlyEventVisitor;
29 } // namespace gd
30 
31 namespace gd {
32 
33 class BaseEvent;
34 typedef std::shared_ptr<BaseEvent> BaseEventSPtr;
35 
44 class GD_CORE_API BaseEvent {
45  public:
46  BaseEvent();
47  virtual ~BaseEvent(){};
48 
59  virtual gd::BaseEvent* Clone() const { return new BaseEvent(*this); }
60 
66 
71  virtual bool IsExecutable() const { return false; };
72 
77  virtual bool CanHaveSubEvents() const { return false; }
78 
82  virtual const gd::EventsList& GetSubEvents() const { return badSubEvents; };
83 
87  virtual gd::EventsList& GetSubEvents() { return badSubEvents; };
88 
93  bool HasSubEvents() const;
94 
99  virtual std::vector<gd::InstructionsList*> GetAllConditionsVectors() {
100  std::vector<gd::InstructionsList*> noConditions;
101  return noConditions;
102  };
103  virtual std::vector<const gd::InstructionsList*> GetAllConditionsVectors()
104  const {
105  std::vector<const gd::InstructionsList*> noConditions;
106  return noConditions;
107  };
108 
113  virtual std::vector<gd::InstructionsList*> GetAllActionsVectors() {
114  std::vector<gd::InstructionsList*> noActions;
115  return noActions;
116  };
117  virtual std::vector<const gd::InstructionsList*> GetAllActionsVectors()
118  const {
119  std::vector<const gd::InstructionsList*> noActions;
120  return noActions;
121  };
122 
127  virtual std::vector<gd::String> GetAllSearchableStrings() const {
128  std::vector<gd::String> noSearchableStrings;
129  return noSearchableStrings;
130  };
131 
132  virtual bool ReplaceAllSearchableStrings(
133  std::vector<gd::String> newSearchableString) {
134  return false;
135  };
136 
141  virtual std::vector<std::pair<gd::Expression*, gd::ParameterMetadata> >
143  std::vector<std::pair<gd::Expression*, gd::ParameterMetadata> > noExpr;
144  return noExpr;
145  };
146  virtual std::vector<
147  std::pair<const gd::Expression*, const gd::ParameterMetadata> >
148  GetAllExpressionsWithMetadata() const {
149  std::vector<std::pair<const gd::Expression*, const gd::ParameterMetadata> >
150  noExpr;
151  return noExpr;
152  };
153 
160  virtual const std::vector<gd::String>& GetSourceFileDependencies() const {
161  return emptyDependencies;
162  };
163 
170  gd::Project& project) const {
171  return emptySourceFile;
172  };
174 
179 
193  virtual gd::String GenerateEventCode(
194  gd::EventsCodeGenerator& codeGenerator,
196 
210  virtual void Preprocess(gd::EventsCodeGenerator& codeGenerator,
211  gd::EventsList& eventList,
212  std::size_t indexOfTheEventInThisList);
213 
217  void PreprocessAsyncActions(const gd::Platform& platform);
218 
227  virtual bool MustBePreprocessed() { return false; }
229 
233 
236  virtual void SerializeTo(SerializerElement& element) const {};
237 
241  virtual void UnserializeFrom(gd::Project& project,
242  const SerializerElement& element){};
243 
244  virtual bool AcceptVisitor(gd::EventVisitor& eventVisitor);
245  virtual void AcceptVisitor(gd::ReadOnlyEventVisitor& eventVisitor) const;
247 
253 
257  const gd::String& GetType() const { return type; };
258 
262  void SetType(gd::String type_) { type = type_; };
263 
267  void SetDisabled(bool disable = true) { disabled = disable; }
268 
272  bool IsDisabled() const { return disabled; }
273 
278  void SetFolded(bool fold = true) { folded = fold; }
279 
283  bool IsFolded() const { return folded; }
285 
286  std::weak_ptr<gd::BaseEvent>
290  signed long long
296 
297  private:
298  bool folded;
299  bool disabled;
300  gd::String type;
302 
303  static gd::EventsList badSubEvents;
304  static std::vector<gd::String> emptyDependencies;
305  static gd::String emptySourceFile;
306 };
307 
315 BaseEventSPtr GD_CORE_API CloneRememberingOriginalEvent(BaseEventSPtr event);
316 
321 class EmptyEvent : public BaseEvent {
322  public:
323  EmptyEvent() : BaseEvent(){};
324  virtual ~EmptyEvent(){};
325 };
326 
327 } // namespace gd
328 
329 #endif // GDCORE_EVENT_H
330 #endif
Base class defining an event.
Definition: Event.h:44
float percentDuringLastSession
Definition: Event.h:294
void SetType(gd::String type_)
Change the event type.
Definition: Event.h:262
virtual std::vector< gd::InstructionsList * > GetAllActionsVectors()
Return a list of all actions of the event.
Definition: Event.h:113
virtual const std::vector< gd::String > & GetSourceFileDependencies() const
Returns the dependencies on source files of the project.
Definition: Event.h:160
virtual std::vector< std::pair< gd::Expression *, gd::ParameterMetadata > > GetAllExpressionsWithMetadata()
Return a list of all expressions of the event, each with their associated metadata.
Definition: Event.h:142
virtual gd::BaseEvent * Clone() const
Definition: Event.h:59
virtual std::vector< gd::InstructionsList * > GetAllConditionsVectors()
Return a list of all conditions of the event.
Definition: Event.h:99
virtual bool CanHaveSubEvents() const
Definition: Event.h:77
virtual void SerializeTo(SerializerElement &element) const
Serialize event.
Definition: Event.h:236
void SetFolded(bool fold=true)
Set if the event must be folded (i.e: sub events must be hidden in the events editor).
Definition: Event.h:278
bool IsDisabled() const
True if event is disabled.
Definition: Event.h:272
virtual void UnserializeFrom(gd::Project &project, const SerializerElement &element)
Unserialize the event.
Definition: Event.h:241
virtual bool MustBePreprocessed()
If MustBePreprocessed is redefined to return true, the gd::EventMetadata::preprocessing associated to...
Definition: Event.h:227
virtual std::vector< gd::String > GetAllSearchableStrings() const
Return a list of all strings of the event.
Definition: Event.h:127
virtual bool IsExecutable() const
Definition: Event.h:71
virtual gd::EventsList & GetSubEvents()
Definition: Event.h:87
void SetDisabled(bool disable=true)
Set if the event if disabled or not.
Definition: Event.h:267
virtual const gd::EventsList & GetSubEvents() const
Definition: Event.h:82
std::weak_ptr< gd::BaseEvent > originalEvent
Definition: Event.h:287
bool IsFolded() const
True if the event should be folded in the events editor.
Definition: Event.h:283
const gd::String & GetType() const
Return the event type.
Definition: Event.h:257
signed long long totalTimeDuringLastSession
Definition: Event.h:291
virtual const gd::String & GetAssociatedGDManagedSourceFile(gd::Project &project) const
Returns the name of the source file associated with the event.
Definition: Event.h:169
Empty event doing nothing.
Definition: Event.h:321
Visitor of any kind of event.
Definition: EventVisitor.h:26
Used to manage the context when generating code for events.
Definition: EventsCodeGenerationContext.h:27
Internal class used to generate code from events.
Definition: EventsCodeGenerator.h:40
A list of events.
Definition: EventsList.h:33
Base class for implementing a platform.
Definition: Platform.h:42
Base class representing a project (game), including all resources, scenes, objects,...
Definition: Project.h:50
Visitor of any kind of event.
Definition: EventVisitor.h:54
A generic container that can represent a value ( containing a string, double, bool or int),...
Definition: SerializerElement.h:37
String represents an UTF8 encoded string.
Definition: String.h:31
BaseEventSPtr GD_CORE_API CloneRememberingOriginalEvent(BaseEventSPtr event)
Definition: Event.cpp:152
Definition: CommonTools.h:24