Try sifting through this. D:
KaosScript.h
#ifndef kaosscript_h
#define kaosscript_h
#include <vector>
#include <string>
#include <sstream>
class KSBlock
{
public:
KSBlock() { }
std::string block_name;
std::vector<std::string> value_names;
std::vector<std::string> values;
std::string GetString(std::string value_name);
float GetFloat(std::string value_name);
int GetInt(std::string value_name);
};
class KaosScript
{
public:
KaosScript(std::string file_path);
std::vector<KSBlock> blocks;
KSBlock Block(std::string block_name);
};
#endif
KaosScript.cpp
#include "KaosScript.h"
#include <DarkGDK.h>
#include <fstream>
std::vector<std::string> Explode(std::string tosplit, std::string delim)
{
std::vector<std::string> tmp;
std::string tmp_str;
for (unsigned int i = 0; i < tosplit.length() - 1; i++)
{
if (tosplit[i] == delim[0])
{
tmp_str = tosplit.substr(0, i-1);
tosplit = tosplit.substr(delim.length() - 1);
tmp.push_back(tmp_str);
tmp_str.erase();
}
}
tosplit.erase();
return tmp;
}
KaosScript::KaosScript(std::string file_path)
{
blocks.reserve(50);
std::ifstream new_f(file_path.c_str());
if (!new_f.is_open())
return;
std::string holder;
std::string line;
while (!new_f.eof())
{
std::getline(new_f, line);
holder+=line;
}
line.erase();
new_f.close();
std::vector<std::string> tmp_blocks;
tmp_blocks.reserve(50);
tmp_blocks = Explode(holder, "{/}");
for (unsigned int i = 0; i < tmp_blocks.size() - 1; i++)
{
int tag_end = tmp_blocks[i].find_first_of("}");
KSBlock new_block;
new_block.block_name = tmp_blocks[i].substr(1, tag_end - 1);
tmp_blocks.at(i) = tmp_blocks[i].substr(tag_end + 1);
int val_end = tmp_blocks[i].find_first_of("{");
tmp_blocks[i] = tmp_blocks[i].substr(0, val_end);
std::vector<std::string> tmp_vals;
std::vector<std::string> tmp_names;
std::vector<std::string> tmp_both;
std::vector<std::string> tmp_both2;
tmp_both = Explode(tmp_blocks[i], ";");
for (unsigned int v = 0; v < tmp_both.size() - 1; v++)
{
tmp_both2 = Explode(tmp_both[i], "=");
tmp_vals.push_back(tmp_both2[1]);
tmp_names.push_back(tmp_both2[0]);
tmp_both2.clear();
}
tmp_both.clear();
new_block.values = tmp_vals;
new_block.value_names = tmp_names;
tmp_vals.clear();
tmp_names.clear();
blocks.push_back(new_block);
}
holder.erase();
tmp_blocks.clear();
}
KSBlock KaosScript::Block(std::string block_name)
{
for (unsigned int i = 0; i < blocks.size() - 1; i++)
{
if (blocks[i].block_name == block_name)
{
return blocks[i];
}
}
}
std::string KSBlock::GetString(std::string value_name)
{
for (unsigned int i = 0; i < values.size() - 1; i++)
{
if (value_names[i] == value_name)
{
return values[i];
}
}
return "";
}
float KSBlock::GetFloat(std::string value_name)
{
for (unsigned int i = 0; i < values.size() - 1; i++)
{
if (value_names[i] == value_name)
{
return atof(values[i].c_str());
}
}
return 0.0f;
}
int KSBlock::GetInt(std::string value_name)
{
for (unsigned int i = 0; i < values.size() - 1; i++)
{
if (value_names[i] == value_name)
{
return atoi(values[i].c_str());
}
}
return 0;
}