mirror of
https://github.com/zhenyan121/Cubed.git
synced 2026-06-18 00:27:02 +08:00
feat: block switching (#2)
* feat: add item tab item in dev panel * feat: add block switching via mouse wheel
This commit is contained in:
@@ -6,21 +6,26 @@
|
||||
|
||||
namespace Cubed {
|
||||
|
||||
std::unordered_map<unsigned, std::string> MapTable::id_to_name_map;
|
||||
std::unordered_map<size_t, unsigned> MapTable::name_to_id_map;
|
||||
|
||||
const std::string& MapTable::get_name_from_id(unsigned id) {
|
||||
std::string_view MapTable::get_name_from_id(unsigned id) {
|
||||
auto it = id_to_name_map.find(id);
|
||||
ASSERT_MSG(it != id_to_name_map.end(),
|
||||
"Id: " + std::to_string(id) + " is not exist");
|
||||
return it->second;
|
||||
}
|
||||
|
||||
unsigned MapTable::get_id_from_name(const std::string& name) {
|
||||
auto it = name_to_id_map.find(HASH::str(name));
|
||||
ASSERT_MSG(it != name_to_id_map.end(), "Name " + name + " is not exist");
|
||||
return it->second;
|
||||
}
|
||||
|
||||
std::string_view MapTable::item_name(unsigned id) {
|
||||
ASSERT_MSG(id < item_id_to_name.size(), "ID is invalid");
|
||||
return item_id_to_name[id];
|
||||
}
|
||||
|
||||
const std::vector<std::string>& MapTable::item_map() { return item_id_to_name; }
|
||||
|
||||
void MapTable::init_map() {
|
||||
id_to_name_map.reserve(MAX_BLOCK_NUM);
|
||||
name_to_id_map.reserve(MAX_BLOCK_NUM);
|
||||
@@ -29,6 +34,9 @@ void MapTable::init_map() {
|
||||
id_to_name_map[i] = BLOCK_REISTER[i];
|
||||
name_to_id_map[HASH::str(BLOCK_REISTER[i])] = i;
|
||||
}
|
||||
for (auto s : BLOCK_REISTER) {
|
||||
item_id_to_name.emplace_back(s);
|
||||
}
|
||||
}
|
||||
|
||||
} // namespace Cubed
|
||||
|
||||
Reference in New Issue
Block a user