Ticket #1696: progress_1696_II.patch
File progress_1696_II.patch, 6.4 KB (added by , 10 years ago) |
---|
-
binaries/data/mods/public/simulation/data/placeablesFilter.json
1 { 2 "templates": [ 3 {"directory": "campaigns", "file": "*.xml"}, 4 {"directory": "gaia", "file": "*.xml"}, 5 {"directory": "other", "file": "*.xml"}, 6 {"directory": "structures", "file": "*.xml"}, 7 {"directory": "units", "file": "*.xml"}, 8 {"directory": "special", "file": "trigger_point*.xml"}, 9 {"directory": "special", "file": "territory*.xml"} 10 ] 11 } 12 No newline at end of file -
source/ps/TemplateLoader.cpp
191 191 return INFO::OK; 192 192 } 193 193 194 std::vector<std::string> CTemplateLoader::FindPlaceablesTemplates(const std::string& path, bool includeSubdirectories, ETemplatesType templatesType, ScriptInterface& scriptInterface) 195 { 196 197 std::vector<std::string> templates; 198 Status ok; 199 VfsPath templatePath; 200 201 202 if (templatesType == SIMULATION_TEMPLATES || templatesType == ALL_TEMPLATES) 203 { 204 CScriptValRooted placeablesFilter = scriptInterface.ReadJSONFile("simulation/data/placeablesFilter.json"); 205 206 std::vector<CScriptValRooted> folders; 207 if (scriptInterface.GetProperty(placeablesFilter.get(), "templates", folders)) 208 { 209 templatePath = VfsPath(TEMPLATE_ROOT) / path; 210 //I have every object inside, just run for each 211 for (std::vector<CScriptValRooted>::iterator iterator = folders.begin(); iterator != folders.end();++iterator) 212 { 213 jsval val = (*iterator).get(); 214 std::string directoryPath; 215 std::wstring fileFilter; 216 scriptInterface.GetProperty(val, "directory", directoryPath); 217 scriptInterface.GetProperty(val, "file", fileFilter); 218 219 VfsPaths filenames; 220 if (vfs::GetPathnames(g_VFS, templatePath / (directoryPath + "/"), fileFilter.c_str(), filenames) == INFO::OK) 221 { 222 for (VfsPaths::iterator it = filenames.begin(); it != filenames.end(); ++it) 223 { 224 VfsPath filename = *it; 225 // Strip the .xml extension 226 VfsPath pathstem = filename.ChangeExtension(L""); 227 // Strip the root from the path 228 std::wstring name = pathstem.string().substr(ARRAY_SIZE(TEMPLATE_ROOT) - 1); 229 230 templates.push_back(std::string(name.begin(), name.end())); 231 } 232 } 233 } 234 235 } 236 } 237 238 if (templatesType == ACTOR_TEMPLATES || templatesType == ALL_TEMPLATES) 239 { 240 templatePath = VfsPath(ACTOR_ROOT) / path; 241 if (includeSubdirectories) 242 ok = vfs::ForEachFile(g_VFS, templatePath, AddActorToTemplates, (uintptr_t)&templates, L"*.xml", vfs::DIR_RECURSIVE); 243 else 244 ok = vfs::ForEachFile(g_VFS, templatePath, AddActorToTemplates, (uintptr_t)&templates, L"*.xml"); 245 WARN_IF_ERR(ok); 246 } 247 248 if (templatesType != SIMULATION_TEMPLATES && templatesType != ACTOR_TEMPLATES && templatesType != ALL_TEMPLATES) 249 LOGERROR(L"Undefined template type (valid: all, simulation, actor)"); 250 251 return templates; 252 } 253 194 254 std::vector<std::string> CTemplateLoader::FindTemplates(const std::string& path, bool includeSubdirectories, ETemplatesType templatesType) 195 255 { 196 256 std::vector<std::string> templates; -
source/ps/TemplateLoader.h
19 19 #define INCLUDED_TEMPLATELOADER 20 20 21 21 #include "simulation2/system/ParamNode.h" 22 #include "scriptinterface/ScriptInterface.h" 22 23 23 24 enum ETemplatesType 24 25 { … … 55 56 */ 56 57 std::vector<std::string> FindTemplates(const std::string& path, bool includeSubdirectories, ETemplatesType templatesType); 57 58 59 std::vector<std::string> FindPlaceablesTemplates(const std::string& path, bool includeSubdirectories, ETemplatesType templatesType, ScriptInterface& scriptInterface); 60 58 61 private: 59 62 /** 60 63 * (Re)loads the given template, regardless of whether it exists already, -
source/simulation2/components/CCmpTemplateManager.cpp
130 130 131 131 virtual std::vector<std::string> FindAllTemplates(bool includeActors); 132 132 133 virtual std::vector<std::string> FindAllPlaceablesTemplates(bool includeActors); 134 133 135 virtual std::vector<entity_id_t> GetEntitiesUsingTemplate(std::string templateName); 134 136 135 137 private: … … 232 234 return m_templateLoader.FindTemplates("", true, templatesType); 233 235 } 234 236 237 std::vector<std::string> CCmpTemplateManager::FindAllPlaceablesTemplates(bool includeActors) 238 { 239 ScriptInterface& scriptInterface = this->GetSimContext().GetScriptInterface(); 240 241 ETemplatesType templatesType = includeActors ? ALL_TEMPLATES : SIMULATION_TEMPLATES; 242 return m_templateLoader.FindPlaceablesTemplates("", true, templatesType, scriptInterface); 243 } 244 235 245 /** 236 246 * Get the list of entities using the specified template 237 247 */ -
source/simulation2/components/ICmpTemplateManager.h
99 99 */ 100 100 virtual std::vector<std::string> FindAllTemplates(bool includeActors) = 0; 101 101 102 virtual std::vector<std::string> FindAllPlaceablesTemplates(bool includeActors) = 0; 103 102 104 /** 103 105 * Permanently disable XML validation (intended solely for test cases). 104 106 */ -
source/tools/atlas/GameInterface/Handlers/ObjectHandlers.cpp
68 68 CmpPtr<ICmpTemplateManager> cmpTemplateManager(*g_Game->GetSimulation2(), SYSTEM_ENTITY); 69 69 if (cmpTemplateManager) 70 70 { 71 std::vector<std::string> names = cmpTemplateManager->FindAll Templates(true);71 std::vector<std::string> names = cmpTemplateManager->FindAllPlaceablesTemplates(true); 72 72 73 73 for (std::vector<std::string>::iterator it = names.begin(); it != names.end(); ++it) 74 74 {