From b29349d400674f4f2b84a5ee88cdea0b9e84638e Mon Sep 17 00:00:00 2001 From: Yann Herklotz Date: Thu, 21 Sep 2017 01:25:22 +0100 Subject: Added parser --- yage/base/spritesheet.cpp | 29 +++++++++++++++++++++++++---- yage/base/spritesheet.h | 4 ++++ 2 files changed, 29 insertions(+), 4 deletions(-) (limited to 'yage/base') diff --git a/yage/base/spritesheet.cpp b/yage/base/spritesheet.cpp index ed4055ab..748cdb5c 100644 --- a/yage/base/spritesheet.cpp +++ b/yage/base/spritesheet.cpp @@ -62,16 +62,20 @@ bool SpriteSheetHandler::Key(const char *str, rapidjson::SizeType length, bool) bool SpriteSheetHandler::StartObject() { - if(depth_ == 2) { - map_[current_key_] = Coordinate(); + depth_++; + + if(depth_ == 3) { + current_image_ = current_key_; } - depth_++; return true; } bool SpriteSheetHandler::EndObject(rapidjson::SizeType) { + if(depth_ == 3) { + map_[current_image_] = coord_; + } depth_--; return true; } @@ -86,12 +90,29 @@ bool SpriteSheetHandler::EndArray(rapidjson::SizeType) return true; } +SpriteMap SpriteSheetHandler::spriteMap() const +{ + return map_; +} + bool SpriteSheetHandler::handleNumber(int i) { if(current_key_ == "width") { if(depth_ == 1) { - + image_width_ = i; + } else { + coord_.width = i; + } + } else if(current_key_ == "height") { + if(depth_ == 1) { + image_height_ = i; + } else { + coord_.height = i; } + } else if(current_key_ == "x") { + coord_.x = i; + } else if(current_key_ == "y") { + coord_.y = i; } return true; } diff --git a/yage/base/spritesheet.h b/yage/base/spritesheet.h index 60c98840..bc60f8b9 100644 --- a/yage/base/spritesheet.h +++ b/yage/base/spritesheet.h @@ -61,7 +61,11 @@ public: private: std::string current_key_; + std::string current_image_; + Coordinate coord_; int depth_; + int image_width_; + int image_height_; SpriteMap map_; bool handleNumber(int i); -- cgit