added type structure and parsing for the csv
This commit is contained in:
4
Makefile
4
Makefile
@@ -1,2 +1,2 @@
|
|||||||
main: main.cpp
|
main: main.cpp type.cpp
|
||||||
g++ main.cpp -o build/main `pkg-config --cflags --libs gtkmm-4.0`
|
g++ -Wall main.cpp type.cpp -o build/main `pkg-config --cflags --libs gtkmm-4.0`
|
||||||
19
chart.csv
Normal file
19
chart.csv
Normal file
@@ -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
|
||||||
|
74
main.cpp
74
main.cpp
@@ -1,13 +1,19 @@
|
|||||||
#include <iostream>
|
#include <iostream>
|
||||||
|
#include <fstream>
|
||||||
|
#include <string>
|
||||||
|
#include <regex>
|
||||||
#include <gtkmm/button.h>
|
#include <gtkmm/button.h>
|
||||||
#include <gtkmm.h>
|
#include <gtkmm.h>
|
||||||
#include <gtkmm/application.h>
|
#include <gtkmm/application.h>
|
||||||
|
#include "type.cpp"
|
||||||
|
|
||||||
|
|
||||||
class MyWindow : public Gtk::Window
|
class MyWindow : public Gtk::Window
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
MyWindow(){
|
MyWindow(){
|
||||||
|
loadTypesFromCsv("chart.csv");
|
||||||
|
|
||||||
loadCss();
|
loadCss();
|
||||||
m_button_not_effective = Gtk::Button("Not Effective");
|
m_button_not_effective = Gtk::Button("Not Effective");
|
||||||
m_button_not_effective.signal_clicked().connect(sigc::mem_fun(*this,&MyWindow::onNotEffectiveButtonClicked));
|
m_button_not_effective.signal_clicked().connect(sigc::mem_fun(*this,&MyWindow::onNotEffectiveButtonClicked));
|
||||||
@@ -40,6 +46,7 @@ class MyWindow : public Gtk::Window
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
{
|
||||||
m_layout_grid.attach(m_label_left, 1, 1, 2);
|
m_layout_grid.attach(m_label_left, 1, 1, 2);
|
||||||
m_layout_grid.attach(m_label_right, 4, 1, 2);
|
m_layout_grid.attach(m_label_right, 4, 1, 2);
|
||||||
m_layout_grid.set_row_homogeneous(true);
|
m_layout_grid.set_row_homogeneous(true);
|
||||||
@@ -47,10 +54,12 @@ class MyWindow : public Gtk::Window
|
|||||||
m_layout_grid.attach(m_button_not_effective, 2, 3);
|
m_layout_grid.attach(m_button_not_effective, 2, 3);
|
||||||
m_layout_grid.attach(m_button_super_effective, 4, 3);
|
m_layout_grid.attach(m_button_super_effective, 4, 3);
|
||||||
m_layout_grid.add_css_class("grid");
|
m_layout_grid.add_css_class("grid");
|
||||||
|
}
|
||||||
|
|
||||||
set_child(m_layout_grid);
|
set_child(m_layout_grid);
|
||||||
set_size_request(800,600);
|
set_size_request(800,600);
|
||||||
}
|
}
|
||||||
|
private:
|
||||||
void onNotEffectiveButtonClicked(){
|
void onNotEffectiveButtonClicked(){
|
||||||
std::cout<<"Not effective\n";
|
std::cout<<"Not effective\n";
|
||||||
}
|
}
|
||||||
@@ -61,6 +70,71 @@ class MyWindow : public Gtk::Window
|
|||||||
css_provider = Gtk::CssProvider::create();
|
css_provider = Gtk::CssProvider::create();
|
||||||
css_provider->load_from_path("main.css");
|
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")<<std::endl;
|
||||||
|
std::string line;
|
||||||
|
// Get the first line
|
||||||
|
std::getline(in_file, line);
|
||||||
|
parseFirstCsvLine(line);
|
||||||
|
// Parse the Rest
|
||||||
|
while(std::getline(in_file, line)) {
|
||||||
|
std::cout << line << '\n';
|
||||||
|
std::regex outer_delimiter(";");
|
||||||
|
std::sregex_token_iterator outer_iterator(line.begin(), line.end(), outer_delimiter, -1);
|
||||||
|
std::sregex_token_iterator outer_end;
|
||||||
|
std::string type_string = *outer_iterator++;
|
||||||
|
Type* currentType;
|
||||||
|
for (auto it = m_types.begin(); it != m_types.end(); ++it) {
|
||||||
|
if (it->nameMatches(type_string))
|
||||||
|
{
|
||||||
|
currentType = &*it;
|
||||||
|
std::cout << "found match for "<<type_string << " Id: "<<currentType->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<int> 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<int> result = std::vector<int>();
|
||||||
|
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<<std::endl;
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
void parseFirstCsvLine(std::string line){
|
||||||
|
std::cout << line << '\n';
|
||||||
|
std::regex delimiter(";");
|
||||||
|
std::sregex_token_iterator iterator(line.begin(), line.end(), delimiter, -1);
|
||||||
|
std::sregex_token_iterator end;
|
||||||
|
while (iterator != end) {
|
||||||
|
m_types.push_back(Type(*iterator));
|
||||||
|
++iterator;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
std::vector<Type> m_types = std::vector<Type>();
|
||||||
Gtk::Button m_button_not_effective;
|
Gtk::Button m_button_not_effective;
|
||||||
Gtk::Button m_button_super_effective;
|
Gtk::Button m_button_super_effective;
|
||||||
Gtk::Label m_label_left;
|
Gtk::Label m_label_left;
|
||||||
|
|||||||
25
type.cpp
Normal file
25
type.cpp
Normal file
@@ -0,0 +1,25 @@
|
|||||||
|
#include <iostream>
|
||||||
|
#include <vector>
|
||||||
|
#include <glibmm/ustring.h>
|
||||||
|
static int currentId = 0;
|
||||||
|
class Type{
|
||||||
|
public:
|
||||||
|
Type(const std::string name){
|
||||||
|
id = ++currentId;
|
||||||
|
this->name = name;
|
||||||
|
std::cout << "Type "<<name<<" constructed. Id: "<<id<<"\n";
|
||||||
|
}
|
||||||
|
~Type(){
|
||||||
|
// std::cout << "Type "<<name<<" destructed "<<id<<"\n";
|
||||||
|
resistantAgainstTypes.~vector();
|
||||||
|
weakAgainstTypes.~vector();
|
||||||
|
}
|
||||||
|
bool nameMatches(std::string comparison){
|
||||||
|
return name.compare(comparison) == 0;
|
||||||
|
}
|
||||||
|
std::string name;
|
||||||
|
int id;
|
||||||
|
|
||||||
|
std::vector<int> resistantAgainstTypes = std::vector<int>();
|
||||||
|
std::vector<int> weakAgainstTypes = std::vector<int>();
|
||||||
|
};
|
||||||
Reference in New Issue
Block a user