#include "../Skin.hpp" std::vector skin::loadSkin(std::string skinName){ std::vector skinLoaded; std::ifstream skinFile("./bin/skin/"+skinName+"/skin.txt"); try{ if(!skinFile.is_open()) throw 1; } catch(int code){ std::cout << "Failed to open skin " + skinName + "check the location and the permissions !"; exit(code); } std::string line; std::vector linesVector; while (std::getline(skinFile, line)) { if(!line.empty() && !skin::containOnlySpace(line)) linesVector.push_back(line); } linesVector=skin::removeComments(linesVector); for(int i=0;i rgba; rgba=skin::extractRGBA(linesVector.at(i)); if(rgba.size()==3) skinLoaded.push_back(sf::Color(rgba.at(0), rgba.at(1), rgba.at(2))); else skinLoaded.push_back(sf::Color(rgba.at(0), rgba.at(1), rgba.at(2),rgba.at(3))); } return skinLoaded; } std::vector skin::removeComments(std::vector linesVector){ std::vector linesWitouthCom; for(int i=0;i skin::extractRGBA(std::string line){ std::vector rgba; std::string numberFound; int start=0; try { for(int j=0;j<3;j++){ for(int i=start;i='0' && ch <='9'){ numberFound.push_back(ch); } else if(ch==' ' && numberFound.size() > 0){ start=i; break; } } rgba.push_back(std::stoi(numberFound)); numberFound.clear(); } if(rgba.size()<3 || rgba.size()>4){ throw "Invalid thème format"; exit(1); } } catch(std::string error){ std::cout << error; exit(1); } return rgba; }