Модуль:Entity Lookup: различия между версиями

suffix
Нет описания правки
 
(не показаны 3 промежуточные версии этого же участника)
Строка 11: Строка 11:
p.name_overrides = safeLoad("entity name overrides.json")
p.name_overrides = safeLoad("entity name overrides.json")


local IgnoredSuffixTokens = {}
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.ustring.lower(entity.label or "")
local suffix = ""
local suffix = mw.ustring.lower(entity.suffix or "")


local rawSuffix = entity.suffix
if useSuffix and suffix ~= "" then
if rawSuffix and mw.text.trim(rawSuffix) ~= "" then
local parts = {}
local parts = {}
for part in tostring(rawSuffix):gmatch("[^,;]+") do
for part in tostring(suffix):gmatch("[^,;]+") do
part = mw.text.trim(part)
part = part
if part ~= "" and not IgnoredSuffixTokens[part] then
if part ~= "" then
parts[#parts + 1] = part
parts[#parts + 1] = part
end
end
end
end
if #parts > 0 then
suffix = table.concat(parts, ", ")
suffix = string.lower(table.concat(parts, ", "))
end
end
end


if label ~= "" and suffix ~= "" and label:lower() == suffix:lower() then
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 entity and buildName(entity) or "Не найдено"
if not entity then
return "Не найдено"
end
 
local useSuffix = frame.args and frame.args.suffix and frame.args.suffix ~= ""
return buildName(entity, useSuffix)
end
end