forked from jaildesigner-jailgames/jaildoctors_dilemma
Añadidos parametros al programa
This commit is contained in:
@@ -6,6 +6,7 @@ Asset::Asset(std::string path)
|
||||
{
|
||||
executablePath = path;
|
||||
longestName = 0;
|
||||
verbose = true;
|
||||
}
|
||||
|
||||
// Añade un elemento a la lista
|
||||
@@ -26,8 +27,8 @@ std::string Asset::get(std::string text)
|
||||
{
|
||||
for (auto f : fileList)
|
||||
{
|
||||
const size_t lastIndex = f.file.find_last_of("/")+1;
|
||||
const std:: string file = f.file.substr(lastIndex, std::string::npos);
|
||||
const size_t lastIndex = f.file.find_last_of("/") + 1;
|
||||
const std::string file = f.file.substr(lastIndex, std::string::npos);
|
||||
|
||||
if (file == text)
|
||||
{
|
||||
@@ -35,7 +36,10 @@ std::string Asset::get(std::string text)
|
||||
}
|
||||
}
|
||||
|
||||
std::cout << "Warning: file " << text.c_str() << " not found" << std::endl;
|
||||
if (verbose)
|
||||
{
|
||||
std::cout << "Warning: file " << text.c_str() << " not found" << std::endl;
|
||||
}
|
||||
return "";
|
||||
}
|
||||
|
||||
@@ -44,7 +48,10 @@ bool Asset::check()
|
||||
{
|
||||
bool success = true;
|
||||
|
||||
std::cout << "\n** Checking files." << std::endl;
|
||||
if (verbose)
|
||||
{
|
||||
std::cout << "\n** Checking files." << std::endl;
|
||||
}
|
||||
|
||||
// Comprueba la lista de ficheros clasificandolos por tipo
|
||||
for (int type = 0; type < t_maxAssetType; ++type)
|
||||
@@ -63,7 +70,10 @@ bool Asset::check()
|
||||
// Si hay ficheros de ese tipo, comprueba si existen
|
||||
if (any)
|
||||
{
|
||||
std::cout << "\n>> " << getTypeName(type).c_str() << " FILES" << std::endl;
|
||||
if (verbose)
|
||||
{
|
||||
std::cout << "\n>> " << getTypeName(type).c_str() << " FILES" << std::endl;
|
||||
}
|
||||
|
||||
for (auto f : fileList)
|
||||
{
|
||||
@@ -76,15 +86,18 @@ bool Asset::check()
|
||||
}
|
||||
|
||||
// Resultado
|
||||
if (success)
|
||||
if (verbose)
|
||||
{
|
||||
std::cout << "\n** All files OK.\n"
|
||||
<< std::endl;
|
||||
}
|
||||
else
|
||||
{
|
||||
std::cout << "\n** A file is missing. Exiting.\n"
|
||||
<< std::endl;
|
||||
if (success)
|
||||
{
|
||||
std::cout << "\n** All files OK.\n"
|
||||
<< std::endl;
|
||||
}
|
||||
else
|
||||
{
|
||||
std::cout << "\n** A file is missing. Exiting.\n"
|
||||
<< std::endl;
|
||||
}
|
||||
}
|
||||
|
||||
return success;
|
||||
@@ -107,12 +120,15 @@ bool Asset::checkFile(std::string path)
|
||||
SDL_RWclose(file);
|
||||
}
|
||||
|
||||
std::cout.setf(std::ios::left, std::ios::adjustfield);
|
||||
std::cout << "Checking file: ";
|
||||
std::cout.width(longestName + 2);
|
||||
std::cout.fill('.');
|
||||
std::cout << filename + " ";
|
||||
std::cout << " [" + result + "]" << std::endl;
|
||||
if (verbose)
|
||||
{
|
||||
std::cout.setf(std::ios::left, std::ios::adjustfield);
|
||||
std::cout << "Checking file: ";
|
||||
std::cout.width(longestName + 2);
|
||||
std::cout.fill('.');
|
||||
std::cout << filename + " ";
|
||||
std::cout << " [" + result + "]" << std::endl;
|
||||
}
|
||||
|
||||
return success;
|
||||
}
|
||||
@@ -162,4 +178,10 @@ std::string Asset::getTypeName(int type)
|
||||
return "ERROR";
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
// Establece si ha de mostrar texto por pantalla
|
||||
void Asset::setVerbose(bool value)
|
||||
{
|
||||
verbose = value;
|
||||
}
|
||||
@@ -34,9 +34,10 @@ private:
|
||||
};
|
||||
|
||||
// Variables
|
||||
int longestName; // Contiene la longitud del nombre de fichero mas largo
|
||||
std::vector<item_t> fileList;
|
||||
std::string executablePath;
|
||||
int longestName; // Contiene la longitud del nombre de fichero mas largo
|
||||
std::vector<item_t> fileList; // Listado con todas las rutas a los ficheros
|
||||
std::string executablePath; // Ruta al ejecutable
|
||||
bool verbose; // Indica si ha de mostrar información por pantalla
|
||||
|
||||
// Comprueba que existe un fichero
|
||||
bool checkFile(std::string path);
|
||||
@@ -56,6 +57,9 @@ public:
|
||||
|
||||
// Comprueba que existen todos los elementos
|
||||
bool check();
|
||||
|
||||
// Establece si ha de mostrar texto por pantalla
|
||||
void setVerbose(bool value);
|
||||
};
|
||||
|
||||
#endif
|
||||
|
||||
@@ -18,17 +18,19 @@ Input::Input(std::string file)
|
||||
gcb.active = false;
|
||||
gameControllerBindings.resize(17, gcb);
|
||||
|
||||
verbose = true;
|
||||
|
||||
// Comprueba si hay un mando conectado
|
||||
discoverGameController();
|
||||
}
|
||||
|
||||
// Asigna uno de los posibles inputs a una tecla del teclado
|
||||
// Asigna inputs a teclas
|
||||
void Input::bindKey(Uint8 input, SDL_Scancode code)
|
||||
{
|
||||
keyBindings.at(input).scancode = code;
|
||||
}
|
||||
|
||||
// Asigna uno de los posibles inputs a un botón del mando
|
||||
// Asigna inputs a botones del mando
|
||||
void Input::bindGameControllerButton(Uint8 input, SDL_GameControllerButton button)
|
||||
{
|
||||
gameControllerBindings.at(input).button = button;
|
||||
@@ -41,7 +43,9 @@ bool Input::checkInput(Uint8 input, bool repeat, int device, int index)
|
||||
bool successGameController = false;
|
||||
|
||||
if (device == INPUT_USE_ANY)
|
||||
{
|
||||
index = 0;
|
||||
}
|
||||
|
||||
if (device == INPUT_USE_KEYBOARD || device == INPUT_USE_ANY)
|
||||
{
|
||||
@@ -183,7 +187,10 @@ bool Input::discoverGameController()
|
||||
|
||||
if (SDL_GameControllerAddMappingsFromFile(dbPath.c_str()) < 0)
|
||||
{
|
||||
std::cout << "Error, could not load " << dbPath.c_str() << " file: " << SDL_GetError() << std::endl;
|
||||
if (verbose)
|
||||
{
|
||||
std::cout << "Error, could not load " << dbPath.c_str() << " file: " << SDL_GetError() << std::endl;
|
||||
}
|
||||
}
|
||||
|
||||
const int nJoysticks = SDL_NumJoysticks();
|
||||
@@ -198,8 +205,11 @@ bool Input::discoverGameController()
|
||||
}
|
||||
}
|
||||
|
||||
std::cout << "\nChecking for game controllers...\n";
|
||||
std::cout << nJoysticks << " joysticks found, " << numGamepads << " are gamepads\n";
|
||||
if (verbose)
|
||||
{
|
||||
std::cout << "\nChecking for game controllers...\n";
|
||||
std::cout << nJoysticks << " joysticks found, " << numGamepads << " are gamepads\n";
|
||||
}
|
||||
|
||||
if (numGamepads > 0)
|
||||
{
|
||||
@@ -216,12 +226,18 @@ bool Input::discoverGameController()
|
||||
std::string name = SDL_GameControllerNameForIndex(i);
|
||||
name.resize(25);
|
||||
name = name + separator + std::to_string(i);
|
||||
std::cout << name << std::endl;
|
||||
if (verbose)
|
||||
{
|
||||
std::cout << name << std::endl;
|
||||
}
|
||||
controllerNames.push_back(name);
|
||||
}
|
||||
else
|
||||
{
|
||||
std::cout << "SDL_GetError() = " << SDL_GetError() << std::endl;
|
||||
if (verbose)
|
||||
{
|
||||
std::cout << "SDL_GetError() = " << SDL_GetError() << std::endl;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -261,4 +277,10 @@ std::string Input::getControllerName(int index)
|
||||
int Input::getNumControllers()
|
||||
{
|
||||
return numGamepads;
|
||||
}
|
||||
|
||||
// Establece si ha de mostrar mensajes
|
||||
void Input::setVerbose(bool value)
|
||||
{
|
||||
verbose = value;
|
||||
}
|
||||
@@ -49,7 +49,7 @@ private:
|
||||
};
|
||||
|
||||
// Objetos y punteros
|
||||
std::vector<SDL_GameController *> connectedControllers; // Vector con todos los mandos conectados
|
||||
std::vector<SDL_GameController *> connectedControllers; // Vector con todos los mandos conectados
|
||||
|
||||
// Variables
|
||||
std::vector<keyBindings_t> keyBindings; // Vector con las teclas asociadas a los inputs predefinidos
|
||||
@@ -57,6 +57,7 @@ private:
|
||||
std::vector<std::string> controllerNames; // Vector con los nombres de los mandos
|
||||
int numGamepads; // Numero de mandos conectados
|
||||
std::string dbPath; // Ruta al archivo gamecontrollerdb.txt
|
||||
bool verbose; // Indica si ha de mostrar mensajes
|
||||
|
||||
// Comprueba si hay un mando conectado
|
||||
bool discoverGameController();
|
||||
@@ -65,10 +66,10 @@ public:
|
||||
// Constructor
|
||||
Input(std::string file);
|
||||
|
||||
// Asigna uno de los posibles inputs a una tecla del teclado
|
||||
// Asigna inputs a teclas
|
||||
void bindKey(Uint8 input, SDL_Scancode code);
|
||||
|
||||
// Asigna uno de los posibles inputs a un botón del mando
|
||||
// Asigna inputs a botones del mando
|
||||
void bindGameControllerButton(Uint8 input, SDL_GameControllerButton button);
|
||||
|
||||
// Comprueba si un input esta activo
|
||||
@@ -85,6 +86,9 @@ public:
|
||||
|
||||
// Obten el nombre de un mando de juego
|
||||
std::string getControllerName(int index);
|
||||
|
||||
// Establece si ha de mostrar mensajes
|
||||
void setVerbose(bool value);
|
||||
};
|
||||
|
||||
#endif
|
||||
|
||||
@@ -14,8 +14,11 @@ void Resource::loadTextures(std::vector<std::string> list)
|
||||
{
|
||||
for (auto l : list)
|
||||
{
|
||||
std::cout << "\nLOAD TEXTURE: " << l << std::endl;
|
||||
std::cout << "png: " << asset->get(l) << std::endl;
|
||||
if (options->console)
|
||||
{
|
||||
std::cout << "\nLOAD TEXTURE: " << l << std::endl;
|
||||
std::cout << "png: " << asset->get(l) << std::endl;
|
||||
}
|
||||
|
||||
res_texture_t t;
|
||||
t.name = l;
|
||||
@@ -33,9 +36,12 @@ void Resource::loadAnimations(std::vector<std::string> list)
|
||||
const size_t lastIndex = l.find_last_of(".");
|
||||
const std::string pngFile = l.substr(0, lastIndex) + ".png";
|
||||
|
||||
std::cout << "\nLOAD ANIMATION: " << l << std::endl;
|
||||
std::cout << "png: " << asset->get(pngFile) << std::endl;
|
||||
std::cout << "ani: " << asset->get(l) << std::endl;
|
||||
if (options->console)
|
||||
{
|
||||
std::cout << "\nLOAD ANIMATION: " << l << std::endl;
|
||||
std::cout << "png: " << asset->get(pngFile) << std::endl;
|
||||
std::cout << "ani: " << asset->get(l) << std::endl;
|
||||
}
|
||||
|
||||
res_animation_t as;
|
||||
as.name = l;
|
||||
@@ -196,7 +202,10 @@ Texture *Resource::getTexture(std::string name)
|
||||
}
|
||||
}
|
||||
|
||||
std::cout << "NOT FOUND ON CACHE: " << name << std::endl;
|
||||
if (options->console)
|
||||
{
|
||||
std::cout << "NOT FOUND ON CACHE: " << name << std::endl;
|
||||
}
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
@@ -214,7 +223,10 @@ animatedSprite_t *Resource::getAnimation(std::string name)
|
||||
}
|
||||
}
|
||||
|
||||
std::cout << "NOT FOUND ON CACHE: " << name << std::endl;
|
||||
if (options->console)
|
||||
{
|
||||
std::cout << "NOT FOUND ON CACHE: " << name << std::endl;
|
||||
}
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
@@ -230,7 +242,10 @@ textFile_t *Resource::getOffset(std::string name)
|
||||
}
|
||||
}
|
||||
|
||||
std::cout << "NOT FOUND ON CACHE: " << name << std::endl;
|
||||
if (options->console)
|
||||
{
|
||||
std::cout << "NOT FOUND ON CACHE: " << name << std::endl;
|
||||
}
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
@@ -246,7 +261,10 @@ std::vector<int> *Resource::getTileMap(std::string name)
|
||||
}
|
||||
}
|
||||
|
||||
std::cout << "NOT FOUND ON CACHE: " << name << std::endl;
|
||||
if (options->console)
|
||||
{
|
||||
std::cout << "NOT FOUND ON CACHE: " << name << std::endl;
|
||||
}
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
@@ -262,6 +280,9 @@ room_t *Resource::getRoom(std::string name)
|
||||
}
|
||||
}
|
||||
|
||||
std::cout << "NOT FOUND ON CACHE: " << name << std::endl;
|
||||
if (options->console)
|
||||
{
|
||||
std::cout << "NOT FOUND ON CACHE: " << name << std::endl;
|
||||
}
|
||||
return nullptr;
|
||||
}
|
||||
@@ -75,6 +75,8 @@ struct options_t
|
||||
bool borderEnabled; // Indica si ha de mostrar el borde en el modo de ventana
|
||||
float borderSize; // Porcentaje de borde que se añade a lo ventana
|
||||
palette_e palette; // Paleta de colores a usar en el juego
|
||||
bool console; // Indica si ha de mostrar información por la consola de texto
|
||||
bool infiniteLives; // Indica si el jugador dispone de vidas infinitas
|
||||
};
|
||||
|
||||
// Calcula el cuadrado de la distancia entre dos puntos
|
||||
|
||||
Reference in New Issue
Block a user