1 /* 2 Copyright (C) 2010-2014 Kristian Duske 3 4 This file is part of TrenchBroom. 5 6 TrenchBroom is free software: you can redistribute it and/or modify 7 it under the terms of the GNU General Public License as published by 8 the Free Software Foundation, either version 3 of the License, or 9 (at your option) any later version. 10 11 TrenchBroom is distributed in the hope that it will be useful, 12 but WITHOUT ANY WARRANTY; without even the implied warranty of 13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 GNU General Public License for more details. 15 16 You should have received a copy of the GNU General Public License 17 along with TrenchBroom. If not, see <http://www.gnu.org/licenses/>. 18 */ 19 20 #include "GameConfig.h" 21 22 #include "CollectionUtils.h" 23 #include "IO/DiskFileSystem.h" 24 #include "IO/SystemPaths.h" 25 26 #include <cassert> 27 28 namespace TrenchBroom { 29 namespace Model { FileSystemConfig(const IO::Path & i_searchPath,const String & i_packageFormat)30 GameConfig::FileSystemConfig::FileSystemConfig(const IO::Path& i_searchPath, const String& i_packageFormat) : 31 searchPath(i_searchPath), 32 packageFormat(i_packageFormat) {} 33 TextureConfig(const String & i_type,const String & i_attribute,const IO::Path & i_palette,const IO::Path & i_builtinTexturesSearchPath)34 GameConfig::TextureConfig::TextureConfig(const String& i_type, const String& i_attribute, const IO::Path& i_palette, const IO::Path& i_builtinTexturesSearchPath) : 35 type(i_type), 36 attribute(i_attribute), 37 palette(i_palette), 38 builtinTexturesSearchPath(i_builtinTexturesSearchPath) {} 39 EntityConfig(const IO::Path & i_defFilePath,const StringSet & i_modelFormats,const Color & i_defaultColor)40 GameConfig::EntityConfig::EntityConfig(const IO::Path& i_defFilePath, const StringSet& i_modelFormats, const Color& i_defaultColor) : 41 modelFormats(i_modelFormats), 42 defaultColor(i_defaultColor) { 43 defFilePaths.push_back(i_defFilePath); 44 } 45 EntityConfig(const IO::Path::List & i_defFilePaths,const StringSet & i_modelFormats,const Color & i_defaultColor)46 GameConfig::EntityConfig::EntityConfig(const IO::Path::List& i_defFilePaths, const StringSet& i_modelFormats, const Color& i_defaultColor) : 47 defFilePaths(i_defFilePaths), 48 modelFormats(i_modelFormats), 49 defaultColor(i_defaultColor) {} 50 FlagConfig(const String & i_name,const String & i_description)51 GameConfig::FlagConfig::FlagConfig(const String& i_name, const String& i_description) : 52 name(i_name), 53 description(i_description) {} 54 FlagsConfig()55 GameConfig::FlagsConfig::FlagsConfig() {} 56 FlagsConfig(const FlagConfigList & i_flags)57 GameConfig::FlagsConfig::FlagsConfig(const FlagConfigList& i_flags) : 58 flags(i_flags) {} 59 flagValue(const String & flagName) const60 int GameConfig::FlagsConfig::flagValue(const String& flagName) const { 61 for (size_t i = 0; i < flags.size(); ++i) { 62 if (flags[i].name == flagName) 63 return static_cast<int>(1 << i); 64 } 65 return 0; 66 } 67 flagName(const size_t index) const68 String GameConfig::FlagsConfig::flagName(const size_t index) const { 69 assert(index < flags.size()); 70 return flags[index].name; 71 } 72 flagNames(const int mask) const73 StringList GameConfig::FlagsConfig::flagNames(const int mask) const { 74 if (mask == 0) 75 return EmptyStringList; 76 77 StringList names; 78 for (size_t i = 0; i < flags.size(); ++i) { 79 if (mask & (1 << i)) 80 names.push_back(flags[i].name); 81 } 82 return names; 83 } 84 FaceAttribsConfig()85 GameConfig::FaceAttribsConfig::FaceAttribsConfig() {} 86 FaceAttribsConfig(const FlagConfigList & i_surfaceFlags,const FlagConfigList & i_contentFlags)87 GameConfig::FaceAttribsConfig::FaceAttribsConfig(const FlagConfigList& i_surfaceFlags, const FlagConfigList& i_contentFlags) : 88 surfaceFlags(i_surfaceFlags), 89 contentFlags(i_contentFlags) {} 90 GameConfig()91 GameConfig::GameConfig() : 92 m_path(IO::Path("")), 93 m_icon(IO::Path("")), 94 m_fileSystemConfig(IO::Path(""), ""), 95 m_textureConfig("", "", IO::Path(""), IO::Path("")), 96 m_entityConfig(IO::Path(""), StringSet(), Color()) {} 97 GameConfig(const String & name,const IO::Path & path,const IO::Path & icon,const StringList & fileFormats,const FileSystemConfig & fileSystemConfig,const TextureConfig & textureConfig,const EntityConfig & entityConfig,const FaceAttribsConfig & faceAttribsConfig,const BrushContentType::List & brushContentTypes)98 GameConfig::GameConfig(const String& name, 99 const IO::Path& path, 100 const IO::Path& icon, 101 const StringList& fileFormats, 102 const FileSystemConfig& fileSystemConfig, 103 const TextureConfig& textureConfig, 104 const EntityConfig& entityConfig, 105 const FaceAttribsConfig& faceAttribsConfig, 106 const BrushContentType::List& brushContentTypes) : 107 m_name(name), 108 m_path(path), 109 m_icon(icon), 110 m_fileFormats(fileFormats), 111 m_fileSystemConfig(fileSystemConfig), 112 m_textureConfig(textureConfig), 113 m_entityConfig(entityConfig), 114 m_faceAttribsConfig(faceAttribsConfig), 115 m_brushContentTypes(brushContentTypes) { 116 assert(!StringUtils::trim(m_name).empty()); 117 assert(m_path.isEmpty() || m_path.isAbsolute()); 118 } 119 name() const120 const String& GameConfig::name() const { 121 return m_name; 122 } 123 path() const124 const IO::Path& GameConfig::path() const { 125 return m_path; 126 } 127 icon() const128 const IO::Path& GameConfig::icon() const { 129 return m_icon; 130 } 131 fileFormats() const132 const StringList& GameConfig::fileFormats() const { 133 return m_fileFormats; 134 } 135 fileSystemConfig() const136 const GameConfig::FileSystemConfig& GameConfig::fileSystemConfig() const { 137 return m_fileSystemConfig; 138 } 139 textureConfig() const140 const GameConfig::TextureConfig& GameConfig::textureConfig() const { 141 return m_textureConfig; 142 } 143 entityConfig() const144 const GameConfig::EntityConfig& GameConfig::entityConfig() const { 145 return m_entityConfig; 146 } 147 faceAttribsConfig() const148 const GameConfig::FaceAttribsConfig& GameConfig::faceAttribsConfig() const { 149 return m_faceAttribsConfig; 150 } 151 brushContentTypes() const152 const BrushContentType::List& GameConfig::brushContentTypes() const { 153 return m_brushContentTypes; 154 } 155 findConfigFile(const IO::Path & filePath) const156 const IO::Path GameConfig::findConfigFile(const IO::Path& filePath) const { 157 const IO::Path relPath = path().deleteLastComponent() + filePath; 158 // if (IO::Disk::fileExists(relPath)) 159 return relPath; 160 // return IO::SystemPaths::resourceDirectory() + filePath; 161 } 162 addBrushContentType(const BrushContentType & contentType)163 void GameConfig::addBrushContentType(const BrushContentType& contentType) { 164 m_brushContentTypes.push_back(contentType); 165 } 166 } 167 } 168