Ya gestiona correctamente los datos online para diferentes usuarios

This commit is contained in:
2023-10-09 22:20:34 +02:00
parent 9b265c6cca
commit c835f943b5
12 changed files with 151 additions and 61 deletions

View File

@@ -2,15 +2,13 @@
#include <iostream>
// Constructor
Cheevos::Cheevos(Screen *screen, options_t *options, std::string file)
Cheevos::Cheevos(Screen *screen, options_t *options, std::string file, Online *online)
{
// Copia la dirección de los objetos
this->options = options;
this->screen = screen;
this->file = file;
// Crea objetos
online = new Online(options);
this->online = online;
// Inicializa los logros
init();
@@ -29,14 +27,13 @@ Cheevos::~Cheevos()
save();
cheevos.clear();
// Libera memoria
delete online;
}
// Inicializa los logros
void Cheevos::init()
{
cheevos.clear();
cheevos_t c;
c.completed = false;
c.valid = true;
@@ -303,9 +300,19 @@ void Cheevos::loadFromServer()
{
std::string cheevosData = online->getCheevos();
// Gestiona los posibles errores
const bool noData = cheevosData == "" ? true : false;
const bool incompleteData = cheevosData.length() != cheevos.size() ? true : false;
if (noData || incompleteData)
{
init();
return;
}
// Asigna los valores leídos desde el servidor
for (int i = 0; i < (int)cheevosData.length(); ++i)
{
bool value = cheevosData.substr(i, 1) == "1" ? true : false;
bool value = cheevosData.at(i) == '1' ? true : false;
cheevos.at(i).completed = value;
}
}
@@ -314,7 +321,7 @@ void Cheevos::loadFromServer()
void Cheevos::saveToServer()
{
std::string cheevosData = "";
// cheevos[2].completed = true;
for (auto cheevo : cheevos)
{
std::string data = cheevo.completed ? "1" : "0";
@@ -322,4 +329,10 @@ void Cheevos::saveToServer()
}
online->setCheevos(cheevosData);
}
// Vuelve a cargar los logros desde el origen
void Cheevos::reload()
{
load();
}