2012-09-01 16:40:18 +02:00
|
|
|
/*
|
|
|
|
* =====================================================================
|
|
|
|
* Version: 1.0
|
|
|
|
* Created: 01.09.2012 14:38:05
|
|
|
|
* Author: Miroslav Bendík
|
|
|
|
* Company: LinuxOS.sk
|
|
|
|
* =====================================================================
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <dirent.h>
|
|
|
|
#include <fstream>
|
|
|
|
#include <sstream>
|
2018-03-25 14:32:11 +02:00
|
|
|
|
2012-09-01 16:40:18 +02:00
|
|
|
#include "config.h"
|
|
|
|
#include "PlayerAttributes.h"
|
2018-03-25 14:32:11 +02:00
|
|
|
#include "util.h"
|
2012-09-01 16:40:18 +02:00
|
|
|
|
|
|
|
using namespace std;
|
|
|
|
|
|
|
|
PlayerAttributes::PlayerAttributes(const std::string &sourceDirectory)
|
|
|
|
{
|
|
|
|
|
|
|
|
string playersPath = sourceDirectory + "players";
|
|
|
|
DIR *dir;
|
|
|
|
dir = opendir (playersPath.c_str());
|
2018-03-25 14:32:11 +02:00
|
|
|
if (dir == NULL)
|
2012-09-01 16:40:18 +02:00
|
|
|
return;
|
|
|
|
|
|
|
|
struct dirent *ent;
|
|
|
|
while ((ent = readdir (dir)) != NULL) {
|
2018-03-25 14:32:11 +02:00
|
|
|
if (ent->d_name[0] == '.')
|
2012-09-01 16:40:18 +02:00
|
|
|
continue;
|
|
|
|
|
|
|
|
string path = playersPath + PATH_SEPARATOR + ent->d_name;
|
2018-03-25 14:32:11 +02:00
|
|
|
ifstream in(path.c_str());
|
|
|
|
if(!in.good())
|
|
|
|
continue;
|
|
|
|
|
|
|
|
string name, position;
|
|
|
|
name = read_setting("name", in);
|
|
|
|
in.seekg(0);
|
|
|
|
position = read_setting("position", in);
|
2012-09-01 16:40:18 +02:00
|
|
|
|
|
|
|
Player player;
|
2018-03-25 14:32:11 +02:00
|
|
|
istringstream iss(position);
|
|
|
|
char tmp;
|
|
|
|
iss >> tmp; // '('
|
|
|
|
iss >> player.x;
|
|
|
|
iss >> tmp; // ','
|
|
|
|
iss >> player.y;
|
|
|
|
iss >> tmp; // ','
|
|
|
|
iss >> player.z;
|
|
|
|
iss >> tmp; // ')'
|
|
|
|
if(tmp != ')')
|
|
|
|
continue;
|
2012-09-01 16:40:18 +02:00
|
|
|
player.name = name;
|
|
|
|
|
2018-03-24 14:54:45 +01:00
|
|
|
player.x /= 10.0;
|
|
|
|
player.y /= 10.0;
|
|
|
|
player.z /= 10.0;
|
|
|
|
|
2012-09-01 16:40:18 +02:00
|
|
|
m_players.push_back(player);
|
|
|
|
}
|
|
|
|
closedir(dir);
|
|
|
|
}
|
|
|
|
|
|
|
|
PlayerAttributes::Players::iterator PlayerAttributes::begin()
|
|
|
|
{
|
|
|
|
return m_players.begin();
|
|
|
|
}
|
|
|
|
|
|
|
|
PlayerAttributes::Players::iterator PlayerAttributes::end()
|
|
|
|
{
|
|
|
|
return m_players.end();
|
|
|
|
}
|
|
|
|
|