Changeset View
Changeset View
Standalone View
Standalone View
source/ps/TemplateLoader.h
/* Copyright (C) 2017 Wildfire Games. | /* Copyright (C) 2021 Wildfire Games. | ||||
* This file is part of 0 A.D. | * This file is part of 0 A.D. | ||||
* | * | ||||
* 0 A.D. is free software: you can redistribute it and/or modify | * 0 A.D. is free software: you can redistribute it and/or modify | ||||
* it under the terms of the GNU General Public License as published by | * it under the terms of the GNU General Public License as published by | ||||
* the Free Software Foundation, either version 2 of the License, or | * the Free Software Foundation, either version 2 of the License, or | ||||
* (at your option) any later version. | * (at your option) any later version. | ||||
* | * | ||||
* 0 A.D. is distributed in the hope that it will be useful, | * 0 A.D. is distributed in the hope that it will be useful, | ||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of | * but WITHOUT ANY WARRANTY; without even the implied warranty of | ||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||||
* GNU General Public License for more details. | * GNU General Public License for more details. | ||||
* | * | ||||
* You should have received a copy of the GNU General Public License | * You should have received a copy of the GNU General Public License | ||||
* along with 0 A.D. If not, see <http://www.gnu.org/licenses/>. | * along with 0 A.D. If not, see <http://www.gnu.org/licenses/>. | ||||
*/ | */ | ||||
#ifndef INCLUDED_TEMPLATELOADER | #ifndef INCLUDED_TEMPLATELOADER | ||||
#define INCLUDED_TEMPLATELOADER | #define INCLUDED_TEMPLATELOADER | ||||
#include "simulation2/system/ParamNode.h" | #include "simulation2/system/ParamNode.h" | ||||
#include "ps/ParamNodeLayer.h" | |||||
#include <unordered_map> | |||||
enum ETemplatesType | enum ETemplatesType | ||||
{ | { | ||||
ALL_TEMPLATES, | ALL_TEMPLATES, | ||||
ACTOR_TEMPLATES, | ACTOR_TEMPLATES, | ||||
SIMULATION_TEMPLATES | SIMULATION_TEMPLATES | ||||
}; | }; | ||||
Show All 34 Lines | public: | ||||
*/ | */ | ||||
std::vector<std::string> FindTemplates(const std::string& path, bool includeSubdirectories, ETemplatesType templatesType) const; | std::vector<std::string> FindTemplates(const std::string& path, bool includeSubdirectories, ETemplatesType templatesType) const; | ||||
private: | private: | ||||
/** | /** | ||||
* (Re)loads the given template, regardless of whether it exists already, | * (Re)loads the given template, regardless of whether it exists already, | ||||
* and saves into m_TemplateFileData. Also loads any parents that are not yet | * and saves into m_TemplateFileData. Also loads any parents that are not yet | ||||
* loaded. Returns false on error. | * loaded. Returns false on error. | ||||
* @param templateName XML filename to load (not a |-separated string) | * @param templateName XML filename to load (may be a |-separated string) | ||||
*/ | */ | ||||
bool LoadTemplateFile(const std::string& templateName, int depth); | bool LoadTemplateFile(const std::string& templateName, int depth); | ||||
/** | /** | ||||
* Constructs a standard static-decorative-object template for the given actor | * Load the given file and apply it on the paramnode. | ||||
*/ | |||||
bool LoadAndApplyLayer(CParamNode& node, const std::string& layerName, const std::string& parentName, int depth); | |||||
/** | |||||
* Layer name -> Param node layer. Unlike TemplateFileData, this is never |-separated. | |||||
*/ | */ | ||||
void ConstructTemplateActor(const std::string& actorName, CParamNode& out); | std::unordered_map<std::string, ParamNodeLayer> m_ParamNodeLayers; | ||||
/** | /** | ||||
* Map from template name (XML filename or special |-separated string) to the most recently | * Map from template name (XML filename or special |-separated string) to the most recently | ||||
* loaded non-broken template data. This includes files that will fail schema validation. | * loaded non-broken template data. This includes files that will fail schema validation. | ||||
* (Failed loads won't remove existing entries under the same name, so we behave more nicely | * (Failed loads won't remove existing entries under the same name, so we behave more nicely | ||||
* when hotloading broken files) | * when hotloading broken files) | ||||
*/ | */ | ||||
std::map<std::string, CParamNode> m_TemplateFileData; | std::map<std::string, CParamNode> m_TemplateFileData; | ||||
}; | }; | ||||
#endif // INCLUDED_TEMPLATELOADER | #endif // INCLUDED_TEMPLATELOADER |
Wildfire Games · Phabricator