world.cxx 1.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142
  1. //
  2. // world.cxx
  3. // danmaku
  4. //
  5. // Created by Sam Jaffe on 5/27/19.
  6. // Copyright © 2019 Sam Jaffe. All rights reserved.
  7. //
  8. #include "danmaku/world.hpp"
  9. #include <json/json.h>
  10. #include "danmaku/level.hpp"
  11. #include "danmaku/player.hpp"
  12. #include "danmaku/serial.hpp"
  13. #include "game/util/env.hpp"
  14. using namespace danmaku;
  15. Json::Value player_json(std::string const & player_file) {
  16. return engine::read_file(env::resource_file("scripts/player/" + player_file));
  17. }
  18. std::shared_ptr<level>
  19. level_from_path(Json::Value const & json, std::string const & path,
  20. std::shared_ptr<engine::game_dispatch> game) {
  21. Json::Value level_json =
  22. engine::read_file(path + "/" + json["path"].asString() + "/level.json");
  23. return std::make_shared<level>(json["name"].asString(), level_json, game);
  24. }
  25. world::world(std::string const & player_file, std::string const & path,
  26. Json::Value const & json,
  27. std::shared_ptr<engine::game_dispatch> game)
  28. : engine::scene("world", game),
  29. player_(to_player(player_json(player_file), graphics_manager())),
  30. levels_(to_vector(json["levels"], level_from_path, path, game)) {}
  31. world::~world() {}
  32. // to_vector(Json::Value const &, ...)
  33. #include "danmaku/serial.tpp"