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  std::vector<std::string> archetypeFiles() const { return myArchetypes.files(); }
112 
113  const std::map<std::string, std::set<const quest_definition*> >& questOrigins() const { return myQuests.origins(); }
114  std::string originOfQuest(const quest_definition *quest) const { return myQuests.originOf(quest); }
115  std::vector<std::string> questFiles() const { return myQuests.files(); }
116 
117  static void archetypeUse(const archetype* item, CREMapInformationManager* store, AssetUseCallback callback);
118 
119  std::string originOf(const Face *face) const { return myFaces.originOf(face); }
120  std::string originOf(const artifact *art) const { return myArtifacts.originOf(art); }
121 
122  bool hasPendingChanges() const {
123  return
129  ;
130  }
131 
133  ObjectWrapper *wrap(object *ob, AssetWrapper *parent) { return myWrappedObjects.wrap(ob, parent, this); }
134  AssetWrapper *wrap(Face *face, AssetWrapper *parent) { return myWrappedFaces.wrap(face, parent, this); }
135  AssetWrapper *wrap(Animations *anim, AssetWrapper *parent) { return myWrappedAnimations.wrap(anim, parent, this); }
136  AssetWrapper *wrap(treasurelist *tr, AssetWrapper *parent) { return myWrappedTreasureLists.wrap(tr, parent, this); }
137  AssetWrapper *wrap(treasure *tr, AssetWrapper *parent) { return myWrappedTreasures.wrap(tr, parent, this); }
138  AssetWrapper *wrap(region *reg, AssetWrapper *parent) { return myWrappedRegions.wrap(reg, parent, this); }
139  AssetWrapper *wrap(face_sets *fs, AssetWrapper *parent) { return myWrappedFacesets.wrap(fs, parent, this); }
142  AssetWrapper *wrap(quest_step_definition *step, AssetWrapper *parent) { return myWrappedQuestSteps.wrap(step, parent, this); }
143  AssetWrapper *wrap(artifactlist *al, AssetWrapper *parent) { return myWrappedArtifactLists.wrap(al, parent, this); }
145  auto wrapper = myWrappedArtifacts.wrap(art, parent, this);
146  connect(wrapper, &AssetWrapper::modified, [wrapper, this] { myArtifacts.assetModified(wrapper->wrappedItem()); });
147  return wrapper;
148  }
150  AssetWrapper *wrap(recipe *rc, AssetWrapper *parent) { return myWrappedRecipes.wrap(rc, parent, this); }
152 
154 
155  public slots:
157  void saveArchetypes();
159  void saveQuests();
161  void saveTreasures();
163  void saveGeneralMessages();
164  void saveArtifacts();
165 
166  protected:
168  QList<QHash<QString, recipe*> > myRecipes;
192 };
193 
194 #endif /* RESOURCESMANAGER_H */
ResourcesManager::treasureModified
void treasureModified(treasurelist *treasure)
Definition: ResourcesManager.cpp:230
Face
Definition: face.h:14
ResourcesManager::myQuests
ModifiedAssetsManager< quest_definition > myQuests
Definition: ResourcesManager.h:170
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:186
GeneralMessage
Definition: book.h:44
ResourcesManager::licenseManager
LicenseManager * licenseManager()
Definition: ResourcesManager.h:153
ArtifactListWrapper.h
ResourcesManager::ResourcesManager
ResourcesManager()
Definition: ResourcesManager.cpp:44
W
#define W(x, n)
Definition: QuestWriter.cpp:15
ResourcesManager::myWrappedFaces
AssetWrapperManager< Face, FaceWrapper > myWrappedFaces
Definition: ResourcesManager.h:178
ResourcesManager::wrap
AssetWrapper * wrap(artifact *art, AssetWrapper *parent)
Definition: ResourcesManager.h:144
ResourcesManager::getRecipe
const recipe * getRecipe(int ingredients, const QString &name) const
Definition: ResourcesManager.cpp:130
ResourcesManager
Definition: ResourcesManager.h:80
archininventory.arch
arch
DIALOGCHECK MINARGS 1 MAXARGS 1
Definition: archininventory.py:16
ResourcesManager::saveArchetypes
void saveArchetypes()
Definition: ResourcesManager.cpp:218
ResourcesManager::questModified
void questModified(quest_definition *quest)
Definition: ResourcesManager.cpp:222
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:132
ResourcesManager::myArtifacts
ModifiedAssetsManager< artifact > myArtifacts
Definition: ResourcesManager.h:173
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:115
ResourcesManager::myWrappedRecipeLists
AssetWrapperManager< recipelist, RecipeListWrapper > myWrappedRecipeLists
Definition: ResourcesManager.h:189
guildoracle.list
list
Definition: guildoracle.py:87
ResourcesManager::wrap
AssetWrapper * wrap(treasure *tr, AssetWrapper *parent)
Definition: ResourcesManager.h:137
guildjoin.ob
ob
Definition: guildjoin.py:42
ResourcesManager::myWrappedArtifacts
AssetWrapperManager< artifact, ArtifactWrapper > myWrappedArtifacts
Definition: ResourcesManager.h:188
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:184
ResourcesManager::myLicenseManager
LicenseManager myLicenseManager
Definition: ResourcesManager.h:191
RecipeWrapper.h
ResourcesManager::archetypeUse
static void archetypeUse(const archetype *item, CREMapInformationManager *store, AssetUseCallback callback)
Definition: ResourcesManager.cpp:138
ResourcesManager::recipeMaxIngredients
int recipeMaxIngredients() const
Definition: ResourcesManager.cpp:115
DEATH_ANIM
@ DEATH_ANIM
Definition: ResourcesManager.h:68
ResourcesManager::originOf
std::string originOf(const artifact *art) const
Definition: ResourcesManager.h:120
ResourcesManager::saveQuests
void saveQuests()
Definition: ResourcesManager.cpp:226
npc_dialog.filename
filename
Definition: npc_dialog.py:99
ResourcesManager::myMapInformationManager
CREMapInformationManager * myMapInformationManager
Definition: ResourcesManager.h:167
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:172
ResourcesManager::getMapInformationManager
CREMapInformationManager * getMapInformationManager()
Definition: ResourcesManager.h:91
ResourcesManager::wrap
AssetWrapper * wrap(quest_step_definition *step, AssetWrapper *parent)
Definition: ResourcesManager.h:142
QuestWrapper.h
AssetWrapperManager::remove
void remove(A *asset)
Definition: ResourcesManager.h:55
ResourcesManager::saveArtifacts
void saveArtifacts()
Definition: ResourcesManager.cpp:265
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:140
ResourcesManager::wrap
ObjectWrapper * wrap(object *ob, AssetWrapper *parent)
Definition: ResourcesManager.h:133
ResourcesManager::wrap
AssetWrapper * wrap(recipe *rc, AssetWrapper *parent)
Definition: ResourcesManager.h:150
ObjectWrapper
Definition: ObjectWrapper.h:36
ResourcesManager::origins
const std::map< std::string, std::set< const archetype * > > & origins() const
Definition: ResourcesManager.h:109
AssetsTracker
Definition: AssetsTracker.h:26
ResourcesManager::archetypeFiles
std::vector< std::string > archetypeFiles() const
Definition: ResourcesManager.h:111
recipelist
Definition: recipe.h:37
ResourcesManager::originOf
std::string originOf(const Face *face) const
Definition: ResourcesManager.h:119
ResourcesManager::saveGeneralMessages
void saveGeneralMessages()
Definition: ResourcesManager.cpp:261
ResourcesManager::load
void load()
Definition: ResourcesManager.cpp:57
treasurelist
Definition: treasure.h:85
ResourcesManager::myRecipes
QList< QHash< QString, recipe * > > myRecipes
Definition: ResourcesManager.h:168
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:187
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:143
FacesetsWrapper.h
AssetsTracker.h
ResourcesManager::questOrigins
const std::map< std::string, std::set< const quest_definition * > > & questOrigins() const
Definition: ResourcesManager.h:113
ResourcesManager::myFaces
ModifiedAssetsManager< Face > myFaces
Definition: ResourcesManager.h:174
ArchetypeWrapper.h
artifactlist
Definition: artifact.h:24
ResourcesManager::myWrappedArchetypes
AssetWrapperManager< archetype, ArchetypeWrapper > myWrappedArchetypes
Definition: ResourcesManager.h:176
ResourcesManager::recipes
QStringList recipes(int count) const
Definition: ResourcesManager.cpp:120
disinfect.count
int count
Definition: disinfect.py:7
FaceWrapper.h
archetype
Definition: object.h:483
ResourcesManager::myWrappedTreasureLists
AssetWrapperManager< treasurelist, TreasureListWrapper > myWrappedTreasureLists
Definition: ResourcesManager.h:180
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:134
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:138
ResourcesManager::archetypeModified
void archetypeModified(archetype *arch)
Definition: ResourcesManager.cpp:214
region
Definition: map.h:272
diamondslots.message
string message
Definition: diamondslots.py:57
ResourcesManager::myWrappedRegions
AssetWrapperManager< region, RegionWrapper > myWrappedRegions
Definition: ResourcesManager.h:182
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:149
item
Definition: item.py:1
ArchetypeWrapper
Definition: ArchetypeWrapper.h:25
ModifiedAssetsManager.h
ResourcesManager::myWrappedFacesets
AssetWrapperManager< face_sets, FacesetsWrapper > myWrappedFacesets
Definition: ResourcesManager.h:183
ResourcesManager::remove
void remove(treasure *tr)
Definition: ResourcesManager.h:151
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:136
ResourcesManager::myWrappedAnimations
AssetWrapperManager< Animations, AnimationWrapper > myWrappedAnimations
Definition: ResourcesManager.h:179
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:257
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:175
RANDOM_MAP_FINAL_EXIT
@ RANDOM_MAP_FINAL_EXIT
Definition: ResourcesManager.h:71
ResourcesManager::myWrappedTreasures
AssetWrapperManager< treasure, TreasureWrapper > myWrappedTreasures
Definition: ResourcesManager.h:181
ResourcesManager::myArchetypes
ModifiedAssetsManager< archetype > myArchetypes
Definition: ResourcesManager.h:169
ResourcesManager::myWrappedRecipes
AssetWrapperManager< recipe, RecipeWrapper > myWrappedRecipes
Definition: ResourcesManager.h:190
ResourcesManager::myWrappedObjects
AssetWrapperManager< object, ObjectWrapper > myWrappedObjects
Definition: ResourcesManager.h:177
ResourcesManager::saveTreasures
void saveTreasures()
Definition: ResourcesManager.cpp:234
treasure
Definition: treasure.h:63
artifact
Definition: artifact.h:14
connect
Definition: connect.py:1
ResourcesManager::myTreasures
ModifiedAssetsManager< treasurelist > myTreasures
Definition: ResourcesManager.h:171
CREMapInformationManager
Definition: CREMapInformationManager.h:27
face_sets
Definition: image.h:17
ResourcesManager::originOfQuest
std::string originOfQuest(const quest_definition *quest) const
Definition: ResourcesManager.h:114
ResourcesManager::hasPendingChanges
bool hasPendingChanges() const
Definition: ResourcesManager.h:122
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:49
ResourcesManager::wrap
AssetWrapper * wrap(face_sets *fs, AssetWrapper *parent)
Definition: ResourcesManager.h:139
ResourcesManager::wrap
AssetWrapper * wrap(Animations *anim, AssetWrapper *parent)
Definition: ResourcesManager.h:135
object.h
ResourcesManager::wrap
AssetWrapper * wrap(quest_definition *quest, AssetWrapper *parent)
Definition: ResourcesManager.h:141
give.name
name
Definition: give.py:27
ResourcesManager::myWrappedQuests
AssetWrapperManager< quest_definition, QuestWrapper > myWrappedQuests
Definition: ResourcesManager.h:185