Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //---------------------------
- // Includes
- //---------------------------
- #include <sys/stat.h>
- #include <algorithm>
- //---------------------------
- // Constructor & Destructor
- //---------------------------
- Level::Level(int levelNum)
- {
- std::string levelName = "./resources/Level" + std::to_string(levelNum) + ".txt";
- LevelDetailLoader(levelName);
- }
- Level::~Level()
- {
- }
- void Level::LevelDetailLoader(const std::string& name) {
- if (ExistsTest(name))
- {
- std::wifstream file(name);
- tstring sLine;
- tstring detailText;
- while (!file.eof())
- {
- getline(file, sLine);
- detailText += sLine;
- }
- file.close();
- tstring playerInfo;
- tstring type = _T("PlayerInfo");
- while (ExtractInformation(detailText, playerInfo, type))
- {
- //Do something with playerInfo, this is a std::string type
- }
- }
- }
- bool Level::ExtractInformation(tstring& textRef, tstring& info, tstring& type)
- {
- tstring component = _T("<" + type);
- tstring::iterator posComponent = search(textRef.begin(), textRef.end(), component.begin(), component.end());
- if (posComponent == textRef.end())
- return false;
- tstring::iterator posOpeningDoubleQuote = find(posComponent, textRef.end(), _T('\"'));
- tstring::iterator posClosingDoubleQuote = find(posOpeningDoubleQuote + 1, textRef.end(), _T('\"'));
- info = tstring(posOpeningDoubleQuote + 1, posClosingDoubleQuote);
- textRef.erase(posComponent, posClosingDoubleQuote + 1);
- return true;
- }
- bool Level::ExistsTest(const std::string& name) {
- struct stat buffer;
- return (stat(name.c_str(), &buffer) == 0);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement