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 RemoveObjectInConditions(const gd::Platform& platform,
132  const gd::ProjectScopedContainers& projectScopedContainers,
133  gd::InstructionsList& conditions,
134  gd::String name);
135 
141  static bool RemoveObjectInActions(const gd::Platform& platform,
142  const gd::ProjectScopedContainers& projectScopedContainers,
143  gd::InstructionsList& conditions,
144  gd::String name);
145 
151  static bool ReplaceStringInConditions(gd::ObjectsContainer& project,
152  gd::ObjectsContainer& layout,
153  gd::InstructionsList& conditions,
154  gd::String toReplace,
155  gd::String newString,
156  bool matchCase);
157 
163  static bool ReplaceStringInActions(gd::ObjectsContainer& project,
164  gd::ObjectsContainer& layout,
165  gd::InstructionsList& conditions,
166  gd::String toReplace,
167  gd::String newString,
168  bool matchCase);
169 
176  static bool ReplaceStringInEventSearchableStrings(
177  gd::ObjectsContainer& project,
178  gd::ObjectsContainer& layout,
179  gd::BaseEvent& event,
180  gd::String toReplace,
181  gd::String newString,
182  bool matchCase);
183 
184  static bool SearchStringInFormattedText(const gd::Platform& platform,
185  gd::Instruction& instruction,
186  gd::String search,
187  bool matchCase,
188  bool isCondition,
189  bool inInstructionNames = false);
190  static bool SearchStringInActions(const gd::Platform& platform,
191  gd::InstructionsList& actions,
192  gd::String search,
193  bool matchCase,
194  bool inSentences,
195  bool inInstructionNames = false);
196  static bool SearchStringInConditions(const gd::Platform& platform,
197  gd::InstructionsList& conditions,
198  gd::String search,
199  bool matchCase,
200  bool inSentences,
201  bool inInstructionNames = false);
202  static bool SearchStringInEvent(gd::BaseEvent& events,
203  gd::String search,
204  bool matchCase);
205 
206  static const gd::String searchIgnoredCharacters;
207 
208  EventsRefactorer(){};
209 };
210 
211 } // 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:38
Base class for implementing a platform.
Definition: Platform.h:42
Holds references to variables, objects, properties and other containers.
Definition: ProjectScopedContainers.h:35
String represents an UTF8 encoded string.
Definition: String.h:33
Definition: CommonTools.h:24