#include "../Skin.hpp" std::vector skin::loadShader(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; } std::vector skin::loadSkin(std::string skinName){ sf::Image game; game.loadFromFile("bin/skin/"+skinName+"/game.png"); std::vector skin; //Background skin.push_back(game.getPixel(0,0)); //Background MainWindow skin.push_back(game.getPixel(76,243)); //Background cells skin.push_back(game.getPixel(61,227)); //Background grid color skin.push_back(game.getPixel(326,58)); //Score bg skin.push_back(game.getPixel(441,58)); //Best score bg skin.push_back(sf::Color(143,122,102)); //Button bg skin.push_back(sf::Color(238,228,218,186)); //Game over color bg //Font skin.push_back(game.getPixel(65,105)); //Title font color skin.push_back(game.getPixel(348,78)); //Score title fontcolor skin.push_back(game.getPixel(468,77)); //Best score title font color skin.push_back(game.getPixel(400,96)); //Score font color skin.push_back(game.getPixel(484,97)); //Best score font color skin.push_back(game.getPixel(128,660)); //2 and 4 font color skin.push_back(game.getPixel(359,661)); //other number font Color skin.push_back(sf::Color(143,122,102)); //game over font //Skin 2 et le 4 skin.push_back(game.getPixel(70,597)); //2 skin.push_back(game.getPixel(190,597)); //4 //Skin 8 à 64 skin.push_back(game.getPixel(311,597)); //8 skin.push_back(game.getPixel(431,597)); //16 skin.push_back(game.getPixel(71,477)); //32 skin.push_back(game.getPixel(191,477)); //64 //Skin 128 à 2048 skin.push_back(game.getPixel(312,477)); //128 skin.push_back(game.getPixel(431,477)); //256 skin.push_back(game.getPixel(71,358)); //512 skin.push_back(game.getPixel(191,358)); //1024 skin.push_back(game.getPixel(311,358)); //2048 //Skin for other number skin.push_back(game.getPixel(432,358)); //More than 2048 return skin; }