forked from jaildesigner-jailgames/jaildoctors_dilemma
Mensajes de consola opcionales
This commit is contained in:
@@ -4,7 +4,7 @@
|
||||
#include <fstream>
|
||||
|
||||
// Llena una estructuta textFile_t desde un fichero
|
||||
textFile_t LoadTextFile(std::string file)
|
||||
textFile_t LoadTextFile(std::string file, bool verbose)
|
||||
{
|
||||
textFile_t tf;
|
||||
|
||||
@@ -50,14 +50,20 @@ textFile_t LoadTextFile(std::string file)
|
||||
};
|
||||
|
||||
// Cierra el fichero
|
||||
std::cout << "Text loaded: " << filename.c_str() << std::endl;
|
||||
if (verbose)
|
||||
{
|
||||
std::cout << "Text loaded: " << filename.c_str() << std::endl;
|
||||
}
|
||||
rfile.close();
|
||||
}
|
||||
|
||||
// El fichero no se puede abrir
|
||||
else
|
||||
{
|
||||
std::cout << "Warning: Unable to open " << filename.c_str() << " file" << std::endl;
|
||||
if (verbose)
|
||||
{
|
||||
std::cout << "Warning: Unable to open " << filename.c_str() << " file" << std::endl;
|
||||
}
|
||||
}
|
||||
|
||||
// Establece las coordenadas para cada caracter ascii de la cadena y su ancho
|
||||
@@ -74,7 +80,17 @@ textFile_t LoadTextFile(std::string file)
|
||||
Text::Text(std::string textFile, Texture *texture, SDL_Renderer *renderer)
|
||||
{
|
||||
// Carga los offsets desde el fichero
|
||||
initOffsetFromFile(textFile);
|
||||
textFile_t tf = LoadTextFile(textFile);
|
||||
|
||||
// Inicializa variables desde la estructura
|
||||
boxHeight = tf.boxHeight;
|
||||
boxWidth = tf.boxWidth;
|
||||
for (int i = 0; i < 128; ++i)
|
||||
{
|
||||
offset[i].x = tf.offset[i].x;
|
||||
offset[i].y = tf.offset[i].y;
|
||||
offset[i].w = tf.offset[i].w;
|
||||
}
|
||||
|
||||
// Crea los objetos
|
||||
sprite = new Sprite({0, 0, boxWidth, boxHeight}, texture, renderer);
|
||||
@@ -198,69 +214,6 @@ int Text::lenght(std::string text, int kerning)
|
||||
return shift - kerning;
|
||||
}
|
||||
|
||||
// Inicializa el vector de offsets desde un fichero
|
||||
void Text::initOffsetFromFile(std::string file)
|
||||
{
|
||||
// Inicializa a cero el vector con las coordenadas
|
||||
for (int i = 0; i < 128; ++i)
|
||||
{
|
||||
offset[i].x = 0;
|
||||
offset[i].y = 0;
|
||||
offset[i].w = 0;
|
||||
}
|
||||
|
||||
// Abre el fichero para leer los valores
|
||||
const std::string filename = file.substr(file.find_last_of("\\/") + 1).c_str();
|
||||
std::ifstream rfile(file);
|
||||
|
||||
if (rfile.is_open() && rfile.good())
|
||||
{
|
||||
std::string buffer;
|
||||
|
||||
// Lee los dos primeros valores del fichero
|
||||
std::getline(rfile, buffer);
|
||||
std::getline(rfile, buffer);
|
||||
boxWidth = std::stoi(buffer);
|
||||
|
||||
std::getline(rfile, buffer);
|
||||
std::getline(rfile, buffer);
|
||||
boxHeight = std::stoi(buffer);
|
||||
|
||||
// lee el resto de datos del fichero
|
||||
int index = 32;
|
||||
int line_read = 0;
|
||||
while (std::getline(rfile, buffer))
|
||||
{
|
||||
// Almacena solo las lineas impares
|
||||
if (line_read % 2 == 1)
|
||||
{
|
||||
offset[index++].w = std::stoi(buffer);
|
||||
}
|
||||
|
||||
// Limpia el buffer
|
||||
buffer.clear();
|
||||
line_read++;
|
||||
};
|
||||
|
||||
// Cierra el fichero
|
||||
std::cout << "Text loaded: " << filename.c_str() << std::endl;
|
||||
rfile.close();
|
||||
}
|
||||
|
||||
// El fichero no se puede abrir
|
||||
else
|
||||
{
|
||||
std::cout << "Warning: Unable to open " << filename.c_str() << " file" << std::endl;
|
||||
}
|
||||
|
||||
// Establece las coordenadas para cada caracter ascii de la cadena y su ancho
|
||||
for (int i = 32; i < 128; ++i)
|
||||
{
|
||||
offset[i].x = ((i - 32) % 15) * boxWidth;
|
||||
offset[i].y = ((i - 32) / 15) * boxHeight;
|
||||
}
|
||||
}
|
||||
|
||||
// Devuelve el valor de la variable
|
||||
int Text::getCharacterSize()
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user