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:
2026-08-04 14:24:10 +08:00
parent 5e7c6ec891
commit 2358cfd9a4
16 changed files with 469 additions and 1 deletions

View 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

View 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