ソースを参照

Add default behavior for to_vec

Sam Jaffe 6 年 前
コミット
987604d7b1
2 ファイル変更6 行追加1 行削除
  1. 1 0
      engine/include/game/engine/serial.hpp
  2. 5 1
      engine/src/serial.cxx

+ 1 - 0
engine/include/game/engine/serial.hpp

@@ -20,5 +20,6 @@ namespace graphics {
 
 namespace engine {
   math::vec2 to_vec2(Json::Value const & json);
+  math::vec2 to_vec2(Json::Value const & json, math::vec2 const & backup);
   graphics::object to_object(Json::Value const & json);
 }

+ 5 - 1
engine/src/serial.cxx

@@ -20,6 +20,10 @@ namespace engine {
     return make_vector(json[0].asFloat(), json[1].asFloat());
   }
 
+  math::vec2 to_vec2(Json::Value const & json, math::vec2 const & backup) {
+    return json.isNull() ? backup : to_vec2(json);
+  }
+
   flyweight<graphics::shader_program> to_program(Json::Value const & json) {
     return graphics::shader_program::create(json["fragmentShader"].asString(),
                                             json["vertexShader"].asString());
@@ -33,7 +37,7 @@ namespace engine {
 
   graphics::object to_object(Json::Value const & json) {
     flyweight<graphics::material> mat = to_material(json["material"]);
-    auto frame_size = to_vec2(json["frameSize"]);
+    auto frame_size = to_vec2(json["frameSize"], make_vector(1.f, 1.f));
     math::dim2::rectangle pos = {to_vec2(json["position"]),
                                  mat.actual().size() * frame_size};
     return {pos, pos, mat, {{{0, 0}}, frame_size}};