调用方式
Conditions.item.get_item_desc(items)
记录依赖项 Conditions.item.get_item_desc,然后按该名称调用。带命名空间的调用不会传入 self:请使用冒号调用,或自行传入该对象。
作用
Describes an item reference for the item condition descriptions: an item set name (white for a profile set, cyan for a global one), or the first item's link or name followed by how many others are listed. Returns nil when the reference is invalid, the set is unknown, or the list is empty.
参数
| 名称 | 类型 | 作用 |
|---|---|---|
items | string | table | Item set name, or an array of item IDs or names. |
返回值
| 1 | string | nil | Localized description, or nil when nothing can be described. |
|---|
版本
内置辅助函数在每个版本上都会注册。不同的是它们读取的游戏 API;某个 API 缺失时,辅助函数会改用后备方案,或返回 nil 并附上原因。
它不直接读取任何游戏 API。
插件如何调用它
- 背包中有物品 (print)
item = Functions.presentation.nullable(get_item_desc(value.item), L["<item>"]), - 已装备物品 (print)
return Literal.phrase(L["you {{!have|do not have}} {item} equipped"], {item = Functions.presentation.nullable(get_item_desc(value.item), L["<item>"])}) - 物品可用 (print)
item = Functions.presentation.nullable(get_item_desc(value.item), L["<item>"]), - 物品冷却 (print)
item = Functions.presentation.nullable(get_item_desc(value.item), L["<item>"]), - 物品在射程内 (print)
item = Functions.presentation.nullable(get_item_desc(value.item), L["<item>"]),
依赖项
color(builtin:Conditions/item.lua:color)
源码
Conditions/item.lua,第 62 行。在游戏中为只读;“复制”会生成一份可编辑的副本。
Conditions.item.get_item_desc(items)
if not addon:IsConditionItemReference(items) then return nil end
local itemsets = addon.db.profile.itemsets
local global_itemsets = addon.db.global.itemsets
if itemsets~=nil and type(itemsets)~='table' or global_itemsets~=nil and type(global_itemsets)~='table' then return nil end
if type(items) == "string" then
local set=(itemsets or {})[items];local tint=color.WHITE
if set==nil then set=(global_itemsets or {})[items];tint=color.CYAN end
if type(set)=='table' and type(set.name)=='string' then return string.format(L["a %s item set item"],tint..set.name..color.RESET) end
elseif items and #items > 0 then
local info=addon.Platform:GetItemMetadata(items[1])
local link=info and (info.link or info.name) or items[1]
if #items > 1 then
return string.format(L["%s or %d others"], link, #items-1)
else
return link
end
end
return nil