мНемає опису редагування |
мНемає опису редагування |
||
(Не показано одну проміжну версію цього користувача) | |||
Рядок 24: | Рядок 24: | ||
--- Псевдоніми оригінальної гри |
--- Псевдоніми оригінальної гри |
||
− | local aliases = mw.loadData('Модуль:Інвентарний |
+ | local aliases = mw.loadData('Модуль:Інвентарний слот/Псевдоніми') |
--- Перевірка і заміна всіх фреймів на псевдоніми |
--- Перевірка і заміна всіх фреймів на псевдоніми |
||
Рядок 40: | Рядок 40: | ||
local modAliases |
local modAliases |
||
if frameParts.mod then |
if frameParts.mod then |
||
− | if mw.title.new('Модуль: |
+ | if mw.title.new('Модуль:ІнвСпрайт2/' .. frameParts.mod).exists then |
− | modAliases = mw.loadData('Модуль: |
+ | modAliases = mw.loadData('Модуль:ІнвСпрайт2/' .. frameParts.mod)["налаштування"]["модпсевдоніми"] |
if modAliases and mw.title.new('Модуль:' .. modAliases).exists then |
if modAliases and mw.title.new('Модуль:' .. modAliases).exists then |
||
modAliases = mw.loadData('Модуль:' .. modAliases) |
modAliases = mw.loadData('Модуль:' .. modAliases) |
||
Рядок 84: | Рядок 84: | ||
-- Параметры |
-- Параметры |
||
local sprite |
local sprite |
||
− | local ids = mw.loadData([[Модуль: |
+ | local ids = mw.loadData([[Модуль:ІнвСпрайт2]])["IDи"] |
local modIds = {} |
local modIds = {} |
||
local back_modIds = {} |
local back_modIds = {} |
||
Рядок 186: | Рядок 186: | ||
if mod then |
if mod then |
||
local modData = modIds[mod] |
local modData = modIds[mod] |
||
− | if not modData and mw.title.new('Модуль: |
+ | if not modData and mw.title.new('Модуль:ІнвСпрайт2/' .. mod).exists then |
− | modData = mw.loadData('Модуль: |
+ | modData = mw.loadData('Модуль:ІнвСпрайт2/' .. mod)["IDи"] |
modIds[mod] = modData |
modIds[mod] = modData |
||
end |
end |
Версія за 06:37, 14 червня 2019
local p = {}
-- Список приставок до назв, оброблюваних іншими модулями.
-- Так буде легше, наприклад, прибирати їх з цілей посилань.
-- УВАГА: вказуйте всі варіанти відмінювання за родами і числами.
p.prefixes = {
'Будь-який', 'Будь-яка', 'Будь-яке', 'Будь-які',
'Пошкоджений', 'Пошкоджена', 'Пошкоджене', 'Пошкоджені'
}
p.modAliases = mw.loadData("Модуль:Модифікації")
--- Створення слота
function p.slot(f)
--- Отримання аргументів
local args = f.args or f
if f == mw.getCurrentFrame() and args[1] == nil then
args = f:getParent().args
end
-- Перший аргумент
args[1] = mw.text.trim(args[1] or '')
--- Псевдоніми оригінальної гри
local aliases = mw.loadData('Модуль:Інвентарний слот/Псевдоніми')
--- Перевірка і заміна всіх фреймів на псевдоніми
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('Модуль:ІнвСпрайт2/' .. frameParts.mod).exists then
modAliases = mw.loadData('Модуль:ІнвСпрайт2/' .. 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, ';' )
--- Перевірка і заміна всіх фреймів на псевдоніми (кінець)
--- Побудова спрайту
-- Параметры
local sprite
local ids = mw.loadData([[Модуль:ІнвСпрайт2]])["IDи"]
local modIds = {}
local back_modIds = {}
local animated = mw.ustring.find(args[1], ';')
local pageName = mw.title.getCurrentTitle().text
local imgClass = args["класзобр"]
local imgStyle = args["стильзобр"]
local numStyle = args["стильцифр"]
local scale = args["масштаб"] or '1'
local imgSize = 32 * scale
local valign
local body = mw.html.create('span'):css{['vertical-align'] = args["вирівн"]}
if scale == '0.5' then
body:css('top','-1px')
end
if animated then
body:addClass('animated')
end
if args["клас"] then
body:addClass(args["клас"])
end
body:addClass('invslot')
if scale == '1' then
body:css('width', 32 .. 'px')
body:css('height', 32 .. 'px')
else
body:css('width', scale*32 .. 'px')
body:css('height', scale*32 .. 'px')
end
if args["стиль"] then
body:cssText(args["стиль"])
end
if (args["замовчування"] or '') ~= '' then
body:css('background-image', '{{FileUrl|' .. args["замовчування"] .. '.png}}')
end
--- спрайт для фону
if (args["замовчуванняCSS"] or '') ~= '' then
local mod=args["мод"]
local version = args["Версія"]
if mod and version ~= 'Оригінальна гра' then
local back_modData = back_modIds[mod]
if not back_modData and mw.title.new('Модуль:ФоновийСпрайт/' .. mod).exists then
back_modData = mw.loadData('Модуль:ФоновийСпрайт/' .. mod)
back_modIds[mod] = back_modData
end
if back_modData and back_modData[version] then
param = mw.loadData('Модуль:ФоновийСпрайт/' .. mod)
local n = args["замовчуванняCSS"]
if not back_modData[version][n] and string.find( n, 'fluid' )
then
body:addClass('fluid_invslot')
end
if back_modData[version][n] or '' ~= '' then
local pos = back_modData[version][n] - 1
local size = param["розм"]
local tiles = param["формат"] / size
local left = pos % tiles * size
local top = math.floor( pos / tiles ) * size
body:addClass('gt-invslot')
body:css('background-size', 'auto')
body:css('background-position', '-' .. left .. 'px -' .. top ..'px')
end
end
end
end
--- Обробка фреймів
local first = true
for frame in mw.text.gsplit(args[1], '%s*;%s*') do
local item
if frame ~= '' or frame == '' and animated then
item = body:tag('span'):addClass('invslot-item')
if imgClass then
item:addClass(imgClass)
end
if imgStyle then
item:cssText(imgStyle)
end
end
if frame == '' then
(item or body):tag('br')
else
local category
local parts = p.getParts(frame, args["мод"])
local title = parts.title or mw.text.trim(args["назва"] or '')
local mod = parts.mod
local name = parts.name
local num = parts.num
local description = parts.text
--- Додаємо до доп тексту назва мода
local img, idData, en_name
if mod then
local modData = modIds[mod]
if not modData and mw.title.new('Модуль:ІнвСпрайт2/' .. mod).exists then
modData = mw.loadData('Модуль:ІнвСпрайт2/' .. mod)["IDи"]
modIds[mod] = modData
end
if modData and modData[name] then
idData = modData[name]
en_name = idData["en"]
else
img = name .. ' (' .. mod .. ')'
end
elseif ids[name] then
idData = ids[name]
else
img = name
end
local link = args["посилання"] or ''
if link == '' then
if mod then
link = mod .. '/' .. name
else
link = mw.ustring.gsub(name, '^Пошкоджен[иае]\D ', '')
end
elseif mw.ustring.lower(link) == 'ні' then
link = nil
end
if link == pageName then
link = nil
end
local formattedTitle
local plainTitle
if title == '' then
plainTitle = name
elseif mw.ustring.lower(title) ~= 'ні' then
plainTitle = mw.ustring.gsub(mw.ustring.gsub(title, '\\\\', '\'), '\\&', '&')
local formatPattern = '&[0-9a-fk-or]'
if mw.ustring.match(plainTitle, formatPattern) then
formattedTitle = title
plainTitle = mw.ustring.gsub(plainTitle, formatPattern, '')
end
if plainTitle == '' then
plainTitle = name
else
plainTitle = mw.ustring.gsub(mw.ustring.gsub(plainTitle, '\', '\\'), '&', '&')
end
elseif link then
if img then
formattedTitle = ''
else
plainTitle = ''
end
end
item:attr{
['data-minetip-title'] = formattedTitle,
['data-minetip-text'] = description,
['data-modinfo-text'] = mod,
['data-minetip-lowtitle'] = en_name
}
if img then
-- & is re-escaped because mw.html treats attributes
-- as plain text, but MediaWiki doesn't
local escapedTitle = ( plainTitle or '' ):gsub( '&', '&' )
item:addClass('invslot-item-image')
:wikitext('[[Файл:Grid ', img, '.png|' .. imgSize .. 'x' .. imgSize .. 'px|link=', link or '', '|', escapedTitle, ']]')
:css('width', scale * 32 .. 'px')
:css('height', scale * 32 .. 'px')
else
if not sprite then
sprite = require([[Модуль:Спрайт2]]).sprite
end
local image
if mod then
image = (args["таблспрайтів"] or mod or "Inv") .. 'Sprite.png'
end
if link then
item:wikitext('[[', link, '|')
end
local image, spriteCat;
if not mod then
image, spriteCat = sprite{
["масштаб"] = scale, ["даніID"] = idData, ["назва"] = plainTitle,
["зобр"] = image, ["дані"] = 'ІнвСпрайт'
}
else
image, spriteCat = sprite{
["масштаб"] = scale, ["даніID"] = idData, ["назва"] = plainTitle,
["зобр"] = image, ["дані"] = 'ІнвСпрайт/' .. mod
}
end
item:node(image)
category = spriteCat
end
if num and num > 1 and num < 1000 then
if img and link then
item:wikitext('[[', link, '|')
end
local number = item
:tag('span')
:addClass('invslot-stacksize')
:attr{title = plainTitle}
:wikitext(num)
if numStyle then
number:cssText(numStyle)
end
if img and link then
item:wikitext(']]')
end
end
if idData and link then
item:wikitext(']]')
end
item:wikitext(category)
end
if first then
if animated and item then
item:addClass('active')
end
first = false
end
end
return tostring( body )
end
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 = {}
for aliasFrame in mw.text.gsplit(alias, '%s*;%s*') do
local aliasParts = p.getParts(aliasFrame)
aliasParts.title = frameParts.title or aliasParts.title or ''
aliasParts.mod = frameParts.mod or aliasParts.mod or 'Minecraft'
aliasParts.num = frameParts.num or aliasParts.num or ''
aliasParts.text = frameParts.text or aliasParts.text or ''
table.insert(expandedFrames, mw.ustring.format(
'[%s]%s:%s,%s[%s]',
aliasParts.title, aliasParts.mod, aliasParts.name, aliasParts.num, aliasParts.text
))
end
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
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 _, nameStartV = mw.ustring.find( frame, '^%[[^%]]*%]' )
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)
if parts.num == 0 then
parts.num = nil
end
parts.text = mw.ustring.match(frame, '%[%s*([^%]]+)%s*%]$')
return parts
end
return p