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 extern "C" {
17 #include "global.h"
18 #include "object.h"
19 #include "quest.h"
20 }
21 #include "AssetsTracker.h"
22 #include <set>
23 #include <QObject>
24 #include "ModifiedAssetsManager.h"
25 #include "LicenseManager.h"
26 
30 #include "faces/FaceWrapper.h"
31 #include "faces/FacesetsWrapper.h"
33 #include "quests/QuestWrapper.h"
34 #include "regions/RegionWrapper.h"
40 #include "recipes/RecipeWrapper.h"
41 
42 class CREMapInformation;
44 class AssetWrapper;
45 
46 class ResourcesManager;
47 
48 template<class A, class W>
50 public:
51  W *wrap(A *asset, AssetWrapper *parent, ResourcesManager *resources) {
52  if (!myWrappedAssets.contains(asset)) {
53  myWrappedAssets[asset] = new W(parent, asset, resources);
54  }
55  return myWrappedAssets[asset];
56  }
57  void remove(A *asset) {
58  auto found = myWrappedAssets.find(asset);
59  if (found != myWrappedAssets.end()) {
60  delete found.value();
61  myWrappedAssets.erase(found);
62  }
63  }
64 private:
65  QHash<A *, W *> myWrappedAssets;
66 };
67 
75 };
76 
77 typedef std::function<bool(ArchetypeUse use, const archt*, const treasurelist*, const CREMapInformation*, recipe*)> AssetUseCallback;
78 
79 class ResourcesManager : public QObject, AssetsTracker
80 {
81  Q_OBJECT
82 
83  public:
85  virtual ~ResourcesManager();
86 
87  void setMapInformationManager(CREMapInformationManager *mapInformationManager) {
88  myMapInformationManager = mapInformationManager;
89  }
92  }
93 
94  void load();
95 
96  int recipeMaxIngredients() const;
97  QStringList recipes(int count) const;
98  const recipestruct* getRecipe(int ingredients, const QString& name) const;
99 
100  virtual void assetDefined(const archt *arch, const std::string &filename) override { myArchetypes.assetDefined(arch, filename); }
101  virtual void assetDefined(const quest_definition *asset, const std::string &filename) override { myQuests.assetDefined(asset, filename); }
102  virtual void assetDefined(const treasurelist *asset, const std::string &filename) override { myTreasures.assetDefined(asset, filename); }
103  virtual void assetDefined(const GeneralMessage *asset, const std::string &filename) override { myGeneralMessages.assetDefined(asset, filename); }
104  virtual void assetDefined(const artifact *asset, const std::string &filename) override { myArtifacts.assetDefined(asset, filename); }
105 
106  const std::map<std::string, std::set<const archt*> >& origins() const { return myArchetypes.origins(); }
107  std::string originOf(const archt *arch) const { return myArchetypes.originOf(arch); }
108 
109  const std::map<std::string, std::set<const quest_definition*> >& questOrigins() const { return myQuests.origins(); }
110  std::string originOfQuest(const quest_definition *quest) const { return myQuests.originOf(quest); }
111 
112  static void archetypeUse(const archt* item, CREMapInformationManager* store, AssetUseCallback callback);
113 
114  bool hasPendingChanges() const {
115  return
116  myArchetypes.hasPendingChanges()
118  || myTreasures.hasPendingChanges()
120  || myArtifacts.hasPendingChanges()
121  ;
122  }
123 
124  ArchetypeWrapper *wrap(archt *arch, AssetWrapper *parent) { return myWrappedArchetypes.wrap(arch, parent, this); }
125  ObjectWrapper *wrap(object *ob, AssetWrapper *parent) { return myWrappedObjects.wrap(ob, parent, this); }
126  AssetWrapper *wrap(Face *face, AssetWrapper *parent) { return myWrappedFaces.wrap(face, parent, this); }
127  AssetWrapper *wrap(Animations *anim, AssetWrapper *parent) { return myWrappedAnimations.wrap(anim, parent, this); }
128  AssetWrapper *wrap(treasurelist *tr, AssetWrapper *parent) { return myWrappedTreasureLists.wrap(tr, parent, this); }
129  AssetWrapper *wrap(treasure *tr, AssetWrapper *parent) { return myWrappedTreasures.wrap(tr, parent, this); }
130  AssetWrapper *wrap(region *reg, AssetWrapper *parent) { return myWrappedRegions.wrap(reg, parent, this); }
131  AssetWrapper *wrap(face_sets *fs, AssetWrapper *parent) { return myWrappedFacesets.wrap(fs, parent, this); }
134  AssetWrapper *wrap(quest_step_definition *step, AssetWrapper *parent) { return myWrappedQuestSteps.wrap(step, parent, this); }
135  AssetWrapper *wrap(artifactlist *al, AssetWrapper *parent) { return myWrappedArtifactLists.wrap(al, parent, this); }
137  auto wrapper = myWrappedArtifacts.wrap(art, parent, this);
138  connect(wrapper, &AssetWrapper::modified, [wrapper, this] { myArtifacts.assetModified(wrapper->wrappedItem()); });
139  return wrapper;
140  }
141  AssetWrapper *wrap(recipelist *list, AssetWrapper *parent) { return myWrappedRecipeLists.wrap(list, parent, this); }
142  AssetWrapper *wrap(recipe *rc, AssetWrapper *parent) { return myWrappedRecipes.wrap(rc, parent, this); }
143  void remove(treasure *tr) { myWrappedTreasures.remove(tr); }
144 
146 
147  public slots:
149  void saveArchetypes();
151  void saveQuests();
153  void saveTreasures();
155  void saveGeneralMessages();
156  void saveArtifacts();
157 
158  protected:
160  QList<QHash<QString, recipestruct*> > myRecipes;
182 };
183 
184 #endif /* RESOURCESMANAGER_H */
ResourcesManager::treasureModified
void treasureModified(treasurelist *treasure)
Definition: ResourcesManager.cpp:209
AssetUseCallback
std::function< bool(ArchetypeUse use, const archt *, const treasurelist *, const CREMapInformation *, recipe *)> AssetUseCallback
Definition: ResourcesManager.h:77
Face
Definition: face.h:14
ResourcesManager::myQuests
ModifiedAssetsManager< quest_definition > myQuests
Definition: ResourcesManager.h:162
GeneralMessageWrapper.h
global.h
ModifiedAssetsManager::origins
const std::map< std::string, std::set< const T * > > & origins() const
Definition: ModifiedAssetsManager.h:27
ResourcesManager::myWrappedQuestSteps
AssetWrapperManager< quest_step_definition, QuestStepWrapper > myWrappedQuestSteps
Definition: ResourcesManager.h:176
GeneralMessage
Definition: book.h:44
ResourcesManager::licenseManager
LicenseManager * licenseManager()
Definition: ResourcesManager.h:145
ArtifactListWrapper.h
ResourcesManager::ResourcesManager
ResourcesManager()
Definition: ResourcesManager.cpp:43
W
#define W(x, n)
Definition: QuestWriter.cpp:15
ResourcesManager::archetypeUse
static void archetypeUse(const archt *item, CREMapInformationManager *store, AssetUseCallback callback)
Definition: ResourcesManager.cpp:117
ResourcesManager::myWrappedFaces
AssetWrapperManager< Face, FaceWrapper > myWrappedFaces
Definition: ResourcesManager.h:168
ResourcesManager::wrap
AssetWrapper * wrap(artifact *art, AssetWrapper *parent)
Definition: ResourcesManager.h:136
ResourcesManager::getRecipe
const recipestruct * getRecipe(int ingredients, const QString &name) const
Definition: ResourcesManager.cpp:109
ResourcesManager
Definition: ResourcesManager.h:79
archininventory.arch
arch
DIALOGCHECK MINARGS 1 MAXARGS 1
Definition: archininventory.py:16
ResourcesManager::saveArchetypes
void saveArchetypes()
Definition: ResourcesManager.cpp:197
ResourcesManager::questModified
void questModified(quest_definition *quest)
Definition: ResourcesManager.cpp:201
ResourcesManager::assetDefined
virtual void assetDefined(const quest_definition *asset, const std::string &filename) override
Definition: ResourcesManager.h:101
ResourcesManager::myArtifacts
ModifiedAssetsManager< artifact > myArtifacts
Definition: ResourcesManager.h:165
ModifiedAssetsManager::hasPendingChanges
bool hasPendingChanges() const
Definition: ModifiedAssetsManager.h:59
ResourcesManager::myWrappedRecipeLists
AssetWrapperManager< recipelist, RecipeListWrapper > myWrappedRecipeLists
Definition: ResourcesManager.h:179
guildoracle.list
list
Definition: guildoracle.py:87
ResourcesManager::wrap
AssetWrapper * wrap(treasure *tr, AssetWrapper *parent)
Definition: ResourcesManager.h:129
ResourcesManager::wrap
ArchetypeWrapper * wrap(archt *arch, AssetWrapper *parent)
Definition: ResourcesManager.h:124
guildjoin.ob
ob
Definition: guildjoin.py:42
ResourcesManager::myWrappedArtifacts
AssetWrapperManager< artifact, ArtifactWrapper > myWrappedArtifacts
Definition: ResourcesManager.h:178
ArchetypeUse
ArchetypeUse
Definition: ResourcesManager.h:68
ObjectWrapper.h
ModifiedAssetsManager::originOf
std::string originOf(const T *asset) const
Definition: ModifiedAssetsManager.h:29
ResourcesManager::myWrappedMessages
AssetWrapperManager< GeneralMessage, GeneralMessageWrapper > myWrappedMessages
Definition: ResourcesManager.h:174
ResourcesManager::myLicenseManager
LicenseManager myLicenseManager
Definition: ResourcesManager.h:181
RecipeWrapper.h
ResourcesManager::recipeMaxIngredients
int recipeMaxIngredients() const
Definition: ResourcesManager.cpp:94
DEATH_ANIM
@ DEATH_ANIM
Definition: ResourcesManager.h:70
ResourcesManager::saveQuests
void saveQuests()
Definition: ResourcesManager.cpp:205
npc_dialog.filename
filename
Definition: npc_dialog.py:99
ResourcesManager::myMapInformationManager
CREMapInformationManager * myMapInformationManager
Definition: ResourcesManager.h:159
AssetWrapperManager::wrap
W * wrap(A *asset, AssetWrapper *parent, ResourcesManager *resources)
Definition: ResourcesManager.h:51
treasurestruct
Definition: treasure.h:63
quest_step_definition
Definition: quest.h:33
LicenseManager.h
ResourcesManager::myGeneralMessages
ModifiedAssetsManager< GeneralMessage > myGeneralMessages
Definition: ResourcesManager.h:164
archt
Definition: object.h:469
ResourcesManager::getMapInformationManager
CREMapInformationManager * getMapInformationManager()
Definition: ResourcesManager.h:90
ResourcesManager::wrap
AssetWrapper * wrap(quest_step_definition *step, AssetWrapper *parent)
Definition: ResourcesManager.h:134
QuestWrapper.h
AssetWrapperManager::remove
void remove(A *asset)
Definition: ResourcesManager.h:57
ResourcesManager::saveArtifacts
void saveArtifacts()
Definition: ResourcesManager.cpp:225
quest
Definition: quest.py:1
CREMapInformation
Definition: CREMapInformation.h:27
recipestruct
Definition: recipe.h:10
ResourcesManager::wrap
AssetWrapper * wrap(GeneralMessage *message, AssetWrapper *parent)
Definition: ResourcesManager.h:132
ResourcesManager::wrap
ObjectWrapper * wrap(object *ob, AssetWrapper *parent)
Definition: ResourcesManager.h:125
ResourcesManager::wrap
AssetWrapper * wrap(recipe *rc, AssetWrapper *parent)
Definition: ResourcesManager.h:142
ObjectWrapper
Definition: ObjectWrapper.h:27
AssetsTracker
Definition: AssetsTracker.h:28
ResourcesManager::saveGeneralMessages
void saveGeneralMessages()
Definition: ResourcesManager.cpp:221
ResourcesManager::load
void load()
Definition: ResourcesManager.cpp:56
ResourcesManager::setMapInformationManager
void setMapInformationManager(CREMapInformationManager *mapInformationManager)
Definition: ResourcesManager.h:87
AssetWrapper
Definition: AssetWrapper.h:22
AnimationWrapper.h
ResourcesManager::myWrappedArtifactLists
AssetWrapperManager< artifactlist, ArtifactListWrapper > myWrappedArtifactLists
Definition: ResourcesManager.h:177
ResourcesManager::assetDefined
virtual void assetDefined(const archt *arch, const std::string &filename) override
Definition: ResourcesManager.h:100
ResourcesManager::wrap
AssetWrapper * wrap(artifactlist *al, AssetWrapper *parent)
Definition: ResourcesManager.h:135
FacesetsWrapper.h
AssetsTracker.h
ResourcesManager::questOrigins
const std::map< std::string, std::set< const quest_definition * > > & questOrigins() const
Definition: ResourcesManager.h:109
ArchetypeWrapper.h
artifactliststruct
Definition: artifact.h:26
ResourcesManager::recipes
QStringList recipes(int count) const
Definition: ResourcesManager.cpp:99
disinfect.count
int count
Definition: disinfect.py:7
FaceWrapper.h
ResourcesManager::myWrappedTreasureLists
AssetWrapperManager< treasurelist, TreasureListWrapper > myWrappedTreasureLists
Definition: ResourcesManager.h:170
RegionWrapper.h
AssetWrapper::modified
void modified()
recipeliststruct
Definition: recipe.h:37
animate.anim
string anim
Definition: animate.py:20
RecipeListWrapper.h
MAP_USE
@ MAP_USE
Definition: ResourcesManager.h:72
ResourcesManager::wrap
AssetWrapper * wrap(Face *face, AssetWrapper *parent)
Definition: ResourcesManager.h:126
artifactstruct
Definition: artifact.h:14
ResourcesManager::assetDefined
virtual void assetDefined(const GeneralMessage *asset, const std::string &filename) override
Definition: ResourcesManager.h:103
ResourcesManager::originOf
std::string originOf(const archt *arch) const
Definition: ResourcesManager.h:107
is_valid_types_gen.found
found
Definition: is_valid_types_gen.py:39
ResourcesManager::wrap
AssetWrapper * wrap(region *reg, AssetWrapper *parent)
Definition: ResourcesManager.h:130
ResourcesManager::archetypeModified
void archetypeModified(archetype *arch)
Definition: ResourcesManager.cpp:193
diamondslots.message
string message
Definition: diamondslots.py:57
ResourcesManager::myWrappedRegions
AssetWrapperManager< region, RegionWrapper > myWrappedRegions
Definition: ResourcesManager.h:172
ResourcesManager::myRecipes
QList< QHash< QString, recipestruct * > > myRecipes
Definition: ResourcesManager.h:160
animations_struct
Definition: face.h:25
quest.h
AssetWrapperManager
Definition: ResourcesManager.h:49
TREASURE_USE
@ TREASURE_USE
Definition: ResourcesManager.h:71
ResourcesManager::wrap
AssetWrapper * wrap(recipelist *list, AssetWrapper *parent)
Definition: ResourcesManager.h:141
item
Definition: item.py:1
ArchetypeWrapper
Definition: ArchetypeWrapper.h:28
ModifiedAssetsManager.h
ResourcesManager::myWrappedFacesets
AssetWrapperManager< face_sets, FacesetsWrapper > myWrappedFacesets
Definition: ResourcesManager.h:173
ResourcesManager::remove
void remove(treasure *tr)
Definition: ResourcesManager.h:143
ModifiedAssetsManager
Definition: ModifiedAssetsManager.h:22
quest_definition
Definition: quest.h:42
LicenseManager
Definition: LicenseManager.h:25
ModifiedAssetsManager::assetDefined
void assetDefined(const T *asset, const std::string &filename)
Definition: ModifiedAssetsManager.h:38
TreasureListWrapper.h
ResourcesManager::assetDefined
virtual void assetDefined(const artifact *asset, const std::string &filename) override
Definition: ResourcesManager.h:104
ResourcesManager::wrap
AssetWrapper * wrap(treasurelist *tr, AssetWrapper *parent)
Definition: ResourcesManager.h:128
ResourcesManager::myWrappedAnimations
AssetWrapperManager< Animations, AnimationWrapper > myWrappedAnimations
Definition: ResourcesManager.h:169
ALCHEMY_PRODUCT
@ ALCHEMY_PRODUCT
Definition: ResourcesManager.h:74
AssetWrapperManager::myWrappedAssets
QHash< A *, W * > myWrappedAssets
Definition: ResourcesManager.h:65
ResourcesManager::generalMessageModified
void generalMessageModified(GeneralMessage *message)
Definition: ResourcesManager.cpp:217
ResourcesManager::origins
const std::map< std::string, std::set< const archt * > > & origins() const
Definition: ResourcesManager.h:106
ArtifactWrapper.h
RANDOM_MAP_FINAL_EXIT
@ RANDOM_MAP_FINAL_EXIT
Definition: ResourcesManager.h:73
ResourcesManager::myWrappedTreasures
AssetWrapperManager< treasure, TreasureWrapper > myWrappedTreasures
Definition: ResourcesManager.h:171
ResourcesManager::myArchetypes
ModifiedAssetsManager< archetype > myArchetypes
Definition: ResourcesManager.h:161
ResourcesManager::myWrappedRecipes
AssetWrapperManager< recipe, RecipeWrapper > myWrappedRecipes
Definition: ResourcesManager.h:180
ResourcesManager::myWrappedObjects
AssetWrapperManager< object, ObjectWrapper > myWrappedObjects
Definition: ResourcesManager.h:167
ResourcesManager::saveTreasures
void saveTreasures()
Definition: ResourcesManager.cpp:213
connect
Definition: connect.py:1
ResourcesManager::myWrappedArchetypes
AssetWrapperManager< archt, ArchetypeWrapper > myWrappedArchetypes
Definition: ResourcesManager.h:166
ResourcesManager::myTreasures
ModifiedAssetsManager< treasurelist > myTreasures
Definition: ResourcesManager.h:163
CREMapInformationManager
Definition: CREMapInformationManager.h:29
face_sets
Definition: image.h:17
ResourcesManager::originOfQuest
std::string originOfQuest(const quest_definition *quest) const
Definition: ResourcesManager.h:110
ResourcesManager::hasPendingChanges
bool hasPendingChanges() const
Definition: ResourcesManager.h:114
ResourcesManager::assetDefined
virtual void assetDefined(const treasurelist *asset, const std::string &filename) override
Definition: ResourcesManager.h:102
TreasureWrapper.h
OTHER_ARCH
@ OTHER_ARCH
Definition: ResourcesManager.h:69
ResourcesManager::~ResourcesManager
virtual ~ResourcesManager()
Definition: ResourcesManager.cpp:48
ResourcesManager::wrap
AssetWrapper * wrap(face_sets *fs, AssetWrapper *parent)
Definition: ResourcesManager.h:131
ResourcesManager::wrap
AssetWrapper * wrap(Animations *anim, AssetWrapper *parent)
Definition: ResourcesManager.h:127
object.h
ResourcesManager::wrap
AssetWrapper * wrap(quest_definition *quest, AssetWrapper *parent)
Definition: ResourcesManager.h:133
treasureliststruct
Definition: treasure.h:82
give.name
name
Definition: give.py:27
ResourcesManager::myWrappedQuests
AssetWrapperManager< quest_definition, QuestWrapper > myWrappedQuests
Definition: ResourcesManager.h:175
regiondef
Definition: map.h:275