💿🐜 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.

101 lines
2.4 KiB

  1. /*
  2. * Copyright (C) 2023 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 "game/save.hpp"
  20. #include "application.hpp"
  21. #include "debug/log.hpp"
  22. #include "resources/json.hpp"
  23. #include <fstream>
  24. namespace game {
  25. namespace save {
  26. void colony(game::context& ctx)
  27. {
  28. std::filesystem::path path = ctx.saves_path / "colony.sav";
  29. const std::string path_string = path.string();
  30. debug::log::trace("Saving colony to \"{}\"...", path_string);
  31. try
  32. {
  33. // Construct JSON data describing the colony
  34. json data;
  35. auto& colony = data["colony"];
  36. {
  37. auto& species = colony["species"];
  38. {
  39. auto& morphology = species["morphology"];
  40. {
  41. }
  42. auto& diet = species["diet"];
  43. auto& aggression = species["aggression"];
  44. auto& nest = species["nest"];
  45. }
  46. auto& habitat = colony["habitat"];
  47. {
  48. auto& biome = habitat["biome"];
  49. auto& nest = habitat["nest"];
  50. {
  51. nest["entrance"] = {0, 0, 0};
  52. }
  53. }
  54. auto& members = colony["members"];
  55. members = json::array();
  56. {
  57. }
  58. }
  59. std::ofstream file(path);
  60. file << data;
  61. debug::log::trace("Saved colony to \"{}\"", path_string);
  62. }
  63. catch (...)
  64. {
  65. debug::log::error("Failed to save colony to \"{}\"", path_string);
  66. }
  67. }
  68. void config(game::context& ctx)
  69. {
  70. std::filesystem::path path = ctx.config_path / "config.json";
  71. const std::string path_string = path.string();
  72. debug::log::trace("Saving config to \"{}\"...", path_string);
  73. try
  74. {
  75. std::ofstream file(path);
  76. file << *(ctx.config);
  77. debug::log::trace("Saved config to \"{}\"", path_string);
  78. }
  79. catch (...)
  80. {
  81. debug::log::error("Failed to save config to \"{}\"", path_string);
  82. }
  83. }
  84. } // namespace save
  85. } // namespace game