1
0
forked from 0ad/0ad

Switch back to an unplaceable filter for templates.

This removes FindAllPlaceableTemplates, replaces the few uses of it by
FindAllTemplates,
and makes that ignore all templates starting with special/ in addition
to those starting
with template_.

Now modders can use entirely different template organization schemes
(more folders, different
folders, etc) without having to edit a file that was never well
documented.

In conjunction with a few of the template moving patches preceding this
rubble/ and other/catafalque
are now placeable. The former now does not decay anymore and users that
want that should use the
decay| filter, the latter will be taken care of in #4762.

Return to making FindAllTemplates return all placeable templates again
(switch to unplaceable filter).

To reiterate the main point: Only templates starting with special/ or
template_ will not show up as
placeable in Atlas (or show up to code querying for all (placeable)
templates. If you want to add more
of those use one of these naming schemes (and possibly subfolders in
special/).

Reviewed By: fatherbushido
Differential Revision: https://code.wildfiregames.com/D935
This was SVN commit r20246.
This commit is contained in:
leper 2017-09-30 15:22:51 +00:00
parent 40cafe5049
commit 84674911cc
8 changed files with 6 additions and 114 deletions

View File

@ -31,7 +31,7 @@ let maxh = 0;
let gap = 14;
let cmpTemplateManager = Engine.QueryInterface(SYSTEM_ENTITY, IID_TemplateManager);
for (let template of cmpTemplateManager.FindAllPlaceableTemplates(actors))
for (let template of cmpTemplateManager.FindAllTemplates(actors))
{
print(template + "...\n");

View File

@ -1,14 +0,0 @@
{
"templates": [
{"directory": "campaigns", "file": "*.xml"},
{"directory": "gaia", "file": "*.xml"},
{"directory": "other", "file": "*.xml"},
{"directory": "structures", "file": "*.xml"},
{"directory": "units", "file": "*.xml"},
{"directory": "trigger", "file": "*.xml"},
{"directory": "skirmish/structures", "file": "*.xml"},
{"directory": "skirmish/units", "file": "*.xml"},
{"directory": "special", "file": "trigger_point*.xml"},
{"directory": "special", "file": "territory*.xml"}
]
}

View File

@ -23,6 +23,7 @@
#include "ps/CLogger.h"
#include "ps/Filesystem.h"
#include "ps/XML/Xeromyces.h"
#include "scriptinterface/ScriptConversions.h"
static const wchar_t TEMPLATE_ROOT[] = L"simulation/templates/";
static const wchar_t ACTOR_ROOT[] = L"art/actors/";
@ -130,6 +131,9 @@ static Status AddToTemplates(const VfsPath& pathname, const CFileInfo& UNUSED(fi
if (name.substr(0, 9) == L"template_")
return INFO::OK;
if (name.substr(0, 8) == L"special/")
return INFO::OK;
templates.push_back(std::string(name.begin(), name.end()));
return INFO::OK;
}
@ -152,89 +156,6 @@ bool CTemplateLoader::TemplateExists(const std::string& templateName) const
return VfsFileExists(VfsPath(TEMPLATE_ROOT) / wstring_from_utf8(baseName + ".xml"));
}
std::vector<std::string> CTemplateLoader::FindPlaceableTemplates(const std::string& path, bool includeSubdirectories, ETemplatesType templatesType, ScriptInterface& scriptInterface) const
{
if (templatesType != SIMULATION_TEMPLATES && templatesType != ACTOR_TEMPLATES && templatesType != ALL_TEMPLATES)
{
LOGERROR("Undefined template type (valid: all, simulation, actor)");
return std::vector<std::string>();
}
JSContext* cx = scriptInterface.GetContext();
JSAutoRequest rq(cx);
std::vector<std::string> templates;
Status ok;
VfsPath templatePath;
if (templatesType == SIMULATION_TEMPLATES || templatesType == ALL_TEMPLATES)
{
JS::RootedValue placeablesFilter(cx);
scriptInterface.ReadJSONFile("simulation/data/placeablesFilter.json", &placeablesFilter);
JS::RootedObject folders(cx);
if (scriptInterface.GetProperty(placeablesFilter, "templates", &folders))
{
if (!(JS_IsArrayObject(cx, folders)))
{
LOGERROR("FindPlaceableTemplates: Argument must be an array!");
return templates;
}
u32 length;
if (!JS_GetArrayLength(cx, folders, &length))
{
LOGERROR("FindPlaceableTemplates: Failed to get array length!");
return templates;
}
templatePath = VfsPath(TEMPLATE_ROOT) / path;
//I have every object inside, just run for each
for (u32 i=0; i<length; ++i)
{
JS::RootedValue val(cx);
if (!JS_GetElement(cx, folders, i, &val))
{
LOGERROR("FindPlaceableTemplates: Failed to read array element!");
return templates;
}
std::string directoryPath;
std::wstring fileFilter;
scriptInterface.GetProperty(val, "directory", directoryPath);
scriptInterface.GetProperty(val, "file", fileFilter);
VfsPaths filenames;
if (vfs::GetPathnames(g_VFS, templatePath / (directoryPath + "/"), fileFilter.c_str(), filenames) != INFO::OK)
continue;
for (const VfsPath& filename : filenames)
{
// Strip the .xml extension
VfsPath pathstem = filename.ChangeExtension(L"");
// Strip the root from the path
std::wstring name = pathstem.string().substr(ARRAY_SIZE(TEMPLATE_ROOT) - 1);
templates.emplace_back(name.begin(), name.end());
}
}
}
}
if (templatesType == ACTOR_TEMPLATES || templatesType == ALL_TEMPLATES)
{
templatePath = VfsPath(ACTOR_ROOT) / path;
if (includeSubdirectories)
ok = vfs::ForEachFile(g_VFS, templatePath, AddActorToTemplates, (uintptr_t)&templates, L"*.xml", vfs::DIR_RECURSIVE);
else
ok = vfs::ForEachFile(g_VFS, templatePath, AddActorToTemplates, (uintptr_t)&templates, L"*.xml");
WARN_IF_ERR(ok);
}
return templates;
}
std::vector<std::string> CTemplateLoader::FindTemplates(const std::string& path, bool includeSubdirectories, ETemplatesType templatesType) const
{
std::vector<std::string> templates;

View File

@ -65,8 +65,6 @@ public:
*/
std::vector<std::string> FindTemplates(const std::string& path, bool includeSubdirectories, ETemplatesType templatesType) const;
std::vector<std::string> FindPlaceableTemplates(const std::string& path, bool includeSubdirectories, ETemplatesType templatesType, ScriptInterface& scriptInterface) const;
private:
/**
* (Re)loads the given template, regardless of whether it exists already,

View File

@ -114,8 +114,6 @@ public:
virtual std::vector<std::string> FindAllTemplates(bool includeActors) const;
virtual std::vector<std::string> FindAllPlaceableTemplates(bool includeActors) const;
virtual std::vector<entity_id_t> GetEntitiesUsingTemplate(const std::string& templateName) const;
private:
@ -216,14 +214,6 @@ std::vector<std::string> CCmpTemplateManager::FindAllTemplates(bool includeActor
return m_templateLoader.FindTemplates("", true, templatesType);
}
std::vector<std::string> CCmpTemplateManager::FindAllPlaceableTemplates(bool includeActors) const
{
ScriptInterface& scriptInterface = this->GetSimContext().GetScriptInterface();
ETemplatesType templatesType = includeActors ? ALL_TEMPLATES : SIMULATION_TEMPLATES;
return m_templateLoader.FindPlaceableTemplates("", true, templatesType, scriptInterface);
}
/**
* Get the list of entities using the specified template
*/

View File

@ -27,6 +27,5 @@ DEFINE_INTERFACE_METHOD_1("GetTemplateWithoutValidation", const CParamNode*, ICm
DEFINE_INTERFACE_METHOD_CONST_1("TemplateExists", bool, ICmpTemplateManager, TemplateExists, std::string)
DEFINE_INTERFACE_METHOD_CONST_1("GetCurrentTemplateName", std::string, ICmpTemplateManager, GetCurrentTemplateName, entity_id_t)
DEFINE_INTERFACE_METHOD_CONST_1("FindAllTemplates", std::vector<std::string>, ICmpTemplateManager, FindAllTemplates, bool)
DEFINE_INTERFACE_METHOD_CONST_1("FindAllPlaceableTemplates", std::vector<std::string>, ICmpTemplateManager, FindAllPlaceableTemplates, bool)
DEFINE_INTERFACE_METHOD_CONST_1("GetEntitiesUsingTemplate", std::vector<entity_id_t>, ICmpTemplateManager, GetEntitiesUsingTemplate, std::string)
END_INTERFACE_WRAPPER(TemplateManager)

View File

@ -103,8 +103,6 @@ public:
*/
virtual std::vector<std::string> FindAllTemplates(bool includeActors) const = 0;
virtual std::vector<std::string> FindAllPlaceableTemplates(bool includeActors) const = 0;
/**
* Permanently disable XML validation (intended solely for test cases).
*/

View File

@ -94,7 +94,7 @@ QUERYHANDLER(GetObjectsList)
CmpPtr<ICmpTemplateManager> cmpTemplateManager(*g_Game->GetSimulation2(), SYSTEM_ENTITY);
if (cmpTemplateManager)
{
std::vector<std::string> names = cmpTemplateManager->FindAllPlaceableTemplates(true);
std::vector<std::string> names = cmpTemplateManager->FindAllTemplates(true);
for (std::vector<std::string>::iterator it = names.begin(); it != names.end(); ++it)
{