From 1220e2d70f40139bed69602041ba373297103573 Mon Sep 17 00:00:00 2001 From: manzerbredes Date: Tue, 5 May 2015 16:30:46 +0200 Subject: Add loadable skin and correct some things --- src/Helpers/CMakeLists.txt | 3 + src/Helpers/Skin.hpp | 17 ++++++ src/Helpers/Skin/CMakeLists.txt | 1 + src/Helpers/Skin/Skin.cpp | 118 ++++++++++++++++++++++++++++++++++++++++ 4 files changed, 139 insertions(+) create mode 100644 src/Helpers/CMakeLists.txt create mode 100644 src/Helpers/Skin.hpp create mode 100644 src/Helpers/Skin/CMakeLists.txt create mode 100644 src/Helpers/Skin/Skin.cpp (limited to 'src/Helpers') diff --git a/src/Helpers/CMakeLists.txt b/src/Helpers/CMakeLists.txt new file mode 100644 index 0000000..bde671e --- /dev/null +++ b/src/Helpers/CMakeLists.txt @@ -0,0 +1,3 @@ +#Make Model lib + +add_subdirectory(./Skin/) diff --git a/src/Helpers/Skin.hpp b/src/Helpers/Skin.hpp new file mode 100644 index 0000000..6f01f18 --- /dev/null +++ b/src/Helpers/Skin.hpp @@ -0,0 +1,17 @@ +#include +#include +#include +#include +#include + + +namespace skin{ + + std::vector loadSkin(std::string skinName); + + std::vector removeComments(std::vector linesVector); + + bool containOnlySpace(std::string line); + + std::vector extractRGBA(std::string line); +} diff --git a/src/Helpers/Skin/CMakeLists.txt b/src/Helpers/Skin/CMakeLists.txt new file mode 100644 index 0000000..8ad7f17 --- /dev/null +++ b/src/Helpers/Skin/CMakeLists.txt @@ -0,0 +1 @@ +add_library(Skin Skin.cpp) diff --git a/src/Helpers/Skin/Skin.cpp b/src/Helpers/Skin/Skin.cpp new file mode 100644 index 0000000..b421dae --- /dev/null +++ b/src/Helpers/Skin/Skin.cpp @@ -0,0 +1,118 @@ +#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; + +} -- cgit v1.2.3