Модуль:Entity Lookup: различия между версиями
Pok (обсуждение | вклад) suffix |
Pok (обсуждение | вклад) Нет описания правки |
||
| (не показаны 3 промежуточные версии этого же участника) | |||
| Строка 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. | local label = mw.ustring.lower(entity.label or "") | ||
local suffix = "" | local suffix = mw.ustring.lower(entity.suffix or "") | ||
if useSuffix and suffix ~= "" then | |||
if | |||
local parts = {} | local parts = {} | ||
for part in tostring( | for part in tostring(suffix):gmatch("[^,;]+") do | ||
part = | part = part | ||
if part ~= "" | if part ~= "" then | ||
parts[#parts + 1] = part | parts[#parts + 1] = part | ||
end | end | ||
end | end | ||
suffix = table.concat(parts, ", ") | |||
end | end | ||
if label ~= "" and suffix ~= "" and label | if label ~= "" and suffix ~= "" and label == suffix then | ||
suffix = "" | suffix = "" | ||
end | end | ||
| Строка 51: | Строка 46: | ||
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 lower(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 frame.args.suffix ~= "" | |||
return buildName(entity, useSuffix) | |||
end | end | ||