GDevelop Core
Core library for developing platforms and tools compatible with GDevelop.
ResourcesRenamer.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 
7 #pragma once
8 
9 #include <set>
10 #include <vector>
11 
12 #include "GDCore/IDE/Project/ArbitraryResourceWorker.h"
13 #include "GDCore/String.h"
14 
15 namespace gd {
16 
24  public:
31  const std::map<gd::String, gd::String> &oldToNewNames_)
32  : gd::ArbitraryResourceWorker(resourcesManager),
33  oldToNewNames(oldToNewNames_){};
34 
35  virtual ~ResourcesRenamer(){};
36 
37  virtual void ExposeFile(gd::String& resourceFileName) override{
38  // Don't do anything: we're renaming resources, not the files they are
39  // pointing to.
40  };
41  virtual void ExposeImage(gd::String& imageResourceName) override {
42  RenameIfNeeded(imageResourceName);
43  };
44  virtual void ExposeAudio(gd::String& audioResourceName) override {
45  RenameIfNeeded(audioResourceName);
46  };
47  virtual void ExposeFont(gd::String& fontResourceName) override {
48  RenameIfNeeded(fontResourceName);
49  };
50  virtual void ExposeJson(gd::String& jsonResourceName) override {
51  RenameIfNeeded(jsonResourceName);
52  };
53  virtual void ExposeTilemap(gd::String& tilemapResourceName) override {
54  RenameIfNeeded(tilemapResourceName);
55  };
56  virtual void ExposeTileset(gd::String& tilesetResourceName) override {
57  RenameIfNeeded(tilesetResourceName);
58  };
59  virtual void ExposeVideo(gd::String& videoResourceName) override {
60  RenameIfNeeded(videoResourceName);
61  };
62  virtual void ExposeBitmapFont(gd::String& bitmapFontName) override {
63  RenameIfNeeded(bitmapFontName);
64  };
65  virtual void ExposeModel3D(gd::String& resourceName) override {
66  RenameIfNeeded(resourceName);
67  };
68  virtual void ExposeAtlas(gd::String& resourceName) override {
69  RenameIfNeeded(resourceName);
70  };
71  virtual void ExposeSpine(gd::String& resourceName) override {
72  RenameIfNeeded(resourceName);
73  };
74 
75  private:
76  void RenameIfNeeded(gd::String& resourceName) {
77  if (oldToNewNames.find(resourceName) != oldToNewNames.end())
78  resourceName = oldToNewNames[resourceName];
79  }
80 
81  std::map<gd::String, gd::String> oldToNewNames;
82 };
83 
84 } // namespace gd
ArbitraryResourceWorker is used so as to inventory resources and sometimes update them.
Definition: ArbitraryResourceWorker.h:44
Inventory all resources used by a project.
Definition: ResourcesManager.h:556
Class used to rename resources (in an object, an entire project, etc...)
Definition: ResourcesRenamer.h:23
virtual void ExposeBitmapFont(gd::String &bitmapFontName) override
Expose a bitmap font, which is always a reference to a "bitmapFont" resource.
Definition: ResourcesRenamer.h:62
virtual void ExposeAudio(gd::String &audioResourceName) override
Expose an audio, which is either a reference to an "audio" resource, or a filename if no resource wit...
Definition: ResourcesRenamer.h:44
virtual void ExposeJson(gd::String &jsonResourceName) override
Expose a JSON, which is always a reference to a "json" resource.
Definition: ResourcesRenamer.h:50
ResourcesRenamer(gd::ResourcesManager &resourcesManager, const std::map< gd::String, gd::String > &oldToNewNames_)
Constructor taking the map from old name to new name.
Definition: ResourcesRenamer.h:30
virtual void ExposeTilemap(gd::String &tilemapResourceName) override
Expose a Tilemap, which is always a reference to a "tilemap" resource.
Definition: ResourcesRenamer.h:53
virtual void ExposeModel3D(gd::String &resourceName) override
Expose a 3D model, which is always a reference to a "model3D" resource.
Definition: ResourcesRenamer.h:65
virtual void ExposeFont(gd::String &fontResourceName) override
Expose a font, which is either a reference to a "font" resource, or a filename if no resource with th...
Definition: ResourcesRenamer.h:47
virtual void ExposeImage(gd::String &imageResourceName) override
Expose an image, which is always a reference to a "image" resource.
Definition: ResourcesRenamer.h:41
virtual void ExposeTileset(gd::String &tilesetResourceName) override
Expose a Tileset, which is always a reference to a "tileset" resource.
Definition: ResourcesRenamer.h:56
virtual void ExposeSpine(gd::String &resourceName) override
Expose an spine, which is always a reference to a "spine" resource.
Definition: ResourcesRenamer.h:71
virtual void ExposeFile(gd::String &resourceFileName) override
Expose a raw filename.
Definition: ResourcesRenamer.h:37
virtual void ExposeAtlas(gd::String &resourceName) override
Expose an atlas, which is always a reference to a "atlas" resource.
Definition: ResourcesRenamer.h:68
virtual void ExposeVideo(gd::String &videoResourceName) override
Expose a video, which is always a reference to a "video" resource.
Definition: ResourcesRenamer.h:59
String represents an UTF8 encoded string.
Definition: String.h:33
Definition: CommonTools.h:24