Ticket #4076: extend_templates.2.diff

File extend_templates.2.diff, 2.4 KB (added by sanderd17, 8 years ago)

Fixed a compilation issue, changed some comments and variable names

  • 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
     
    146146    CXeromyces xero;
    147147    PSRETURN ok = xero.Load(g_VFS, path);
    148148    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
    150150
    151151    int attr_parent = xero.GetAttributeID("parent");
    152152    CStr parentName = xero.GetRoot().GetAttributes().GetNamedItem(attr_parent);
     
    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 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
    178199    return true;
    179200}
    180201