Ticket #4076: extend_templates.diff

File extend_templates.diff, 2.0 KB (added by sanderd17, 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) 2015 Wildfire Games.
     1/* Copyright (C) 2016 Wildfire Games.
    22 * This file is part of 0 A.D.
    33 *
    44 * 0 A.D. is free software: you can redistribute it and/or modify
     
    175175    // Load the new file into the template data (overriding parent values)
    176176    CParamNode::LoadXML(m_TemplateFileData[templateName], xero, wstring_from_utf8(templateName).c_str());
    177177
     178    // Load extensions to the template (usually coming from other mods)
     179    VfsPaths fileNames;
     180
     181    if (vfs::GetPathnames(g_VFS, VfsPath(TEMPLATE_ROOT), wstring_from_utf8(templateName + ".EXTENDS.*.xml").c_str(), fileNames) != INFO::OK)
     182        return true; // No extensions found -> use regular data
     183
     184    for (const VfsPath& fileName : fileNames)
     185    {
     186        CXeromyces xero;
     187        PSRETURN ok = xero.Load(g_VFS, fileName);
     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.", fileName.string().c_str());
     194            return false;
     195        }
     196        CParamNode::LoadXML(m_TemplateFileData[templateName], xero, fileName.string().c_str());
     197    }
     198
    178199    return true;
    179200}
    180201