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 #pragma once
7 
8 #include <iostream>
9 #include <memory>
10 #include <vector>
11 
12 #include "GDCore/Events/Instruction.h"
13 #include "GDCore/Events/InstructionsList.h"
14 #include "GDCore/Extensions/Metadata/InstructionMetadata.h"
15 #include "GDCore/Project/MemoryTrackedRegistry.h"
16 #include "GDCore/String.h"
17 namespace gd {
18 class EventsList;
19 class Project;
20 class Layout;
21 class EventsCodeGenerator;
22 class EventsCodeGenerationContext;
23 class Platform;
24 class SerializerElement;
25 class Instruction;
26 class EventVisitor;
27 class ReadOnlyEventVisitor;
28 class VariablesContainer;
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  BaseEvent(const BaseEvent& other);
48  BaseEvent& operator=(const BaseEvent& other);
49  virtual ~BaseEvent(){};
50 
61  virtual gd::BaseEvent* Clone() const { return new BaseEvent(*this); }
62 
68 
73  virtual bool IsExecutable() const { return false; };
74 
79  virtual bool CanHaveSubEvents() const { return false; }
80 
84  virtual const gd::EventsList& GetSubEvents() const { return badSubEvents; };
85 
89  virtual gd::EventsList& GetSubEvents() { return badSubEvents; };
90 
95  bool HasSubEvents() const;
96 
101  virtual bool CanHaveVariables() const { return false; }
102 
106  virtual const gd::VariablesContainer& GetVariables() const {
107  return badLocalVariables;
108  };
109 
114  return badLocalVariables;
115  };
116 
121  bool HasVariables() const;
122 
132  return nullptr;
133  };
134  virtual const gd::InstructionsList* GetInstructionList(
135  const gd::String& label) const {
136  return nullptr;
137  };
138 
139  static const gd::String conditionsLabel;
140  static const gd::String actionsLabel;
141  static const gd::String whileConditionsLabel;
142 
147  virtual std::vector<gd::InstructionsList*> GetAllConditionsVectors() {
148  std::vector<gd::InstructionsList*> noConditions;
149  return noConditions;
150  };
151  virtual std::vector<const gd::InstructionsList*> GetAllConditionsVectors()
152  const {
153  std::vector<const gd::InstructionsList*> noConditions;
154  return noConditions;
155  };
156 
161  virtual std::vector<gd::InstructionsList*> GetAllActionsVectors() {
162  std::vector<gd::InstructionsList*> noActions;
163  return noActions;
164  };
165  virtual std::vector<const gd::InstructionsList*> GetAllActionsVectors()
166  const {
167  std::vector<const gd::InstructionsList*> noActions;
168  return noActions;
169  };
170 
175  virtual std::vector<gd::String> GetAllSearchableStrings() const {
176  std::vector<gd::String> noSearchableStrings;
177  return noSearchableStrings;
178  };
179 
180  virtual bool ReplaceAllSearchableStrings(
181  std::vector<gd::String> newSearchableString) {
182  return false;
183  };
184 
189  virtual std::vector<std::pair<gd::Expression*, gd::ParameterMetadata> >
191  std::vector<std::pair<gd::Expression*, gd::ParameterMetadata> > noExpr;
192  return noExpr;
193  };
194  virtual std::vector<
195  std::pair<const gd::Expression*, const gd::ParameterMetadata> >
196  GetAllExpressionsWithMetadata() const {
197  std::vector<std::pair<const gd::Expression*, const gd::ParameterMetadata> >
198  noExpr;
199  return noExpr;
200  };
202 
207 
221  virtual gd::String GenerateEventCode(
222  gd::EventsCodeGenerator& codeGenerator,
224 
238  virtual void Preprocess(gd::EventsCodeGenerator& codeGenerator,
239  gd::EventsList& eventList,
240  std::size_t indexOfTheEventInThisList);
241 
245  void PreprocessAsyncActions(const gd::Platform& platform);
246 
255  virtual bool MustBePreprocessed() { return false; }
257 
261 
264  virtual void SerializeTo(SerializerElement& element) const {};
265 
269  virtual void UnserializeFrom(gd::Project& project,
270  const SerializerElement& element){};
271 
272  virtual bool AcceptVisitor(gd::EventVisitor& eventVisitor);
273  virtual void AcceptVisitor(gd::ReadOnlyEventVisitor& eventVisitor) const;
275 
281 
285  const gd::String& GetType() const { return type; };
286 
290  void SetType(gd::String type_) { type = type_; };
291 
295  void SetDisabled(bool disable = true) { disabled = disable; }
296 
300  bool IsDisabled() const { return disabled; }
301 
306  void SetFolded(bool fold = true) { folded = fold; }
307 
311  bool IsFolded() const { return folded; }
312 
316  void SetAiGeneratedEventId(const gd::String& aiGeneratedEventId_) {
317  aiGeneratedEventId = aiGeneratedEventId_;
318  }
319 
324  return aiGeneratedEventId;
325  }
327 
328  std::weak_ptr<gd::BaseEvent>
332  signed long long
338 
339  private:
340  bool folded;
341  bool disabled;
342  gd::String type;
344  gd::String aiGeneratedEventId;
345 
346  static gd::EventsList badSubEvents;
347  static gd::VariablesContainer badLocalVariables;
348  gd::MemoryTracked _memoryTracked{this, "BaseEvent"};
349 };
350 
358 BaseEventSPtr GD_CORE_API CloneRememberingOriginalEvent(BaseEventSPtr event);
359 
364 class EmptyEvent : public BaseEvent {
365  public:
366  EmptyEvent() : BaseEvent(){};
367  virtual ~EmptyEvent(){};
368 };
369 
370 } // namespace gd
Base class defining an event.
Definition: Event.h:44
float percentDuringLastSession
Definition: Event.h:336
void SetType(gd::String type_)
Change the event type.
Definition: Event.h:290
virtual std::vector< gd::InstructionsList * > GetAllActionsVectors()
Return a list of all actions of the event.
Definition: Event.h:161
const gd::String & GetAiGeneratedEventId() const
Get the AI generated event ID.
Definition: Event.h:323
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:190
void SetAiGeneratedEventId(const gd::String &aiGeneratedEventId_)
Set the AI generated event ID.
Definition: Event.h:316
virtual gd::BaseEvent * Clone() const
Definition: Event.h:61
virtual std::vector< gd::InstructionsList * > GetAllConditionsVectors()
Return a list of all conditions of the event.
Definition: Event.h:147
virtual bool CanHaveSubEvents() const
Definition: Event.h:79
virtual gd::InstructionsList * GetInstructionList(const gd::String &label)
Return the instruction list identified by label, or nullptr if the event has no such list.
Definition: Event.h:131
virtual void SerializeTo(SerializerElement &element) const
Serialize event.
Definition: Event.h:264
virtual bool CanHaveVariables() const
Definition: Event.h:101
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:306
bool IsDisabled() const
True if event is disabled.
Definition: Event.h:300
virtual void UnserializeFrom(gd::Project &project, const SerializerElement &element)
Unserialize the event.
Definition: Event.h:269
virtual bool MustBePreprocessed()
If MustBePreprocessed is redefined to return true, the gd::EventMetadata::preprocessing associated to...
Definition: Event.h:255
virtual std::vector< gd::String > GetAllSearchableStrings() const
Return a list of all strings of the event.
Definition: Event.h:175
virtual bool IsExecutable() const
Definition: Event.h:73
virtual gd::EventsList & GetSubEvents()
Definition: Event.h:89
void SetDisabled(bool disable=true)
Set if the event if disabled or not.
Definition: Event.h:295
virtual const gd::EventsList & GetSubEvents() const
Definition: Event.h:84
std::weak_ptr< gd::BaseEvent > originalEvent
Definition: Event.h:329
bool IsFolded() const
True if the event should be folded in the events editor.
Definition: Event.h:311
const gd::String & GetType() const
Return the event type.
Definition: Event.h:285
virtual const gd::VariablesContainer & GetVariables() const
Definition: Event.h:106
virtual gd::VariablesContainer & GetVariables()
Definition: Event.h:113
signed long long totalTimeDuringLastSession
Definition: Event.h:333
Empty event doing nothing.
Definition: Event.h:364
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:41
A list of events.
Definition: EventsList.h:32
Definition: InstructionsList.h:25
A non-copyable, non-movable member object that registers/unregisters its owner with MemoryTrackedRegi...
Definition: MemoryTrackedRegistry.h:238
Base class for implementing a platform.
Definition: Platform.h:42
Base class representing a project (game), including all resources, scenes, objects,...
Definition: Project.h:51
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:33
Class defining a container for gd::Variable.
Definition: VariablesContainer.h:29
BaseEventSPtr GD_CORE_API CloneRememberingOriginalEvent(BaseEventSPtr event)
Definition: Event.cpp:180
Definition: CommonTools.h:24