From 43ed99bbddeb0ad8e3c200353a9b52014c411417 Mon Sep 17 00:00:00 2001 From: Tim Kainz Date: Sun, 22 Mar 2026 02:26:33 +0100 Subject: [PATCH] added type structure and parsing for the csv --- Makefile | 4 +-- chart.csv | 19 ++++++++++++ main.cpp | 88 ++++++++++++++++++++++++++++++++++++++++++++++++++----- type.cpp | 25 ++++++++++++++++ 4 files changed, 127 insertions(+), 9 deletions(-) create mode 100644 chart.csv create mode 100644 type.cpp diff --git a/Makefile b/Makefile index 2568970..5d66221 100644 --- a/Makefile +++ b/Makefile @@ -1,2 +1,2 @@ -main: main.cpp - g++ main.cpp -o build/main `pkg-config --cflags --libs gtkmm-4.0` \ No newline at end of file +main: main.cpp type.cpp + g++ -Wall main.cpp type.cpp -o build/main `pkg-config --cflags --libs gtkmm-4.0` \ No newline at end of file diff --git a/chart.csv b/chart.csv new file mode 100644 index 0000000..42271ba --- /dev/null +++ b/chart.csv @@ -0,0 +1,19 @@ +Normal;Fire;Water;Electric;Grass;Ice;Fighting;Poison;Ground;Flying;Psychic;Bug;Rock;Ghost;Dragon;Dark;Steel;Fairy +Normal;Ghost;Fighting +Fire;Fire,Grass,Ice,Bug,Steel,Fairy;Water,Ground,Rock +Water;Fire,Water,Ice,Steel;Electric,Grass +Electric;Electric,Flying,Steel;Ground +Grass;Water,Electric,Grass,Ground;Fire,Ice,Poison,Flying,Bug +Ice;Ice;Fire,Rock,Steel,Fighting +Fighting;Bug,Rock,Dark;Flying,Psychic,Fairy +Poison;Grass,Fighting,Poison,Bug,Fairy;Ground,Psychic +Ground;Poison,Rock,Electric;Water,Grass,Ice +Flying;Fighting,Ground,Bug,Grass;Rock,Electric,Ice +Psychic;Fighting,Psychic;Bug,Ghost,Dark +Bug;Fighting,Ground,Grass;Flying,Rock,Fire +Rock;Normal,Flying,Poison,Fire;Ground,Fighting,Steel,Water,Grass +Ghost;Normal,Fighting,Poison,Bug;Ghost,Dark +Dragon;Fire,Water,Grass,Electric;Ice,Dragon,Fairy +Dark;Ghost,Psychic,Dark;Fighting,Bug,Fairy +Steel;Normal,Flying,Poison,Rock,Bug,Steel,Grass,Psychic,Ice,Dragon,Fairy;Fighting,Ground,Fire +Fairy;Fighting,Bug,Dragon,Dark;Poison,Steel diff --git a/main.cpp b/main.cpp index 7e100c9..948835e 100644 --- a/main.cpp +++ b/main.cpp @@ -1,13 +1,19 @@ #include +#include +#include +#include #include #include #include +#include "type.cpp" class MyWindow : public Gtk::Window { public: MyWindow(){ + loadTypesFromCsv("chart.csv"); + loadCss(); m_button_not_effective = Gtk::Button("Not Effective"); m_button_not_effective.signal_clicked().connect(sigc::mem_fun(*this,&MyWindow::onNotEffectiveButtonClicked)); @@ -40,17 +46,20 @@ class MyWindow : public Gtk::Window } } - m_layout_grid.attach(m_label_left, 1, 1, 2); - m_layout_grid.attach(m_label_right, 4, 1, 2); - m_layout_grid.set_row_homogeneous(true); - m_layout_grid.set_column_homogeneous(true); - m_layout_grid.attach(m_button_not_effective, 2, 3); - m_layout_grid.attach(m_button_super_effective, 4, 3); - m_layout_grid.add_css_class("grid"); + { + m_layout_grid.attach(m_label_left, 1, 1, 2); + m_layout_grid.attach(m_label_right, 4, 1, 2); + m_layout_grid.set_row_homogeneous(true); + m_layout_grid.set_column_homogeneous(true); + m_layout_grid.attach(m_button_not_effective, 2, 3); + m_layout_grid.attach(m_button_super_effective, 4, 3); + m_layout_grid.add_css_class("grid"); + } set_child(m_layout_grid); set_size_request(800,600); } + private: void onNotEffectiveButtonClicked(){ std::cout<<"Not effective\n"; } @@ -61,6 +70,71 @@ class MyWindow : public Gtk::Window css_provider = Gtk::CssProvider::create(); css_provider->load_from_path("main.css"); } + void loadTypesFromCsv(std::string path){ + std::ifstream in_file; + in_file.open(path); + std::cout << "Is open:" << (in_file.is_open()?"true":"false")<nameMatches(type_string)) + { + currentType = &*it; + std::cout << "found match for "<id; + } + } + + std::string resistant_string = *outer_iterator++; + auto resistantIds = parseSubCsv(resistant_string); + + + std::string weak_string = *outer_iterator; + auto weakIds = parseSubCsv(weak_string); + } + } + std::vector parseSubCsv(std::string part){ + std::cout << part << '\n'; + std::regex delimiter(","); + std::sregex_token_iterator regex_iterator(part.begin(), part.end(), delimiter, -1); + std::sregex_token_iterator regex_end; + std::vector result = std::vector(); + while (regex_iterator != regex_end) { + auto type_string = *regex_iterator; + + for (auto it = m_types.begin(); it != m_types.end(); ++it) { + if (it->nameMatches(type_string)) + { + result.push_back(it->id); + std::cout<< it->id<< ", "; + } + } + ++regex_iterator; + } + std::cout< m_types = std::vector(); Gtk::Button m_button_not_effective; Gtk::Button m_button_super_effective; Gtk::Label m_label_left; diff --git a/type.cpp b/type.cpp new file mode 100644 index 0000000..e87ba24 --- /dev/null +++ b/type.cpp @@ -0,0 +1,25 @@ +#include +#include +#include +static int currentId = 0; +class Type{ + public: + Type(const std::string name){ + id = ++currentId; + this->name = name; + std::cout << "Type "< resistantAgainstTypes = std::vector(); + std::vector weakAgainstTypes = std::vector(); +}; \ No newline at end of file