From 942924c65ccd08e405df3549e043cfe922c350fe Mon Sep 17 00:00:00 2001 From: Sergio Valor Date: Tue, 15 Oct 2024 18:24:19 +0200 Subject: [PATCH] Afegit codi per apagar el sistema al eixir del joc --- source/director.cpp | 27 ++++++++++++++++++++++++++- source/director.h | 3 +++ 2 files changed, 29 insertions(+), 1 deletion(-) diff --git a/source/director.cpp b/source/director.cpp index 264f7d1..c2d8722 100644 --- a/source/director.cpp +++ b/source/director.cpp @@ -8,6 +8,7 @@ #include // for SDL_SCANCODE_0, SDL_SCANCODE_DOWN #include // for SDL_bool, Uint32 #include // for SDL_GetTicks +#include // for system #include // for errno, EEXIST, EACCES, ENAMETOO... #include // for printf, perror #include // for strcmp @@ -411,7 +412,7 @@ bool Director::setFileList() Asset::get()->add(prefix + "/data/gfx/game/game_grass.png", AssetType::BITMAP); Asset::get()->add(prefix + "/data/gfx/game/game_power_meter.png", AssetType::BITMAP); Asset::get()->add(prefix + "/data/gfx/game/game_sky_colors.png", AssetType::BITMAP); - + Asset::get()->add(prefix + "/data/gfx/game_text/game_text_1000_points.png", AssetType::BITMAP); Asset::get()->add(prefix + "/data/gfx/game_text/game_text_2500_points.png", AssetType::BITMAP); Asset::get()->add(prefix + "/data/gfx/game_text/game_text_5000_points.png", AssetType::BITMAP); @@ -697,6 +698,12 @@ int Director::run() } } +#ifdef ARCADE + // Comprueba si ha de apagar el sistema + if (section::options == section::Options::QUIT_SHUTDOWN) + shutdownSystem(); +#endif + const int return_code = section::options == section::Options::QUIT_NORMAL ? 0 : 1; return return_code; } @@ -723,4 +730,22 @@ std::string Director::getLangFile(lang::Code code) } return Asset::get()->get("en_UK.txt"); +} + +// Apaga el sistema +void shutdownSystem() +{ +#ifdef _WIN32 + // Apaga el sistema en Windows + system("shutdown /s /t 0"); +#elif __APPLE__ + // Apaga el sistema en macOS + system("sudo shutdown -h now"); +#elif __linux__ + // Apaga el sistema en Linux + system("shutdown -h now"); +#else +// Sistema operativo no compatible +#error "Sistema operativo no soportado" +#endif } \ No newline at end of file diff --git a/source/director.h b/source/director.h index e0033d1..81449c4 100644 --- a/source/director.h +++ b/source/director.h @@ -76,6 +76,9 @@ private: // Obtiene una fichero a partir de un lang::Code std::string getLangFile(lang::Code code); + // Apaga el sistema + void shutdownSystem(); + public: // Constructor Director(int argc, const char *argv[]);