Ticket #4076: extend_templates.2.diff
File extend_templates.2.diff, 2.4 KB (added by , 8 years ago) |
---|
-
binaries/data/mods/public/simulation/templates/template_structure_civic_civil_centre.EXTENDS.public.xml
1 <?xml version="1.0" encoding="utf-8"?> 2 <Entity> 3 <Health> 4 <Max op="mul">10</Max> 5 </Health> 6 </Entity> -
source/ps/TemplateLoader.cpp
1 /* Copyright (C) 201 5Wildfire Games.1 /* Copyright (C) 2016 Wildfire Games. 2 2 * This file is part of 0 A.D. 3 3 * 4 4 * 0 A.D. is free software: you can redistribute it and/or modify … … 146 146 CXeromyces xero; 147 147 PSRETURN ok = xero.Load(g_VFS, path); 148 148 if (ok != PSRETURN_OK) 149 return false; // (Xeromyces already logged an error with the full filename)149 return false; // Xeromyces already logged an error with the full filename 150 150 151 151 int attr_parent = xero.GetAttributeID("parent"); 152 152 CStr parentName = xero.GetRoot().GetAttributes().GetNamedItem(attr_parent); … … 175 175 // Load the new file into the template data (overriding parent values) 176 176 CParamNode::LoadXML(m_TemplateFileData[templateName], xero, wstring_from_utf8(templateName).c_str()); 177 177 178 // Load extensions to the template (usually coming from other mods) 179 VfsPaths paths; 180 181 if (vfs::GetPathnames(g_VFS, VfsPath(TEMPLATE_ROOT), wstring_from_utf8(templateName + ".EXTENDS.*.xml").c_str(), paths) != INFO::OK) 182 return true; // No extensions found -> use regular data 183 184 for (const VfsPath& path : paths) 185 { 186 CXeromyces xero; 187 PSRETURN ok = xero.Load(g_VFS, path); 188 if (ok != PSRETURN_OK) 189 return false; // Xeromyces already logged an error with the full filename 190 CStr parentName = xero.GetRoot().GetAttributes().GetNamedItem(attr_parent); 191 if (!parentName.empty()) 192 { 193 LOGERROR("Failed to load '%s'. Extended templates can't redefine template parents.", utf8_from_wstring(path.string()).c_str()); 194 return false; 195 } 196 CParamNode::LoadXML(m_TemplateFileData[templateName], xero, path.string().c_str()); 197 } 198 178 199 return true; 179 200 } 180 201