subgames.h 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101
  1. /*
  2. Minetest
  3. Copyright (C) 2013 celeron55, Perttu Ahola <celeron55@gmail.com>
  4. This program is free software; you can redistribute it and/or modify
  5. it under the terms of the GNU Lesser General Public License as published by
  6. the Free Software Foundation; either version 2.1 of the License, or
  7. (at your option) any later version.
  8. This program is distributed in the hope that it will be useful,
  9. but WITHOUT ANY WARRANTY; without even the implied warranty of
  10. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  11. GNU Lesser General Public License for more details.
  12. You should have received a copy of the GNU Lesser General Public License along
  13. with this program; if not, write to the Free Software Foundation, Inc.,
  14. 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
  15. */
  16. #pragma once
  17. #include <string>
  18. #include <set>
  19. #include <unordered_map>
  20. #include <vector>
  21. class Settings;
  22. struct SubgameSpec
  23. {
  24. std::string id;
  25. std::string title;
  26. std::string author;
  27. int release;
  28. std::string path;
  29. std::string gamemods_path;
  30. /**
  31. * Map from virtual path to mods path
  32. */
  33. std::unordered_map<std::string, std::string> addon_mods_paths;
  34. std::string menuicon_path;
  35. // For logging purposes
  36. std::vector<const char *> deprecation_msgs;
  37. SubgameSpec(const std::string &id = "", const std::string &path = "",
  38. const std::string &gamemods_path = "",
  39. const std::unordered_map<std::string, std::string> &addon_mods_paths = {},
  40. const std::string &title = "",
  41. const std::string &menuicon_path = "",
  42. const std::string &author = "", int release = 0) :
  43. id(id),
  44. title(title), author(author), release(release), path(path),
  45. gamemods_path(gamemods_path), addon_mods_paths(addon_mods_paths),
  46. menuicon_path(menuicon_path)
  47. {
  48. }
  49. bool isValid() const { return (!id.empty() && !path.empty()); }
  50. void checkAndLog() const;
  51. };
  52. SubgameSpec findSubgame(const std::string &id);
  53. SubgameSpec findWorldSubgame(const std::string &world_path);
  54. std::set<std::string> getAvailableGameIds();
  55. std::vector<SubgameSpec> getAvailableGames();
  56. // Get the list of paths to mods in the environment variable $MINETEST_MOD_PATH
  57. std::vector<std::string> getEnvModPaths();
  58. bool getWorldExists(const std::string &world_path);
  59. //! Try to get the displayed name of a world
  60. std::string getWorldName(const std::string &world_path, const std::string &default_name);
  61. std::string getWorldGameId(const std::string &world_path, bool can_be_legacy = false);
  62. struct WorldSpec
  63. {
  64. std::string path;
  65. std::string name;
  66. std::string gameid;
  67. WorldSpec(const std::string &path = "", const std::string &name = "",
  68. const std::string &gameid = "") :
  69. path(path),
  70. name(name), gameid(gameid)
  71. {
  72. }
  73. bool isValid() const
  74. {
  75. return (!name.empty() && !path.empty() && !gameid.empty());
  76. }
  77. };
  78. std::vector<WorldSpec> getAvailableWorlds();
  79. // loads the subgame's config and creates world directory
  80. // and world.mt if they don't exist
  81. void loadGameConfAndInitWorld(const std::string &path, const std::string &name,
  82. const SubgameSpec &gamespec, bool create_world);