#include "Item.hpp" void Item::set_text_property(const std::string& value, std::string& property, const std::string& property_name) { if (property == "") { if (value != "") { property = value; SDL_Log("set %s to %s in %s", property_name.c_str(), property.c_str(), get_full_name().c_str()); } else { SDL_LogDebug(SDL_LOG_CATEGORY_APPLICATION, "empty string passed, not setting %s in %s", property_name.c_str(), get_full_name().c_str()); } } else { SDL_LogDebug(SDL_LOG_CATEGORY_APPLICATION, "%s already set to %s in %s, not setting", property_name.c_str(), property.c_str(), get_full_name().c_str()); } } void Item::destroy_texture(SDL_Texture* texture) { SDL_LogDebug(SDL_LOG_CATEGORY_APPLICATION, "destroying texture %p", texture); SDL_DestroyTexture(texture); } void Item::add_image_texture(SDL_Texture* texture) { image_textures.push_back(std::shared_ptr(texture, Item::destroy_texture)); } const std::vector>& Item::get_image_textures() const { return image_textures; } const std::shared_ptr& Item::get_active_image_texture() const { return get_image_textures()[current_image_index]; } void Item::set_brand_name(const std::string& name) { set_text_property(name, brand_name, "brand name"); } const std::string& Item::get_brand_name() const { return brand_name; } void Item::set_product_name(const std::string& name) { set_text_property(name, product_name, "product name"); } const std::string& Item::get_product_name() const { return product_name; } void Item::set_upc(const std::string& upc) { set_text_property(upc, this->upc, "UPC"); } const std::string& Item::get_upc() const { return upc; } std::string Item::get_full_name() const { std::string name = get_brand_name(); if (name != "") { name += " "; } name += get_product_name(); return name; } void Item::increment_image_index(int increment) { current_image_index = sfw::mod(current_image_index + increment, static_cast(get_image_textures().size())); } Item::~Item() { SDL_LogDebug(SDL_LOG_CATEGORY_APPLICATION, "destroying item %p", this); }