1 /* 2 * Copyright (C) 2006-2019 Christopho, Solarus - http://www.solarus-games.org 3 * 4 * Solarus is free software; you can redistribute it and/or modify 5 * it under the terms of the GNU General Public License as published by 6 * the Free Software Foundation, either version 3 of the License, or 7 * (at your option) any later version. 8 * 9 * Solarus is distributed in the hope that it will be useful, 10 * but WITHOUT ANY WARRANTY; without even the implied warranty of 11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 * GNU General Public License for more details. 13 * 14 * You should have received a copy of the GNU General Public License along 15 * with this program. If not, see <http://www.gnu.org/licenses/>. 16 */ 17 #ifndef SOLARUS_QUEST_DATABASE_H 18 #define SOLARUS_QUEST_DATABASE_H 19 20 #include "solarus/core/Common.h" 21 #include "solarus/core/EnumInfo.h" 22 #include "solarus/core/ResourceType.h" 23 #include "solarus/lua/LuaData.h" 24 #include <iosfwd> 25 #include <map> 26 #include <string> 27 28 namespace Solarus { 29 30 template <> 31 struct SOLARUS_API EnumInfoTraits<ResourceType> { 32 static const std::string pretty_name; 33 34 static const EnumInfo<ResourceType>::names_type names; 35 }; 36 37 /** 38 * \brief Stores the list of resources and file information of a quest. 39 * 40 * This class stores the content of a quest database file 41 * project_db.dat. 42 * It does not create, remove or rename any file. 43 */ 44 class SOLARUS_API QuestDatabase : public LuaData { 45 46 public: 47 48 /** 49 * Mapping of resource element ids to their description. 50 */ 51 using ResourceMap = std::map<std::string, std::string>; 52 53 /** 54 * Information about a file of the quest. 55 */ 56 struct FileInfo { 57 58 bool is_empty() const { 59 return author.empty() && license.empty(); 60 } 61 62 std::string author; /**< Author of a file or directory. */ 63 std::string license; /**< License of a file or directory. */ 64 }; 65 66 QuestDatabase(); 67 68 void clear(); 69 70 bool resource_exists(ResourceType resource_type, const std::string& id) const; 71 const ResourceMap& get_resource_elements( 72 ResourceType resource_type 73 ) const; 74 ResourceMap& get_resource_elements( 75 ResourceType resource_type 76 ); 77 78 bool add( 79 ResourceType resource_type, 80 const std::string& id, 81 const std::string& description 82 ); 83 bool remove( 84 ResourceType resource_type, 85 const std::string& id 86 ); 87 bool rename( 88 ResourceType resource_type, 89 const std::string& old_id, 90 const std::string& new_id 91 ); 92 std::string get_description( 93 ResourceType resource_type, 94 const std::string& id 95 ) const; 96 bool set_description( 97 ResourceType resource_type, 98 const std::string& id, 99 const std::string& description 100 ); 101 102 const FileInfo& get_file_info(const std::string& path) const; 103 void set_file_info(const std::string& path, const FileInfo& file_info); 104 bool has_file_info(const std::string& path) const; 105 void clear_file_info(const std::string& path); 106 std::map<std::string, FileInfo> get_all_file_info() const; 107 108 virtual bool import_from_lua(lua_State* l) override; 109 virtual bool export_to_lua(std::ostream& out) const override; 110 111 private: 112 113 std::map<ResourceType, ResourceMap> resource_maps; 114 std::map<std::string, FileInfo> files; 115 116 }; 117 118 } 119 120 #endif 121 122