Browse Source

Move reading a json file into serial.cxx

Sam Jaffe 6 years ago
parent
commit
cdcfc4e3e5
3 changed files with 10 additions and 4 deletions
  1. 1 0
      engine/include/game/engine/serial.hpp
  2. 8 0
      engine/src/serial.cxx
  3. 1 4
      engine/src/text_engine.cxx

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

@@ -14,6 +14,7 @@
 #include "game/math/math_fwd.hpp"
 
 namespace engine {
+  Json::Value read_file(std::string const & abs_path);
   math::vec2 to_vec2(Json::Value const & json);
   math::vec2i to_vec2i(Json::Value const & json);
   math::vec2 to_vec2(Json::Value const & json, math::vec2 const & backup);

+ 8 - 0
engine/src/serial.cxx

@@ -8,7 +8,9 @@
 
 #include "game/engine/serial.hpp"
 
+#include <fstream>
 #include <json/json.h>
+#include <json/reader.h>
 
 #include "game/graphics/manager.hpp"
 #include "game/graphics/material.hpp"
@@ -17,6 +19,12 @@
 #include "vector/vector.hpp"
 
 namespace engine {
+  Json::Value read_file(std::string const & abs_path) {
+    Json::Value json;
+    std::ifstream(abs_path) >> json;
+    return json;
+  }
+
   math::vec2 to_vec2(Json::Value const & json) {
     return make_vector(json[0].asFloat(), json[1].asFloat());
   }

+ 1 - 4
engine/src/text_engine.cxx

@@ -26,10 +26,7 @@ Json::Value font_material(std::string const & font) {
 }
 
 Json::Value get_font_config(std::string const & font) {
-  Json::Value value;
-  std::string path = env::resource_file("data/images/fonts/" + font + ".json");
-  std::ifstream(path) >> value;
-  return value;
+  return read_file(env::resource_file("data/images/fonts/" + font + ".json"));
 }
 
 text_engine::text_engine(std::string const & font,