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  bool inInstructionNames = false);
106 
112  static std::vector<EventsSearchResult> ReplaceStringInEvents(
113  gd::ObjectsContainer& project,
114  gd::ObjectsContainer& layout,
115  gd::EventsList& events,
116  gd::String toReplace,
117  gd::String newString,
118  bool matchCase,
119  bool inConditions,
120  bool inActions,
121  bool inEventString);
122 
123  virtual ~EventsRefactorer(){};
124 
125  private:
131  static bool ReplaceStringInConditions(gd::ObjectsContainer& project,
132  gd::ObjectsContainer& layout,
133  gd::InstructionsList& conditions,
134  gd::String toReplace,
135  gd::String newString,
136  bool matchCase);
137 
143  static bool ReplaceStringInActions(gd::ObjectsContainer& project,
144  gd::ObjectsContainer& layout,
145  gd::InstructionsList& conditions,
146  gd::String toReplace,
147  gd::String newString,
148  bool matchCase);
149 
156  static bool ReplaceStringInEventSearchableStrings(
157  gd::ObjectsContainer& project,
158  gd::ObjectsContainer& layout,
159  gd::BaseEvent& event,
160  gd::String toReplace,
161  gd::String newString,
162  bool matchCase);
163 
164  static bool SearchStringInFormattedText(const gd::Platform& platform,
165  gd::Instruction& instruction,
166  gd::String search,
167  bool matchCase,
168  bool isCondition,
169  bool inInstructionNames = false);
170  static bool SearchStringInActions(const gd::Platform& platform,
171  gd::InstructionsList& actions,
172  gd::String search,
173  bool matchCase,
174  bool inSentences,
175  bool inInstructionNames = false);
176  static bool SearchStringInConditions(const gd::Platform& platform,
177  gd::InstructionsList& conditions,
178  gd::String search,
179  bool matchCase,
180  bool inSentences,
181  bool inInstructionNames = false);
182  static bool SearchStringInEvent(gd::BaseEvent& events,
183  gd::String search,
184  bool matchCase);
185 
186  static const gd::String searchIgnoredCharacters;
187 
188  EventsRefactorer(){};
189 };
190 
191 } // namespace gd
Base class defining an event.
Definition: Event.h:44
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:38
Base class for implementing a platform.
Definition: Platform.h:42
Holds references to variables, objects, properties and other containers.
Definition: ProjectScopedContainers.h:36
String represents an UTF8 encoded string.
Definition: String.h:33
Definition: CommonTools.h:24