Изменения

Модуль:Инвентарный слот

1996 байтов добавлено, 08:11, 16 октября 2018
м
Нет описания правки
-------------------------------------------------------------------
--- Модуль для отображения инвентарных слотов в Hilarious Minecraft Wiki.
-------------------------------------------------------------------
local p = {}
 
-- Список приставок к названиям, обрабатываемых другими модулями.
-- Так будет легче, например, убирать их из целей ссылок.
'Повреждённый', 'Повреждённая', 'Повреждённое', 'Повреждённые' -- использование Ё обязательно
}
 
p.modAliases = mw.loadData("Модуль:Модификации")
--- Создание слота
-- Первый аргумент
args[1] = mw.text.trim(args[1] or '')
--- Псевдонимы -- Вы можете закомментировать следующую строку, если не используете псевдонимыоригинальной игры
local aliases = mw.loadData('Модуль:Инвентарный слот/Псевдонимы')
local modAliases = args["модпсевдонимы"] or '' if modAliases ~= '' then modAliases = mw.loadData('Модуль:' .. modAliases) else modAliases = nil end if aliases or modAliases then local frames = {} for frame in mw.text.gsplit( args[1], '%s*;%s*' ) do local frameParts = p.getParts( frame, args["мод"] ) local id = frameParts.name -- if frameParts.mod then -- id = frameParts.mod .. ':' .. id -- end  --- Загрузка списка псевдонимов к модам local modAliases if frameParts.mod then if mw.title.new('Модуль:ИнвСпрайт/' .. frameParts.mod).exists then modAliases = mw.loadData('Модуль:ИнвСпрайт/' .. frameParts.mod)["модпсевдонимы"] if modAliases and mw.title.new('Модуль:' .. modAliases).exists then modAliases = mw.loadData('Модуль:' .. modAliases) end end end local alias= nil if frameParts.mod then if modAliases and modAliases[id] then --- ['имя'] = '[титл]:имя[доп. текст]'  local title = mw.ustring.match ( modAliases[id], '^%[([^%]]+)%]' ) if title then local aaa = mw.ustring.match ( modAliases[id], '^%[[^%]]+%](.+)$' ) if aaa then alias = '[' .. title .. ']' .. frameParts.mod .. ':' .. aaa else alias = '[' .. title .. ']' .. frameParts.mod .. ':' .. frameParts.name end else alias = frameParts.mod .. ':' .. modAliases[id] end end elseif aliases and aliases[id] then alias = aliases[id] end if alias then table.insert( frames, p.expandAlias( frameParts, alias ) ) else table.insert( frames, frame ) end
end
args[1] = table.concat( frames, ';' )
end
args[1] = table.concat( frames, ';' )
--- Построение спрайта
local description = parts.text
local img, idData, en_name
if mod then
local modData = modIds[mod]
if modData and modData[name] then
idData = modData[name]
en_name = idData["en"]
else
img = name .. ' (' .. mod .. ')'
img = name
end
  local vanilla = {v = 1, vanilla = 1, mc = 1, minecraft = 1}
local link = args["ссылка"] or ''
if link == '' then
link = mod .. '/' .. name
else
link = mw.ustring.gsub(name, '^Повреждённ[ыао][йяе] ', '')nil
end
elseif mw.ustring.lower(link) == 'нет' then
item:attr{
['data-minetip-title'] = formattedTitle,
['data-minetip-text'] = description, ['data-modinfo-text'] = mod, ['data-minetip-lowtitle'] = en_name
}
-- & is re-escaped because mw.html treats attributes
-- as plain text, but MediaWiki doesn't
local escapedTitle = mw.ustring.gsub((plainTitle or ''), :gsub( '&', '&')
item:addClass('invslot-item-image')
:wikitext('[[Файл:Grid ', img, '.png|32x32px|link=', link or '', '|', escapedTitle, ']]')
item:wikitext('[[', link, '|')
end
local image, spriteCat; if not mod then image, spriteCat = sprite{ ["данныеID"] = idData, ["назв"] = plainTitle, ["изобр"] = image, ["настройки"] = 'ИнвСпрайт' } else image, spriteCat = sprite{
["данныеID"] = idData, ["назв"] = plainTitle,
["изобр"] = image, ["настройки"] = 'ИнвСпрайт/' .. mod
} else spriteCat = sprite{ ["данныеID"] = idData, ["назв"] = plainTitle, ["изобр"] = image, ["настройки"] = 'ИнвСпрайт' } end
item:node(image)
category = spriteCat
function p.expandAlias( frameParts, alias )
-- If the frame has no parts, we can just return the alias as-is
--[[if not frameParts.title and not frameParts.mod and not frameParts.num and not frameParts.text then
return alias
end--]]
local expandedFrames = {}
return table.concat(expandedFrames, ';')
end
 
function p.getParts(frame, mod)
----Функция получает название предмета в формате "[титл]мод:имя[доп.текст],число"
----parts.title = титл, название предмета при наведении
----parts.mod = мод
----parts.name = имя
----parts.text = текст, дополнительный текст при наведении на предмет
----parts.num = число
 
local parts = {}
parts.title = mw.ustring.match(frame, '^%[%s*([^%]]+)%s*%]')
local modPattern if mw.ustring.match(frame, '^%[.*%]([a-zA-Zа-яА-Я0-9ёЁé _%-\']+):') then modPattern = '^%[.*%]([a-zA-Zа-яА-Я0-9ёЁé _%-\']+):' else modPattern = '^([a-zA-Zа-яА-Я0-9ёЁé _%-\']+):' end  parts.mod = mw.text.trim(mw.ustring.match(frame, '([^:%]]+):'modPattern) or mod or '')---- Получаем название мода
local vanilla = {v = 1, vanilla = 1, mc = 1, minecraft = 1}
if parts.mod == '' or vanilla[mw.ustring.lower(parts.mod)] then link = nil
parts.mod = nil
else
if p.modAliases[parts.mod] then
parts.mod = p.modAliases[parts.mod]
end
parts.mod = mw.ustring.gsub(parts.mod,'_',' ')
end
local nameStart _, nameStartV = (mw.ustring.find(frame, ':^%[[^%]]*%]') or local nameStart = ( ({mw.ustring.find(frame, '%modPattern )})[2]') or nameStartV or 0 ) + 1
if nameStart - 1 == #frame then
nameStart = 1
end
parts.name = mw.text.trim(mw.ustring.sub(frame, nameStart, (mw.ustring.find(frame, '[,%[]', nameStart) or 0) - 1))
parts.num = math.floor(mw.ustring.match(frame, ',%s*(%d+)') or 0)
parts.text = mw.ustring.match(frame, '%[%s*([^%]]+)%s*%]$')
return parts
end
return p
1136
правок