Acabat amb els singletones, de moment
Arreglat els checkEvents
This commit is contained in:
@@ -8,6 +8,27 @@
|
||||
#include "options.h"
|
||||
#include <fstream> // Para fstream
|
||||
|
||||
// [SINGLETON]
|
||||
Cheevos *Cheevos::cheevos_ = nullptr;
|
||||
|
||||
// [SINGLETON] Crearemos el objeto con esta función estática
|
||||
void Cheevos::init(const std::string &file)
|
||||
{
|
||||
Cheevos::cheevos_ = new Cheevos(file);
|
||||
}
|
||||
|
||||
// [SINGLETON] Destruiremos el objeto con esta función estática
|
||||
void Cheevos::destroy()
|
||||
{
|
||||
delete Cheevos::cheevos_;
|
||||
}
|
||||
|
||||
// [SINGLETON] Con este método obtenemos el objeto y podemos trabajar con él
|
||||
Cheevos *Cheevos::get()
|
||||
{
|
||||
return Cheevos::cheevos_;
|
||||
}
|
||||
|
||||
// Constructor
|
||||
Cheevos::Cheevos(const std::string &file)
|
||||
: file_(file)
|
||||
@@ -25,27 +46,27 @@ Cheevos::~Cheevos()
|
||||
// Inicializa los logros
|
||||
void Cheevos::init()
|
||||
{
|
||||
cheevos_.clear();
|
||||
cheevos_.emplace_back(1, "SHINY THINGS", "Get 25% of the items", 2);
|
||||
cheevos_.emplace_back(2, "HALF THE WORK", "Get 50% of the items", 2);
|
||||
cheevos_.emplace_back(3, "GETTING THERE", "Get 75% of the items", 2);
|
||||
cheevos_.emplace_back(4, "THE COLLECTOR", "Get 100% of the items", 2);
|
||||
cheevos_.emplace_back(5, "WANDERING AROUND", "Visit 20 rooms", 2);
|
||||
cheevos_.emplace_back(6, "I GOT LOST", "Visit 40 rooms", 2);
|
||||
cheevos_.emplace_back(7, "I LIKE TO EXPLORE", "Visit all rooms", 2);
|
||||
cheevos_.emplace_back(8, "FINISH THE GAME", "Complete the game", 2);
|
||||
cheevos_.emplace_back(9, "I WAS SUCKED BY A HOLE", "Complete the game without entering the jail", 2);
|
||||
cheevos_.emplace_back(10, "MY LITTLE PROJECTS", "Complete the game with all items", 2);
|
||||
cheevos_.emplace_back(11, "I LIKE MY MULTICOLOURED FRIENDS", "Complete the game without dying", 2);
|
||||
cheevos_.emplace_back(12, "SHIT PROJECTS DONE FAST", "Complete the game in under 30 minutes", 2);
|
||||
cheevos_list_.clear();
|
||||
cheevos_list_.emplace_back(1, "SHINY THINGS", "Get 25% of the items", 2);
|
||||
cheevos_list_.emplace_back(2, "HALF THE WORK", "Get 50% of the items", 2);
|
||||
cheevos_list_.emplace_back(3, "GETTING THERE", "Get 75% of the items", 2);
|
||||
cheevos_list_.emplace_back(4, "THE COLLECTOR", "Get 100% of the items", 2);
|
||||
cheevos_list_.emplace_back(5, "WANDERING AROUND", "Visit 20 rooms", 2);
|
||||
cheevos_list_.emplace_back(6, "I GOT LOST", "Visit 40 rooms", 2);
|
||||
cheevos_list_.emplace_back(7, "I LIKE TO EXPLORE", "Visit all rooms", 2);
|
||||
cheevos_list_.emplace_back(8, "FINISH THE GAME", "Complete the game", 2);
|
||||
cheevos_list_.emplace_back(9, "I WAS SUCKED BY A HOLE", "Complete the game without entering the jail", 2);
|
||||
cheevos_list_.emplace_back(10, "MY LITTLE PROJECTS", "Complete the game with all items", 2);
|
||||
cheevos_list_.emplace_back(11, "I LIKE MY MULTICOLOURED FRIENDS", "Complete the game without dying", 2);
|
||||
cheevos_list_.emplace_back(12, "SHIT PROJECTS DONE FAST", "Complete the game in under 30 minutes", 2);
|
||||
}
|
||||
|
||||
// Busca un logro por id y devuelve el indice
|
||||
int Cheevos::find(int id)
|
||||
{
|
||||
for (int i = 0; i < (int)cheevos_.size(); ++i)
|
||||
for (int i = 0; i < (int)cheevos_list_.size(); ++i)
|
||||
{
|
||||
if (cheevos_[i].id == id)
|
||||
if (cheevos_list_[i].id == id)
|
||||
{
|
||||
return i;
|
||||
}
|
||||
@@ -60,15 +81,15 @@ void Cheevos::unlock(int id)
|
||||
const int index = find(id);
|
||||
|
||||
// Si el índice es inválido, el logro no es válido, ya está completado o el sistema de logros no está habilitado, no hacemos nada
|
||||
if (index == -1 || !cheevos_.at(index).valid || cheevos_.at(index).completed || !enabled_)
|
||||
if (index == -1 || !cheevos_list_.at(index).valid || cheevos_list_.at(index).completed || !enabled_)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
// Marcar el logro como completado
|
||||
cheevos_.at(index).completed = true;
|
||||
cheevos_list_.at(index).completed = true;
|
||||
// Mostrar notificación en la pantalla
|
||||
Notifier::get()->show("ACHIEVEMENT UNLOCKED!", cheevos_.at(index).caption, cheevos_.at(index).icon);
|
||||
Notifier::get()->show("ACHIEVEMENT UNLOCKED!", cheevos_list_.at(index).caption, cheevos_list_.at(index).icon);
|
||||
// Guardar el estado de los logros
|
||||
saveToFile();
|
||||
}
|
||||
@@ -81,7 +102,7 @@ void Cheevos::invalidate(int id)
|
||||
// Si el índice es válido, se invalida el logro
|
||||
if (index != -1)
|
||||
{
|
||||
cheevos_.at(index).valid = false;
|
||||
cheevos_list_.at(index).valid = false;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -109,7 +130,7 @@ void Cheevos::loadFromFile()
|
||||
}
|
||||
|
||||
// Guarda la información
|
||||
for (const auto &cheevo : cheevos_)
|
||||
for (const auto &cheevo : cheevos_list_)
|
||||
{
|
||||
newFile.write(reinterpret_cast<const char *>(&cheevo.completed), sizeof(bool));
|
||||
}
|
||||
@@ -131,7 +152,7 @@ void Cheevos::loadFromFile()
|
||||
}
|
||||
|
||||
// Carga los datos
|
||||
for (auto &cheevo : cheevos_)
|
||||
for (auto &cheevo : cheevos_list_)
|
||||
{
|
||||
file.read(reinterpret_cast<char *>(&cheevo.completed), sizeof(bool));
|
||||
}
|
||||
@@ -146,9 +167,9 @@ void Cheevos::saveToFile()
|
||||
if (file != NULL)
|
||||
{
|
||||
// Guarda la información
|
||||
for (int i = 0; i < (int)cheevos_.size(); ++i)
|
||||
for (int i = 0; i < (int)cheevos_list_.size(); ++i)
|
||||
{
|
||||
SDL_RWwrite(file, &cheevos_[i].completed, sizeof(bool), 1);
|
||||
SDL_RWwrite(file, &cheevos_list_[i].completed, sizeof(bool), 1);
|
||||
}
|
||||
|
||||
// Cierra el fichero
|
||||
@@ -167,7 +188,7 @@ void Cheevos::saveToFile()
|
||||
int Cheevos::unlocked()
|
||||
{
|
||||
int count = 0;
|
||||
for (auto cheevo : cheevos_)
|
||||
for (auto cheevo : cheevos_list_)
|
||||
{
|
||||
if (cheevo.completed)
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user