forked from jaildesigner-jailgames/jaildoctors_dilemma
Eliminat TOT el online i merdes
This commit is contained in:
@@ -1,4 +1,3 @@
|
||||
#include "jail_engine/jscore.h"
|
||||
#include "stats.h"
|
||||
#include <algorithm>
|
||||
#include <fstream>
|
||||
@@ -6,10 +5,9 @@
|
||||
#include <sstream>
|
||||
|
||||
// Constructor
|
||||
Stats::Stats(std::string file, std::string buffer, options_t *options, Online *online)
|
||||
Stats::Stats(std::string file, std::string buffer, options_t *options)
|
||||
{
|
||||
this->options = options;
|
||||
this->online = online;
|
||||
bufferPath = buffer;
|
||||
filePath = file;
|
||||
bufferList.clear();
|
||||
@@ -27,7 +25,6 @@ Stats::~Stats()
|
||||
checkWorstNightmare();
|
||||
|
||||
// Guarda las estadísticas
|
||||
saveToServer();
|
||||
saveToFile(bufferPath, bufferList);
|
||||
saveToFile(filePath, list);
|
||||
|
||||
@@ -37,15 +34,11 @@ Stats::~Stats()
|
||||
}
|
||||
|
||||
// Inicializador
|
||||
// Se debe llamar a este procedimiento una vez se haya creado el diccionario numero-nombre
|
||||
void Stats::init()
|
||||
// Se debe llamar a este procedimiento una vez se haya creado el diccionario numero-nombre
|
||||
{
|
||||
loadFromFile(bufferPath, bufferList);
|
||||
loadFromFile(filePath, list);
|
||||
if (options->online.enabled)
|
||||
{
|
||||
loadFromServer();
|
||||
}
|
||||
|
||||
// Vuelca los datos del buffer en la lista de estadisticas
|
||||
updateListFromBuffer();
|
||||
@@ -54,9 +47,6 @@ void Stats::init()
|
||||
// Añade una muerte a las estadisticas
|
||||
void Stats::addDeath(std::string name)
|
||||
{
|
||||
// Normaliza el nombre
|
||||
// std::replace(name.begin(), name.end(), ' ', '_');
|
||||
|
||||
// Primero busca si ya hay una entrada con ese nombre
|
||||
const int index = findByName(name, bufferList);
|
||||
if (index != -1)
|
||||
@@ -78,9 +68,6 @@ void Stats::addDeath(std::string name)
|
||||
// Añade una visita a las estadisticas
|
||||
void Stats::addVisit(std::string name)
|
||||
{
|
||||
// Normaliza el nombre
|
||||
// std::replace(name.begin(), name.end(), ' ', '_');
|
||||
|
||||
// Primero busca si ya hay una entrada con ese nombre
|
||||
const int index = findByName(name, bufferList);
|
||||
if (index != -1)
|
||||
@@ -163,62 +150,14 @@ bool Stats::loadFromFile(std::string filePath, std::vector<stats_t> &list)
|
||||
|
||||
// El fichero no existe
|
||||
else
|
||||
{ // Crea el fichero con los valores por defecto
|
||||
{
|
||||
// Crea el fichero con los valores por defecto
|
||||
saveToFile(filePath, list);
|
||||
}
|
||||
|
||||
return success;
|
||||
}
|
||||
|
||||
// Carga las estadisticas desde un servidor
|
||||
void Stats::loadFromServer()
|
||||
{
|
||||
// Limpia los datos del servidor
|
||||
// eraseServerData();
|
||||
|
||||
list.clear();
|
||||
|
||||
std::string data;
|
||||
if (options->online.enabled)
|
||||
{
|
||||
//data = jscore::getUserData(options->online.gameID, options->online.jailerID);
|
||||
data = online->getStats();
|
||||
}
|
||||
|
||||
std::stringstream ss(data);
|
||||
std::string tmp;
|
||||
|
||||
int count = 0;
|
||||
|
||||
for (int i = 0; i < (int)data.size(); ++i)
|
||||
{
|
||||
if (data[i] == ';')
|
||||
{
|
||||
count++;
|
||||
}
|
||||
}
|
||||
|
||||
while (count > 0)
|
||||
{
|
||||
stats_t stat;
|
||||
|
||||
// Obtiene el nombre
|
||||
getline(ss, tmp, ';');
|
||||
stat.name = numberToName(tmp);
|
||||
|
||||
// Obtiene las visitas
|
||||
getline(ss, tmp, ';');
|
||||
stat.visited = std::stoi(tmp);
|
||||
|
||||
// Obtiene las muertes
|
||||
getline(ss, tmp, ';');
|
||||
stat.died = std::stoi(tmp);
|
||||
|
||||
list.push_back(stat);
|
||||
count = count - 3;
|
||||
}
|
||||
}
|
||||
|
||||
// Guarda las estadisticas en un fichero
|
||||
void Stats::saveToFile(std::string filePath, std::vector<stats_t> &list)
|
||||
{
|
||||
@@ -236,21 +175,6 @@ void Stats::saveToFile(std::string filePath, std::vector<stats_t> &list)
|
||||
file.close();
|
||||
}
|
||||
|
||||
// Guarda las estadisticas en un servidor
|
||||
void Stats::saveToServer()
|
||||
{
|
||||
std::string data = "";
|
||||
if (options->online.enabled)
|
||||
{
|
||||
for (auto item : list)
|
||||
{
|
||||
data = data + nameToNumber(item.name) + ";" + std::to_string(item.visited) + ";" + std::to_string(item.died) + ";";
|
||||
}
|
||||
//jscore::setUserData(options->online.gameID, options->online.jailerID, data);
|
||||
online->setStats(data);
|
||||
}
|
||||
}
|
||||
|
||||
// Calcula cual es la habitación con más muertes
|
||||
void Stats::checkWorstNightmare()
|
||||
{
|
||||
@@ -320,13 +244,6 @@ void Stats::updateListFromBuffer()
|
||||
}
|
||||
}
|
||||
|
||||
// Sube los datos al servidor
|
||||
if (options->online.enabled)
|
||||
{
|
||||
saveToServer();
|
||||
bufferList.clear();
|
||||
}
|
||||
|
||||
saveToFile(bufferPath, bufferList);
|
||||
saveToFile(filePath, list);
|
||||
}
|
||||
Reference in New Issue
Block a user