System.cpp 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104
  1. /**
  2. * Copyright (c) 2006-2024 LOVE Development Team
  3. *
  4. * This software is provided 'as-is', without any express or implied
  5. * warranty. In no event will the authors be held liable for any damages
  6. * arising from the use of this software.
  7. *
  8. * Permission is granted to anyone to use this software for any purpose,
  9. * including commercial applications, and to alter it and redistribute it
  10. * freely, subject to the following restrictions:
  11. *
  12. * 1. The origin of this software must not be misrepresented; you must not
  13. * claim that you wrote the original software. If you use this software
  14. * in a product, an acknowledgment in the product documentation would be
  15. * appreciated but is not required.
  16. * 2. Altered source versions must be plainly marked as such, and must not be
  17. * misrepresented as being the original software.
  18. * 3. This notice may not be removed or altered from any source distribution.
  19. **/
  20. // LOVE
  21. #include "common/config.h"
  22. #include "System.h"
  23. #if defined(LOVE_IOS)
  24. #include "common/ios.h"
  25. #elif defined(LOVE_ANDROID)
  26. #include "common/android.h"
  27. #endif
  28. namespace love
  29. {
  30. namespace system
  31. {
  32. System::System(const char *name)
  33. : Module(M_SYSTEM, name)
  34. {
  35. }
  36. const char *System::getOS()
  37. {
  38. #if defined(LOVE_MACOS)
  39. return "OS X";
  40. #elif defined(LOVE_IOS)
  41. return "iOS";
  42. #elif defined(LOVE_WINDOWS_UWP)
  43. return "UWP";
  44. #elif defined(LOVE_WINDOWS)
  45. return "Windows";
  46. #elif defined(LOVE_ANDROID)
  47. return "Android";
  48. #elif defined(LOVE_LINUX)
  49. return "Linux";
  50. #else
  51. return "Unknown";
  52. #endif
  53. }
  54. void System::vibrate(double seconds) const
  55. {
  56. #ifdef LOVE_ANDROID
  57. love::android::vibrate(seconds);
  58. #elif defined(LOVE_IOS)
  59. love::ios::vibrate();
  60. #else
  61. LOVE_UNUSED(seconds);
  62. #endif
  63. }
  64. bool System::hasBackgroundMusic() const
  65. {
  66. #if defined(LOVE_ANDROID)
  67. return love::android::hasBackgroundMusic();
  68. #elif defined(LOVE_IOS)
  69. return love::ios::hasBackgroundMusic();
  70. #else
  71. return false;
  72. #endif
  73. }
  74. bool System::getConstant(const char *in, System::PowerState &out)
  75. {
  76. return powerStates.find(in, out);
  77. }
  78. bool System::getConstant(System::PowerState in, const char *&out)
  79. {
  80. return powerStates.find(in, out);
  81. }
  82. StringMap<System::PowerState, System::POWER_MAX_ENUM>::Entry System::powerEntries[] =
  83. {
  84. {"unknown", System::POWER_UNKNOWN},
  85. {"battery", System::POWER_BATTERY},
  86. {"nobattery", System::POWER_NO_BATTERY},
  87. {"charging", System::POWER_CHARGING},
  88. {"charged", System::POWER_CHARGED},
  89. };
  90. StringMap<System::PowerState, System::POWER_MAX_ENUM> System::powerStates(System::powerEntries, sizeof(System::powerEntries));
  91. } // system
  92. } // love