Модуль:Entity Lookup: различия между версиями
Pok (обсуждение | вклад) suffix |
Pok (обсуждение | вклад) Нет описания правки |
||
| Строка 11: | Строка 11: | ||
p.name_overrides = safeLoad("entity name overrides.json") | p.name_overrides = safeLoad("entity name overrides.json") | ||
local function buildName(entity, useSuffix) | |||
local function buildName(entity) | |||
local name = entity.name or "" | local name = entity.name or "" | ||
local label = mw.text.trim(entity.label or "") | local label = mw.text.trim(entity.label or ""):lower() | ||
local suffix = "" | local suffix = "" | ||
local rawSuffix = entity.suffix | if useSuffix then | ||
local rawSuffix = entity.suffix | |||
if rawSuffix and mw.text.trim(rawSuffix) ~= "" then | |||
local parts = {} | |||
for part in tostring(rawSuffix):gmatch("[^,;]+") do | |||
part = mw.text.trim(part) | |||
if part ~= "" then | |||
parts[#parts + 1] = part | |||
end | |||
end | |||
if #parts > 0 then | |||
suffix = string.lower(table.concat(parts, ", ")) | |||
end | end | ||
end | end | ||
end | end | ||
if label ~= "" and suffix ~= "" and label | if label ~= "" and suffix ~= "" and label == suffix then | ||
suffix = "" | suffix = "" | ||
end | end | ||
| Строка 51: | Строка 51: | ||
function p.getname(frame, entid) -- {{#invoke:Entity Lookup|getname|ProtoID}} | function p.getname(frame, entid) -- {{#invoke:Entity Lookup|getname|ProtoID}} | ||
local id = frame.args and frame.args[1] or entid | local id = frame.args and frame.args[1] or entid | ||
if not id then return "Не найдено" end | if not id then | ||
return "Не найдено" | |||
end | |||
local override = p.name_overrides[id] | local override = p.name_overrides[id] | ||
if override then return override end | if override then | ||
return override | |||
end | |||
local entity = p.entities[id] | local entity = p.entities[id] | ||
return | if not entity then | ||
return "Не найдено" | |||
end | |||
local useSuffix = frame.args and frame.args.suffix and mw.text.trim(frame.args.suffix) ~= "" | |||
return buildName(entity, useSuffix) | |||
end | end | ||