#ifndef LLMR_STYLE_SPRITE #define LLMR_STYLE_SPRITE #include #include #include #include #include #include namespace llmr { class Map; class SpritePosition { public: SpritePosition(uint16_t x, uint16_t y, uint16_t width, uint16_t height, uint8_t pixelRatio = 1); uint16_t x = 0, y = 0; uint16_t width = 0, height = 0; uint8_t pixelRatio = 1; }; class ImagePosition { public: ImagePosition() {} ImagePosition(const vec2& size, vec2 tl, vec2 br); vec2 size = { 0, 0 }; vec2 tl = { 0, 0 }; vec2 br = { 0, 0 }; }; class Sprite : public std::enable_shared_from_this { public: Sprite(Map &map, float pixelRatio = 1); void load(const std::string& base_url); ImagePosition getPosition(const std::string& name, bool repeating = false); bool isLoaded() const; public: const float pixelRatio; std::shared_ptr raster; private: void asyncParseJSON(); void asyncParseImage(); static void parseJSON(std::shared_ptr &sprite); static void parseImage(std::shared_ptr &sprite); static void complete(std::shared_ptr &sprite); private: Map ↦ mutable std::mutex mtx; std::string body; bool loaded = false; std::map pos; }; } #endif