mirror of
https://github.com/minetest-mods/craftguide.git
synced 2024-12-14 02:30:17 +01:00
[WIP] Use of lang_code
This commit is contained in:
parent
4b744e243c
commit
b6e1a4965e
61
init.lua
61
init.lua
@ -38,6 +38,7 @@ local slz, dslz = core.serialize, core.deserialize
|
|||||||
local on_mods_loaded = core.register_on_mods_loaded
|
local on_mods_loaded = core.register_on_mods_loaded
|
||||||
local on_leaveplayer = core.register_on_leaveplayer
|
local on_leaveplayer = core.register_on_leaveplayer
|
||||||
local get_player_info = core.get_player_information
|
local get_player_info = core.get_player_information
|
||||||
|
local get_translation = minetest.get_translated_string
|
||||||
local on_receive_fields = core.register_on_player_receive_fields
|
local on_receive_fields = core.register_on_player_receive_fields
|
||||||
|
|
||||||
local ESC = core.formspec_escape
|
local ESC = core.formspec_escape
|
||||||
@ -59,8 +60,6 @@ local min, max, floor, ceil = math.min, math.max, math.floor, math.ceil
|
|||||||
local pairs, next, type, tostring, unpack = pairs, next, type, tostring, unpack
|
local pairs, next, type, tostring, unpack = pairs, next, type, tostring, unpack
|
||||||
local vec_add, vec_mul = vector.add, vector.multiply
|
local vec_add, vec_mul = vector.add, vector.multiply
|
||||||
|
|
||||||
local FORMSPEC_MINIMAL_VERSION = 3
|
|
||||||
|
|
||||||
local ROWS = 9
|
local ROWS = 9
|
||||||
local LINES = sfinv_only and 5 or 10
|
local LINES = sfinv_only and 5 or 10
|
||||||
local IPP = ROWS * LINES
|
local IPP = ROWS * LINES
|
||||||
@ -106,9 +105,9 @@ local FMT = {
|
|||||||
arrow = "image_button[%f,%f;0.8,0.8;%s;%s;;;false;%s]",
|
arrow = "image_button[%f,%f;0.8,0.8;%s;%s;;;false;%s]",
|
||||||
}
|
}
|
||||||
|
|
||||||
local function get_fs_version(name)
|
local function get_lang_code(name)
|
||||||
local info = get_player_info(name)
|
local info = get_player_info(name)
|
||||||
return info and info.formspec_version or 1
|
return info and info.lang_code
|
||||||
end
|
end
|
||||||
|
|
||||||
local function outdated(name)
|
local function outdated(name)
|
||||||
@ -791,23 +790,29 @@ local function is_fav(data)
|
|||||||
return fav, i
|
return fav, i
|
||||||
end
|
end
|
||||||
|
|
||||||
local function check_newline(def)
|
local function desc_newline(def)
|
||||||
return def and def.description and find(def.description, "\n")
|
return def and def.description and find(def.description, "\n")
|
||||||
end
|
end
|
||||||
|
|
||||||
local function get_desc(name)
|
local function get_desc(item, data)
|
||||||
if sub(name, 1, 1) == "_" then
|
if sub(item, 1, 1) == "_" then
|
||||||
name = sub(name, 2)
|
item = sub(item, 2)
|
||||||
end
|
end
|
||||||
|
|
||||||
local def = reg_items[name]
|
local def = reg_items[item]
|
||||||
|
|
||||||
return def and (match(def.description, "%)([%w%s]*)") or def.description) or
|
if def then
|
||||||
(def and match(name, ":.*"):gsub("%W%l", upper):sub(2):gsub("_", " ") or
|
if true_str(def.description) then
|
||||||
S("Unknown Item (@1)", name))
|
return match(get_translation(data.lang_code, def.description), "[^\n]*")
|
||||||
|
elseif true_str(item) then
|
||||||
|
return match(item, ":.*"):gsub("%W%l", upper):sub(2):gsub("_", " ")
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
local function get_tooltip(name, info)
|
return S("Unknown Item (@1)", item)
|
||||||
|
end
|
||||||
|
|
||||||
|
local function get_tooltip(item, info)
|
||||||
local tooltip
|
local tooltip
|
||||||
|
|
||||||
if info.groups then
|
if info.groups then
|
||||||
@ -825,7 +830,7 @@ local function get_tooltip(name, info)
|
|||||||
tooltip = S("Any item belonging to the group(s): @1", groupstr)
|
tooltip = S("Any item belonging to the group(s): @1", groupstr)
|
||||||
end
|
end
|
||||||
else
|
else
|
||||||
tooltip = get_desc(name)
|
tooltip = get_desc(item, info.data)
|
||||||
end
|
end
|
||||||
|
|
||||||
local function add(str)
|
local function add(str)
|
||||||
@ -841,7 +846,7 @@ local function get_tooltip(name, info)
|
|||||||
end
|
end
|
||||||
|
|
||||||
if info.replace then
|
if info.replace then
|
||||||
local desc = clr("#ff0", get_desc(info.replace))
|
local desc = clr("#ff0", get_desc(info.replace, info.data))
|
||||||
|
|
||||||
if info.cooktime then
|
if info.cooktime then
|
||||||
tooltip = add(S("Replaced by @1 on smelting", desc))
|
tooltip = add(S("Replaced by @1 on smelting", desc))
|
||||||
@ -868,18 +873,18 @@ local function get_tooltip(name, info)
|
|||||||
if several then
|
if several then
|
||||||
for i = 1, #info.tools do
|
for i = 1, #info.tools do
|
||||||
names = fmt("%s\t\t- %s\n",
|
names = fmt("%s\t\t- %s\n",
|
||||||
names, clr("#ff0", get_desc(info.tools[i])))
|
names, clr("#ff0", get_desc(info.tools[i], info.data)))
|
||||||
end
|
end
|
||||||
|
|
||||||
tooltip = add(S("Only drop if using one of these tools: @1",
|
tooltip = add(S("Only drop if using one of these tools: @1",
|
||||||
sub(names, 1, -2)))
|
sub(names, 1, -2)))
|
||||||
else
|
else
|
||||||
tooltip = add(S("Only drop if using this tool: @1",
|
tooltip = add(S("Only drop if using this tool: @1",
|
||||||
clr("#ff0", get_desc(info.tools[1]))))
|
clr("#ff0", get_desc(info.tools[1], info.data))))
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
return fmt("tooltip[%s;%s]", name, ESC(tooltip))
|
return fmt("tooltip[%s;%s]", item, ESC(tooltip))
|
||||||
end
|
end
|
||||||
|
|
||||||
local function get_output_fs(data, fs, rcp, shapeless, right, btn_size, _btn_size, spacing)
|
local function get_output_fs(data, fs, rcp, shapeless, right, btn_size, _btn_size, spacing)
|
||||||
@ -936,11 +941,12 @@ local function get_output_fs(data, fs, rcp, shapeless, right, btn_size, _btn_siz
|
|||||||
|
|
||||||
local infos = {
|
local infos = {
|
||||||
unknown = not def or nil,
|
unknown = not def or nil,
|
||||||
|
weird_desc = not true_str(def.description) or desc_newline(def),
|
||||||
burntime = fuel_cache[name],
|
burntime = fuel_cache[name],
|
||||||
repair = repairable(name),
|
repair = repairable(name),
|
||||||
rarity = rcp.rarity,
|
rarity = rcp.rarity,
|
||||||
tools = rcp.tools,
|
tools = rcp.tools,
|
||||||
newline = check_newline(def),
|
data = data,
|
||||||
}
|
}
|
||||||
|
|
||||||
if next(infos) then
|
if next(infos) then
|
||||||
@ -1042,11 +1048,12 @@ local function get_grid_fs(data, fs, rcp, spacing)
|
|||||||
|
|
||||||
local infos = {
|
local infos = {
|
||||||
unknown = not def or nil,
|
unknown = not def or nil,
|
||||||
|
weird_desc = not true_str(def.description) or desc_newline(def),
|
||||||
groups = groups,
|
groups = groups,
|
||||||
burntime = fuel_cache[name],
|
burntime = fuel_cache[name],
|
||||||
cooktime = cooktime,
|
cooktime = cooktime,
|
||||||
replace = replace,
|
replace = replace,
|
||||||
newline = check_newline(def),
|
data = data,
|
||||||
}
|
}
|
||||||
|
|
||||||
if next(infos) then
|
if next(infos) then
|
||||||
@ -1112,7 +1119,7 @@ local function get_rcp_lbl(data, fs, panel, spacing, rn, is_recipe)
|
|||||||
end
|
end
|
||||||
|
|
||||||
local function get_title_fs(data, fs, spacing)
|
local function get_title_fs(data, fs, spacing)
|
||||||
local desc = ESC(get_desc(data.query_item))
|
local desc = ESC(get_desc(data.query_item, data))
|
||||||
desc = #desc > 33 and fmt("%s...", sub(desc, 1, 30)) or desc
|
desc = #desc > 33 and fmt("%s...", sub(desc, 1, 30)) or desc
|
||||||
local t_desc = data.query_item
|
local t_desc = data.query_item
|
||||||
t_desc = #t_desc > 40 and fmt("%s...", sub(t_desc, 1, 37)) or t_desc
|
t_desc = #t_desc > 40 and fmt("%s...", sub(t_desc, 1, 37)) or t_desc
|
||||||
@ -1577,7 +1584,7 @@ local function init_data(name)
|
|||||||
items = init_items,
|
items = init_items,
|
||||||
items_raw = init_items,
|
items_raw = init_items,
|
||||||
favs = {},
|
favs = {},
|
||||||
fs_version = get_fs_version(name),
|
lang_code = get_lang_code(name),
|
||||||
}
|
}
|
||||||
end
|
end
|
||||||
|
|
||||||
@ -1599,7 +1606,7 @@ on_joinplayer(function(player)
|
|||||||
local name = player:get_player_name()
|
local name = player:get_player_name()
|
||||||
init_data(name)
|
init_data(name)
|
||||||
|
|
||||||
if pdata[name].fs_version < FORMSPEC_MINIMAL_VERSION then
|
if not pdata[name].lang_code then
|
||||||
outdated(name)
|
outdated(name)
|
||||||
end
|
end
|
||||||
end)
|
end)
|
||||||
@ -1700,7 +1707,7 @@ if sfinv_only then
|
|||||||
|
|
||||||
is_in_nav = function(self, player, context)
|
is_in_nav = function(self, player, context)
|
||||||
local name = player:get_player_name()
|
local name = player:get_player_name()
|
||||||
return get_fs_version(name) >= FORMSPEC_MINIMAL_VERSION
|
return get_lang_code(name)
|
||||||
end,
|
end,
|
||||||
|
|
||||||
get = function(self, player, context)
|
get = function(self, player, context)
|
||||||
@ -1735,7 +1742,7 @@ else
|
|||||||
local name = user:get_player_name()
|
local name = user:get_player_name()
|
||||||
local data = pdata[name]
|
local data = pdata[name]
|
||||||
|
|
||||||
if data.fs_version < FORMSPEC_MINIMAL_VERSION then
|
if not data.lang_code then
|
||||||
return outdated(name)
|
return outdated(name)
|
||||||
end
|
end
|
||||||
|
|
||||||
@ -2096,11 +2103,11 @@ function craftguide.show(name, item, show_usages)
|
|||||||
if not recipes and not usages then
|
if not recipes and not usages then
|
||||||
if not recipes_cache[item] and not usages_cache[item] then
|
if not recipes_cache[item] and not usages_cache[item] then
|
||||||
return false, msg(name, fmt("%s: %s",
|
return false, msg(name, fmt("%s: %s",
|
||||||
S"No recipe or usage for this item", get_desc(item)))
|
S"No recipe or usage for this item", get_desc(item, data)))
|
||||||
end
|
end
|
||||||
|
|
||||||
return false, msg(name, fmt("%s: %s",
|
return false, msg(name, fmt("%s: %s",
|
||||||
S"You don't know a recipe or usage for this item", get_desc(item)))
|
S"You don't know a recipe or usage for this item", get_desc(item, data)))
|
||||||
end
|
end
|
||||||
|
|
||||||
data.query_item = item
|
data.query_item = item
|
||||||
|
Loading…
Reference in New Issue
Block a user