summaryrefslogtreecommitdiffstats
path: root/game/shared/world/item_registry.hh
blob: 7508f2aeac1feba7c5cb49d33a9a652d09ffb339 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
#ifndef SHARED_ITEM_REGISTRY_HH
#define SHARED_ITEM_REGISTRY_HH 1
#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
{
struct ItemInfo final {
    std::string name;
    std::string texture;
    voxel_id place_voxel;

    resource_ptr<TextureGUI> cached_texture; // Client-side only
};
} // namespace world

namespace world
{
class ItemInfoBuilder final {
public:
    explicit ItemInfoBuilder(std::string_view name);
    virtual ~ItemInfoBuilder(void) = default;

public:
    ItemInfoBuilder& set_texture(std::string_view texture);
    ItemInfoBuilder& set_place_voxel(voxel_id place_voxel);

public:
    item_id build(void) const;

private:
    ItemInfo prototype;
};
} // namespace world

namespace world::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 world::item_registry

namespace world::item_registry
{
ItemInfoBuilder& construct(std::string_view name);
ItemInfo* find(std::string_view name);
ItemInfo* find(const item_id item);
} // namespace world::item_registry

namespace world::item_registry
{
void purge(void);
} // namespace world::item_registry

namespace world::item_registry
{
std::uint64_t calculate_checksum(void);
} // namespace world::item_registry

#endif // SHARED_ITEM_REGISTRY_HH