GDevelop Core
Core library for developing platforms and tools compatible with GDevelop.
WholeProjectRefactorer.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 <set>
9 #include <unordered_set>
10 #include <unordered_map>
11 #include <vector>
12 #include <memory>
13 #include "GDCore/String.h"
14 #include "GDCore/Project/Variable.h"
15 
16 namespace gd {
17 class Platform;
18 class Project;
19 class Layout;
20 class Layer;
21 class Object;
22 class ObjectGroup;
23 class String;
24 class EventsFunctionsExtension;
25 class EventsFunction;
26 class ObjectsContainer;
27 class VariablesContainer;
28 class EventsBasedBehavior;
29 class EventsBasedObject;
30 class Behavior;
31 class UnfilledRequiredBehaviorPropertyProblem;
32 class ProjectBrowser;
33 class SerializerElement;
34 class ProjectScopedContainers;
35 struct VariablesRenamingChangesetNode;
36 } // namespace gd
37 
38 namespace gd {
39 
41  std::unordered_map<gd::String, gd::String> oldToNewVariableNames;
42  std::unordered_map<gd::String, std::shared_ptr<gd::VariablesRenamingChangesetNode>>
43  modifiedVariables;
44 };
45 
47  std::unordered_set<gd::String> removedVariableNames;
48 
54  std::unordered_set<gd::String> typeChangedVariableNames;
55  std::unordered_set<gd::String> valueChangedVariableNames;
56  std::unordered_set<gd::String> addedVariableNames;
57 
58  bool HasRemovedVariables() { return !removedVariableNames.empty(); }
59 
60  VariablesChangeset& ClearRemovedVariables() { removedVariableNames.clear(); return *this; }
61 };
62 
71 class GD_CORE_API WholeProjectRefactorer {
72  public:
73 
77  static VariablesChangeset ComputeChangesetForVariablesContainer(
78  const gd::SerializerElement &oldSerializedVariablesContainer,
79  const gd::VariablesContainer &newVariablesContainer);
80 
85  static void ApplyRefactoringForVariablesContainer(
86  gd::Project &project, gd::VariablesContainer &variablesContainer,
87  const gd::VariablesChangeset &changeset,
88  const gd::SerializerElement &originalSerializedVariables);
89 
94  static void ApplyRefactoringForGroupVariablesContainer(
95  gd::Project &project, gd::ObjectsContainer &globalObjectsContainer,
96  gd::ObjectsContainer &objectsContainer,
97  const gd::VariablesContainer &groupVariablesContainer,
98  const gd::ObjectGroup &objectGroup,
99  const gd::VariablesChangeset &changeset,
100  const gd::SerializerElement &originalSerializedVariables);
101 
110  static void RenameEventsFunctionsExtension(
111  gd::Project& project,
112  const gd::EventsFunctionsExtension& eventsFunctionsExtension,
113  const gd::String& oldName,
114  const gd::String& newName);
115 
120  static void UpdateExtensionNameInEventsBasedBehavior(
121  gd::Project &project,
122  const gd::EventsFunctionsExtension &eventsFunctionsExtension,
123  gd::EventsBasedBehavior &eventsBasedBehavior,
124  const gd::String &sourceExtensionName);
125 
130  static void UpdateExtensionNameInEventsBasedObject(
131  gd::Project &project,
132  const gd::EventsFunctionsExtension &eventsFunctionsExtension,
133  gd::EventsBasedObject &eventsBasedObject,
134  const gd::String &sourceExtensionName);
135 
143  static void RenameEventsFunction(
144  gd::Project& project,
145  const gd::EventsFunctionsExtension& eventsFunctionsExtension,
146  const gd::String& oldFunctionName,
147  const gd::String& newFunctionName);
148 
157  static void RenameBehaviorEventsFunction(
158  gd::Project& project,
159  const gd::EventsFunctionsExtension& eventsFunctionsExtension,
160  const gd::EventsBasedBehavior& eventsBasedBehavior,
161  const gd::String& oldFunctionName,
162  const gd::String& newFunctionName);
163 
172  static void RenameObjectEventsFunction(
173  gd::Project& project,
174  const gd::EventsFunctionsExtension& eventsFunctionsExtension,
175  const gd::EventsBasedObject& eventsBasedObject,
176  const gd::String& oldFunctionName,
177  const gd::String& newFunctionName);
178 
186  static void
187  RenameParameter(gd::Project &project,
188  gd::ProjectScopedContainers &projectScopedContainers,
189  gd::EventsFunction &eventsFunction,
190  const gd::ObjectsContainer &parameterObjectsContainer,
191  const gd::String &oldParameterName,
192  const gd::String &newParameterName);
193 
202  static void MoveEventsFunctionParameter(
203  gd::Project& project,
204  const gd::EventsFunctionsExtension& eventsFunctionsExtension,
205  const gd::String& functionName,
206  std::size_t oldIndex,
207  std::size_t newIndex);
208 
217  static void MoveBehaviorEventsFunctionParameter(
218  gd::Project& project,
219  const gd::EventsFunctionsExtension& eventsFunctionsExtension,
220  const gd::EventsBasedBehavior& eventsBasedBehavior,
221  const gd::String& functionName,
222  std::size_t oldIndex,
223  std::size_t newIndex);
224 
233  static void MoveObjectEventsFunctionParameter(
234  gd::Project& project,
235  const gd::EventsFunctionsExtension& eventsFunctionsExtension,
236  const gd::EventsBasedObject& eventsBasedObject,
237  const gd::String& functionName,
238  std::size_t oldIndex,
239  std::size_t newIndex);
240 
249  static void RenameEventsBasedBehaviorProperty(
250  gd::Project& project,
251  const gd::EventsFunctionsExtension& eventsFunctionsExtension,
252  const gd::EventsBasedBehavior& eventsBasedBehavior,
253  const gd::String& oldPropertyName,
254  const gd::String& newPropertyName);
255 
264  static void RenameEventsBasedBehaviorSharedProperty(
265  gd::Project& project,
266  const gd::EventsFunctionsExtension& eventsFunctionsExtension,
267  const gd::EventsBasedBehavior& eventsBasedBehavior,
268  const gd::String& oldPropertyName,
269  const gd::String& newPropertyName);
270 
279  static void RenameEventsBasedObjectProperty(
280  gd::Project& project,
281  const gd::EventsFunctionsExtension& eventsFunctionsExtension,
282  const gd::EventsBasedObject& eventsBasedObject,
283  const gd::String& oldPropertyName,
284  const gd::String& newPropertyName);
285 
290  static void AddBehaviorAndRequiredBehaviors(gd::Project& project,
291  gd::Object& object,
292  const gd::String& behaviorType,
293  const gd::String& behaviorName);
298  static void AddRequiredBehaviorsFor(gd::Project& project,
299  gd::Object& object,
300  const gd::String& behaviorName);
301 
306  static std::vector<gd::String> FindDependentBehaviorNames(
307  const gd::Project& project,
308  const gd::Object& object,
309  const gd::String& behaviorName);
310 
314  static std::vector<gd::String> GetBehaviorsWithType(const gd::Object& object,
315  const gd::String& type);
316 
321  static std::vector<gd::UnfilledRequiredBehaviorPropertyProblem>
322  FindInvalidRequiredBehaviorProperties(const gd::Project& project);
323 
329  static bool
330  FixInvalidRequiredBehaviorProperties(gd::Project& project);
331 
339  static void RenameEventsBasedBehavior(
340  gd::Project& project,
341  const gd::EventsFunctionsExtension& eventsFunctionsExtension,
342  const gd::String& oldBehaviorName,
343  const gd::String& newBehaviorName);
344 
349  static void UpdateBehaviorNameInEventsBasedBehavior(
350  gd::Project &project,
351  const gd::EventsFunctionsExtension &eventsFunctionsExtension,
352  gd::EventsBasedBehavior &eventsBasedBehavior,
353  const gd::String &sourceBehaviorName);
354 
362  static void RenameEventsBasedObject(
363  gd::Project& project,
364  const gd::EventsFunctionsExtension& eventsFunctionsExtension,
365  const gd::String& oldObjectName,
366  const gd::String& newObjectName);
367 
372  static void UpdateObjectNameInEventsBasedObject(
373  gd::Project &project,
374  const gd::EventsFunctionsExtension &eventsFunctionsExtension,
375  gd::EventsBasedObject &eventsBasedObject,
376  const gd::String &sourceObjectName);
377 
381  static void RenameLayout(gd::Project &project, const gd::String &oldName,
382  const gd::String &newName);
386  static void RenameExternalLayout(gd::Project &project,
387  const gd::String &oldName,
388  const gd::String &newName);
392  static void RenameExternalEvents(gd::Project &project,
393  const gd::String &oldName,
394  const gd::String &newName);
395 
399  static void RenameLayerInScene(gd::Project &project, gd::Layout &scene,
400  const gd::String &oldName,
401  const gd::String &newName);
402 
406  static void RenameLayerInEventsBasedObject(
407  gd::Project &project,
408  gd::EventsFunctionsExtension &eventsFunctionsExtension,
409  gd::EventsBasedObject &eventsBasedObject, const gd::String &oldName,
410  const gd::String &newName);
411 
415  static void RenameLayerEffectInScene(gd::Project &project, gd::Layout &scene,
416  gd::Layer &layer,
417  const gd::String &oldName,
418  const gd::String &newName);
419 
423  static void RenameLayerEffectInEventsBasedObject(
424  gd::Project &project,
425  gd::EventsFunctionsExtension &eventsFunctionsExtension,
426  gd::EventsBasedObject &eventsBasedObject, gd::Layer &layer,
427  const gd::String &oldName, const gd::String &newName);
428 
432  static void RenameObjectAnimationInScene(gd::Project &project,
433  gd::Layout &scene,
434  gd::Object &object,
435  const gd::String &oldName,
436  const gd::String &newName);
437 
441  static void RenameObjectAnimationInEventsBasedObject(
442  gd::Project &project,
443  gd::EventsFunctionsExtension &eventsFunctionsExtension,
444  gd::EventsBasedObject &eventsBasedObject, gd::Object &object,
445  const gd::String &oldName, const gd::String &newName);
446 
450  static void RenameObjectPointInScene(gd::Project &project, gd::Layout &scene,
451  gd::Object &object,
452  const gd::String &oldName,
453  const gd::String &newName);
454 
458  static void RenameObjectPointInEventsBasedObject(
459  gd::Project &project,
460  gd::EventsFunctionsExtension &eventsFunctionsExtension,
461  gd::EventsBasedObject &eventsBasedObject, gd::Object &object,
462  const gd::String &oldName, const gd::String &newName);
463 
467  static void RenameObjectEffectInScene(gd::Project &project, gd::Layout &scene,
468  gd::Object &object,
469  const gd::String &oldName,
470  const gd::String &newName);
471 
475  static void RenameObjectEffectInEventsBasedObject(
476  gd::Project &project,
477  gd::EventsFunctionsExtension &eventsFunctionsExtension,
478  gd::EventsBasedObject &eventsBasedObject, gd::Object &object,
479  const gd::String &oldName, const gd::String &newName);
480 
487  static void ObjectOrGroupRenamedInScene(gd::Project &project,
488  gd::Layout &scene,
489  const gd::String &oldName,
490  const gd::String &newName,
491  bool isObjectGroup);
492 
499  static void ObjectRemovedInScene(gd::Project &project, gd::Layout &scene,
500  const gd::String &objectName);
501 
510  static void BehaviorsAddedToObjectInScene(gd::Project &project,
511  gd::Layout &layout,
512  const gd::String &objectName);
513 
520  static void ObjectRemovedInEventsBasedObject(
521  gd::Project& project,
522  gd::EventsBasedObject& eventsBasedObject,
523  const gd::String& objectName);
524 
530  static void ObjectOrGroupRenamedInEventsBasedObject(
531  gd::Project& project,
532  const gd::ProjectScopedContainers &projectScopedContainers,
533  gd::EventsBasedObject& eventsBasedObject,
534  const gd::String& oldName,
535  const gd::String& newName,
536  bool isObjectGroup);
537 
543  static void ObjectOrGroupRenamedInEventsFunction(
544  gd::Project& project,
545  const gd::ProjectScopedContainers &projectScopedContainers,
546  gd::EventsFunction& eventsFunction,
547  const gd::ObjectsContainer &targetedObjectsContainer,
548  const gd::String& oldName,
549  const gd::String& newName,
550  bool isObjectGroup);
551 
557  static void ObjectRemovedInEventsFunction(
558  gd::Project& project,
559  gd::EventsFunction& eventsFunction,
560  const gd::String& objectName);
561 
568  static void GlobalObjectOrGroupRenamed(gd::Project& project,
569  const gd::String& oldName,
570  const gd::String& newName,
571  bool isObjectGroup);
572 
579  static void GlobalObjectRemoved(gd::Project& project,
580  const gd::String& objectName);
581 
589  void BehaviorsAddedToGlobalObject(gd::Project &project,
590  const gd::String &objectName);
591 
596  static std::set<gd::String> GetAllObjectTypesUsingEventsBasedBehavior(
597  const gd::Project& project,
598  const gd::EventsFunctionsExtension& eventsFunctionsExtension,
599  const gd::EventsBasedBehavior& eventsBasedBehavior);
600 
606  static void EnsureBehaviorEventsFunctionsProperParameters(
607  const gd::EventsFunctionsExtension& eventsFunctionsExtension,
608  const gd::EventsBasedBehavior& eventsBasedBehavior);
609 
614  static void EnsureObjectEventsFunctionsProperParameters(
615  const gd::EventsFunctionsExtension& eventsFunctionsExtension,
616  const gd::EventsBasedObject& eventsBasedObject);
617 
621  static void RemoveLayerInScene(gd::Project &project, gd::Layout &scene,
622  const gd::String &layerName);
623 
627  static void MergeLayersInScene(gd::Project &project, gd::Layout &scene,
628  const gd::String &originLayerName,
629  const gd::String &targetLayerName);
630 
634  static void
635  RemoveLayerInEventsBasedObject(gd::EventsBasedObject &eventsBasedObject,
636  const gd::String &layerName);
637 
641  static void
642  MergeLayersInEventsBasedObject(gd::EventsBasedObject &eventsBasedObject,
643  const gd::String &originLayerName,
644  const gd::String &targetLayerName);
645 
649  static void
650  RenameLeaderboards(gd::Project &project,
651  const std::map<gd::String, gd::String> &leaderboardIdMap);
652 
656  static std::set<gd::String> FindAllLeaderboardIds(gd::Project &project);
657 
662  static size_t GetLayoutAndExternalLayoutLayerInstancesCount(
663  gd::Project &project, gd::Layout &layout, const gd::String &layerName);
664 
665  virtual ~WholeProjectRefactorer(){};
666 
667  private:
668  static void ObjectOrGroupRenamedInScene(gd::Project &project,
669  gd::Layout &scene,
670  const gd::ObjectsContainer &targetedObjectsContainer,
671  const gd::String &oldName,
672  const gd::String &newName,
673  bool isObjectGroup);
674  static std::vector<gd::String> GetAssociatedExternalLayouts(
675  gd::Project& project, gd::Layout& layout);
676  static std::vector<gd::String>
677  GetAssociatedExternalLayouts(gd::Project &project,
678  const gd::String &layoutName);
679  static std::vector<gd::String>
680  GetAssociatedExternalEvents(gd::Project &project,
681  const gd::String &layoutName);
682 
683  static void DoRenameEventsFunction(gd::Project& project,
684  const gd::EventsFunction& eventsFunction,
685  const gd::String& oldFullType,
686  const gd::String& newFullType,
687  const gd::ProjectBrowser& projectBrowser);
688 
689  static void DoRenameBehavior(gd::Project& project,
690  const gd::String& oldBehaviorType,
691  const gd::String& newBehaviorType,
692  const gd::ProjectBrowser& projectBrowser);
693 
694  static void DoRenameObject(gd::Project& project,
695  const gd::String& oldObjectType,
696  const gd::String& newObjectType,
697  const gd::ProjectBrowser& projectBrowser);
698 
707  static void RenameEventsFunctionsExtension(
708  gd::Project& project,
709  const gd::EventsFunctionsExtension& eventsFunctionsExtension,
710  const gd::String& oldName,
711  const gd::String& newName,
712  const gd::ProjectBrowser& projectBrowser);
713 
721  static void RenameEventsBasedBehavior(
722  gd::Project &project,
723  const gd::EventsFunctionsExtension &eventsFunctionsExtension,
724  const gd::EventsBasedBehavior &eventsBasedBehavior,
725  const gd::String &oldBehaviorName,
726  const gd::String &newBehaviorName,
727  const gd::ProjectBrowser &projectBrowser);
728 
736  static void RenameEventsBasedObject(
737  gd::Project &project,
738  const gd::EventsFunctionsExtension &eventsFunctionsExtension,
739  const gd::EventsBasedObject &eventsBasedObject,
740  const gd::String &oldObjectName, const gd::String &newObjectName,
741  const gd::ProjectBrowser &projectBrowser);
742 
743  static void FindDependentBehaviorNames(
744  const gd::Project& project,
745  const gd::Object& object,
746  const gd::String& behaviorName,
747  std::unordered_set<gd::String>& dependentBehaviorNames);
748 
749  static std::shared_ptr<VariablesRenamingChangesetNode>
750  ComputeChangesetForVariable(const gd::Variable &oldVariable,
751  const gd::Variable &newVariable);
752 
753  static bool HasAnyVariableTypeChanged(const gd::Variable &oldVariable,
754  const gd::Variable &newVariable);
755 
756  static const gd::String behaviorObjectParameterName;
757  static const gd::String parentObjectParameterName;
758 
760 };
761 
762 } // namespace gd
Represents a behavior that is implemented with events.
Definition: EventsBasedBehavior.h:32
Represents an object that is implemented with events.
Definition: EventsBasedObject.h:30
Events that can be generated as a stand-alone function, and used as a condition, action or expression...
Definition: EventsFunction.h:38
Hold a list of Events Functions (gd::EventsFunction) and Events Based Behaviors.
Definition: EventsFunctionsExtension.h:38
Represents a layer of a layout.
Definition: Layer.h:91
Represent a layout ( also called a scene ) of a project.
Definition: Layout.h:40
Represents an object group.
Definition: ObjectGroup.h:28
Represent an object of a platform.
Definition: Object.h:37
Used as a base class for classes that will own objects (see gd::Object).
Definition: ObjectsContainer.h:37
Expose a subset of the project to workers.
Definition: ProjectBrowser.h:29
Base class representing a project (game), including all resources, scenes, objects,...
Definition: Project.h:51
Holds references to variables, objects, properties and other containers.
Definition: ProjectScopedContainers.h:34
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
Defines a variable which can be used by an object, a layout or a project.
Definition: Variable.h:29
Class defining a container for gd::Variable.
Definition: VariablesContainer.h:28
Tool functions to do refactoring on the whole project after changes like deletion or renaming of an o...
Definition: WholeProjectRefactorer.h:71
Definition: CommonTools.h:24
Definition: WholeProjectRefactorer.h:46
std::unordered_set< gd::String > typeChangedVariableNames
Definition: WholeProjectRefactorer.h:54
Definition: WholeProjectRefactorer.h:40