This commit is contained in:
2026-04-17 22:20:37 +02:00
parent 513eacf356
commit 20b9a95619
38 changed files with 310 additions and 622 deletions

View File

@@ -25,14 +25,14 @@ auto Asset::get() -> Asset * {
}
// Constructor
Asset::Asset(std::string executablePath) {
this->executablePath = executablePath.substr(0, executablePath.find_last_of("\\/"));
longestName = 0;
verbose = true;
Asset::Asset(const std::string &executablePath)
: longestName(0),
executablePath(executablePath.substr(0, executablePath.find_last_of("\\/"))),
verbose(true) {
}
// Añade un elemento a la lista
void Asset::add(std::string file, enum assetType type, bool required, bool absolute) {
void Asset::add(const std::string &file, enum assetType type, bool required, bool absolute) {
item_t temp;
temp.file = absolute ? file : executablePath + file;
temp.type = type;
@@ -44,8 +44,8 @@ void Asset::add(std::string file, enum assetType type, bool required, bool absol
}
// Devuelve el fichero de un elemento de la lista a partir de una cadena
std::string Asset::get(std::string text) {
for (auto f : fileList) {
std::string Asset::get(const std::string &text) {
for (const auto &f : fileList) {
const size_t lastIndex = f.file.find_last_of("/") + 1;
const std::string file = f.file.substr(lastIndex, std::string::npos);
@@ -76,7 +76,7 @@ bool Asset::check() {
// Comprueba si hay ficheros de ese tipo
bool any = false;
for (auto f : fileList) {
for (const auto &f : fileList) {
if ((f.required) && (f.type == type)) {
any = true;
}
@@ -88,7 +88,7 @@ bool Asset::check() {
std::cout << "\n>> " << getTypeName(type).c_str() << " FILES" << std::endl;
}
for (auto f : fileList) {
for (const auto &f : fileList) {
if ((f.required) && (f.type == type)) {
success &= checkFile(f.file);
}
@@ -111,7 +111,7 @@ bool Asset::check() {
}
// Comprueba que existe un fichero
bool Asset::checkFile(std::string path) {
bool Asset::checkFile(const std::string &path) {
bool success = false;
std::string result = "ERROR";

View File

@@ -34,13 +34,13 @@ class Asset {
bool verbose; // Indica si ha de mostrar información por pantalla
// Comprueba que existe un fichero
bool checkFile(std::string executablePath);
bool checkFile(const std::string &executablePath);
// Devuelve el nombre del tipo de recurso
std::string getTypeName(int type);
// Constructor privado (usar Asset::init)
Asset(std::string path);
explicit Asset(const std::string &path);
// Instancia única
static Asset *instance;
@@ -52,10 +52,10 @@ class Asset {
static auto get() -> Asset *; // Obtiene el puntero a la instancia
// Añade un elemento a la lista
void add(std::string file, enum assetType type, bool required = true, bool absolute = false);
void add(const std::string &file, enum assetType type, bool required = true, bool absolute = false);
// Devuelve un elemento de la lista a partir de una cadena
std::string get(std::string text);
std::string get(const std::string &text);
// Devuelve toda la lista de items registrados
const std::vector<item_t> &getAll() const { return fileList; }

View File

@@ -30,7 +30,7 @@ class Resource {
const std::vector<uint8_t> &getDemoBytes() const { return demoBytes_; }
private:
Resource(SDL_Renderer *renderer);
explicit Resource(SDL_Renderer *renderer);
~Resource();
void preloadAll();

View File

@@ -5,6 +5,7 @@
#include <filesystem>
#include <fstream>
#include <iostream>
#include <numeric>
#include <utility>
const std::string ResourcePack::DEFAULT_ENCRYPT_KEY = "CCRS_RESOURCES__2026";
@@ -17,11 +18,8 @@ ResourcePack::~ResourcePack() {
}
uint32_t ResourcePack::calculateChecksum(const std::vector<uint8_t>& data) {
uint32_t checksum = 0x12345678;
for (unsigned char i : data) {
checksum = ((checksum << 5) + checksum) + i;
}
return checksum;
return std::accumulate(data.begin(), data.end(), uint32_t(0x12345678),
[](uint32_t acc, uint8_t b) { return ((acc << 5) + acc) + b; });
}
void ResourcePack::encryptData(std::vector<uint8_t>& data, const std::string& key) {