💿🐜 Antkeeper source code https://antkeeper.com
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

128 lines
2.7 KiB

6 years ago
6 years ago
6 years ago
  1. /*
  2. * Copyright (C) 2017 Christopher J. Howard
  3. *
  4. * This file is part of Antkeeper Source Code.
  5. *
  6. * Antkeeper Source Code is free software: you can redistribute it and/or modify
  7. * it under the terms of the GNU General Public License as published by
  8. * the Free Software Foundation, either version 3 of the License, or
  9. * (at your option) any later version.
  10. *
  11. * Antkeeper Source Code is distributed in the hope that it will be useful,
  12. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  13. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  14. * GNU General Public License for more details.
  15. *
  16. * You should have received a copy of the GNU General Public License
  17. * along with Antkeeper Source Code. If not, see <http://www.gnu.org/licenses/>.
  18. */
  19. #include "loading-state.hpp"
  20. #include "../application.hpp"
  21. #include "splash-state.hpp"
  22. #include "title-state.hpp"
  23. LoadingState::LoadingState(Application* application):
  24. ApplicationState(application)
  25. {}
  26. LoadingState::~LoadingState()
  27. {}
  28. void LoadingState::enter()
  29. {
  30. bool failure = false;
  31. std::cout << "Loading controls... ";
  32. if (!application->loadControls())
  33. {
  34. std::cout << "failed" << std::endl;
  35. failure = true;
  36. }
  37. else
  38. {
  39. std::cout << "success" << std::endl;
  40. }
  41. std::cout << "Loading scene... ";
  42. if (!application->loadScene())
  43. {
  44. std::cout << "failed" << std::endl;
  45. failure = true;
  46. }
  47. else
  48. {
  49. std::cout << "success" << std::endl;
  50. }
  51. std::cout << "Loading models... ";
  52. if (!application->loadModels())
  53. {
  54. std::cout << "failed" << std::endl;
  55. failure = true;
  56. }
  57. else
  58. {
  59. std::cout << "success" << std::endl;
  60. }
  61. std::cout << "Loading game... ";
  62. if (!application->loadGame())
  63. {
  64. std::cout << "failed" << std::endl;
  65. failure = true;
  66. }
  67. else
  68. {
  69. std::cout << "success" << std::endl;
  70. }
  71. std::cout << "Loading UI... ";
  72. if (!application->loadUI())
  73. {
  74. std::cout << "failed" << std::endl;
  75. failure = true;
  76. }
  77. else
  78. {
  79. std::cout << "success" << std::endl;
  80. }
  81. if (failure)
  82. {
  83. application->close(EXIT_FAILURE);
  84. }
  85. application->splashBackgroundImage->setVisible(true);
  86. }
  87. void LoadingState::execute()
  88. {
  89. // Check for splash screen and title skip settings
  90. bool skipSplash = false;
  91. bool skipTitle = false;
  92. application->settings.get("skip_splash", &skipSplash);
  93. //application->settings.get("skip_title", &skipTitle);
  94. // Determine next state
  95. ApplicationState* nextState = application->splashState;
  96. if (skipSplash)
  97. {
  98. nextState = application->titleState;
  99. /*
  100. if (skipTitle)
  101. {
  102. nextState = application->mainMenuState;
  103. }
  104. */
  105. }
  106. // Change state
  107. application->changeState(nextState);
  108. }
  109. void LoadingState::exit()
  110. {
  111. application->splashBackgroundImage->setVisible(false);
  112. }