gunkiss/src/Item.cpp

128 lines
2.9 KiB
C++

/* _______________ ,-------------------------------------------------.
//`````````````\\ \ \
//~~~~~~~~~~~~~~~\\ \ by @ohsqueezy & @sleepin \
//=================\\ \ [ohsqueezy.itch.io] [sleepin.itch.io] \
// \\ \ \
// \\ \ zlib licensed code at [git.nugget.fun/pudding] \
// ☆ GUNKISS ☆ \\ \ \
//_________________________\\ `-------------------------------------------------*/
#include "Item.hpp"
Item::Item() {};
void Item::text_property(const std::string& value, std::string& property, const std::string& property_name)
{
if (property == "")
{
if (value != "")
{
property = value;
sb::Log::log("set " + property_name + " to " + property + " in " + full_name());
}
else
{
sb::Log::log("empty string passed, not setting " + property_name + " in " + full_name(), sb::Log::DEBUG);
}
}
else
{
sb::Log::log(property_name + " already set to " + property + " in " + full_name() + ", not setting", sb::Log::DEBUG);
}
}
void Item::brand_name(const std::string& name)
{
text_property(name, item_brand_name, "brand name");
}
const std::string& Item::brand_name() const
{
return item_brand_name;
}
void Item::product_name(const std::string& name)
{
text_property(name, item_product_name, "product name");
}
const std::string& Item::product_name() const
{
return item_product_name;
}
void Item::upc(const std::string& upc)
{
text_property(upc, item_upc, "UPC");
}
const std::string& Item::upc() const
{
return item_upc;
}
std::string Item::full_name() const
{
std::string name = brand_name();
if (name != "")
{
name += " ";
}
name += product_name();
return name;
}
void Item::texture(sb::Texture& texture, const std::string& name)
{
item_view.texture(texture, name);
}
sb::Texture& Item::current_texture()
{
return carousel.current(item_view.textures())->second;
}
void Item::next_texture()
{
carousel.next(item_view.textures());
}
void Item::previous_texture()
{
carousel.previous(item_view.textures());
}
std::size_t Item::texture_count()
{
return item_view.textures().size();
}
Plane& Item::view()
{
return item_view;
}
/* Return true if the current texture is the first texture added. */
bool Item::at_first() const
{
return carousel.at_beginning();
}
/* Return true if the current texture is the last texture added. */
bool Item::at_last()
{
return carousel.at_end(item_view.textures());
}
/* Set current texture to the first texture added. */
void Item::to_first()
{
carousel.beginning();
}
/* Set texture to the last texture added. */
void Item::to_last()
{
carousel.end(item_view.textures());
}