mirror of
https://github.com/Laupetin/OpenAssetTools.git
synced 2025-05-07 13:04:58 +00:00
chore: small code adjustments for generation code in zcg
This commit is contained in:
parent
d94a004433
commit
2eefad105e
@ -7,6 +7,7 @@
|
|||||||
#include "Templates/ZoneWriteTemplate.h"
|
#include "Templates/ZoneWriteTemplate.h"
|
||||||
|
|
||||||
#include <filesystem>
|
#include <filesystem>
|
||||||
|
#include <format>
|
||||||
#include <fstream>
|
#include <fstream>
|
||||||
#include <iostream>
|
#include <iostream>
|
||||||
|
|
||||||
@ -41,7 +42,7 @@ bool CodeGenerator::GenerateCodeForTemplate(RenderingContext* context, ICodeTemp
|
|||||||
|
|
||||||
if (!stream.is_open())
|
if (!stream.is_open())
|
||||||
{
|
{
|
||||||
std::cout << "Failed to open file '" << p.string() << "'\n";
|
std::cerr << std::format("Failed to open file '{}'\n", p.string());
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -58,7 +59,7 @@ bool CodeGenerator::GetAssetWithName(IDataRepository* repository, const std::str
|
|||||||
auto* def = repository->GetDataDefinitionByName(name);
|
auto* def = repository->GetDataDefinitionByName(name);
|
||||||
if (def == nullptr)
|
if (def == nullptr)
|
||||||
{
|
{
|
||||||
std::cout << "Could not find type with name '" << name << "'\n";
|
std::cerr << std::format("Could not find type with name '{}'\n", name);
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -66,13 +67,13 @@ bool CodeGenerator::GetAssetWithName(IDataRepository* repository, const std::str
|
|||||||
auto* info = defWithMembers != nullptr ? repository->GetInformationFor(defWithMembers) : nullptr;
|
auto* info = defWithMembers != nullptr ? repository->GetInformationFor(defWithMembers) : nullptr;
|
||||||
if (info == nullptr)
|
if (info == nullptr)
|
||||||
{
|
{
|
||||||
std::cout << "Could not find type with name '" << name << "'\n";
|
std::cerr << std::format("Could not find type with name '{}'\n", name);
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!StructureComputations(info).IsAsset())
|
if (!StructureComputations(info).IsAsset())
|
||||||
{
|
{
|
||||||
std::cout << "Type is not an asset '" << name << "'\n";
|
std::cerr << std::format("Type is not an asset '{}'\n", name);
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -100,7 +101,7 @@ bool CodeGenerator::GenerateCode(IDataRepository* repository)
|
|||||||
const auto foundTemplate = m_template_mapping.find(templateName);
|
const auto foundTemplate = m_template_mapping.find(templateName);
|
||||||
if (foundTemplate == m_template_mapping.end())
|
if (foundTemplate == m_template_mapping.end())
|
||||||
{
|
{
|
||||||
std::cout << "Unknown template '" << generationTask.m_template_name << "'.\n";
|
std::cerr << std::format("Unknown template '{}'.\n", generationTask.m_template_name);
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -111,13 +112,13 @@ bool CodeGenerator::GenerateCode(IDataRepository* repository)
|
|||||||
auto context = RenderingContext::BuildContext(repository, asset);
|
auto context = RenderingContext::BuildContext(repository, asset);
|
||||||
if (!GenerateCodeForTemplate(context.get(), foundTemplate->second.get()))
|
if (!GenerateCodeForTemplate(context.get(), foundTemplate->second.get()))
|
||||||
{
|
{
|
||||||
std::cout << "Failed to generate code for asset '" << asset->m_definition->GetFullName() << "' with preset '" << foundTemplate->first
|
std::cerr << std::format(
|
||||||
<< "'\n";
|
"Failed to generate code for asset '{}' with preset '{}'\n", asset->m_definition->GetFullName(), foundTemplate->first);
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
std::cout << "Successfully generated code for asset '" << asset->m_definition->GetFullName() << "' with preset '" << foundTemplate->first
|
std::cout << std::format(
|
||||||
<< "'\n";
|
"Successfully generated code for asset '{}' with preset '{}'\n", asset->m_definition->GetFullName(), foundTemplate->first);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
@ -133,9 +134,7 @@ bool CodeGenerator::GenerateCode(IDataRepository* repository)
|
|||||||
}
|
}
|
||||||
const auto end = std::chrono::steady_clock::now();
|
const auto end = std::chrono::steady_clock::now();
|
||||||
if (m_args->m_verbose)
|
if (m_args->m_verbose)
|
||||||
{
|
std::cout << std::format("Generating code took {}ms\n", std::chrono::duration_cast<std::chrono::milliseconds>(end - start).count());
|
||||||
std::cout << "Generating code took " << std::chrono::duration_cast<std::chrono::milliseconds>(end - start).count() << "ms\n";
|
|
||||||
}
|
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
@ -21,6 +21,5 @@ private:
|
|||||||
static bool GetAssetWithName(IDataRepository* repository, const std::string& name, StructureInformation*& asset);
|
static bool GetAssetWithName(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;
|
||||||
};
|
};
|
||||||
|
@ -9,14 +9,14 @@
|
|||||||
class CodeTemplateFile
|
class CodeTemplateFile
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
std::string m_file_name;
|
|
||||||
int m_tag;
|
|
||||||
|
|
||||||
CodeTemplateFile(std::string fileName, const int tag)
|
CodeTemplateFile(std::string fileName, const int tag)
|
||||||
: m_file_name(std::move(fileName)),
|
: m_file_name(std::move(fileName)),
|
||||||
m_tag(tag)
|
m_tag(tag)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
|
std::string m_file_name;
|
||||||
|
int m_tag;
|
||||||
};
|
};
|
||||||
|
|
||||||
class ICodeTemplate
|
class ICodeTemplate
|
||||||
|
@ -3,6 +3,7 @@
|
|||||||
#include "Domain/Computations/MemberComputations.h"
|
#include "Domain/Computations/MemberComputations.h"
|
||||||
#include "Domain/Computations/StructureComputations.h"
|
#include "Domain/Computations/StructureComputations.h"
|
||||||
#include "Internal/BaseTemplate.h"
|
#include "Internal/BaseTemplate.h"
|
||||||
|
#include "Utils/StringUtils.h"
|
||||||
|
|
||||||
#include <cassert>
|
#include <cassert>
|
||||||
#include <iostream>
|
#include <iostream>
|
||||||
@ -1349,8 +1350,7 @@ std::vector<CodeTemplateFile> ZoneLoadTemplate::GetFilesToRender(RenderingContex
|
|||||||
std::vector<CodeTemplateFile> files;
|
std::vector<CodeTemplateFile> files;
|
||||||
|
|
||||||
auto assetName = context->m_asset->m_definition->m_name;
|
auto assetName = context->m_asset->m_definition->m_name;
|
||||||
for (auto& c : assetName)
|
utils::MakeStringLowerCase(assetName);
|
||||||
c = static_cast<char>(tolower(c));
|
|
||||||
|
|
||||||
files.emplace_back(std::format("{0}/{0}_load_db.h", assetName), TAG_HEADER);
|
files.emplace_back(std::format("{0}/{0}_load_db.h", assetName), TAG_HEADER);
|
||||||
files.emplace_back(std::format("{0}/{0}_load_db.cpp", assetName), TAG_SOURCE);
|
files.emplace_back(std::format("{0}/{0}_load_db.cpp", assetName), TAG_SOURCE);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user