Skip to content

Commit

Permalink
Enhanced header definition
Browse files Browse the repository at this point in the history
  • Loading branch information
KiritoDv committed Feb 18, 2024
1 parent 510ffd4 commit 298b3ff
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 6 deletions.
32 changes: 27 additions & 5 deletions src/Companion.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -139,8 +139,25 @@ void Companion::ParseCurrentFileConfig(YAML::Node node) {
}
}
if(node["header"]) {
for(auto line = node["header"].begin(); line != node["header"].end(); ++line) {
this->gFileHeader += line->as<std::string>() + "\n";
auto header = node["header"];
switch (this->gConfig.exporterType) {
case ExportType::Header: {
if(header["header"].IsSequence()) {
for(auto line = header["header"].begin(); line != header["header"].end(); ++line) {
this->gFileHeader += line->as<std::string>() + "\n";
}
}
break;
}
case ExportType::Code: {
if(header["code"].IsSequence()) {
for(auto line = header["code"].begin(); line != header["code"].end(); ++line) {
this->gFileHeader += line->as<std::string>() + "\n";
}
}
break;
}
default: break;
}
}
}
Expand Down Expand Up @@ -387,15 +404,16 @@ void Companion::Process() {
}

if(this->gConfig.exporterType != ExportType::Binary){
std::string output = (this->gConfig.outputPath / this->gCurrentDirectory).string();
auto fsout = fs::path(this->gConfig.outputPath);
std::string filename = this->gCurrentDirectory.filename().string();

switch (this->gConfig.exporterType) {
case ExportType::Header: {
output += "/definition.h";
fsout /= filename + ".h";
break;
}
case ExportType::Code: {
output += "/bin.c";
fsout /= this->gCurrentDirectory / "bin.c";
break;
}
default: break;
Expand Down Expand Up @@ -447,6 +465,7 @@ void Companion::Process() {
continue;
}

std::string output = fsout.string();
std::replace(output.begin(), output.end(), '\\', '/');
if(!exists(fs::path(output).parent_path())){
create_directories(fs::path(output).parent_path());
Expand All @@ -459,6 +478,9 @@ void Companion::Process() {
std::transform(symbol.begin(), symbol.end(), symbol.begin(), toupper);
file << "#ifndef " << symbol << "_H" << std::endl;
file << "#define " << symbol << "_H" << std::endl << std::endl;
if(!this->gFileHeader.empty()) {
file << this->gFileHeader << std::endl;
}
file << buffer;
file << std::endl << "#endif" << std::endl;
} else {
Expand Down
6 changes: 5 additions & 1 deletion src/factories/TextureFactory.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,11 @@ void TextureHeaderExporter::Export(std::ostream &write, std::shared_ptr<IParsedD
return;
}

write << "extern u8 " << symbol << "[" << data.size() << "];\n";
if(node["ctype"]) {
write << "extern " << node["ctype"].as<std::string>() << " " << symbol << "[];\n";
} else {
write << "extern u8 " << symbol << "[];\n";
}
}

void TextureCodeExporter::Export(std::ostream &write, std::shared_ptr<IParsedData> raw, std::string& entryName, YAML::Node &node, std::string* replacement) {
Expand Down

0 comments on commit 298b3ff

Please sign in to comment.