skills toml database setup

This commit is contained in:
zxvfxwing
2022-07-10 22:25:23 +02:00
parent 7d9ab717f1
commit 08588cc587
13 changed files with 1315 additions and 191 deletions
-9
View File
@@ -1,9 +0,0 @@
[
{
"name": "Kamura Legacy Set",
"head": {
},
""
}
]
+46 -19
View File
@@ -1,47 +1,74 @@
[[set]]
[set."Kamura Legacy Set"]
[sets."Kamura Legacy Set"]
rarity = 8
resistances = [10, 0, 0, 0, 0]
defense = 400
[set."Kamura Legacy Set".helm]
[sets."Kamura Legacy Set".head]
name = "Kamura Legacy Head Scarf"
defense = 80
resistances = [2, 0, 0, 0, 0]
slots = [2]
skills."Devine Blessing" = 2
skills."Resuscitate" = 1
[set."Kamura Legacy Set".chest]
[sets."Kamura Legacy Set".chest]
name = "Kamura Legacy Garb"
defense = 80
resistances = [2, 0, 0, 0, 0]
slots = [1, 1]
skills."Wirebug Whisperer" = 2
skills."Wall Runner" = 1
skills."Critical Eye" = 1
[set."Kamura Legacy Set".arms]
[sets."Kamura Legacy Set".arms]
name = "Kamura Legacy Braces"
defense = 80
resistances = [2, 0, 0, 0, 0]
slots = [1]
skills."Divine Blessing" = 2
skills."Heroics" = 1
skills."Critical Eye" = 2
[set."Kamura Legacy Set".waist]
[sets."Kamura Legacy Set".waist]
name = "Kamura Legacy Obi"
defense = 80
resistances = [2, 0, 0, 0, 0]
slots = [4, 1]
skills."Wirebug Whisperer" = 1
skills."Critical Eye" = 1
[set."Kamura Legacy Set".legs]
[sets."Kamura Legacy Set".legs]
name = "Kamura Legacy Leggins"
defense = 80
resistances = [2, 0, 0, 0, 0]
slots = [2]
skills."Wall Runner" = 2
skills."Resuscitate" = 1
skills."Affinity Sliding" = 1
skills."Affinity Sliding" = 1
[sets."Aelucanth X Set"]
rarity = 8
resistances = [-10, 0, 15, -10, 10]
defense = 550
[sets."Aelucanth X Set".head]
name = "Aelucanth Vertex X"
slots = [2]
skills."Critical Element" = 2
skills."Evade Window" = 2
[sets."Aelucanth X Set".chest]
name = "Aelucanth Thorax X"
slots = [1, 1]
skills."Critical Element" = 1
skills."Critical Eye" = 3
skills."Dragon Attack" = 1
[sets."Aelucanth X Set".arms]
name = "Aelucanth Brachia X"
slots = [3]
skills."Evade Window" = 2
skills."Critical Eye" = 1
[sets."Aelucanth X Set".waist]
name = "Aelucanth Elytra X"
slots = [4]
skills."Dragon Attack" = 3
skills."Critical Eye" = 1
[sets."Aelucanth X Set".legs]
name = "Aelucanth Crura X"
slots = [2, 1]
skills."Critical Eye" = 3
skills."Dragon Attack" = 1
skills."Evade Window" = 1
+23 -6
View File
@@ -4,14 +4,31 @@
#include <string>
#include <array>
#include <toml++/toml.h>
#include "mhache_skill.h"
class MHacheArmor {
private:
std::string _name;
struct Piece {
std::string _name;
std::vector<unsigned char> _slots;
std::vector<std::pair<MHacheSkill*, unsigned char>> _skills;
struct piece {
std::string _name;
std::array<char, 5> _resistances;
MHacheArmor* _armor;
};
}
#endif
private:
std::string _name;
std::array<char, 5> _resistances;
Piece _head;
Piece _chest;
Piece _arms;
Piece _waist;
Piece _legs;
public:
static MHacheArmor* BuildFromTOML(const toml::table& armor);
};
#endif
+32
View File
@@ -0,0 +1,32 @@
#ifndef MHACHERESEARCHER_H
#define MHACHERESEARCHER_H
#include <set>
#include <memory>
#include <filesystem>
#include "mhache_skill.h"
#include "mhache_armor.h"
class MHacheResearcher {
private:
std::set<std::unique_ptr<MHacheSkill>> _skills;
std::set<std::unique_ptr<MHacheArmor>> _armors;
private:
MHacheResearcher() = default;
MHacheResearcher(const MHacheResearcher&) = delete;
MHacheResearcher(MHacheResearcher&&) = delete;
MHacheResearcher& operator =(const MHacheResearcher&) = delete;
MHacheResearcher& operator =(MHacheResearcher&&) = delete;
public:
virtual ~MHacheResearcher() = default;
static MHacheResearcher& instance();
bool load_armors(const std::filesystem::path& armors_dot_toml);
bool load_skills(const std::filesystem::path& skills_dot_toml);
};
#endif
+13
View File
@@ -0,0 +1,13 @@
#ifndef MHACHESKILL
#define MHACHESKILL
#include <string>
class MHacheSkill {
private:
std::string _name;
unsigned char _level;
const unsigned char _levels;
};
#endif
+15 -6
View File
@@ -1,6 +1,7 @@
#ifndef MHACHEWINDOW_H
#define MHACHEWINDOW_H
#include <csignal>
#include <GLFW/glfw3.h>
class MHacheWindow {
@@ -10,19 +11,27 @@ private:
GLFWwindow* _window;
static constexpr const int _opengl_major_version = 3;
static constexpr const int _opengl_minor_version = 0;
static constexpr const char* _title = "MHache 0.1";
static constexpr const char* _GLSL_version = "#version 130";
void prepare_frame();
void render_frame();
void build_window();
void build_menu();
// Handle external signals:
static volatile std::sig_atomic_t _signal_status;
private:
static void callback_signals(int signal);
static void callback_glfw_error(int error, const char* description);
static void callback_glfw_keyboard(GLFWwindow* window, int key, int scancode, int action, int mods);
void new_frame();
void render_frame();
void build_widgets();
void build_menu();
MHacheWindow() = delete;
MHacheWindow(const MHacheWindow&) = delete;
MHacheWindow(MHacheWindow&&) = delete;
@@ -35,4 +44,4 @@ public:
void display();
};
#endif
#endif
+1097 -129
View File
File diff suppressed because it is too large Load Diff
+3
View File
@@ -3,7 +3,10 @@ find_package(OpenGL REQUIRED)
add_executable(
${PROJECT_NAME}
main.cpp
mhache_armor.cpp
mhache_skill.cpp
mhache_window.cpp
mhache_researcher.cpp
)
target_compile_options(
+1 -11
View File
@@ -7,17 +7,7 @@
int main(int argc, char** argv)
{
toml::parse_result result = toml::parse_file("../../armors.toml");
if (!result) {
std::cerr << "Parsing of TOML file" << result.error().source().path << " failed." << std::endl;
std::cerr << "-> " << result.error().description() << std::endl;
return 1;
}
std::cerr << result.table() << std::endl;
auto window = std::make_unique<MHacheWindow>(620, 480);
window->display();
return 0;
}
}
View File
+51
View File
@@ -0,0 +1,51 @@
#include "mhache_researcher.h"
#include <iostream>
#include <string>
#include <filesystem>
#include <toml++/toml.h>
MHacheResearcher& MHacheResearcher::instance()
{
static MHacheResearcher researcher;
return researcher;
}
bool
MHacheResearcher::load_armors(const std::filesystem::path& armors_dot_toml)
{
toml::parse_result result = toml::parse_file(armors_dot_toml.u8string());
if (!result) {
std::cerr << "Parsing of TOML file" << result.error().source().path << " failed." << std::endl;
std::cerr << "-> " << result.error().description() << std::endl;
return false;
}
// do something
}
bool
MHacheResearcher::load_skills(const std::filesystem::path& skills_dot_toml)
{
toml::parse_result result = toml::parse_file(skills_dot_toml.u8string());
if (!result) {
std::cerr << "Parsing of TOML file" << result.error().source().path << " failed." << std::endl;
std::cerr << "-> " << result.error().description() << std::endl;
return false;
}
const toml::table root = std::move(result.table());
const auto nv_skills = root["skills"];
if (!(nv_skills.is_table() && nv_skills.is_homogeneous()))
return false;
const toml::table& skills = *(nv_skills.as_table());
skills.for_each([](const toml::key& skill_name, const toml::table& skill){
std::cerr << skill_name << ": " << skill["description"] << std::endl;
});
}
+1
View File
@@ -0,0 +1 @@
#include "mhache_skill.h"
+33 -11
View File
@@ -1,7 +1,8 @@
#include "mhache_window.h"
#include <cstdlib>
#include <cstdio>
#include <csignal>
#include <iostream>
#include <functional>
#include "imgui.h"
#include "imgui_impl_glfw.h"
@@ -9,18 +10,26 @@
#include <GLFW/glfw3.h>
#include "mhache_researcher.h"
volatile std::sig_atomic_t MHacheWindow::_signal_status = 0;
MHacheWindow::MHacheWindow(int width, int height)
: _width(width), _height(height), _window(nullptr)
{
glfwSetErrorCallback(&MHacheWindow::callback_glfw_error);
if (GLFW_TRUE == glfwInit()) {
glfwWindowHint(GLFW_CONTEXT_VERSION_MAJOR, 3);
glfwWindowHint(GLFW_CONTEXT_VERSION_MINOR, 0);
glfwWindowHint(GLFW_CONTEXT_VERSION_MAJOR, _opengl_major_version);
glfwWindowHint(GLFW_CONTEXT_VERSION_MINOR, _opengl_minor_version);
_window = glfwCreateWindow(_width, _height, _title, nullptr, nullptr);
if (_window) {
std::signal(SIGINT, &MHacheWindow::callback_signals);
std::signal(SIGTERM, &MHacheWindow::callback_signals);
std::signal(SIGABRT, &MHacheWindow::callback_signals);
glfwSetKeyCallback(_window, &MHacheWindow::callback_glfw_keyboard);
glfwMakeContextCurrent(_window);
@@ -31,6 +40,10 @@ MHacheWindow::MHacheWindow(int width, int height)
ImGui_ImplOpenGL3_Init(_GLSL_version);
}
}
MHacheResearcher& mhr = MHacheResearcher::instance();
mhr.load_armors("../../armors.toml");
mhr.load_skills("../../skills.toml");
}
MHacheWindow::~MHacheWindow()
@@ -43,10 +56,16 @@ MHacheWindow::~MHacheWindow()
glfwTerminate();
}
void
MHacheWindow::callback_signals(int signal)
{
_signal_status = signal;
}
void
MHacheWindow::callback_glfw_error(int error, const char* description)
{
fprintf(stderr, "GLFW error (%d) = %s\n", error, description);
std::cerr << "GLFW error (" << error << ") = " << description << std::endl;
}
void
@@ -61,7 +80,7 @@ MHacheWindow::callback_glfw_keyboard(GLFWwindow* window, int key, int scancode,
}
void
MHacheWindow::prepare_frame()
MHacheWindow::new_frame()
{
ImGui_ImplOpenGL3_NewFrame();
ImGui_ImplGlfw_NewFrame();
@@ -83,7 +102,7 @@ MHacheWindow::render_frame()
}
void
MHacheWindow::build_window()
MHacheWindow::build_widgets()
{
ImGuiWindowFlags window_flags = 0;
window_flags |= ImGuiWindowFlags_NoBackground;
@@ -122,7 +141,10 @@ MHacheWindow::build_menu()
bool
MHacheWindow::ready()
{
return (_window && !glfwWindowShouldClose(_window));
return (
!(SIGINT == _signal_status || SIGTERM == _signal_status || SIGABRT == _signal_status)
&& _window && !glfwWindowShouldClose(_window)
);
}
void
@@ -130,8 +152,8 @@ MHacheWindow::display()
{
while (ready()) {
glfwPollEvents();
prepare_frame();
build_window();
new_frame();
build_widgets();
render_frame();
}
}
}