serial.cxx 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344
  1. //
  2. // serial.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/serial.hpp"
  9. #include <json/json.h>
  10. #include "danmaku/actor.hpp"
  11. #include "danmaku/bullet_pattern.hpp"
  12. #include "danmaku/enemy.hpp"
  13. #include "danmaku/player.hpp"
  14. #include "resource_factory/prototype_factory.hpp"
  15. namespace danmaku {
  16. std::unique_ptr<actor> to_actor(Json::Value const & json,
  17. graphics::manager const & mgr) {
  18. auto & bp_factory = bullet_pattern_factory::instance();
  19. auto get_attack = [&](Json::Value const & j, actor * a) {
  20. return bp_factory.get(j["id"].asString(), std::move(a), j, mgr);
  21. };
  22. return actor_factory::instance().get(json["type"].asString(), json,
  23. engine::to_object(json, mgr),
  24. get_attack);
  25. }
  26. std::unique_ptr<player> to_player(Json::Value const & json,
  27. graphics::manager const & mgr) {
  28. auto & bp_factory = bullet_pattern_factory::instance();
  29. auto get_attack = [&](Json::Value const & j, actor * a) {
  30. return bp_factory.get(j["id"].asString(), std::move(a), j, mgr);
  31. };
  32. return std::make_unique<player>(json, engine::to_object(json, mgr),
  33. get_attack);
  34. }
  35. points_map to_points_map(Json::Value const & json) {
  36. return {json["damage"].asInt(), json["kill"].asInt()};
  37. }
  38. }