Browse Source

Move object load to own function

Sam Jaffe 6 years ago
parent
commit
27f2081d8d
1 changed files with 12 additions and 3 deletions
  1. 12 3
      engine/src/entity.cxx

+ 12 - 3
engine/src/entity.cxx

@@ -36,14 +36,23 @@ static flyweight<graphics::material> to_material(Json::Value const & json) {
                                     json["texture"]["uniform"].asString());
 }
 
+static graphics::object to_object(Json::Value const & json) {
+  flyweight<graphics::material> mat = to_material(json["material"]);
+  auto frame_size = to_vec2(json["frameSize"]);
+  return {{to_vec2(json["position"]), mat.actual().size() * frame_size},
+          {},
+          mat,
+          {{}, frame_size}};
+}
+
 entity::entity(Json::Value const & json)
     : identity<entity>(next_id()), in_scene(), last_position({-1, -1}),
       velocity(to_vec2(json["velocity"])), acceleration(),
-      angular_velocity(0.f),
-      render_info({{}, {}, to_material(json["material"]), {}}), frame_index(0),
+      angular_velocity(0.f), render_info(to_object(json)), frame_index(0),
       frame_texture_coords({make_vector(0.f, 0.f)}),
       scale(json["size"].asFloat()), collides_with(0), collides_as(0) {
-  render_info.location.origin = to_vec2(json["position"]);
+  render_info.location.size *= scale;
+  render_info.frame.origin = frame_texture_coords[frame_index];
 }
 
 void entity::update(tick const & tk) {