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/String.h"
16 namespace gd {
17 class EventsList;
18 class Project;
19 class Layout;
20 class EventsCodeGenerator;
21 class EventsCodeGenerationContext;
22 class Platform;
23 class SerializerElement;
24 class Instruction;
25 class EventVisitor;
26 class ReadOnlyEventVisitor;
27 class VariablesContainer;
28 } // namespace gd
29 
30 namespace gd {
31 
32 class BaseEvent;
33 typedef std::shared_ptr<BaseEvent> BaseEventSPtr;
34 
43 class GD_CORE_API BaseEvent {
44  public:
45  BaseEvent();
46  virtual ~BaseEvent(){};
47 
58  virtual gd::BaseEvent* Clone() const { return new BaseEvent(*this); }
59 
65 
70  virtual bool IsExecutable() const { return false; };
71 
76  virtual bool CanHaveSubEvents() const { return false; }
77 
81  virtual const gd::EventsList& GetSubEvents() const { return badSubEvents; };
82 
86  virtual gd::EventsList& GetSubEvents() { return badSubEvents; };
87 
92  bool HasSubEvents() const;
93 
98  virtual bool CanHaveVariables() const { return false; }
99 
103  virtual const gd::VariablesContainer& GetVariables() const {
104  return badLocalVariables;
105  };
106 
111  return badLocalVariables;
112  };
113 
118  bool HasVariables() const;
119 
129  return nullptr;
130  };
131  virtual const gd::InstructionsList* GetInstructionList(
132  const gd::String& label) const {
133  return nullptr;
134  };
135 
136  static const gd::String conditionsLabel;
137  static const gd::String actionsLabel;
138  static const gd::String whileConditionsLabel;
139 
144  virtual std::vector<gd::InstructionsList*> GetAllConditionsVectors() {
145  std::vector<gd::InstructionsList*> noConditions;
146  return noConditions;
147  };
148  virtual std::vector<const gd::InstructionsList*> GetAllConditionsVectors()
149  const {
150  std::vector<const gd::InstructionsList*> noConditions;
151  return noConditions;
152  };
153 
158  virtual std::vector<gd::InstructionsList*> GetAllActionsVectors() {
159  std::vector<gd::InstructionsList*> noActions;
160  return noActions;
161  };
162  virtual std::vector<const gd::InstructionsList*> GetAllActionsVectors()
163  const {
164  std::vector<const gd::InstructionsList*> noActions;
165  return noActions;
166  };
167 
172  virtual std::vector<gd::String> GetAllSearchableStrings() const {
173  std::vector<gd::String> noSearchableStrings;
174  return noSearchableStrings;
175  };
176 
177  virtual bool ReplaceAllSearchableStrings(
178  std::vector<gd::String> newSearchableString) {
179  return false;
180  };
181 
186  virtual std::vector<std::pair<gd::Expression*, gd::ParameterMetadata> >
188  std::vector<std::pair<gd::Expression*, gd::ParameterMetadata> > noExpr;
189  return noExpr;
190  };
191  virtual std::vector<
192  std::pair<const gd::Expression*, const gd::ParameterMetadata> >
193  GetAllExpressionsWithMetadata() const {
194  std::vector<std::pair<const gd::Expression*, const gd::ParameterMetadata> >
195  noExpr;
196  return noExpr;
197  };
199 
204 
218  virtual gd::String GenerateEventCode(
219  gd::EventsCodeGenerator& codeGenerator,
221 
235  virtual void Preprocess(gd::EventsCodeGenerator& codeGenerator,
236  gd::EventsList& eventList,
237  std::size_t indexOfTheEventInThisList);
238 
242  void PreprocessAsyncActions(const gd::Platform& platform);
243 
252  virtual bool MustBePreprocessed() { return false; }
254 
258 
261  virtual void SerializeTo(SerializerElement& element) const {};
262 
266  virtual void UnserializeFrom(gd::Project& project,
267  const SerializerElement& element){};
268 
269  virtual bool AcceptVisitor(gd::EventVisitor& eventVisitor);
270  virtual void AcceptVisitor(gd::ReadOnlyEventVisitor& eventVisitor) const;
272 
278 
282  const gd::String& GetType() const { return type; };
283 
287  void SetType(gd::String type_) { type = type_; };
288 
292  void SetDisabled(bool disable = true) { disabled = disable; }
293 
297  bool IsDisabled() const { return disabled; }
298 
303  void SetFolded(bool fold = true) { folded = fold; }
304 
308  bool IsFolded() const { return folded; }
309 
313  void SetAiGeneratedEventId(const gd::String& aiGeneratedEventId_) {
314  aiGeneratedEventId = aiGeneratedEventId_;
315  }
316 
321  return aiGeneratedEventId;
322  }
324 
325  std::weak_ptr<gd::BaseEvent>
329  signed long long
335 
336  private:
337  bool folded;
338  bool disabled;
339  gd::String type;
341  gd::String aiGeneratedEventId;
342 
343  static gd::EventsList badSubEvents;
344  static gd::VariablesContainer badLocalVariables;
345 };
346 
354 BaseEventSPtr GD_CORE_API CloneRememberingOriginalEvent(BaseEventSPtr event);
355 
360 class EmptyEvent : public BaseEvent {
361  public:
362  EmptyEvent() : BaseEvent(){};
363  virtual ~EmptyEvent(){};
364 };
365 
366 } // namespace gd
Base class defining an event.
Definition: Event.h:43
float percentDuringLastSession
Definition: Event.h:333
void SetType(gd::String type_)
Change the event type.
Definition: Event.h:287
virtual std::vector< gd::InstructionsList * > GetAllActionsVectors()
Return a list of all actions of the event.
Definition: Event.h:158
const gd::String & GetAiGeneratedEventId() const
Get the AI generated event ID.
Definition: Event.h:320
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:187
void SetAiGeneratedEventId(const gd::String &aiGeneratedEventId_)
Set the AI generated event ID.
Definition: Event.h:313
virtual gd::BaseEvent * Clone() const
Definition: Event.h:58
virtual std::vector< gd::InstructionsList * > GetAllConditionsVectors()
Return a list of all conditions of the event.
Definition: Event.h:144
virtual bool CanHaveSubEvents() const
Definition: Event.h:76
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:128
virtual void SerializeTo(SerializerElement &element) const
Serialize event.
Definition: Event.h:261
virtual bool CanHaveVariables() const
Definition: Event.h:98
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:303
bool IsDisabled() const
True if event is disabled.
Definition: Event.h:297
virtual void UnserializeFrom(gd::Project &project, const SerializerElement &element)
Unserialize the event.
Definition: Event.h:266
virtual bool MustBePreprocessed()
If MustBePreprocessed is redefined to return true, the gd::EventMetadata::preprocessing associated to...
Definition: Event.h:252
virtual std::vector< gd::String > GetAllSearchableStrings() const
Return a list of all strings of the event.
Definition: Event.h:172
virtual bool IsExecutable() const
Definition: Event.h:70
virtual gd::EventsList & GetSubEvents()
Definition: Event.h:86
void SetDisabled(bool disable=true)
Set if the event if disabled or not.
Definition: Event.h:292
virtual const gd::EventsList & GetSubEvents() const
Definition: Event.h:81
std::weak_ptr< gd::BaseEvent > originalEvent
Definition: Event.h:326
bool IsFolded() const
True if the event should be folded in the events editor.
Definition: Event.h:308
const gd::String & GetType() const
Return the event type.
Definition: Event.h:282
virtual const gd::VariablesContainer & GetVariables() const
Definition: Event.h:103
virtual gd::VariablesContainer & GetVariables()
Definition: Event.h:110
signed long long totalTimeDuringLastSession
Definition: Event.h:330
Empty event doing nothing.
Definition: Event.h:360
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
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:156
Definition: CommonTools.h:24