mirror of
https://github.com/Laupetin/OpenAssetTools.git
synced 2026-01-09 18:21: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') .. '"'
|
||||
.. ' -c "' .. path.join(path.getabsolute(ProjectFolder()), 'ZoneCode/Game/%{file.basename}/%{file.basename}_Commands.txt') .. '"'
|
||||
.. ' -o "%{wks.location}/src/ZoneCode/Game/%{file.basename}/XAssets"'
|
||||
.. ' -g "*" ZoneLoad'
|
||||
.. ' -g "*" ZoneMark'
|
||||
.. ' -g "*" ZoneWrite'
|
||||
.. ' -g "*" AssetStructTests'
|
||||
.. ' -g ZoneLoad'
|
||||
.. ' -g ZoneMark'
|
||||
.. ' -g ZoneWrite'
|
||||
.. ' -g AssetStructTests'
|
||||
}
|
||||
buildinputs {
|
||||
path.join(ProjectFolder(), "ZoneCode/Game/%{file.basename}/%{file.basename}_ZoneCode.h"),
|
||||
|
||||
@@ -6,11 +6,11 @@
|
||||
#include "Templates/ZoneMarkTemplate.h"
|
||||
#include "Templates/ZoneWriteTemplate.h"
|
||||
#include "Utils/Logging/Log.h"
|
||||
#include "Utils/StringUtils.h"
|
||||
|
||||
#include <filesystem>
|
||||
#include <format>
|
||||
#include <fstream>
|
||||
#include <iostream>
|
||||
|
||||
namespace fs = std::filesystem;
|
||||
|
||||
@@ -55,7 +55,7 @@ bool CodeGenerator::GenerateCodeForTemplate(const RenderingContext& context, ICo
|
||||
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);
|
||||
if (def == nullptr)
|
||||
@@ -64,7 +64,7 @@ bool CodeGenerator::GetAssetWithName(IDataRepository* repository, const std::str
|
||||
return false;
|
||||
}
|
||||
|
||||
auto* defWithMembers = dynamic_cast<DefinitionWithMembers*>(def);
|
||||
const auto* defWithMembers = dynamic_cast<DefinitionWithMembers*>(def);
|
||||
asset = defWithMembers != nullptr ? repository->GetInformationFor(defWithMembers) : nullptr;
|
||||
if (asset == nullptr)
|
||||
{
|
||||
@@ -81,7 +81,7 @@ bool CodeGenerator::GetAssetWithName(IDataRepository* repository, const std::str
|
||||
return true;
|
||||
}
|
||||
|
||||
bool CodeGenerator::GenerateCode(IDataRepository* repository)
|
||||
bool CodeGenerator::GenerateCode(const IDataRepository* repository)
|
||||
{
|
||||
std::vector<StructureInformation*> assets;
|
||||
|
||||
@@ -93,42 +93,28 @@ bool CodeGenerator::GenerateCode(IDataRepository* repository)
|
||||
}
|
||||
|
||||
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;
|
||||
for (auto& c : templateName)
|
||||
c = static_cast<char>(tolower(c));
|
||||
std::string lowerTemplateName(templateName);
|
||||
utils::MakeStringLowerCase(lowerTemplateName);
|
||||
|
||||
const auto foundTemplate = m_template_mapping.find(templateName);
|
||||
const auto foundTemplate = m_template_mapping.find(lowerTemplateName);
|
||||
if (foundTemplate == m_template_mapping.end())
|
||||
{
|
||||
con::error("Unknown template '{}'.", generationTask.m_template_name);
|
||||
con::error("Unknown template '{}'.", templateName);
|
||||
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);
|
||||
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);
|
||||
}
|
||||
}
|
||||
const auto end = std::chrono::steady_clock::now();
|
||||
|
||||
@@ -12,13 +12,13 @@ class CodeGenerator
|
||||
public:
|
||||
explicit CodeGenerator(const ZoneCodeGeneratorArguments* args);
|
||||
|
||||
bool GenerateCode(IDataRepository* repository);
|
||||
bool GenerateCode(const IDataRepository* repository);
|
||||
|
||||
private:
|
||||
void SetupTemplates();
|
||||
|
||||
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;
|
||||
std::unordered_map<std::string, std::unique_ptr<ICodeTemplate>> m_template_mapping;
|
||||
|
||||
@@ -6,7 +6,6 @@
|
||||
#include "Utils/Logging/Log.h"
|
||||
|
||||
#include <format>
|
||||
#include <iostream>
|
||||
#include <type_traits>
|
||||
|
||||
// clang-format off
|
||||
@@ -81,9 +80,8 @@ const CommandLineOption* const OPTION_GENERATE =
|
||||
CommandLineOption::Builder::Create()
|
||||
.WithShortName("g")
|
||||
.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)
|
||||
.WithParameter("assetName")
|
||||
.WithParameter("preset")
|
||||
.Reusable()
|
||||
.Build();
|
||||
@@ -103,28 +101,10 @@ const CommandLineOption* const COMMAND_LINE_OPTIONS[]{
|
||||
|
||||
namespace
|
||||
{
|
||||
static constexpr unsigned FLAG_TASK_GENERATE = 1 << 0;
|
||||
static constexpr unsigned FLAG_TASK_PRINT = 1 << 1;
|
||||
constexpr unsigned FLAG_TASK_GENERATE = 1 << 0;
|
||||
constexpr unsigned FLAG_TASK_PRINT = 1 << 1;
|
||||
} // 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()
|
||||
: m_argument_parser(COMMAND_LINE_OPTIONS, std::extent_v<decltype(COMMAND_LINE_OPTIONS)>),
|
||||
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))
|
||||
{
|
||||
m_task_flags |= FLAG_TASK_GENERATE;
|
||||
const auto generateParameterValues = 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);
|
||||
}
|
||||
m_template_names = m_argument_parser.GetParametersForOption(OPTION_GENERATE);
|
||||
}
|
||||
|
||||
if (m_task_flags == 0)
|
||||
|
||||
@@ -5,18 +5,6 @@
|
||||
#include <string>
|
||||
#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
|
||||
{
|
||||
public:
|
||||
@@ -30,7 +18,7 @@ public:
|
||||
std::vector<std::string> m_command_paths;
|
||||
std::string m_output_directory;
|
||||
|
||||
std::vector<GenerationTask> m_generation_tasks;
|
||||
std::vector<std::string> m_template_names;
|
||||
|
||||
private:
|
||||
void PrintUsage() const;
|
||||
|
||||
Reference in New Issue
Block a user