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

suffix
Нет описания правки
 
(не показаны 4 промежуточные версии этого же участника)
Строка 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 = ""


local rawSuffix = entity.suffix
if useSuffix then
if rawSuffix and mw.text.trim(rawSuffix) ~= "" then
suffix = mw.ustring.lower(entity.suffix or "")
local parts = {}
 
for part in tostring(rawSuffix):gmatch("[^,;]+") do
if suffix ~= "" then
part = mw.text.trim(part)
local parts = {}
if part ~= "" and not IgnoredSuffixTokens[part] then
for part in tostring(suffix):gmatch("[^,;]+") do
parts[#parts + 1] = part
part = mw.text.trim(part)
if part ~= "" then
parts[#parts + 1] = part
end
end
end
end
suffix = table.concat(parts, ", ")
if #parts > 0 then
suffix = string.lower(table.concat(parts, ", "))
end
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: Строка 50:
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