mirror of
https://github.com/Laupetin/OpenAssetTools.git
synced 2026-01-10 02:31:49 +00:00
chore: do not specify assets for zcg templates
This commit is contained in:
@@ -321,10 +321,10 @@ function ZoneCode:project()
|
|||||||
.. ' -h "' .. path.join(path.getabsolute(ProjectFolder()), 'ZoneCode/Game/%{file.basename}/%{file.basename}_ZoneCode.h') .. '"'
|
.. ' -h "' .. path.join(path.getabsolute(ProjectFolder()), 'ZoneCode/Game/%{file.basename}/%{file.basename}_ZoneCode.h') .. '"'
|
||||||
.. ' -c "' .. path.join(path.getabsolute(ProjectFolder()), 'ZoneCode/Game/%{file.basename}/%{file.basename}_Commands.txt') .. '"'
|
.. ' -c "' .. path.join(path.getabsolute(ProjectFolder()), 'ZoneCode/Game/%{file.basename}/%{file.basename}_Commands.txt') .. '"'
|
||||||
.. ' -o "%{wks.location}/src/ZoneCode/Game/%{file.basename}/XAssets"'
|
.. ' -o "%{wks.location}/src/ZoneCode/Game/%{file.basename}/XAssets"'
|
||||||
.. ' -g "*" ZoneLoad'
|
.. ' -g ZoneLoad'
|
||||||
.. ' -g "*" ZoneMark'
|
.. ' -g ZoneMark'
|
||||||
.. ' -g "*" ZoneWrite'
|
.. ' -g ZoneWrite'
|
||||||
.. ' -g "*" AssetStructTests'
|
.. ' -g AssetStructTests'
|
||||||
}
|
}
|
||||||
buildinputs {
|
buildinputs {
|
||||||
path.join(ProjectFolder(), "ZoneCode/Game/%{file.basename}/%{file.basename}_ZoneCode.h"),
|
path.join(ProjectFolder(), "ZoneCode/Game/%{file.basename}/%{file.basename}_ZoneCode.h"),
|
||||||
|
|||||||
@@ -6,11 +6,11 @@
|
|||||||
#include "Templates/ZoneMarkTemplate.h"
|
#include "Templates/ZoneMarkTemplate.h"
|
||||||
#include "Templates/ZoneWriteTemplate.h"
|
#include "Templates/ZoneWriteTemplate.h"
|
||||||
#include "Utils/Logging/Log.h"
|
#include "Utils/Logging/Log.h"
|
||||||
|
#include "Utils/StringUtils.h"
|
||||||
|
|
||||||
#include <filesystem>
|
#include <filesystem>
|
||||||
#include <format>
|
#include <format>
|
||||||
#include <fstream>
|
#include <fstream>
|
||||||
#include <iostream>
|
|
||||||
|
|
||||||
namespace fs = std::filesystem;
|
namespace fs = std::filesystem;
|
||||||
|
|
||||||
@@ -55,7 +55,7 @@ bool CodeGenerator::GenerateCodeForTemplate(const RenderingContext& context, ICo
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool CodeGenerator::GetAssetWithName(IDataRepository* repository, const std::string& name, StructureInformation*& asset)
|
bool CodeGenerator::GetAssetWithName(const IDataRepository* repository, const std::string& name, StructureInformation*& asset)
|
||||||
{
|
{
|
||||||
auto* def = repository->GetDataDefinitionByName(name);
|
auto* def = repository->GetDataDefinitionByName(name);
|
||||||
if (def == nullptr)
|
if (def == nullptr)
|
||||||
@@ -64,7 +64,7 @@ bool CodeGenerator::GetAssetWithName(IDataRepository* repository, const std::str
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
auto* defWithMembers = dynamic_cast<DefinitionWithMembers*>(def);
|
const auto* defWithMembers = dynamic_cast<DefinitionWithMembers*>(def);
|
||||||
asset = defWithMembers != nullptr ? repository->GetInformationFor(defWithMembers) : nullptr;
|
asset = defWithMembers != nullptr ? repository->GetInformationFor(defWithMembers) : nullptr;
|
||||||
if (asset == nullptr)
|
if (asset == nullptr)
|
||||||
{
|
{
|
||||||
@@ -81,7 +81,7 @@ bool CodeGenerator::GetAssetWithName(IDataRepository* repository, const std::str
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool CodeGenerator::GenerateCode(IDataRepository* repository)
|
bool CodeGenerator::GenerateCode(const IDataRepository* repository)
|
||||||
{
|
{
|
||||||
std::vector<StructureInformation*> assets;
|
std::vector<StructureInformation*> assets;
|
||||||
|
|
||||||
@@ -93,42 +93,28 @@ bool CodeGenerator::GenerateCode(IDataRepository* repository)
|
|||||||
}
|
}
|
||||||
|
|
||||||
const auto start = std::chrono::steady_clock::now();
|
const auto start = std::chrono::steady_clock::now();
|
||||||
for (const auto& generationTask : m_args->m_generation_tasks)
|
for (const auto& templateName : m_args->m_template_names)
|
||||||
{
|
{
|
||||||
auto templateName = generationTask.m_template_name;
|
std::string lowerTemplateName(templateName);
|
||||||
for (auto& c : templateName)
|
utils::MakeStringLowerCase(lowerTemplateName);
|
||||||
c = static_cast<char>(tolower(c));
|
|
||||||
|
|
||||||
const auto foundTemplate = m_template_mapping.find(templateName);
|
const auto foundTemplate = m_template_mapping.find(lowerTemplateName);
|
||||||
if (foundTemplate == m_template_mapping.end())
|
if (foundTemplate == m_template_mapping.end())
|
||||||
{
|
{
|
||||||
con::error("Unknown template '{}'.", generationTask.m_template_name);
|
con::error("Unknown template '{}'.", templateName);
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (generationTask.m_all_assets)
|
for (auto* asset : assets)
|
||||||
{
|
{
|
||||||
for (auto* asset : assets)
|
|
||||||
{
|
|
||||||
auto context = RenderingContext::BuildContext(repository, asset);
|
|
||||||
if (!GenerateCodeForTemplate(*context, foundTemplate->second.get()))
|
|
||||||
{
|
|
||||||
con::error("Failed to generate code for asset '{}' with preset '{}'", asset->m_definition->GetFullName(), foundTemplate->first);
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
con::info("Successfully generated code for asset '{}' with preset '{}'", asset->m_definition->GetFullName(), foundTemplate->first);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
StructureInformation* asset;
|
|
||||||
if (!GetAssetWithName(repository, generationTask.m_asset_name, asset))
|
|
||||||
return false;
|
|
||||||
|
|
||||||
auto context = RenderingContext::BuildContext(repository, asset);
|
auto context = RenderingContext::BuildContext(repository, asset);
|
||||||
if (!GenerateCodeForTemplate(*context, foundTemplate->second.get()))
|
if (!GenerateCodeForTemplate(*context, foundTemplate->second.get()))
|
||||||
|
{
|
||||||
|
con::error("Failed to generate code for asset '{}' with preset '{}'", asset->m_definition->GetFullName(), foundTemplate->first);
|
||||||
return false;
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
con::info("Successfully generated code for asset '{}' with preset '{}'", asset->m_definition->GetFullName(), foundTemplate->first);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
const auto end = std::chrono::steady_clock::now();
|
const auto end = std::chrono::steady_clock::now();
|
||||||
|
|||||||
@@ -12,13 +12,13 @@ class CodeGenerator
|
|||||||
public:
|
public:
|
||||||
explicit CodeGenerator(const ZoneCodeGeneratorArguments* args);
|
explicit CodeGenerator(const ZoneCodeGeneratorArguments* args);
|
||||||
|
|
||||||
bool GenerateCode(IDataRepository* repository);
|
bool GenerateCode(const IDataRepository* repository);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
void SetupTemplates();
|
void SetupTemplates();
|
||||||
|
|
||||||
bool GenerateCodeForTemplate(const RenderingContext& context, ICodeTemplate* codeTemplate) const;
|
bool GenerateCodeForTemplate(const RenderingContext& context, ICodeTemplate* codeTemplate) const;
|
||||||
static bool GetAssetWithName(IDataRepository* repository, const std::string& name, StructureInformation*& asset);
|
static bool GetAssetWithName(const IDataRepository* repository, const std::string& name, StructureInformation*& asset);
|
||||||
|
|
||||||
const ZoneCodeGeneratorArguments* m_args;
|
const ZoneCodeGeneratorArguments* m_args;
|
||||||
std::unordered_map<std::string, std::unique_ptr<ICodeTemplate>> m_template_mapping;
|
std::unordered_map<std::string, std::unique_ptr<ICodeTemplate>> m_template_mapping;
|
||||||
|
|||||||
@@ -6,7 +6,6 @@
|
|||||||
#include "Utils/Logging/Log.h"
|
#include "Utils/Logging/Log.h"
|
||||||
|
|
||||||
#include <format>
|
#include <format>
|
||||||
#include <iostream>
|
|
||||||
#include <type_traits>
|
#include <type_traits>
|
||||||
|
|
||||||
// clang-format off
|
// clang-format off
|
||||||
@@ -81,9 +80,8 @@ const CommandLineOption* const OPTION_GENERATE =
|
|||||||
CommandLineOption::Builder::Create()
|
CommandLineOption::Builder::Create()
|
||||||
.WithShortName("g")
|
.WithShortName("g")
|
||||||
.WithLongName("generate")
|
.WithLongName("generate")
|
||||||
.WithDescription("Generates a specified asset/preset combination. Can be used multiple times. Available presets: ZoneLoad, ZoneWrite, AssetStructTests")
|
.WithDescription("Generates a specified preset. Can be used multiple times. Available presets: ZoneLoad, ZoneWrite, AssetStructTests")
|
||||||
.WithCategory(CATEGORY_OUTPUT)
|
.WithCategory(CATEGORY_OUTPUT)
|
||||||
.WithParameter("assetName")
|
|
||||||
.WithParameter("preset")
|
.WithParameter("preset")
|
||||||
.Reusable()
|
.Reusable()
|
||||||
.Build();
|
.Build();
|
||||||
@@ -103,28 +101,10 @@ const CommandLineOption* const COMMAND_LINE_OPTIONS[]{
|
|||||||
|
|
||||||
namespace
|
namespace
|
||||||
{
|
{
|
||||||
static constexpr unsigned FLAG_TASK_GENERATE = 1 << 0;
|
constexpr unsigned FLAG_TASK_GENERATE = 1 << 0;
|
||||||
static constexpr unsigned FLAG_TASK_PRINT = 1 << 1;
|
constexpr unsigned FLAG_TASK_PRINT = 1 << 1;
|
||||||
} // namespace
|
} // namespace
|
||||||
|
|
||||||
GenerationTask::GenerationTask()
|
|
||||||
: m_all_assets(false)
|
|
||||||
{
|
|
||||||
}
|
|
||||||
|
|
||||||
GenerationTask::GenerationTask(std::string templateName)
|
|
||||||
: m_all_assets(true),
|
|
||||||
m_template_name(std::move(templateName))
|
|
||||||
{
|
|
||||||
}
|
|
||||||
|
|
||||||
GenerationTask::GenerationTask(std::string assetName, std::string templateName)
|
|
||||||
: m_all_assets(false),
|
|
||||||
m_asset_name(std::move(assetName)),
|
|
||||||
m_template_name(std::move(templateName))
|
|
||||||
{
|
|
||||||
}
|
|
||||||
|
|
||||||
ZoneCodeGeneratorArguments::ZoneCodeGeneratorArguments()
|
ZoneCodeGeneratorArguments::ZoneCodeGeneratorArguments()
|
||||||
: m_argument_parser(COMMAND_LINE_OPTIONS, std::extent_v<decltype(COMMAND_LINE_OPTIONS)>),
|
: m_argument_parser(COMMAND_LINE_OPTIONS, std::extent_v<decltype(COMMAND_LINE_OPTIONS)>),
|
||||||
m_task_flags(0u)
|
m_task_flags(0u)
|
||||||
@@ -217,17 +197,7 @@ bool ZoneCodeGeneratorArguments::ParseArgs(const int argc, const char** argv, bo
|
|||||||
if (m_argument_parser.IsOptionSpecified(OPTION_GENERATE))
|
if (m_argument_parser.IsOptionSpecified(OPTION_GENERATE))
|
||||||
{
|
{
|
||||||
m_task_flags |= FLAG_TASK_GENERATE;
|
m_task_flags |= FLAG_TASK_GENERATE;
|
||||||
const auto generateParameterValues = m_argument_parser.GetParametersForOption(OPTION_GENERATE);
|
m_template_names = m_argument_parser.GetParametersForOption(OPTION_GENERATE);
|
||||||
for (auto i = 0u; i < generateParameterValues.size(); i += 2)
|
|
||||||
{
|
|
||||||
const auto& assetName = generateParameterValues[i];
|
|
||||||
const auto& templateName = generateParameterValues[i + 1];
|
|
||||||
|
|
||||||
if (assetName == "*")
|
|
||||||
m_generation_tasks.emplace_back(templateName);
|
|
||||||
else
|
|
||||||
m_generation_tasks.emplace_back(assetName, templateName);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (m_task_flags == 0)
|
if (m_task_flags == 0)
|
||||||
|
|||||||
@@ -5,18 +5,6 @@
|
|||||||
#include <string>
|
#include <string>
|
||||||
#include <vector>
|
#include <vector>
|
||||||
|
|
||||||
class GenerationTask
|
|
||||||
{
|
|
||||||
public:
|
|
||||||
bool m_all_assets;
|
|
||||||
std::string m_asset_name;
|
|
||||||
std::string m_template_name;
|
|
||||||
|
|
||||||
GenerationTask();
|
|
||||||
explicit GenerationTask(std::string templateName);
|
|
||||||
GenerationTask(std::string assetName, std::string templateName);
|
|
||||||
};
|
|
||||||
|
|
||||||
class ZoneCodeGeneratorArguments
|
class ZoneCodeGeneratorArguments
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
@@ -30,7 +18,7 @@ public:
|
|||||||
std::vector<std::string> m_command_paths;
|
std::vector<std::string> m_command_paths;
|
||||||
std::string m_output_directory;
|
std::string m_output_directory;
|
||||||
|
|
||||||
std::vector<GenerationTask> m_generation_tasks;
|
std::vector<std::string> m_template_names;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
void PrintUsage() const;
|
void PrintUsage() const;
|
||||||
|
|||||||
Reference in New Issue
Block a user