diff options
| author | untodesu <kirill@untode.su> | 2025-09-12 14:09:34 +0500 |
|---|---|---|
| committer | untodesu <kirill@untode.su> | 2025-09-12 14:09:34 +0500 |
| commit | 73cbcdd6e8c849e32abbf9757e603e6a6654e870 (patch) | |
| tree | 136e1aef82a25c31552b8990952a7607cfd4708e /game/shared/world/item.hh | |
| parent | e9076f22fe2a49d1cd8933e54b7b00c5dd943269 (diff) | |
| download | voxelius-73cbcdd6e8c849e32abbf9757e603e6a6654e870.tar.bz2 voxelius-73cbcdd6e8c849e32abbf9757e603e6a6654e870.zip | |
Metaitems
Diffstat (limited to 'game/shared/world/item.hh')
| -rw-r--r-- | game/shared/world/item.hh | 84 |
1 files changed, 84 insertions, 0 deletions
diff --git a/game/shared/world/item.hh b/game/shared/world/item.hh new file mode 100644 index 0000000..ffa7f5c --- /dev/null +++ b/game/shared/world/item.hh @@ -0,0 +1,84 @@ +#pragma once + +#include "core/resource/resource.hh" + +#include "shared/types.hh" + +// This resource is only defined client-side and +// resource_ptr<TextureGUI> should remain set to null +// anywhere else in the shared and server code +struct TextureGUI; + +namespace world +{ +class Voxel; +} // namespace world + +namespace world +{ +class Item { +public: + Item(void) = default; + explicit Item(const Item& source, item_id id) noexcept; + + constexpr std::string_view get_name(void) const noexcept; + constexpr item_id get_id(void) const noexcept; + + constexpr std::string_view get_texture(void) const noexcept; + constexpr const Voxel* get_place_voxel(void) const noexcept; + + constexpr resource_ptr<TextureGUI>& get_cached_texture(void) const noexcept; + void set_cached_texture(resource_ptr<TextureGUI> texture) const noexcept; + + std::uint64_t get_checksum(std::uint64_t combine = 0U) const; + +protected: + std::string m_name; + item_id m_id { NULL_ITEM_ID }; + + std::string m_texture; + const Voxel* m_place_voxel { nullptr }; + + mutable resource_ptr<TextureGUI> m_cached_texture; // Client-side only +}; +} // namespace world + +namespace world +{ +class ItemBuilder final : public Item { +public: + explicit ItemBuilder(std::string_view name); + + void set_name(std::string_view name); + + void set_texture(std::string_view texture); + void set_place_voxel(const Voxel* place_voxel); + + std::unique_ptr<Item> build(item_id id) const; +}; +} // namespace world + +constexpr std::string_view world::Item::get_name(void) const noexcept +{ + return m_name; +} + +constexpr item_id world::Item::get_id(void) const noexcept +{ + return m_id; +} + +constexpr std::string_view world::Item::get_texture(void) const noexcept +{ + return m_texture; +} + +constexpr const world::Voxel* world::Item::get_place_voxel(void) const noexcept +{ + return m_place_voxel; +} + +constexpr resource_ptr<TextureGUI>& world::Item::get_cached_texture(void) const noexcept +{ + return m_cached_texture; +} |
