GDevelop Core
Core library for developing platforms and tools compatible with GDevelop.
ArbitraryEventsWorker.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 <map>
9 #include <memory>
10 #include <vector>
11 #include "GDCore/Events/InstructionsList.h"
12 #include "GDCore/Events/EventVisitor.h"
13 #include "GDCore/Project/ProjectScopedContainers.h"
14 #include "GDCore/String.h"
15 
16 namespace gd {
17 class Instruction;
18 class BaseEvent;
19 class LinkEvent;
20 class EventsList;
21 class ObjectsContainer;
22 class Expression;
23 class ParameterMetadata;
24 } // namespace gd
25 
26 namespace gd {
27 
37 class GD_CORE_API AbstractArbitraryEventsWorker : private EventVisitor {
38  public:
41 
46  void SetSkipDisabledEvents(bool skip) { skipDisabledEvents_ = skip; }
47 
48 protected:
49  virtual bool VisitEvent(gd::BaseEvent& event) override;
50  void VisitEventList(gd::EventsList& events);
51 
52  private:
53  bool skipDisabledEvents_ = false;
54  bool VisitLinkEvent(gd::LinkEvent& linkEvent) override;
55  void VisitInstructionList(gd::InstructionsList& instructions,
56  bool areConditions);
57  bool VisitInstruction(gd::Instruction& instruction, bool isCondition);
58  bool VisitEventExpression(gd::Expression& expression, const gd::ParameterMetadata& metadata);
59 
63  virtual void DoVisitEventList(gd::EventsList& events){};
64 
70  virtual bool DoVisitEvent(gd::BaseEvent& event) { return false; };
71 
80  virtual bool DoVisitLinkEvent(gd::LinkEvent& event) { return false; };
81 
85  virtual void DoVisitInstructionList(gd::InstructionsList& instructions,
86  bool areConditions){};
87 
93  virtual bool DoVisitInstruction(gd::Instruction& instruction,
94  bool isCondition) {
95  return false;
96  };
97 
103  virtual bool DoVisitEventExpression(gd::Expression& expression,
104  const gd::ParameterMetadata& metadata) {
105  return false;
106  }
107 };
108 
119 public:
121  virtual ~ArbitraryEventsWorker();
122 
126  void Launch(gd::EventsList &events) {
127  AbstractArbitraryEventsWorker::VisitEventList(events);
128  };
129 
130 private:
131  bool VisitEvent(gd::BaseEvent &event) override;
132 };
133 
144  public:
146  : currentProjectScopedContainers(nullptr){};
148 
153  void Launch(gd::EventsList& events,
154  const gd::ProjectScopedContainers& projectScopedContainers) {
155  currentProjectScopedContainers = &projectScopedContainers;
156  AbstractArbitraryEventsWorker::VisitEventList(events);
157  };
158 
159 protected:
160  const gd::ProjectScopedContainers& GetProjectScopedContainers() {
161  // Pointers are guaranteed to be not nullptr after
162  // Launch was called.
163  return *currentProjectScopedContainers;
164  };
165  const gd::ObjectsContainersList& GetObjectsContainersList() {
166  // Pointers are guaranteed to be not nullptr after
167  // Launch was called.
168  return currentProjectScopedContainers->GetObjectsContainersList();
169  };
170 
171  private:
172  bool VisitEvent(gd::BaseEvent& event) override;
173 
174  const gd::ProjectScopedContainers* currentProjectScopedContainers;
175 };
176 
187  public:
188  AbstractReadOnlyArbitraryEventsWorker() : shouldStopIteration(false) {};
190 
195  void SetSkipDisabledEvents(bool skip) { skipDisabledEvents_ = skip; }
196 
197 protected:
198  void StopAnyEventIteration() override;
199  virtual void VisitEvent(const gd::BaseEvent& event) override;
200 
201  void VisitEventList(const gd::EventsList& events);
202 
203  private:
204  bool skipDisabledEvents_ = false;
205  void VisitLinkEvent(const gd::LinkEvent& linkEvent) override;
206  void VisitInstructionList(const gd::InstructionsList& instructions,
207  bool areConditions);
208  void VisitInstruction(const gd::Instruction& instruction, bool isCondition);
209  void VisitEventExpression(const gd::Expression& expression, const gd::ParameterMetadata& metadata);
210 
214  virtual void DoVisitEventList(const gd::EventsList& events){};
215 
219  virtual void DoVisitEvent(const gd::BaseEvent& event) {};
220 
226  virtual void DoVisitLinkEvent(const gd::LinkEvent& linkEvent) {};
227 
231  virtual void DoVisitInstructionList(const gd::InstructionsList& instructions,
232  bool areConditions){};
233 
237  virtual void DoVisitInstruction(const gd::Instruction& instruction,
238  bool isCondition) {};
239 
243  virtual void DoVisitEventExpression(const gd::Expression& expression,
244  const gd::ParameterMetadata& metadata) {
245  }
246 
247  bool shouldStopIteration;
248 };
249 
260 public:
263 
267  void Launch(const gd::EventsList &events) {
268  AbstractReadOnlyArbitraryEventsWorker::VisitEventList(events);
269  };
270 
271 private:
272  void VisitEvent(const gd::BaseEvent &event) override;
273 };
274 
285  public:
287  : currentProjectScopedContainers(nullptr){};
289 
294  void Launch(const gd::EventsList& events,
295  const gd::ProjectScopedContainers& projectScopedContainers) {
296  currentProjectScopedContainers = &projectScopedContainers;
297  DoOnLaunch(events);
298  AbstractReadOnlyArbitraryEventsWorker::VisitEventList(events);
299  };
300 
301 protected:
302  const gd::ProjectScopedContainers& GetProjectScopedContainers() {
303  // Pointers are guaranteed to be not nullptr after
304  // Launch was called.
305  return *currentProjectScopedContainers;
306  };
307 
312  virtual void DoOnLaunch(const gd::EventsList& events) {};
313 
314  private:
315  void VisitEvent(const gd::BaseEvent& event) override;
316 
317  const gd::ProjectScopedContainers* currentProjectScopedContainers;
318 };
319 
320 } // namespace gd
AbstractArbitraryEventsWorker is a base abstract class used to browse events (and instructions) and d...
Definition: ArbitraryEventsWorker.h:37
void SetSkipDisabledEvents(bool skip)
When enabled, disabled events and their entire subtree are skipped during traversal.
Definition: ArbitraryEventsWorker.h:46
ReadOnlyArbitraryEventsWorker is an abstract class used to browse events (and instructions)....
Definition: ArbitraryEventsWorker.h:186
void SetSkipDisabledEvents(bool skip)
When enabled, disabled events and their entire subtree are skipped during traversal.
Definition: ArbitraryEventsWorker.h:195
ArbitraryEventsWorker is an abstract class used to browse events (and instructions) and do some work ...
Definition: ArbitraryEventsWorker.h:118
void Launch(gd::EventsList &events)
Launch the worker on the specified events list.
Definition: ArbitraryEventsWorker.h:126
An events worker that will know about the context (the objects container). Useful for workers working...
Definition: ArbitraryEventsWorker.h:143
void Launch(gd::EventsList &events, const gd::ProjectScopedContainers &projectScopedContainers)
Launch the worker on the specified events list, giving the objects container on which the events are ...
Definition: ArbitraryEventsWorker.h:153
Base class defining an event.
Definition: Event.h:43
Visitor of any kind of event.
Definition: EventVisitor.h:26
A list of events.
Definition: EventsList.h:32
Class representing an expression used as a parameter of a gd::Instruction. This class is nothing more...
Definition: Expression.h:30
An instruction is a member of an event: It can be a condition or an action.
Definition: Instruction.h:30
Definition: InstructionsList.h:25
A list of objects containers, useful for accessing objects in a scoped way, along with methods to acc...
Definition: ObjectsContainersList.h:29
Describe a parameter of an instruction (action, condition) or of an expression: type,...
Definition: ParameterMetadata.h:27
Holds references to variables, objects, properties and other containers.
Definition: ProjectScopedContainers.h:36
ReadOnlyArbitraryEventsWorker is an abstract class used to browse events (and instructions)....
Definition: ArbitraryEventsWorker.h:259
void Launch(const gd::EventsList &events)
Launch the worker on the specified events list.
Definition: ArbitraryEventsWorker.h:267
An events worker that will know about the context (the objects container). Useful for workers working...
Definition: ArbitraryEventsWorker.h:284
virtual void DoOnLaunch(const gd::EventsList &events)
Called at the start of each Launch, before event traversal begins. Override this to perform setup whe...
Definition: ArbitraryEventsWorker.h:312
void Launch(const gd::EventsList &events, const gd::ProjectScopedContainers &projectScopedContainers)
Launch the worker on the specified events list, giving the objects container on which the events are ...
Definition: ArbitraryEventsWorker.h:294
Visitor of any kind of event.
Definition: EventVisitor.h:54
Definition: CommonTools.h:24