Skip to content

Commit

Permalink
Added Language Builder (#38)
Browse files Browse the repository at this point in the history
  • Loading branch information
SmokeyStack authored May 29, 2024
2 parents 3b7f0b7 + 504cbea commit bf83041
Show file tree
Hide file tree
Showing 4 changed files with 44 additions and 57 deletions.
7 changes: 3 additions & 4 deletions adk/data/include/builder_creative_menu.h
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,9 @@
namespace adk {
class BuilderCreativeMenu {
public:
BuilderCreativeMenu(std::string id) { id_ = id; }
BuilderCreativeMenu(std::string id) { mod_id_ = id; }

void AddItem(std::string id, std::string group = "") {
auto registry = GetIDs();
std::variant<Block*, Item*>* entry = NULL;

for (const auto& entries : registry_global) {
Expand All @@ -41,7 +40,7 @@ namespace adk {
TempFile >> output;
}

output["minecraft:" + content->GetType()]["description"]["menu_category"]["category"] = id_;
output["minecraft:" + content->GetType()]["description"]["menu_category"]["category"] = mod_id_;

if (!group.empty())
output["minecraft:" + content->GetType()]["description"]["menu_category"]["group"] = group;
Expand All @@ -54,6 +53,6 @@ namespace adk {
*entry);
}
private:
std::string id_;
std::string mod_id_;
};
} // namespace adk
76 changes: 34 additions & 42 deletions adk/data/include/builder_language.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,62 +8,54 @@
#include "registry_global.h"
#include "registry.h"
#include "json.hpp"
#include "utility/logger.h"

namespace adk {
class LanguageBuilder {
protected:
std::string mod_id;
std::string locale;
std::vector<std::string> entries;

void add(std::string id, std::string value) {
for (auto const entry : registry_global) {
std::map<std::string, std::variant<Block*, Item*>> registry_check;
registry_check = entry->GetRegistry();
class BuilderLanguage {
public:
BuilderLanguage(std::string locale) { locale_ = locale; };

for (std::map<std::string, std::variant<Block*, Item*>>::iterator
it = registry_check.begin();
it != registry_check.end(); ++it) {
if (it->first == (mod_id + ":" + id)) {
if (std::get_if<Block*>(&it->second))
entries.push_back("tile." + mod_id + ":" + id +
".name=" + value);
else if (std::get_if<Item*>(&it->second))
entries.push_back("tile." + mod_id + ":" + id +
".name=" + value);
BuilderLanguage Add(std::string id, std::string value) {
std::variant<Block*, Item*>* entry = NULL;

break;
}
}
for (const auto& entries : registry_global) {
entry = entries->Get(id);
if (std::get_if<Block*>(entry)) break;
else if (std::get_if<Item*>(entry)) break;
}
}

void createLangFile() {
if (!std::filesystem::exists("./RP/texts/")) std::filesystem::create_directory("./RP/texts/");
if (entry == NULL) return *this;

if (!std::filesystem::exists("./RP/texts/" + locale + ".lang")) {
std::ofstream MyLang("./RP/texts/" + locale + ".lang");
std::visit(
[=](auto&& content) {
if (content->GetType() == "block")
this->entries_.push_back("tile." + id + ".name=" + value);
else if (content->GetType() == "item")
this->entries_.push_back("item." + id + "=" + value);
},
*entry);

for (auto const entry : entries) {
MyLang << entry << '\n';
}
return *this;
}

MyLang.close();
void Build() {
if (!std::filesystem::exists("./RP/texts/")) std::filesystem::create_directory("./RP/texts/");

if (!std::filesystem::exists("./RP/texts/" + locale_ + ".lang")) {
{
std::ofstream OutputFile("./RP/texts/" + locale_ + ".lang");
for (const auto& entry : entries_) OutputFile << entry << '\n';
}
}
else {
std::ofstream MyLang("./RP/texts/" + locale + ".lang",
std::ios::app);

for (auto const entry : entries) {
MyLang << '\n' << entry;
{
std::ofstream OutputFile("./RP/texts/" + locale_ + ".lang", std::ios::app);
for (const auto& entry : entries_) OutputFile << entry << '\n';
}

MyLang.close();
}
}

public:
LanguageBuilder() {};
private:
std::string locale_;
std::vector<std::string> entries_;
};
} // namespace adk
7 changes: 2 additions & 5 deletions adk/data/include/language.h
Original file line number Diff line number Diff line change
@@ -1,12 +1,9 @@
#pragma once

#include <string>

#include "builder_language.h"
namespace adk {
class Language : public LanguageBuilder {
class Language {
public:
Language(std::string id, std::string locale);
Language();

void init();
};
Expand Down
11 changes: 5 additions & 6 deletions adk/data/src/language.cpp
Original file line number Diff line number Diff line change
@@ -1,12 +1,11 @@
#include "language.h"

#include "registry_global.h"
#include "builder_language.h"

namespace adk {
Language::Language(std::string id, std::string locale) {
mod_id = id;
this->locale = locale;
}
Language::Language() {}

void Language::init() { createLangFile(); }
void Language::init() {
BuilderLanguage("en_US").Add("adk:adk", "ADK").Build();
}
} // namespace adk

0 comments on commit bf83041

Please sign in to comment.