summaryrefslogtreecommitdiffstats
path: root/game/shared/item_registry.hh
diff options
context:
space:
mode:
authoruntodesu <kirill@untode.su>2025-03-15 16:22:09 +0500
committeruntodesu <kirill@untode.su>2025-03-15 16:22:09 +0500
commit3bf42c6ff3805a0d42bbc661794a95ff31bedc26 (patch)
tree05049955847504808d6bed2bb7b155f8b03807bb /game/shared/item_registry.hh
parent02294547dcde0d4ad76e229106702261e9f10a51 (diff)
downloadvoxelius-3bf42c6ff3805a0d42bbc661794a95ff31bedc26.tar.bz2
voxelius-3bf42c6ff3805a0d42bbc661794a95ff31bedc26.zip
Add whatever I was working on for the last month
Diffstat (limited to 'game/shared/item_registry.hh')
-rw-r--r--game/shared/item_registry.hh57
1 files changed, 57 insertions, 0 deletions
diff --git a/game/shared/item_registry.hh b/game/shared/item_registry.hh
new file mode 100644
index 0000000..7160b0b
--- /dev/null
+++ b/game/shared/item_registry.hh
@@ -0,0 +1,57 @@
+#ifndef SHARED_ITEM_REGISTRY_HH
+#define SHARED_ITEM_REGISTRY_HH 1
+#pragma once
+
+#include "core/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;
+
+struct ItemInfo final {
+ std::string name;
+ std::string texture;
+ voxel_id place_voxel;
+
+ resource_ptr<TextureGUI> cached_texture; // Client-side only
+};
+
+class ItemInfoBuilder final {
+public:
+ explicit ItemInfoBuilder(const char *name);
+ virtual ~ItemInfoBuilder(void) = default;
+
+public:
+ ItemInfoBuilder &set_texture(const char *texture);
+ ItemInfoBuilder &set_place_voxel(voxel_id place_voxel);
+
+public:
+ item_id build(void) const;
+
+private:
+ ItemInfo prototype;
+};
+
+namespace item_registry
+{
+extern std::unordered_map<std::string, ItemInfoBuilder> builders;
+extern std::unordered_map<std::string, item_id> names;
+extern std::vector<std::shared_ptr<ItemInfo>> items;
+} // namespace item_registry
+
+namespace item_registry
+{
+ItemInfoBuilder &construct(const char *name);
+ItemInfo *find(const char *name);
+ItemInfo *find(const item_id item);
+} // namespace item_registry
+
+namespace item_registry
+{
+void purge(void);
+} // namespace item_registry
+
+#endif /* SHARED_ITEM_REGISTRY_HH */