mirror of
https://github.com/zhenyan121/Cubed.git
synced 2026-08-08 17:57:02 +08:00
feat(item): add item manager with JSON asset loading
Implement ItemManager to load and query item definitions from assets/item JSON files. Add ItemData struct, item asset metadata, CMake source registration, and initialize the manager during app startup. Also add AGENTS.md repository guidelines.
This commit is contained in:
14
include/Cubed/gameplay/item.hpp
Normal file
14
include/Cubed/gameplay/item.hpp
Normal file
@@ -0,0 +1,14 @@
|
||||
#pragma once
|
||||
#include <cstdint>
|
||||
#include <string>
|
||||
namespace Cubed {
|
||||
using ItemID = uint16_t;
|
||||
|
||||
struct ItemData {
|
||||
ItemID id = 0;
|
||||
std::string name;
|
||||
std::string description;
|
||||
std::string path;
|
||||
};
|
||||
|
||||
} // namespace Cubed
|
||||
36
include/Cubed/gameplay/item_manager.hpp
Normal file
36
include/Cubed/gameplay/item_manager.hpp
Normal file
@@ -0,0 +1,36 @@
|
||||
#pragma once
|
||||
|
||||
#include "Cubed/gameplay/item.hpp"
|
||||
|
||||
#include <filesystem>
|
||||
#include <string_view>
|
||||
#include <tbb/concurrent_hash_map.h>
|
||||
namespace Cubed {
|
||||
class ItemManager {
|
||||
public:
|
||||
ItemManager();
|
||||
void init();
|
||||
static ItemManager& instance();
|
||||
|
||||
static const ItemData& get(std::string_view key);
|
||||
static const ItemData& get(ItemID id);
|
||||
|
||||
const ItemData& get_item_data(std::string_view key) const;
|
||||
const ItemData& get_item_data(ItemID id) const;
|
||||
|
||||
private:
|
||||
using ItemMap = tbb::concurrent_hash_map<ItemID, ItemData>;
|
||||
using acc = ItemMap::accessor;
|
||||
using cacc = ItemMap::const_accessor;
|
||||
|
||||
using IDMap = tbb::concurrent_hash_map<std::string_view, ItemID>;
|
||||
|
||||
void add(const std::filesystem::path& path);
|
||||
|
||||
ItemMap m_map;
|
||||
|
||||
IDMap m_id_map;
|
||||
|
||||
static constexpr ItemData EMPTY;
|
||||
};
|
||||
} // namespace Cubed
|
||||
Reference in New Issue
Block a user