New tools refactor first pass
This commit is contained in:
@ -9,7 +9,7 @@ add_executable(audiogen)
|
||||
target_sources(audiogen
|
||||
PRIVATE
|
||||
main.cpp
|
||||
../../utils/file.cpp
|
||||
../../util/file.cpp
|
||||
)
|
||||
target_include_directories(audiogen
|
||||
PUBLIC
|
||||
|
@ -4,7 +4,7 @@
|
||||
// https://opensource.org/licenses/MIT
|
||||
|
||||
#include "dawnsharedlibs.hpp"
|
||||
#include "../../utils/file.hpp"
|
||||
#include "../../util/file.hpp"
|
||||
#include "AudioFile.h"
|
||||
|
||||
int main(int argc, char *argv[]) {
|
||||
|
@ -9,8 +9,8 @@ add_executable(texturegen)
|
||||
target_sources(texturegen
|
||||
PRIVATE
|
||||
main.cpp
|
||||
../../utils/file.cpp
|
||||
../../utils/image.cpp
|
||||
../../util/file.cpp
|
||||
../../util/image.cpp
|
||||
)
|
||||
target_include_directories(texturegen
|
||||
PUBLIC
|
||||
|
@ -6,8 +6,8 @@
|
||||
*/
|
||||
|
||||
#include "dawnsharedlibs.hpp"
|
||||
#include "../../utils/file.hpp"
|
||||
#include "../../utils/image.hpp"
|
||||
#include "../../util/file.hpp"
|
||||
#include "../../util/image.hpp"
|
||||
|
||||
int main(int argc, char *argv[]) {
|
||||
FILE *file;
|
||||
|
@ -9,8 +9,8 @@ add_executable(tilesetgen)
|
||||
target_sources(tilesetgen
|
||||
PRIVATE
|
||||
main.cpp
|
||||
../../utils/file.cpp
|
||||
../../utils/image.cpp
|
||||
../../util/file.cpp
|
||||
../../util/image.cpp
|
||||
)
|
||||
target_include_directories(tilesetgen
|
||||
PUBLIC
|
||||
|
@ -6,8 +6,8 @@
|
||||
*/
|
||||
|
||||
#include "dawnsharedlibs.hpp"
|
||||
#include "../../utils/file.hpp"
|
||||
#include "../../utils/image.hpp"
|
||||
#include "../../util/file.hpp"
|
||||
#include "../../util/image.hpp"
|
||||
|
||||
int main(int argc, char *argv[]) {
|
||||
char *in;
|
||||
|
@ -9,8 +9,8 @@ add_executable(truetypegen)
|
||||
target_sources(truetypegen
|
||||
PRIVATE
|
||||
main.cpp
|
||||
../../utils/file.cpp
|
||||
../../utils/image.cpp
|
||||
../../util/file.cpp
|
||||
../../util/image.cpp
|
||||
)
|
||||
target_include_directories(truetypegen
|
||||
PUBLIC
|
||||
|
@ -6,8 +6,8 @@
|
||||
*/
|
||||
|
||||
#include "dawnsharedlibs.hpp"
|
||||
#include "../../utils/file.hpp"
|
||||
#include "../../utils/image.hpp"
|
||||
#include "../../util/file.hpp"
|
||||
#include "../../util/image.hpp"
|
||||
#ifndef STB_TRUETYPE_IMPLEMENTATION
|
||||
#define STB_TRUETYPE_IMPLEMENTATION
|
||||
#include <stb_truetype.h>
|
||||
|
@ -9,8 +9,8 @@ add_executable(uigen)
|
||||
target_sources(uigen
|
||||
PRIVATE
|
||||
main.cpp
|
||||
../../utils/file.cpp
|
||||
../../utils/xml.cpp
|
||||
../../util/file.cpp
|
||||
../../util/xml.cpp
|
||||
)
|
||||
target_include_directories(uigen
|
||||
PUBLIC
|
||||
|
@ -5,8 +5,8 @@
|
||||
* https://opensource.org/licenses/MIT
|
||||
*/
|
||||
|
||||
#include "../../utils/xml.hpp"
|
||||
#include "../../utils/file.hpp"
|
||||
#include "../../util/xml.hpp"
|
||||
#include "../../util/file.hpp"
|
||||
#include <iostream>
|
||||
#include <vector>
|
||||
|
||||
|
@ -8,10 +8,11 @@ project(languagegen VERSION 2.0)
|
||||
add_executable(languagegen)
|
||||
target_sources(languagegen
|
||||
PRIVATE
|
||||
main.cpp
|
||||
../../utils/file.cpp
|
||||
../../utils/csv.cpp
|
||||
../../utils/xml.cpp
|
||||
LanguageGen.cpp
|
||||
../../util/DawnTool.cpp
|
||||
../../util/file.cpp
|
||||
../../util/csv.cpp
|
||||
../../util/xml.cpp
|
||||
)
|
||||
target_include_directories(languagegen
|
||||
PUBLIC
|
||||
|
@ -5,85 +5,23 @@
|
||||
* https://opensource.org/licenses/MIT
|
||||
*/
|
||||
|
||||
#include "dawnsharedlibs.hpp"
|
||||
#include "../../utils/file.hpp"
|
||||
#include "../../utils/csv.hpp"
|
||||
#include "../../utils/xml.hpp"
|
||||
#include <iostream>
|
||||
#include <map>
|
||||
#include <vector>
|
||||
#include <algorithm>
|
||||
#include <iterator>
|
||||
#include "LanguageGen.hpp"
|
||||
|
||||
struct LanguageString {
|
||||
std::string key;
|
||||
std::string value;
|
||||
};
|
||||
using namespace Dawn;
|
||||
|
||||
int32_t parseString(
|
||||
xml_t *stringNode,
|
||||
std::string key,
|
||||
std::map<std::string,std::vector<struct LanguageString>> *strings
|
||||
) {
|
||||
auto attrLang = xmlGetAttributeByName(stringNode, "lang");
|
||||
if(attrLang == -1) {
|
||||
std::cout << "String is missing lang parameter." << std::endl;
|
||||
return -1;
|
||||
}
|
||||
|
||||
std::string lang(stringNode->attributeDatas[attrLang]);
|
||||
struct LanguageString str;
|
||||
str.key = key;
|
||||
str.value = std::string(stringNode->value);
|
||||
|
||||
auto existing = (*strings).find(lang);
|
||||
if(existing == (*strings).end()) {
|
||||
(*strings).insert(std::make_pair(lang, std::vector<struct LanguageString>()));
|
||||
}
|
||||
(*strings)[lang].push_back(str);
|
||||
return 0;
|
||||
LanguageGen::LanguageGen(const int argc, const char *argv[]) :
|
||||
DawnTool(argc, argv)
|
||||
{
|
||||
}
|
||||
|
||||
int32_t parseGroup(
|
||||
xml_t *groupNode,
|
||||
std::string key,
|
||||
std::map<std::string,std::vector<struct LanguageString>> *strings
|
||||
) {
|
||||
int32_t ret;
|
||||
|
||||
auto attrKey = xmlGetAttributeByName(groupNode, "key");
|
||||
if(attrKey == -1) {
|
||||
std::cout << "Group node is missing key" << std::endl;
|
||||
return 1;
|
||||
}
|
||||
|
||||
if(key.size() > 0) key += ".";
|
||||
key += std::string(groupNode->attributeDatas[attrKey]);
|
||||
|
||||
for(int32_t i = 0; i < groupNode->childrenCount; i++) {
|
||||
auto c = groupNode->children + i;
|
||||
if(std::string(c->node) == "string") {
|
||||
ret = parseString(c, key, strings);
|
||||
if(ret != 0) return ret;
|
||||
} else if(std::string(c->node) == "group") {
|
||||
ret = parseGroup(c, key, strings);
|
||||
if(ret != 0) return ret;
|
||||
}
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
int main(int argc, char *argv[]) {
|
||||
if(argc != 3) {
|
||||
int32_t LanguageGen::start() {
|
||||
if(this->args.size() != 3) {
|
||||
std::cout << "Invalid number of arguments provided to language gen!" << std::endl;
|
||||
return 1;
|
||||
}
|
||||
|
||||
char *fileInName = argv[1];
|
||||
fileNormalizeSlashes(fileInName);
|
||||
|
||||
FILE *fileIn = fopen(fileInName, "rb");
|
||||
auto fileInName = fileNormalizeSlashesNew(this->args[1]);
|
||||
FILE *fileIn = fopen(fileInName.c_str(), "rb");
|
||||
if(fileIn == NULL) {
|
||||
std::cout << "Failed to open input file " << fileInName << std::endl;
|
||||
return 1;
|
||||
@ -124,7 +62,7 @@ int main(int argc, char *argv[]) {
|
||||
for(int32_t i = 0; i < xml.childrenCount; i++) {
|
||||
auto c = xml.children + i;
|
||||
if(std::string(c->node) == "group") {
|
||||
auto ret = parseGroup(c, "", &strings);
|
||||
auto ret = this->parseGroup(c, "", &strings);
|
||||
if(ret != 0) {
|
||||
xmlDispose(&xml);
|
||||
return ret;
|
||||
@ -170,20 +108,12 @@ int main(int argc, char *argv[]) {
|
||||
it2++;
|
||||
}
|
||||
|
||||
std::string filenameOut(argv[2]);
|
||||
std::string filenameOut = this->args[2];
|
||||
filenameOut += "/language_" + it->first + ".language";
|
||||
filenameOut = fileNormalizeSlashesNew(filenameOut);
|
||||
|
||||
char *filenameOutC = (char *)malloc(sizeof(char) * (filenameOut.size() + 1));
|
||||
if(filenameOutC == NULL) {
|
||||
std::cout << "Failed to allocate filename memory" << std::endl;
|
||||
return 1;
|
||||
}
|
||||
strcpy(filenameOutC, filenameOut.c_str());
|
||||
fileNormalizeSlashes(filenameOutC);
|
||||
|
||||
fileMkdirp(filenameOutC);
|
||||
FILE *fileOut = fopen(filenameOutC, "wb");
|
||||
free(filenameOutC);
|
||||
fileMkdirp((char *)filenameOut.c_str());
|
||||
FILE *fileOut = fopen(filenameOut.c_str(), "wb");
|
||||
if(fileOut == NULL) {
|
||||
std::cout << "Failed to create output file " << filenameOut << std::endl;
|
||||
return 1;
|
||||
@ -211,4 +141,62 @@ int main(int argc, char *argv[]) {
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
int32_t LanguageGen::parseString(
|
||||
xml_t *stringNode,
|
||||
std::string key,
|
||||
std::map<std::string,std::vector<struct LanguageString>> *strings
|
||||
) {
|
||||
auto attrLang = xmlGetAttributeByName(stringNode, "lang");
|
||||
if(attrLang == -1) {
|
||||
std::cout << "String is missing lang parameter." << std::endl;
|
||||
return -1;
|
||||
}
|
||||
|
||||
std::string lang(stringNode->attributeDatas[attrLang]);
|
||||
struct LanguageString str;
|
||||
str.key = key;
|
||||
str.value = std::string(stringNode->value);
|
||||
|
||||
auto existing = (*strings).find(lang);
|
||||
if(existing == (*strings).end()) {
|
||||
(*strings).insert(std::make_pair(lang, std::vector<struct LanguageString>()));
|
||||
}
|
||||
(*strings)[lang].push_back(str);
|
||||
return 0;
|
||||
}
|
||||
|
||||
int32_t LanguageGen::parseGroup(
|
||||
xml_t *groupNode,
|
||||
std::string key,
|
||||
std::map<std::string,std::vector<struct LanguageString>> *strings
|
||||
) {
|
||||
int32_t ret;
|
||||
|
||||
auto attrKey = xmlGetAttributeByName(groupNode, "key");
|
||||
if(attrKey == -1) {
|
||||
std::cout << "Group node is missing key" << std::endl;
|
||||
return 1;
|
||||
}
|
||||
|
||||
if(key.size() > 0) key += ".";
|
||||
key += std::string(groupNode->attributeDatas[attrKey]);
|
||||
|
||||
for(int32_t i = 0; i < groupNode->childrenCount; i++) {
|
||||
auto c = groupNode->children + i;
|
||||
if(std::string(c->node) == "string") {
|
||||
ret = this->parseString(c, key, strings);
|
||||
if(ret != 0) return ret;
|
||||
} else if(std::string(c->node) == "group") {
|
||||
ret = this->parseGroup(c, key, strings);
|
||||
if(ret != 0) return ret;
|
||||
}
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
int main(const int argc, const char *argv[]) {
|
||||
return (LanguageGen(argc, argv)).start();
|
||||
}
|
34
src/dawntools/locale/languagegen/LanguageGen.hpp
Normal file
34
src/dawntools/locale/languagegen/LanguageGen.hpp
Normal file
@ -0,0 +1,34 @@
|
||||
// Copyright (c) 2023 Dominic Masters
|
||||
//
|
||||
// This software is released under the MIT License.
|
||||
// https://opensource.org/licenses/MIT
|
||||
|
||||
#pragma once
|
||||
#include "util/DawnTool.hpp"
|
||||
|
||||
namespace Dawn {
|
||||
struct LanguageString {
|
||||
std::string key;
|
||||
std::string value;
|
||||
};
|
||||
|
||||
class LanguageGen : public DawnTool {
|
||||
protected:
|
||||
int32_t parseGroup(
|
||||
xml_t *node,
|
||||
std::string key,
|
||||
std::map<std::string, std::vector<struct LanguageString>> *strings
|
||||
);
|
||||
|
||||
int32_t parseString(
|
||||
xml_t *node,
|
||||
std::string key,
|
||||
std::map<std::string, std::vector<struct LanguageString>> *strings
|
||||
);
|
||||
|
||||
public:
|
||||
LanguageGen(const int argc, const char *argv[]);
|
||||
|
||||
int32_t start() override;
|
||||
};
|
||||
}
|
14
src/dawntools/util/DawnTool.cpp
Normal file
14
src/dawntools/util/DawnTool.cpp
Normal file
@ -0,0 +1,14 @@
|
||||
// Copyright (c) 2023 Dominic Masters
|
||||
//
|
||||
// This software is released under the MIT License.
|
||||
// https://opensource.org/licenses/MIT
|
||||
|
||||
#include "DawnTool.hpp"
|
||||
|
||||
using namespace Dawn;
|
||||
|
||||
DawnTool::DawnTool(const int argc, const char *argv[]) {
|
||||
for(int32_t i = 0; i < argc; i++) {
|
||||
this->args.push_back(std::string(argv[i]));
|
||||
}
|
||||
}
|
27
src/dawntools/util/DawnTool.hpp
Normal file
27
src/dawntools/util/DawnTool.hpp
Normal file
@ -0,0 +1,27 @@
|
||||
// Copyright (c) 2023 Dominic Masters
|
||||
//
|
||||
// This software is released under the MIT License.
|
||||
// https://opensource.org/licenses/MIT
|
||||
|
||||
#pragma once
|
||||
#include "dawnsharedlibs.hpp"
|
||||
#include "../../util/file.hpp"
|
||||
#include "../../util/csv.hpp"
|
||||
#include "../../util/xml.hpp"
|
||||
#include <iostream>
|
||||
#include <map>
|
||||
#include <vector>
|
||||
#include <algorithm>
|
||||
#include <iterator>
|
||||
|
||||
namespace Dawn {
|
||||
class DawnTool {
|
||||
protected:
|
||||
std::vector<std::string> args;
|
||||
|
||||
public:
|
||||
DawnTool(const int argc, const char *argv[]);
|
||||
|
||||
virtual int32_t start() = 0;
|
||||
};
|
||||
}
|
@ -192,4 +192,8 @@ bool fileListChildren(
|
||||
*count = i;
|
||||
return true;
|
||||
#endif
|
||||
}
|
||||
|
||||
std::string fileNormalizeSlashesNew(std::string str) {
|
||||
return str;
|
||||
}
|
@ -72,4 +72,6 @@ int32_t readAhead(
|
||||
int32_t skipAhead(
|
||||
char *bufferIn, int32_t start,
|
||||
char *needles, int32_t needleCount
|
||||
);
|
||||
);
|
||||
|
||||
std::string fileNormalizeSlashesNew(std::string str);
|
@ -9,8 +9,8 @@ add_executable(vnscenegen)
|
||||
target_sources(vnscenegen
|
||||
PRIVATE
|
||||
main.cpp
|
||||
../../utils/file.cpp
|
||||
../../utils/xml.cpp
|
||||
../../util/file.cpp
|
||||
../../util/xml.cpp
|
||||
)
|
||||
target_include_directories(vnscenegen
|
||||
PUBLIC
|
||||
|
@ -3,8 +3,8 @@
|
||||
// This software is released under the MIT License.
|
||||
// https://opensource.org/licenses/MIT
|
||||
|
||||
#include "../../utils/file.hpp"
|
||||
#include "../../utils/xml.hpp"
|
||||
#include "../../util/file.hpp"
|
||||
#include "../../util/xml.hpp"
|
||||
#include <iostream>
|
||||
#include <vector>
|
||||
|
||||
|
Reference in New Issue
Block a user