Index: binaries/data/mods/public/maps/scenarios/units_demo.js =================================================================== --- binaries/data/mods/public/maps/scenarios/units_demo.js +++ binaries/data/mods/public/maps/scenarios/units_demo.js @@ -30,9 +30,13 @@ */ let gap = 14; -let cmpTemplateManager = Engine.QueryInterface(SYSTEM_ENTITY, IID_TemplateManager); -for (let template of cmpTemplateManager.FindAllTemplates(actors)) +const cmpTemplateManager = Engine.QueryInterface(SYSTEM_ENTITY, IID_TemplateManager); +for (const template of cmpTemplateManager.FindAllTemplates(actors)) { + const templateData = cmpTemplateManager.GetTemplate(template); + if (!templateData?.Position) + continue; + print(template + "...\n"); let ent = Engine.AddEntity(template); @@ -42,19 +46,17 @@ continue; } - let cmpFootprint = Engine.QueryInterface(ent, IID_Footprint); - if (!cmpFootprint) + let w = h = 1; + const cmpFootprint = Engine.QueryInterface(ent, IID_Footprint); + if (cmpFootprint) { - print(template + " has no footprint\n"); - continue; - } - - let shape = cmpFootprint.GetShape(); - let w = shape.width; - let h = shape.depth; + let shape = cmpFootprint.GetShape(); + let w = shape.width; + let h = shape.depth; - if (shape.type == 'circle') - w = h = shape.radius * 2; + if (shape.type == 'circle') + w = h = shape.radius * 2; + } if (x + w >= stopX) { Index: source/ps/TemplateLoader.h =================================================================== --- source/ps/TemplateLoader.h +++ source/ps/TemplateLoader.h @@ -1,4 +1,4 @@ -/* Copyright (C) 2022 Wildfire Games. +/* Copyright (C) 2023 Wildfire Games. * This file is part of 0 A.D. * * 0 A.D. is free software: you can redistribute it and/or modify @@ -67,12 +67,6 @@ */ std::vector FindTemplates(const std::string& path, bool includeSubdirectories, ETemplatesType templatesType) const; - /** - * Returns a list of strings that could validly be passed as @c templateName to LoadTemplateFile. - * Not ignoring any special directories. - */ - std::vector FindTemplatesUnrestricted(const std::string& path, bool includeSubdirectories) const; - private: /** * (Re)loads the given template, regardless of whether it exists already, Index: source/ps/TemplateLoader.cpp =================================================================== --- source/ps/TemplateLoader.cpp +++ source/ps/TemplateLoader.cpp @@ -1,4 +1,4 @@ -/* Copyright (C) 2022 Wildfire Games. +/* Copyright (C) 2023 Wildfire Games. * This file is part of 0 A.D. * * 0 A.D. is free software: you can redistribute it and/or modify @@ -159,17 +159,6 @@ return templates; } -std::vector CTemplateLoader::FindTemplatesUnrestricted(const std::string& path, bool includeSubdirectories) const -{ - std::vector templates; - - size_t flags = includeSubdirectories ? vfs::DIR_RECURSIVE : 0; - - WARN_IF_ERR(vfs::ForEachFile(g_VFS, VfsPath(TEMPLATE_ROOT) / path, AddToTemplatesUnrestricted, (uintptr_t)&templates, L"*.xml", flags)); - - return templates; -} - const CParamNode& CTemplateLoader::GetTemplateFileData(const std::string& templateName) { if (std::unordered_map::const_iterator it = m_TemplateFileData.find(templateName); it != m_TemplateFileData.end()) Index: source/simulation2/components/CCmpTemplateManager.cpp =================================================================== --- source/simulation2/components/CCmpTemplateManager.cpp +++ source/simulation2/components/CCmpTemplateManager.cpp @@ -1,4 +1,4 @@ -/* Copyright (C) 2022 Wildfire Games. +/* Copyright (C) 2023 Wildfire Games. * This file is part of 0 A.D. * * 0 A.D. is free software: you can redistribute it and/or modify @@ -221,10 +221,12 @@ { std::vector> data; - std::vector names = m_templateLoader.FindTemplatesUnrestricted("special/players/", false); - data.reserve(names.size()); + std::vector names = FindAllTemplates(false); for (const std::string& name : names) { + if (!GetTemplate(name)->GetChild("Player").IsOk()) + continue; + const CParamNode& identity = GetTemplate(name)->GetChild("Identity"); data.push_back(std::vector { identity.GetChild("Civ").ToWString(), Index: source/tools/atlas/GameInterface/Handlers/ObjectHandlers.cpp =================================================================== --- source/tools/atlas/GameInterface/Handlers/ObjectHandlers.cpp +++ source/tools/atlas/GameInterface/Handlers/ObjectHandlers.cpp @@ -1,4 +1,4 @@ -/* Copyright (C) 2021 Wildfire Games. +/* Copyright (C) 2023 Wildfire Games. * This file is part of 0 A.D. * * 0 A.D. is free software: you can redistribute it and/or modify @@ -100,6 +100,8 @@ for (std::vector::iterator it = names.begin(); it != names.end(); ++it) { std::wstring name(it->begin(), it->end()); + if (!cmpTemplateManager->GetTemplate(*it)->GetChild("Position").IsOk()) + continue; sObjectsListItem e; e.id = name;