Модуль:Entity Lookup: различия между версиями
Pok (обсуждение | вклад) мНет описания правки |
Pok (обсуждение | вклад) м поддержка суффиксов Метка: отменено |
||
| Строка 5: | Строка 5: | ||
p.entities = prototypes.entities | p.entities = prototypes.entities | ||
p.name_overrides = overrides.name_overrides or {} | p.name_overrides = overrides.name_overrides or {} | ||
-- p.getname{args={"FreedomImplant"}} | -- p.getname{args={"FreedomImplant"}} | ||
| Строка 12: | Строка 11: | ||
if not id then return "Не найдено" end | if not id then return "Не найдено" end | ||
if p.name_overrides[id] then | |||
return p.name_overrides[id] | |||
return | |||
end | end | ||
local entity = p.entities[id] | local entity = p.entities[id] | ||
if entity then | if entity then | ||
local name = entity.name or "" | |||
if entity.suffix and entity.suffix ~= "" then | |||
name = name .. " (" .. entity.suffix .. ")" | |||
end | |||
return name | |||
end | end | ||
return "Не найдено" | return "Не найдено" | ||
end | end | ||
-- p.getidbyname{args={"Швабра"}} | -- p.getidbyname{args={"Швабра"}} | ||
| Строка 38: | Строка 39: | ||
for id, entity in pairs(p.entities) do | for id, entity in pairs(p.entities) do | ||
if entity. | local actualName = entity.name | ||
if entity.suffix and entity.suffix ~= "" then | |||
actualName = actualName .. " (" .. entity.suffix .. ")" | |||
end | |||
if actualName == name then | |||
return id | return id | ||
end | end | ||
| Строка 46: | Строка 51: | ||
end | end | ||
-- p.getdesc{args={"FreedomImplant"}} | |||
-- p. | |||
function p.getdesc(frame, entid) -- {{#invoke:Entity Lookup|getdesc|ProtoID}} | function p.getdesc(frame, entid) -- {{#invoke:Entity Lookup|getdesc|ProtoID}} | ||
local id = frame.args and frame.args[1] or entid | |||
local entity = p.entities[id] | |||
if entity then | |||
return entity.desc or "" | |||
end | |||
return "Не найдено" | |||
end | end | ||
-- p.createtexttooltip{args={"Верхний текст", "FreedomImplant", "Файл:Honks.gif"}} | -- p.createtexttooltip{args={"Верхний текст", "FreedomImplant", "Файл:Honks.gif"}} | ||
function p.createtexttooltip(frame) -- {{#invoke:Entity Lookup|createtexttooltip|Текст|ProtoID|img=картиночка}} | function p.createtexttooltip(frame) -- {{#invoke:Entity Lookup|createtexttooltip|Текст|ProtoID|img=картиночка}} | ||
local | local args = frame.args | ||
local entity = p.entities[ | local label, id, img = args[1], args[2], args.img | ||
local stats = frame:preprocess("{{Особое|".. | local entity = p.entities[id] | ||
if entity | local stats = frame:preprocess("{{Особое|" .. id .. "}}") | ||
if | if entity then | ||
local displayName = entity.name | |||
if entity.suffix and entity.suffix ~= "" then | |||
displayName = displayName .. " (" .. entity.suffix .. ")" | |||
end | |||
local desc = string.gsub(entity.desc or "", "\n", "<br>") | |||
if img then | |||
return frame:preprocess("{{Tooltip|" .. label .. "|" .. displayName .. "|" .. desc .. "|" .. stats .. "|img=" .. img .. "}}") | |||
else | |||
return frame:preprocess("{{Tooltip|" .. label .. "|" .. displayName .. "|" .. desc .. "|" .. stats .. "}}") | |||
end | end | ||
end | end | ||
return | return frame:preprocess("{{Tooltip|" .. label .. "|Не найден|Предмет не найден|img=Mousegif.gif}}") | ||
end | end | ||
-- p.createimagetooltip{args={"Файл:Honks.gif", "FreedomImplant", Статы="Имеет 3 заряда"}} | -- p.createimagetooltip{args={"Файл:Honks.gif", "FreedomImplant", Статы="Имеет 3 заряда"}} | ||
function p.createimagetooltip(frame) -- {{#invoke:Entity Lookup|createimagetooltip|Картинка|ProtoID|Мета=мета|Статы=статы}} | function p.createimagetooltip(frame) -- {{#invoke:Entity Lookup|createimagetooltip|Картинка|ProtoID|Мета=мета|Статы=статы}} | ||
local | local picFile, id = frame.args[1], frame.args[2] | ||
local meta = frame.args["Мета"] or "64x64px|link=" | |||
local stats = frame:preprocess("{{Особое|" .. id .. "}}") | |||
local meta = frame.args["Мета"] | |||
local stats = frame:preprocess("{{Особое|".. | |||
meta = meta:gsub(',', '|') | meta = meta:gsub(',', '|') | ||
pic = "[[ | local pic = string.format("[[%s|%s]]", picFile, meta) | ||
local entity = p.entities[id] | |||
if entity then | |||
local displayName = entity.name | |||
if entity.suffix and entity.suffix ~= "" then | |||
displayName = displayName .. " (" .. entity.suffix .. ")" | |||
end | end | ||
local desc = entity.desc or "" | |||
return frame:preprocess(string.format("{{Tooltip|%s|%s|%s|%s|no-text-decoration=1}}", pic, displayName, desc, stats)) | |||
end | |||
-- {{Tooltip|Текст|[[картиночка|64x64px|left|middle|link=]] Название|Описание}} | -- {{Tooltip|Текст|[[картиночка|64x64px|left|middle|link=]] Название|Описание}} | ||
return frame:preprocess(string.format("{{Tooltip|%s|Не найден|Предмет не найден|img=Mousegif.gif|no-text-decoration=1}}", pic)) | |||
end | end | ||
return p | return p | ||