GDevelop Core
Core library for developing platforms and tools compatible with GDevelop.
EventsRefactorer.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 <memory>
9 #include <vector>
10 
11 #include "GDCore/Events/Instruction.h"
12 #include "GDCore/Extensions/Metadata/InstructionMetadata.h"
13 #include "GDCore/String.h"
14 namespace gd {
15 class EventsList;
16 class ObjectsContainer;
17 class ObjectsContainersList;
18 class ProjectScopedContainers;
19 class Platform;
20 class ExternalEvents;
21 class BaseEvent;
22 class Instruction;
23 typedef std::shared_ptr<gd::BaseEvent> BaseEventSPtr;
24 } // namespace gd
25 
26 namespace gd {
27 
34 class GD_CORE_API EventsSearchResult {
35  public:
36  EventsSearchResult(std::weak_ptr<gd::BaseEvent> event_,
37  gd::EventsList* eventsList_,
38  std::size_t positionInList_);
40  ~EventsSearchResult(){};
41 
42  std::weak_ptr<gd::BaseEvent> event;
43  gd::EventsList* eventsList;
44  std::size_t positionInList;
45 
46  bool IsEventsListValid() const { return eventsList != nullptr; }
47 
53  const gd::EventsList& GetEventsList() const { return *eventsList; }
54 
55  std::size_t GetPositionInList() const { return positionInList; }
56 
57  bool IsEventValid() const { return !event.expired(); }
58 
63  const gd::BaseEvent& GetEvent() const { return *event.lock(); }
64 };
65 
76 class GD_CORE_API EventsRefactorer {
77  public:
83  static void RenameObjectInEvents(const gd::Platform& platform,
84  const gd::ProjectScopedContainers& projectScopedContainers,
85  gd::EventsList& events,
86  const gd::ObjectsContainer &targetedObjectsContainer,
87  gd::String oldName,
88  gd::String newName);
89 
96  static std::vector<EventsSearchResult> SearchInEvents(
97  const gd::Platform& platform,
98  gd::EventsList& events,
99  gd::String search,
100  bool matchCase,
101  bool inConditions,
102  bool inActions,
103  bool inEventStrings,
104  bool inEventSentences);
105 
111  static std::vector<EventsSearchResult> ReplaceStringInEvents(
112  gd::ObjectsContainer& project,
113  gd::ObjectsContainer& layout,
114  gd::EventsList& events,
115  gd::String toReplace,
116  gd::String newString,
117  bool matchCase,
118  bool inConditions,
119  bool inActions,
120  bool inEventString);
121 
122  virtual ~EventsRefactorer(){};
123 
124  private:
130  static bool RemoveObjectInConditions(const gd::Platform& platform,
131  const gd::ProjectScopedContainers& projectScopedContainers,
132  gd::InstructionsList& conditions,
133  gd::String name);
134 
140  static bool RemoveObjectInActions(const gd::Platform& platform,
141  const gd::ProjectScopedContainers& projectScopedContainers,
142  gd::InstructionsList& conditions,
143  gd::String name);
144 
150  static bool ReplaceStringInConditions(gd::ObjectsContainer& project,
151  gd::ObjectsContainer& layout,
152  gd::InstructionsList& conditions,
153  gd::String toReplace,
154  gd::String newString,
155  bool matchCase);
156 
162  static bool ReplaceStringInActions(gd::ObjectsContainer& project,
163  gd::ObjectsContainer& layout,
164  gd::InstructionsList& conditions,
165  gd::String toReplace,
166  gd::String newString,
167  bool matchCase);
168 
175  static bool ReplaceStringInEventSearchableStrings(
176  gd::ObjectsContainer& project,
177  gd::ObjectsContainer& layout,
178  gd::BaseEvent& event,
179  gd::String toReplace,
180  gd::String newString,
181  bool matchCase);
182 
183  static bool SearchStringInFormattedText(const gd::Platform& platform,
184  gd::Instruction& instruction,
185  gd::String search,
186  bool matchCase,
187  bool isCondition);
188  static bool SearchStringInActions(const gd::Platform& platform,
189  gd::InstructionsList& actions,
190  gd::String search,
191  bool matchCase,
192  bool inSentences);
193  static bool SearchStringInConditions(const gd::Platform& platform,
194  gd::InstructionsList& conditions,
195  gd::String search,
196  bool matchCase,
197  bool inSentences);
198  static bool SearchStringInEvent(gd::BaseEvent& events,
199  gd::String search,
200  bool matchCase);
201 
202  static const gd::String searchIgnoredCharacters;
203 
204  EventsRefactorer(){};
205 };
206 
207 } // namespace gd
Base class defining an event.
Definition: Event.h:43
A list of events.
Definition: EventsList.h:32
Class containing functions to do refactoring tasks on events.
Definition: EventsRefactorer.h:76
Class used to return result when calling EventsRefactorer::SearchInEvents.
Definition: EventsRefactorer.h:34
const gd::BaseEvent & GetEvent() const
Get the event pointed by the EventsSearchResult.
Definition: EventsRefactorer.h:63
const gd::EventsList & GetEventsList() const
Get the events list containing the event pointed by the EventsSearchResult.
Definition: EventsRefactorer.h:53
An instruction is a member of an event: It can be a condition or an action.
Definition: Instruction.h:30
Definition: InstructionsList.h:25
Used as a base class for classes that will own objects (see gd::Object).
Definition: ObjectsContainer.h:37
Base class for implementing a platform.
Definition: Platform.h:42
Holds references to variables, objects, properties and other containers.
Definition: ProjectScopedContainers.h:34
String represents an UTF8 encoded string.
Definition: String.h:33
Definition: CommonTools.h:24