minetestmapper/PlayerAttributes.cpp

77 lines
1.5 KiB
C++
Raw Normal View History

/*
* =====================================================================
* 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
#include "config.h"
#include "PlayerAttributes.h"
2018-03-25 14:32:11 +02:00
#include "util.h"
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)
return;
struct dirent *ent;
while ((ent = readdir (dir)) != NULL) {
2018-03-25 14:32:11 +02:00
if (ent->d_name[0] == '.')
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);
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;
player.name = name;
2018-03-24 14:54:45 +01:00
player.x /= 10.0;
player.y /= 10.0;
player.z /= 10.0;
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();
}