mirror of
https://github.com/zhenyan121/Cubed.git
synced 2026-08-09 02:07:04 +08:00
refactor(localization): switch block translations to item naming
Remove the `name_key` field from block definitions and use item-based localization keys (`item.*.name`) for inventory display. Item data now stores the localized name at load time.
This commit is contained in:
@@ -8,5 +8,4 @@ is_passable = true
|
||||
is_transitional = false
|
||||
is_transparent = true
|
||||
name = 'air'
|
||||
name_key = 'block.air'
|
||||
roughness = 1.0
|
||||
@@ -8,5 +8,4 @@ is_passable = false
|
||||
is_transitional = true
|
||||
is_transparent = false
|
||||
name = 'dirt'
|
||||
name_key = 'block.dirt'
|
||||
roughness = 1.0
|
||||
@@ -8,5 +8,4 @@ is_passable = true
|
||||
is_transitional = false
|
||||
is_transparent = true
|
||||
name = 'grass'
|
||||
name_key = 'block.grass'
|
||||
roughness = 0.90000000000000002
|
||||
@@ -8,5 +8,4 @@ is_passable = false
|
||||
is_transitional = true
|
||||
is_transparent = false
|
||||
name = 'grass_block'
|
||||
name_key = 'block.grass_block'
|
||||
roughness = 0.90000000000000002
|
||||
@@ -8,5 +8,4 @@ is_passable = false
|
||||
is_transitional = false
|
||||
is_transparent = true
|
||||
name = 'leaf'
|
||||
name_key = 'block.leaf'
|
||||
roughness = 0.69999999999999996
|
||||
@@ -8,5 +8,4 @@ is_passable = false
|
||||
is_transitional = false
|
||||
is_transparent = false
|
||||
name = 'log'
|
||||
name_key = 'block.log'
|
||||
roughness = 0.69999999999999996
|
||||
@@ -8,5 +8,4 @@ is_passable = false
|
||||
is_transitional = true
|
||||
is_transparent = false
|
||||
name = 'sand'
|
||||
name_key = 'block.sand'
|
||||
roughness = 0.80000000000000004
|
||||
@@ -8,5 +8,4 @@ is_passable = false
|
||||
is_transitional = true
|
||||
is_transparent = false
|
||||
name = 'snowy_grass_block'
|
||||
name_key = 'block.snowy_grass_block'
|
||||
roughness = 0.90000000000000002
|
||||
@@ -8,5 +8,4 @@ is_passable = false
|
||||
is_transitional = true
|
||||
is_transparent = false
|
||||
name = 'stone'
|
||||
name_key = 'block.stone'
|
||||
roughness = 0.75
|
||||
@@ -9,4 +9,3 @@ is_discard = false
|
||||
is_blend = false
|
||||
is_transitional = false
|
||||
roughness = 1.0
|
||||
name_key = "block.template"
|
||||
|
||||
@@ -8,5 +8,4 @@ is_passable = true
|
||||
is_transitional = false
|
||||
is_transparent = true
|
||||
name = 'water'
|
||||
name_key = 'block.water'
|
||||
roughness = 0.02
|
||||
@@ -36,14 +36,15 @@
|
||||
"joingame.server_ip": "Server Ip",
|
||||
"joingame.join_world": "Join World",
|
||||
"error.disable_voice": "Server Disable Voice Chat",
|
||||
"block.air": "air",
|
||||
"block.dirt": "dirt",
|
||||
"block.grass_block": "grass block",
|
||||
"block.grass": "grass",
|
||||
"block.leaf": "leaf",
|
||||
"block.log": "log",
|
||||
"block.sand": "sand",
|
||||
"block.snowy_grass_block": "snowy grass block",
|
||||
"block.stone": "stone",
|
||||
"block.water": "water"
|
||||
"item.air.name": "air",
|
||||
"item.dirt.name": "dirt",
|
||||
"item.grass_block.name": "grass block",
|
||||
"item.grass.name": "grass",
|
||||
"item.leaf.name": "leaf",
|
||||
"item.log.name": "log",
|
||||
"item.sand.name": "sand",
|
||||
"item.snowy_grass_block.name": "snowy grass block",
|
||||
"item.stone.name": "stone",
|
||||
"item.water.name": "water",
|
||||
"item.pig_spawn_egg.name": "pig spawn egg"
|
||||
}
|
||||
@@ -36,14 +36,15 @@
|
||||
"joingame.server_ip": "服务器IP",
|
||||
"joingame.join_world": "加入世界",
|
||||
"error.disable_voice": "服务器已禁用语音聊天",
|
||||
"block.air": "空气",
|
||||
"block.dirt": "泥土",
|
||||
"block.grass_block": "草方块",
|
||||
"block.grass": "草",
|
||||
"block.leaf": "树叶",
|
||||
"block.log": "原木",
|
||||
"block.sand": "沙子",
|
||||
"block.snowy_grass_block": "覆雪草方块",
|
||||
"block.stone": "石头",
|
||||
"block.water": "水"
|
||||
"item.air.name": "空气",
|
||||
"item.dirt.name": "泥土",
|
||||
"item.grass_block.name": "草方块",
|
||||
"item.grass.name": "草",
|
||||
"item.leaf.name": "树叶",
|
||||
"item.log.name": "原木",
|
||||
"item.sand.name": "沙子",
|
||||
"item.snowy_grass_block.name": "覆雪草方块",
|
||||
"item.stone.name": "石头",
|
||||
"item.water.name": "水",
|
||||
"item.pig_spawn_egg.name": "猪猪刷怪蛋"
|
||||
}
|
||||
@@ -42,7 +42,6 @@ struct LookBlock {
|
||||
|
||||
struct BlockData {
|
||||
std::string name;
|
||||
std::string name_key;
|
||||
BlockType id = 0;
|
||||
|
||||
bool is_liquid = false;
|
||||
@@ -56,17 +55,14 @@ struct BlockData {
|
||||
bool is_blend = false;
|
||||
bool is_transitional = false;
|
||||
float roughness = 1.0f;
|
||||
BlockData(std::string_view b_name, std::string_view name_k, BlockType b_id,
|
||||
bool liquid, bool passable, bool cross_plane, bool transparent,
|
||||
bool gas, bool discard, bool blend, bool transitional, float r)
|
||||
: name(b_name), name_key(name_k), id(b_id), is_liquid(liquid),
|
||||
is_gas(gas), is_passable(passable), is_cross_plane(cross_plane),
|
||||
BlockData(std::string_view b_name, BlockType b_id, bool liquid,
|
||||
bool passable, bool cross_plane, bool transparent, bool gas,
|
||||
bool discard, bool blend, bool transitional, float r)
|
||||
: name(b_name), id(b_id), is_liquid(liquid), is_gas(gas),
|
||||
is_passable(passable), is_cross_plane(cross_plane),
|
||||
is_transparent(transparent), is_discard(discard), is_blend(blend),
|
||||
is_transitional(transitional), roughness(r) {}
|
||||
BlockData() {
|
||||
name = "";
|
||||
name_key = "";
|
||||
}
|
||||
BlockData() { name = ""; }
|
||||
};
|
||||
|
||||
} // namespace Cubed
|
||||
@@ -11,7 +11,6 @@ public:
|
||||
static unsigned sums();
|
||||
static unsigned cross_plane_sum();
|
||||
static const std::string& name_form_id(BlockType id);
|
||||
static std::string local_name(BlockType id);
|
||||
static bool is_gas(BlockType id);
|
||||
static bool is_liquid(BlockType id);
|
||||
|
||||
|
||||
@@ -19,6 +19,7 @@ using ItemProperty = std::variant<BlockType, std::string>;
|
||||
struct ItemData {
|
||||
ItemID id = 0;
|
||||
std::string name;
|
||||
std::string local_name;
|
||||
std::string description;
|
||||
std::string path;
|
||||
ItemKind kind = ItemKind::NONE;
|
||||
|
||||
@@ -1,6 +1,5 @@
|
||||
#include "Cubed/gameplay/block_manager.hpp"
|
||||
|
||||
#include "Cubed/localization.hpp"
|
||||
#include "Cubed/tools/cubed_assert.hpp"
|
||||
#include "Cubed/tools/log.hpp"
|
||||
#include "Cubed/tools/toml.utils.hpp"
|
||||
@@ -36,14 +35,6 @@ const std::string& BlockManager::name_form_id(BlockType id) {
|
||||
}
|
||||
return c->second.name;
|
||||
}
|
||||
std::string BlockManager::local_name(BlockType id) {
|
||||
cacc c;
|
||||
if (!m_datas.find(c, id)) {
|
||||
ASSERT(false);
|
||||
return EMPTY.name_key;
|
||||
}
|
||||
return tr(c->second.name_key);
|
||||
}
|
||||
bool BlockManager::is_gas(BlockType id) {
|
||||
cacc c;
|
||||
if (!m_datas.find(c, id)) {
|
||||
@@ -160,12 +151,18 @@ void BlockManager::init() {
|
||||
auto is_blend = safe_get_value(block, "is_blend", false);
|
||||
auto is_transitional = safe_get_value(block, "is_transitional", false);
|
||||
auto roughness = safe_get_value(block, "roughness", 1.0);
|
||||
auto name_key = safe_get_value(block, "name_key", "Unknow_key");
|
||||
BlockData data{
|
||||
*name, *name_key, static_cast<BlockType>(*id),
|
||||
*is_liquid, *is_passable, *is_cross_plane,
|
||||
*is_transparent, *is_gas, *is_discard,
|
||||
*is_blend, *is_transitional, static_cast<float>(*roughness)};
|
||||
|
||||
BlockData data{*name,
|
||||
static_cast<BlockType>(*id),
|
||||
*is_liquid,
|
||||
*is_passable,
|
||||
*is_cross_plane,
|
||||
*is_transparent,
|
||||
*is_gas,
|
||||
*is_discard,
|
||||
*is_blend,
|
||||
*is_transitional,
|
||||
static_cast<float>(*roughness)};
|
||||
|
||||
if (!m_datas.emplace(static_cast<BlockType>(*id), std::move(data))) {
|
||||
Logger::error("Block Type {} already exist!", *id);
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
#include "Cubed/gameplay/item_manager.hpp"
|
||||
|
||||
#include "Cubed/gameplay/block_manager.hpp"
|
||||
#include "Cubed/localization.hpp"
|
||||
#include "Cubed/tools/cubed_assert.hpp"
|
||||
#include "Cubed/tools/log.hpp"
|
||||
|
||||
@@ -76,6 +77,7 @@ void ItemManager::add(const std::filesystem::path& path) {
|
||||
data.property = "cubed:pig";
|
||||
}
|
||||
}
|
||||
data.local_name = tr(std::format("item.{}.name", data.name));
|
||||
acc a;
|
||||
if (m_map.emplace(a, data.id, std::move(data))) {
|
||||
if (!m_id_map.emplace(a->second.name, a->first)) {
|
||||
|
||||
@@ -109,7 +109,7 @@ void InventoryUI::update_item_info() {
|
||||
|
||||
if (type != 0) {
|
||||
auto& data = ItemManager::get(type);
|
||||
m_item_info->set_text(data.name).set_visible(true);
|
||||
m_item_info->set_text(data.local_name).set_visible(true);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user