Crossfire Server, Trunk
ResourcesManager.h
Go to the documentation of this file.
1 /*
2  * Crossfire -- cooperative multi-player graphical RPG and adventure game
3  *
4  * Copyright (c) 2022 the Crossfire Development Team
5  *
6  * Crossfire is free software and comes with ABSOLUTELY NO WARRANTY. You are
7  * welcome to redistribute it under certain conditions. For details, please
8  * see COPYING and LICENSE.
9  *
10  * The authors can be reached via e-mail at <crossfire@metalforge.org>.
11  */
12 
13 #ifndef RESOURCESMANAGER_H
14 #define RESOURCESMANAGER_H
15 
16 #include "global.h"
17 #include "object.h"
18 #include "quest.h"
19 #include "AssetsTracker.h"
20 #include <set>
21 #include <QObject>
22 #include "ModifiedAssetsManager.h"
23 #include "LicenseManager.h"
24 
28 #include "faces/FaceWrapper.h"
29 #include "faces/FacesetsWrapper.h"
31 #include "quests/QuestWrapper.h"
32 #include "regions/RegionWrapper.h"
38 #include "recipes/RecipeWrapper.h"
39 
40 class CREMapInformation;
42 class AssetWrapper;
43 
44 class ResourcesManager;
45 
46 template<class A, class W>
48 public:
49  W *wrap(A *asset, AssetWrapper *parent, ResourcesManager *resources) {
50  if (!myWrappedAssets.contains(asset)) {
51  myWrappedAssets[asset] = new W(parent, asset, resources);
52  }
53  return myWrappedAssets[asset];
54  }
55  void remove(A *asset) {
56  auto found = myWrappedAssets.find(asset);
57  if (found != myWrappedAssets.end()) {
58  delete found.value();
59  myWrappedAssets.erase(found);
60  }
61  }
62 private:
63  QHash<A *, W *> myWrappedAssets;
64 };
65 
73 };
74 
75 typedef std::function<bool(ArchetypeUse use, const archetype*, const treasurelist*, const CREMapInformation*, recipe*)> AssetUseCallback;
76 
80 class ResourcesManager : public QObject, AssetsTracker
81 {
82  Q_OBJECT
83 
84  public:
86  virtual ~ResourcesManager();
87 
88  void setMapInformationManager(CREMapInformationManager *mapInformationManager) {
89  myMapInformationManager = mapInformationManager;
90  }
93  }
94 
95  void load();
96 
97  int recipeMaxIngredients() const;
98  QStringList recipes(int count) const;
99  const recipe* getRecipe(int ingredients, const QString& name) const;
100 
101  virtual void assetDefined(const archetype *arch, const std::string &filename) override { myArchetypes.assetDefined(arch, filename); }
102  virtual void assetDefined(const quest_definition *asset, const std::string &filename) override { myQuests.assetDefined(asset, filename); }
103  virtual void assetDefined(const treasurelist *asset, const std::string &filename) override { myTreasures.assetDefined(asset, filename); }
104  virtual void assetDefined(const GeneralMessage *asset, const std::string &filename) override { myGeneralMessages.assetDefined(asset, filename); }
105  virtual void assetDefined(const artifact *asset, const std::string &filename) override { myArtifacts.assetDefined(asset, filename); }
106  virtual void assetDefined(const Face *asset, const std::string &filename) override { myFaces.assetDefined(asset, filename); }
107  virtual void assetDefined(const Animations *asset, const std::string &filename) override { myAnimations.assetDefined(asset, filename); }
108 
109  const std::map<std::string, std::set<const archetype*> >& origins() const { return myArchetypes.origins(); }
110  std::string originOf(const archetype *arch) const { return myArchetypes.originOf(arch); }
111 
112  const std::map<std::string, std::set<const quest_definition*> >& questOrigins() const { return myQuests.origins(); }
113  std::string originOfQuest(const quest_definition *quest) const { return myQuests.originOf(quest); }
114  std::vector<std::string> questFiles() const { return myQuests.files(); }
115 
116  static void archetypeUse(const archetype* item, CREMapInformationManager* store, AssetUseCallback callback);
117 
118  std::string originOf(const Face *face) const { return myFaces.originOf(face); }
119 
120  bool hasPendingChanges() const {
121  return
127  ;
128  }
129 
131  ObjectWrapper *wrap(object *ob, AssetWrapper *parent) { return myWrappedObjects.wrap(ob, parent, this); }
132  AssetWrapper *wrap(Face *face, AssetWrapper *parent) { return myWrappedFaces.wrap(face, parent, this); }
133  AssetWrapper *wrap(Animations *anim, AssetWrapper *parent) { return myWrappedAnimations.wrap(anim, parent, this); }
134  AssetWrapper *wrap(treasurelist *tr, AssetWrapper *parent) { return myWrappedTreasureLists.wrap(tr, parent, this); }
135  AssetWrapper *wrap(treasure *tr, AssetWrapper *parent) { return myWrappedTreasures.wrap(tr, parent, this); }
136  AssetWrapper *wrap(region *reg, AssetWrapper *parent) { return myWrappedRegions.wrap(reg, parent, this); }
137  AssetWrapper *wrap(face_sets *fs, AssetWrapper *parent) { return myWrappedFacesets.wrap(fs, parent, this); }
140  AssetWrapper *wrap(quest_step_definition *step, AssetWrapper *parent) { return myWrappedQuestSteps.wrap(step, parent, this); }
141  AssetWrapper *wrap(artifactlist *al, AssetWrapper *parent) { return myWrappedArtifactLists.wrap(al, parent, this); }
143  auto wrapper = myWrappedArtifacts.wrap(art, parent, this);
144  connect(wrapper, &AssetWrapper::modified, [wrapper, this] { myArtifacts.assetModified(wrapper->wrappedItem()); });
145  return wrapper;
146  }
148  AssetWrapper *wrap(recipe *rc, AssetWrapper *parent) { return myWrappedRecipes.wrap(rc, parent, this); }
150 
152 
153  public slots:
155  void saveArchetypes();
157  void saveQuests();
159  void saveTreasures();
161  void saveGeneralMessages();
162  void saveArtifacts();
163 
164  protected:
166  QList<QHash<QString, recipe*> > myRecipes;
190 };
191 
192 #endif /* RESOURCESMANAGER_H */
ResourcesManager::treasureModified
void treasureModified(treasurelist *treasure)
Definition: ResourcesManager.cpp:229
Face
Definition: face.h:14
ResourcesManager::myQuests
ModifiedAssetsManager< quest_definition > myQuests
Definition: ResourcesManager.h:168
ResourcesManager::assetDefined
virtual void assetDefined(const Animations *asset, const std::string &filename) override
Definition: ResourcesManager.h:107
GeneralMessageWrapper.h
global.h
ModifiedAssetsManager::origins
const std::map< std::string, std::set< const T * > > & origins() const
Definition: ModifiedAssetsManager.h:29
ResourcesManager::myWrappedQuestSteps
AssetWrapperManager< quest_step_definition, QuestStepWrapper > myWrappedQuestSteps
Definition: ResourcesManager.h:184
GeneralMessage
Definition: book.h:44
ResourcesManager::licenseManager
LicenseManager * licenseManager()
Definition: ResourcesManager.h:151
ArtifactListWrapper.h
ResourcesManager::ResourcesManager
ResourcesManager()
Definition: ResourcesManager.cpp:43
W
#define W(x, n)
Definition: QuestWriter.cpp:15
ResourcesManager::myWrappedFaces
AssetWrapperManager< Face, FaceWrapper > myWrappedFaces
Definition: ResourcesManager.h:176
ResourcesManager::wrap
AssetWrapper * wrap(artifact *art, AssetWrapper *parent)
Definition: ResourcesManager.h:142
ResourcesManager::getRecipe
const recipe * getRecipe(int ingredients, const QString &name) const
Definition: ResourcesManager.cpp:129
ResourcesManager
Definition: ResourcesManager.h:80
archininventory.arch
arch
DIALOGCHECK MINARGS 1 MAXARGS 1
Definition: archininventory.py:16
ResourcesManager::saveArchetypes
void saveArchetypes()
Definition: ResourcesManager.cpp:217
ResourcesManager::questModified
void questModified(quest_definition *quest)
Definition: ResourcesManager.cpp:221
ResourcesManager::assetDefined
virtual void assetDefined(const quest_definition *asset, const std::string &filename) override
Definition: ResourcesManager.h:102
ResourcesManager::wrap
ArchetypeWrapper * wrap(archetype *arch, AssetWrapper *parent)
Definition: ResourcesManager.h:130
ResourcesManager::myArtifacts
ModifiedAssetsManager< artifact > myArtifacts
Definition: ResourcesManager.h:171
ModifiedAssetsManager::hasPendingChanges
bool hasPendingChanges() const
Definition: ModifiedAssetsManager.h:69
ResourcesManager::assetDefined
virtual void assetDefined(const archetype *arch, const std::string &filename) override
Definition: ResourcesManager.h:101
ResourcesManager::questFiles
std::vector< std::string > questFiles() const
Definition: ResourcesManager.h:114
ResourcesManager::myWrappedRecipeLists
AssetWrapperManager< recipelist, RecipeListWrapper > myWrappedRecipeLists
Definition: ResourcesManager.h:187
guildoracle.list
list
Definition: guildoracle.py:87
ResourcesManager::wrap
AssetWrapper * wrap(treasure *tr, AssetWrapper *parent)
Definition: ResourcesManager.h:135
guildjoin.ob
ob
Definition: guildjoin.py:42
ResourcesManager::myWrappedArtifacts
AssetWrapperManager< artifact, ArtifactWrapper > myWrappedArtifacts
Definition: ResourcesManager.h:186
ArchetypeUse
ArchetypeUse
Definition: ResourcesManager.h:66
ModifiedAssetsManager::files
std::vector< std::string > files() const
Definition: ModifiedAssetsManager.h:31
ObjectWrapper.h
ModifiedAssetsManager::originOf
std::string originOf(const T *asset) const
Definition: ModifiedAssetsManager.h:39
ResourcesManager::myWrappedMessages
AssetWrapperManager< GeneralMessage, GeneralMessageWrapper > myWrappedMessages
Definition: ResourcesManager.h:182
ResourcesManager::myLicenseManager
LicenseManager myLicenseManager
Definition: ResourcesManager.h:189
RecipeWrapper.h
ResourcesManager::archetypeUse
static void archetypeUse(const archetype *item, CREMapInformationManager *store, AssetUseCallback callback)
Definition: ResourcesManager.cpp:137
ResourcesManager::recipeMaxIngredients
int recipeMaxIngredients() const
Definition: ResourcesManager.cpp:114
DEATH_ANIM
@ DEATH_ANIM
Definition: ResourcesManager.h:68
ResourcesManager::saveQuests
void saveQuests()
Definition: ResourcesManager.cpp:225
npc_dialog.filename
filename
Definition: npc_dialog.py:99
ResourcesManager::myMapInformationManager
CREMapInformationManager * myMapInformationManager
Definition: ResourcesManager.h:165
AssetWrapperManager::wrap
W * wrap(A *asset, AssetWrapper *parent, ResourcesManager *resources)
Definition: ResourcesManager.h:49
quest_step_definition
Definition: quest.h:29
LicenseManager.h
ResourcesManager::myGeneralMessages
ModifiedAssetsManager< GeneralMessage > myGeneralMessages
Definition: ResourcesManager.h:170
ResourcesManager::getMapInformationManager
CREMapInformationManager * getMapInformationManager()
Definition: ResourcesManager.h:91
ResourcesManager::wrap
AssetWrapper * wrap(quest_step_definition *step, AssetWrapper *parent)
Definition: ResourcesManager.h:140
QuestWrapper.h
AssetWrapperManager::remove
void remove(A *asset)
Definition: ResourcesManager.h:55
ResourcesManager::saveArtifacts
void saveArtifacts()
Definition: ResourcesManager.cpp:264
quest
Definition: quest.py:1
CREMapInformation
Definition: CREMapInformation.h:27
ResourcesManager::originOf
std::string originOf(const archetype *arch) const
Definition: ResourcesManager.h:110
ResourcesManager::wrap
AssetWrapper * wrap(GeneralMessage *message, AssetWrapper *parent)
Definition: ResourcesManager.h:138
ResourcesManager::wrap
ObjectWrapper * wrap(object *ob, AssetWrapper *parent)
Definition: ResourcesManager.h:131
ResourcesManager::wrap
AssetWrapper * wrap(recipe *rc, AssetWrapper *parent)
Definition: ResourcesManager.h:148
ObjectWrapper
Definition: ObjectWrapper.h:24
ResourcesManager::origins
const std::map< std::string, std::set< const archetype * > > & origins() const
Definition: ResourcesManager.h:109
AssetsTracker
Definition: AssetsTracker.h:26
recipelist
Definition: recipe.h:37
ResourcesManager::originOf
std::string originOf(const Face *face) const
Definition: ResourcesManager.h:118
ResourcesManager::saveGeneralMessages
void saveGeneralMessages()
Definition: ResourcesManager.cpp:260
ResourcesManager::load
void load()
Definition: ResourcesManager.cpp:56
treasurelist
Definition: treasure.h:85
ResourcesManager::myRecipes
QList< QHash< QString, recipe * > > myRecipes
Definition: ResourcesManager.h:166
ResourcesManager::setMapInformationManager
void setMapInformationManager(CREMapInformationManager *mapInformationManager)
Definition: ResourcesManager.h:88
AssetWrapper
Definition: AssetWrapper.h:25
AnimationWrapper.h
ResourcesManager::myWrappedArtifactLists
AssetWrapperManager< artifactlist, ArtifactListWrapper > myWrappedArtifactLists
Definition: ResourcesManager.h:185
AssetUseCallback
std::function< bool(ArchetypeUse use, const archetype *, const treasurelist *, const CREMapInformation *, recipe *)> AssetUseCallback
Definition: ResourcesManager.h:75
ResourcesManager::wrap
AssetWrapper * wrap(artifactlist *al, AssetWrapper *parent)
Definition: ResourcesManager.h:141
FacesetsWrapper.h
AssetsTracker.h
ResourcesManager::questOrigins
const std::map< std::string, std::set< const quest_definition * > > & questOrigins() const
Definition: ResourcesManager.h:112
ResourcesManager::myFaces
ModifiedAssetsManager< Face > myFaces
Definition: ResourcesManager.h:172
ArchetypeWrapper.h
artifactlist
Definition: artifact.h:24
ResourcesManager::myWrappedArchetypes
AssetWrapperManager< archetype, ArchetypeWrapper > myWrappedArchetypes
Definition: ResourcesManager.h:174
ResourcesManager::recipes
QStringList recipes(int count) const
Definition: ResourcesManager.cpp:119
disinfect.count
int count
Definition: disinfect.py:7
FaceWrapper.h
archetype
Definition: object.h:472
ResourcesManager::myWrappedTreasureLists
AssetWrapperManager< treasurelist, TreasureListWrapper > myWrappedTreasureLists
Definition: ResourcesManager.h:178
RegionWrapper.h
AssetWrapper::modified
void modified()
animate.anim
string anim
Definition: animate.py:20
RecipeListWrapper.h
MAP_USE
@ MAP_USE
Definition: ResourcesManager.h:70
ResourcesManager::wrap
AssetWrapper * wrap(Face *face, AssetWrapper *parent)
Definition: ResourcesManager.h:132
ResourcesManager::assetDefined
virtual void assetDefined(const GeneralMessage *asset, const std::string &filename) override
Definition: ResourcesManager.h:104
is_valid_types_gen.found
found
Definition: is_valid_types_gen.py:39
recipe
Definition: recipe.h:10
ResourcesManager::wrap
AssetWrapper * wrap(region *reg, AssetWrapper *parent)
Definition: ResourcesManager.h:136
ResourcesManager::archetypeModified
void archetypeModified(archetype *arch)
Definition: ResourcesManager.cpp:213
region
Definition: map.h:275
diamondslots.message
string message
Definition: diamondslots.py:57
ResourcesManager::myWrappedRegions
AssetWrapperManager< region, RegionWrapper > myWrappedRegions
Definition: ResourcesManager.h:180
quest.h
AssetWrapperManager
Definition: ResourcesManager.h:47
ModifiedAssetsManager::assetModified
void assetModified(T *asset)
Definition: ModifiedAssetsManager.h:55
TREASURE_USE
@ TREASURE_USE
Definition: ResourcesManager.h:69
ResourcesManager::wrap
AssetWrapper * wrap(recipelist *list, AssetWrapper *parent)
Definition: ResourcesManager.h:147
item
Definition: item.py:1
ArchetypeWrapper
Definition: ArchetypeWrapper.h:25
ModifiedAssetsManager.h
ResourcesManager::myWrappedFacesets
AssetWrapperManager< face_sets, FacesetsWrapper > myWrappedFacesets
Definition: ResourcesManager.h:181
ResourcesManager::remove
void remove(treasure *tr)
Definition: ResourcesManager.h:149
Animations
Definition: face.h:25
ModifiedAssetsManager< archetype >
quest_definition
Definition: quest.h:37
LicenseManager
Definition: LicenseManager.h:25
ModifiedAssetsManager::assetDefined
void assetDefined(const T *asset, const std::string &filename)
Definition: ModifiedAssetsManager.h:48
TreasureListWrapper.h
ResourcesManager::assetDefined
virtual void assetDefined(const artifact *asset, const std::string &filename) override
Definition: ResourcesManager.h:105
ResourcesManager::wrap
AssetWrapper * wrap(treasurelist *tr, AssetWrapper *parent)
Definition: ResourcesManager.h:134
ResourcesManager::myWrappedAnimations
AssetWrapperManager< Animations, AnimationWrapper > myWrappedAnimations
Definition: ResourcesManager.h:177
ALCHEMY_PRODUCT
@ ALCHEMY_PRODUCT
Definition: ResourcesManager.h:72
AssetWrapperManager::myWrappedAssets
QHash< A *, W * > myWrappedAssets
Definition: ResourcesManager.h:63
ResourcesManager::generalMessageModified
void generalMessageModified(GeneralMessage *message)
Definition: ResourcesManager.cpp:256
ArtifactWrapper.h
ResourcesManager::assetDefined
virtual void assetDefined(const Face *asset, const std::string &filename) override
Definition: ResourcesManager.h:106
ResourcesManager::myAnimations
ModifiedAssetsManager< Animations > myAnimations
Definition: ResourcesManager.h:173
RANDOM_MAP_FINAL_EXIT
@ RANDOM_MAP_FINAL_EXIT
Definition: ResourcesManager.h:71
ResourcesManager::myWrappedTreasures
AssetWrapperManager< treasure, TreasureWrapper > myWrappedTreasures
Definition: ResourcesManager.h:179
ResourcesManager::myArchetypes
ModifiedAssetsManager< archetype > myArchetypes
Definition: ResourcesManager.h:167
ResourcesManager::myWrappedRecipes
AssetWrapperManager< recipe, RecipeWrapper > myWrappedRecipes
Definition: ResourcesManager.h:188
ResourcesManager::myWrappedObjects
AssetWrapperManager< object, ObjectWrapper > myWrappedObjects
Definition: ResourcesManager.h:175
ResourcesManager::saveTreasures
void saveTreasures()
Definition: ResourcesManager.cpp:233
treasure
Definition: treasure.h:63
artifact
Definition: artifact.h:14
connect
Definition: connect.py:1
ResourcesManager::myTreasures
ModifiedAssetsManager< treasurelist > myTreasures
Definition: ResourcesManager.h:169
CREMapInformationManager
Definition: CREMapInformationManager.h:27
face_sets
Definition: image.h:17
ResourcesManager::originOfQuest
std::string originOfQuest(const quest_definition *quest) const
Definition: ResourcesManager.h:113
ResourcesManager::hasPendingChanges
bool hasPendingChanges() const
Definition: ResourcesManager.h:120
ResourcesManager::assetDefined
virtual void assetDefined(const treasurelist *asset, const std::string &filename) override
Definition: ResourcesManager.h:103
TreasureWrapper.h
OTHER_ARCH
@ OTHER_ARCH
Definition: ResourcesManager.h:67
ResourcesManager::~ResourcesManager
virtual ~ResourcesManager()
Definition: ResourcesManager.cpp:48
ResourcesManager::wrap
AssetWrapper * wrap(face_sets *fs, AssetWrapper *parent)
Definition: ResourcesManager.h:137
ResourcesManager::wrap
AssetWrapper * wrap(Animations *anim, AssetWrapper *parent)
Definition: ResourcesManager.h:133
object.h
ResourcesManager::wrap
AssetWrapper * wrap(quest_definition *quest, AssetWrapper *parent)
Definition: ResourcesManager.h:139
give.name
name
Definition: give.py:27
ResourcesManager::myWrappedQuests
AssetWrapperManager< quest_definition, QuestWrapper > myWrappedQuests
Definition: ResourcesManager.h:183