Moduł:Inventory slot: Różnice pomiędzy wersjami
Przejdź do nawigacji
Przejdź do wyszukiwania
| [wersja nieprzejrzana] | [wersja przejrzana] |
"karmazynowy" zamieniony na "purpurowy". |
|||
| (Nie pokazano 170 wersji utworzonych przez 7 użytkowników) | |||
| Linia 1: | Linia 1: | ||
------------------------------------------------------------------- | |||
--- Moduł do wyświetlania ikon przedmiotów jak w ekwipunku. | |||
------------------------------------------------------------------- | |||
local p = {} | local p = {} | ||
p.modAliases = { | |||
["thaum"] = "ThaumCraft", | |||
p. | ["bc"] = "BuildCraft" | ||
} | } | ||
function p.slot( f ) | --- Tworzenie slotów | ||
function p.slot(f) | |||
--- Pozyskiwanie argumentów | |||
local args = f.args or f | local args = f.args or f | ||
if f == mw.getCurrentFrame() and args[1] == nil then | if f == mw.getCurrentFrame() and args[1] == nil then | ||
| Linia 15: | Linia 18: | ||
end | end | ||
args[1] = mw.text.trim( args[1] or '' ) | -- Pierwszy argument | ||
args[1] = mw.text.trim(args[1] or '') | |||
-- | --- Skróty | ||
local aliases = mw.loadData( ' | -- Możesz skomentować następujący wiersz, jeśli nie używasz aliasów | ||
-- local aliases = mw.loadData('Moduł:Inventory slot/Aliases') | |||
local modAliases = args | local modAliases = args["aliasyModow"] or '' | ||
if modAliases ~= '' then | if modAliases ~= '' then | ||
modAliases = mw.loadData( ' | modAliases = mw.loadData('Moduł:' .. modAliases) | ||
else | else | ||
modAliases = nil | modAliases = nil | ||
end | |||
--- Obsługa przedrostka "jakikolwiek", "każdy" i "dowolny" oraz ich typów | |||
while string.find(args[1], 'Dowoln[yea]') or string.find(args[1], 'Jak[ia]kolwiek') or string.find(args[1], 'Jakiekolwiek') or string.find(args[1], 'Każd[yae]') do | |||
local current = string.sub(args[1], (string.find(args[1], 'Dowoln[yea]') or string.find(args[1], 'Jak[ia]kolwiek') or string.find(args[1], 'Jakiekolwiek') or string.find(args[1], 'Każd[yae]')), -1) | |||
current = string.sub(current, 1, (string.find(current, ',') or string.find(current, ';') or 0) - 1) | |||
local prefix = string.sub(current, 1, string.find(current, ' ') - 1) | |||
current = string.sub(current, string.find(current, ' '), -1) | |||
local gender = string.sub(prefix, -1) | |||
local replacement = '' | |||
-- Sprawdzenie czy nawias to typ dowolności i tego, czy jest standardowy, czy nie | |||
local tylkoBarwione = false | |||
local standardowe = true | |||
if string.find(current, '%(barwion[yae]%)') then | |||
tylkoBarwione = true | |||
current = string.sub(current, 1, string.find(current, 'barwion') - 2) | |||
else | |||
niestandardowe = mw.loadData('Moduł:Inventory slot/Niestandardowe dowolności') | |||
if niestandardowe[mw.text.trim(current)] or niestandardowe[mw.text.trim(string.sub(current, 1, (string.find(current, '%(') or 0) - 1))..' %(prefiks%)'] or niestandardowe[mw.text.trim(string.sub(current, 1, (string.find(current, '%(') or 0) - 1))..' %(sufiks%)'] then | |||
standardowe = false | |||
local relay = '' | |||
if string.find(current, '%(') then | |||
relay = string.sub(current, string.find(current, '%(') + 1, string.find(current, '%)') - 1) | |||
end | |||
local base = string.sub(current, 1, (string.find(current, '%(') or 0) - 1) | |||
if niestandardowe[mw.text.trim(base)..' '..'%(prefiks%)'] then | |||
for i, v in ipairs(niestandardowe[mw.text.trim(base)..' %(prefiks%)']) do | |||
if string.find(v, 'Każd[xyea]') then | |||
replacement = replacement..v..' %('..mw.text.trim(relay)..'%);' | |||
else | |||
replacement = replacement..v..' '..mw.text.trim(relay)..';' | |||
end | |||
end | |||
elseif niestandardowe[mw.text.trim(base)..' %(sufiks%)'] then | |||
for i, v in ipairs(niestandardowe[mw.text.trim(base)..' %(sufiks%)']) do | |||
if string.find(v, 'Każd[xyea]') then | |||
replacement = replacement..v..' %('..mw.text.trim(relay)..'%);' | |||
else | |||
replacement = replacement..mw.text.trim(relay)..' '..v..';' | |||
end | |||
end | |||
else | |||
for i, v in ipairs(niestandardowe[mw.text.trim(current)]) do | |||
replacement = replacement..v..';' | |||
end | |||
end | |||
replacement = string.gsub(replacement, 'x', gender) | |||
replacement = string.sub(replacement, 1, -2) | |||
-- Usuwanie znaków "%" powodujących błędy | |||
replacement = string.gsub(replacement, '%%', '') | |||
end | |||
end | |||
-- Standardowy typ dowolności | |||
if standardowe then | |||
if (prefix == 'Dowolny') or (prefix == 'Jakikolwiek') or (prefix == 'Każdy') then | |||
replacement = 'Czerwony'..current..';Pomarańczowy'..current..';Żółty'..current..';Jasnozielony'..current..';Zielony'..current..';Błękitny'..current..';Jasnoniebieski'..current..';Niebieski'..current..';Fioletowy'..current..';Purpurowy'..current..';Różowy'..current..';Brązowy'..current..';Czarny'..current..';Szary'..current..';Jasnoszary'..current..';Biały'..current | |||
else | |||
if (prefix == 'Dowolna') or (prefix == 'Jakakolwiek') or (prefix == 'Każda') then | |||
replacement = 'Czerwona'..current..';Pomarańczowa'..current..';Żółta'..current..';Jasnozielona'..current..';Zielona'..current..';Błękitna'..current..';Jasnoniebieska'..current..';Niebieska'..current..';Fioletowa'..current..';Purpurowa'..current..';Różowa'..current..';Brązowa'..current..';Czarna'..current..';Szara'..current..';Jasnoszara'..current..';Biała'..current | |||
else replacement = 'Czerwone'..current..';Pomarańczowe'..current..';Żółte'..current..';Jasnozielone'..current..';Zielone'..current..';Błękitne'..current..';Jasnoniebieskie'..current..';Niebieskie'..current..';Fioletowe'..current..';Purpurowe'..current..';Różowe'..current..';Brązowe'..current..';Czarne'..current..';Szare'..current..';Jasnoszare'..current..';Białe'..current | |||
end | |||
end | |||
end | |||
if tylkoBarwione then replacement = string.sub(replacement, 1, string.find(replacement, ';Biał') - 1) end | |||
args[1] = string.sub(args[1], 1, (string.find(args[1], 'Dowoln[yea]') or string.find(args[1], 'Jak[ia]kolwiek') or string.find(args[1], 'Jakiekolwiek') or string.find(args[1], 'Każd[yae]')) - 1)..replacement..string.sub(args[1], string.find(args[1], string.sub(current, 1, (string.find(current,'%(') or 0) - 1)) + string.len(current), -1) | |||
if tylkoBarwione then args[1] = string.sub(args[1], 1, string.find(args[1], '(barwion[yae])') - 2) end | |||
args[1] = mw.text.trim(args[1] or '') | |||
end | end | ||
| Linia 30: | Linia 108: | ||
local frames = {} | local frames = {} | ||
for frame in mw.text.gsplit( args[1], '%s*;%s*' ) do | for frame in mw.text.gsplit( args[1], '%s*;%s*' ) do | ||
local frameParts = p.getParts( frame, args | local frameParts = p.getParts( frame, args["mod"] ) | ||
local id = frameParts.name | local id = frameParts.name | ||
| Linia 54: | Linia 132: | ||
end | end | ||
--- Tworzenie spriteów | |||
-- Opcje | |||
local sprite | local sprite | ||
local ids = mw.loadData( [[ | local ids = mw.loadData([[Moduł:InvSprite/IDs]])["ids"] | ||
local modIds = {} | local modIds = {} | ||
local animated = args[1] | local back_modIds = {} | ||
local animated = mw.ustring.find(args[1], ';') | |||
local pageName = mw.title.getCurrentTitle().text | local pageName = mw.title.getCurrentTitle().text | ||
local imgClass = args | local imgClass = args["klasa obrazu"] | ||
local numStyle = args | local numStyle = args["styl numerów"] | ||
local body = mw.html.create( 'span | |||
local body = mw.html.create('span'):css{['vertical-align'] = args["wyrówn"]} | |||
if animated then | if animated then | ||
body:addClass( 'animated' ) | body:addClass('animated') | ||
end | end | ||
if args | if args["klasa"] then | ||
body:addClass( args | body:addClass(args["klasa"]) | ||
end | end | ||
if args | body:addClass('invslot') | ||
body:cssText( args | if args["styl"] then | ||
body:cssText(args["styl"]) | |||
end | end | ||
if ( args | --[[ | ||
body:css( 'background-image', '{{FileUrl|' .. args. | if (args["domyślne"] or '') ~= '' then | ||
body:css('background-image', '{{FileUrl|' .. args["domyślne"] .. '.png}}') | |||
end | |||
--]] | |||
--- sprity w tle | |||
if (args["domyślneCSS"] or '') ~= '' then | |||
local mod=args["mod"] | |||
if mod then | |||
local back_modData = back_modIds[mod] | |||
if not back_modData and mw.title.new('Moduł:TłoSprit/' .. mod .. '/ID').exists then | |||
back_modData = mw.loadData('Moduł:TłoSprit/' .. mod .. '/ID') | |||
back_modIds[mod] = back_modData | |||
end | |||
if back_modData then | |||
param = mw.loadData('Moduł:TłoSprit/' .. mod) | |||
local n = args["domyślneCSS"] | |||
local pos = back_modData[n] - 1 | |||
local size = param["wielkość"] | |||
local tiles = param["format"] / size | |||
local left = pos % tiles * size | |||
local top = math.floor( pos / tiles ) * size | |||
-- body:css('background-image', '{{FileUrl|' .. mod .. 'CSS.png}}') | |||
body:css('background-size', 'auto') | |||
body:css('background-position', '-' .. left .. 'px -' .. top ..'px') | |||
end | |||
end | |||
end | end | ||
--- Obsługa klatek | |||
local first = true | local first = true | ||
for frame in mw.text.gsplit( args[1], '%s*;%s*' ) do | for frame in mw.text.gsplit(args[1], '%s*;%s*') do | ||
local item | local item | ||
if frame ~= '' or frame == '' and animated then | if frame ~= '' or frame == '' and animated then | ||
item = body:tag( 'span' ):addClass( 'invslot-item' ) | item = body:tag('span'):addClass('invslot-item') | ||
if imgClass then | if imgClass then | ||
item:addClass( imgClass ) | item:addClass(imgClass) | ||
end | end | ||
end | end | ||
if frame == '' then | if frame == '' then | ||
( item or body ):tag( 'br' ) | (item or body):tag('br') | ||
else | else | ||
local category | local category | ||
local parts = p.getParts( frame, args | local parts = p.getParts(frame, args["mod"]) | ||
local title = parts.title or mw.text.trim( args | local title = parts.title or mw.text.trim(args["title"] or '') | ||
local mod = parts.mod | local mod = parts.mod | ||
local name = parts.name | local name = parts.name | ||
| Linia 100: | Linia 212: | ||
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('Moduł:InvSprite/' .. mod .. '/ID').exists then | ||
modData = mw.loadData( ' | modData = mw.loadData('Moduł:InvSprite/' .. mod .. '/ID')["IDs"] | ||
modIds[mod] = modData | modIds[mod] = modData | ||
end | end | ||
| Linia 115: | Linia 227: | ||
end | end | ||
local link = args | local link = args["link"] or '' | ||
if link == '' then | if link == '' then | ||
if mod then | if mod then | ||
link = | link = mod .. '/' .. name | ||
else | else | ||
link = | link = mw.ustring.gsub(name, '^Uszkodzon[yea] ', '') | ||
end | end | ||
elseif | elseif mw.ustring.lower(link) == 'nie' then | ||
link = nil | link = nil | ||
end | end | ||
| Linia 133: | Linia 245: | ||
if title == '' then | if title == '' then | ||
plainTitle = name | plainTitle = name | ||
elseif | elseif mw.ustring.lower(title) ~= 'nie' then | ||
plainTitle = | plainTitle = mw.ustring.gsub(mw.ustring.gsub(title, '\\\\', '\'), '\\&', '&') | ||
local formatPattern = '&[0-9a-fk-or]' | local formatPattern = '&[0-9a-fk-or]' | ||
if | if mw.ustring.match(plainTitle, formatPattern) then | ||
formattedTitle = title | formattedTitle = title | ||
plainTitle = | plainTitle = mw.ustring.gsub(plainTitle, formatPattern, '') | ||
end | end | ||
| Linia 145: | Linia 257: | ||
plainTitle = name | plainTitle = name | ||
else | else | ||
plainTitle = | plainTitle = mw.ustring.gsub(mw.ustring.gsub(plainTitle, '\', '\\'), '&', '&') | ||
end | end | ||
elseif link then | elseif link then | ||
| Linia 161: | Linia 273: | ||
if img then | if img then | ||
-- & | --- Obsługa rozszerzeń | ||
-- | local extension = '' | ||
if mw.title.new('Grid '..img..'.gif', 'Plik').exists then | |||
extension = '.gif' | |||
else | |||
extension = '.png' | |||
end | |||
-- & jest ponownie zmieniany, ponieważ mw.html traktuje atrybuty | |||
-- jako zwykły tekst, ale MediaWiki tego nie robi | |||
local escapedTitle = ( plainTitle or '' ):gsub( '&', '&' ) | local escapedTitle = ( plainTitle or '' ):gsub( '&', '&' ) | ||
item:addClass( 'invslot-item-image' ) | local file = 'Grid '..img..extension | ||
:wikitext( '[[ | if not mw.title.new(file, 'Plik').exists then | ||
file = 'No image.svg' | |||
end | |||
item:addClass('invslot-item-image') | |||
:wikitext('[[Plik:', file, '|32x32px|link=', link or '', '|', escapedTitle, ']]') | |||
else | else | ||
if not sprite then | if not sprite then | ||
sprite = require( [[ | sprite = require([[Moduł:Sprite]]).sprite | ||
end | end | ||
local image | local image | ||
if mod then | if mod then | ||
image = args | image = (args["tablica Ikonek"] or mod or "Inv") .. 'CSS.png' | ||
end | end | ||
if link then | if link then | ||
item:wikitext( '[[', link, '|' ) | item:wikitext('[[', link, '|') | ||
end | end | ||
local image, spriteCat = sprite{ | |||
local image, spriteCat; | |||
if not mod then | |||
image, spriteCat = sprite{ | |||
item:node( image ) | ["danychID"] = idData, ["title"] = plainTitle, | ||
["obraz"] = image, ["ustawienia"] = 'InvSprite' | |||
} | |||
else | |||
image, spriteCat = sprite{ | |||
["danychID"] = idData, ["title"] = plainTitle, | |||
["obraz"] = image, ["ustawienia"] = 'InvSprite/' .. mod | |||
} | |||
end | |||
item:node(image) | |||
category = spriteCat | category = spriteCat | ||
end | end | ||
| Linia 187: | Linia 319: | ||
if num and num > 1 and num < 1000 then | if num and num > 1 and num < 1000 then | ||
if img and link then | if img and link then | ||
item:wikitext( '[[', link, '|' ) | item:wikitext('[[', link, '|') | ||
end | end | ||
local number = item | local number = item | ||
:tag( 'span' ) | :tag('span') | ||
:addClass( 'invslot-stacksize' ) | :addClass('invslot-stacksize') | ||
:attr{ title = plainTitle } | :attr{title = plainTitle} | ||
:wikitext( num ) | :wikitext(num) | ||
if numStyle then | if numStyle then | ||
number:cssText( numStyle ) | number:cssText(numStyle) | ||
end | end | ||
if img and link then | if img and link then | ||
item:wikitext( ']]' ) | item:wikitext(']]') | ||
end | end | ||
end | end | ||
if idData and link then | if idData and link then | ||
item:wikitext( ']]' ) | item:wikitext(']]') | ||
end | end | ||
item:wikitext( category ) | item:wikitext(category) | ||
end | end | ||
if first then | if first then | ||
if animated and item then | if animated and item then | ||
item:addClass( 'active' ) | item:addClass('active') | ||
end | end | ||
first = false | first = false | ||
end | end | ||
if item then | |||
item:addClass('animated-active') | |||
end | |||
end | end | ||
| Linia 221: | Linia 357: | ||
function p.expandAlias( frameParts, alias ) | function p.expandAlias( frameParts, alias ) | ||
-- | -- Jeśli ramka nie ma części, możemy po prostu zwrócić alias bez zmian | ||
if not frameParts.title and not frameParts.mod and not frameParts.num and not frameParts.text then | --[[if not frameParts.title and not frameParts.mod and not frameParts.num and not frameParts.text then | ||
return alias | return alias | ||
end | end--]] | ||
local expandedFrames = {} | local expandedFrames = {} | ||
for aliasFrame in mw.text.gsplit( alias, '%s*;%s*' ) do | for aliasFrame in mw.text.gsplit(alias, '%s*;%s*') do | ||
local aliasParts = p.getParts( aliasFrame ) | local aliasParts = p.getParts(aliasFrame) | ||
aliasParts.title = frameParts.title or aliasParts.title or '' | aliasParts.title = frameParts.title or aliasParts.title or '' | ||
aliasParts.mod = frameParts.mod or aliasParts.mod or 'Minecraft' | aliasParts.mod = frameParts.mod or aliasParts.mod or 'Minecraft' | ||
| Linia 234: | Linia 370: | ||
aliasParts.text = frameParts.text or aliasParts.text or '' | aliasParts.text = frameParts.text or aliasParts.text or '' | ||
table.insert( expandedFrames, | table.insert(expandedFrames, mw.ustring.format( | ||
'[%s]%s:%s,%s[%s]', | '[%s]%s:%s,%s[%s]', | ||
aliasParts.title, aliasParts.mod, aliasParts.name, aliasParts.num, aliasParts.text | aliasParts.title, aliasParts.mod, aliasParts.name, aliasParts.num, aliasParts.text | ||
) ) | )) | ||
end | end | ||
return table.concat( expandedFrames, ';' ) | return table.concat(expandedFrames, ';') | ||
end | end | ||
function p.getParts( frame, mod ) | |||
function p.getParts(frame, mod) | |||
----Funkcja pobiera nazwę pozycji w formacie "[tytuł] mod: nazwa [tekst], numer" | |||
----parts.title = tytuł, nazwa przedmiotu po najechaniu myszą | |||
----parts.mod = mod | |||
----parts.name = Nazwa | |||
----parts.text = tekst, dodatkowy tekst po najechaniu kursorem na element | |||
----parts.num = numer | |||
local parts = {} | local parts = {} | ||
parts.title = | 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 '') ---- Uzyskaj nazwę modyfikacji | |||
local vanilla = { v = 1, vanilla = 1, mc = 1, minecraft = 1 } | local vanilla = {v = 1, vanilla = 1, mc = 1, minecraft = 1} | ||
if parts.mod == '' or vanilla[mw.ustring.lower( parts.mod )] then | if parts.mod == '' or vanilla[mw.ustring.lower(parts.mod)] then | ||
parts.mod = nil | parts.mod = nil | ||
end | end | ||
if p.modAliases[parts.mod] then | |||
local | parts.mod = p.modAliases[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 | if nameStart - 1 == #frame then | ||
nameStart = 1 | nameStart = 1 | ||
end | end | ||
parts.name = mw.text.trim( | parts.name = mw.text.trim( mw.ustring.sub( frame, nameStart, ( mw.ustring.find( frame, '[,%[]', nameStart ) or 0 ) - 1 ) ) | ||
parts.num = math.floor( | parts.num = math.floor(mw.ustring.match(frame, ',%s*(%d+)') or 0) | ||
if parts.num == 0 then | if parts.num == 0 then | ||
parts.num = nil | parts.num = nil | ||
end | end | ||
parts.text = | parts.text = mw.ustring.match(frame, '%[%s*([^%]]+)%s*%]$') | ||
return parts | return parts | ||
Aktualna wersja na dzień 19:00, 30 kwi 2025
Ten moduł implementuje {{inventory slot}}.
Zależności
-------------------------------------------------------------------
--- Moduł do wyświetlania ikon przedmiotów jak w ekwipunku.
-------------------------------------------------------------------
local p = {}
p.modAliases = {
["thaum"] = "ThaumCraft",
["bc"] = "BuildCraft"
}
--- Tworzenie slotów
function p.slot(f)
--- Pozyskiwanie argumentów
local args = f.args or f
if f == mw.getCurrentFrame() and args[1] == nil then
args = f:getParent().args
end
-- Pierwszy argument
args[1] = mw.text.trim(args[1] or '')
--- Skróty
-- Możesz skomentować następujący wiersz, jeśli nie używasz aliasów
-- local aliases = mw.loadData('Moduł:Inventory slot/Aliases')
local modAliases = args["aliasyModow"] or ''
if modAliases ~= '' then
modAliases = mw.loadData('Moduł:' .. modAliases)
else
modAliases = nil
end
--- Obsługa przedrostka "jakikolwiek", "każdy" i "dowolny" oraz ich typów
while string.find(args[1], 'Dowoln[yea]') or string.find(args[1], 'Jak[ia]kolwiek') or string.find(args[1], 'Jakiekolwiek') or string.find(args[1], 'Każd[yae]') do
local current = string.sub(args[1], (string.find(args[1], 'Dowoln[yea]') or string.find(args[1], 'Jak[ia]kolwiek') or string.find(args[1], 'Jakiekolwiek') or string.find(args[1], 'Każd[yae]')), -1)
current = string.sub(current, 1, (string.find(current, ',') or string.find(current, ';') or 0) - 1)
local prefix = string.sub(current, 1, string.find(current, ' ') - 1)
current = string.sub(current, string.find(current, ' '), -1)
local gender = string.sub(prefix, -1)
local replacement = ''
-- Sprawdzenie czy nawias to typ dowolności i tego, czy jest standardowy, czy nie
local tylkoBarwione = false
local standardowe = true
if string.find(current, '%(barwion[yae]%)') then
tylkoBarwione = true
current = string.sub(current, 1, string.find(current, 'barwion') - 2)
else
niestandardowe = mw.loadData('Moduł:Inventory slot/Niestandardowe dowolności')
if niestandardowe[mw.text.trim(current)] or niestandardowe[mw.text.trim(string.sub(current, 1, (string.find(current, '%(') or 0) - 1))..' %(prefiks%)'] or niestandardowe[mw.text.trim(string.sub(current, 1, (string.find(current, '%(') or 0) - 1))..' %(sufiks%)'] then
standardowe = false
local relay = ''
if string.find(current, '%(') then
relay = string.sub(current, string.find(current, '%(') + 1, string.find(current, '%)') - 1)
end
local base = string.sub(current, 1, (string.find(current, '%(') or 0) - 1)
if niestandardowe[mw.text.trim(base)..' '..'%(prefiks%)'] then
for i, v in ipairs(niestandardowe[mw.text.trim(base)..' %(prefiks%)']) do
if string.find(v, 'Każd[xyea]') then
replacement = replacement..v..' %('..mw.text.trim(relay)..'%);'
else
replacement = replacement..v..' '..mw.text.trim(relay)..';'
end
end
elseif niestandardowe[mw.text.trim(base)..' %(sufiks%)'] then
for i, v in ipairs(niestandardowe[mw.text.trim(base)..' %(sufiks%)']) do
if string.find(v, 'Każd[xyea]') then
replacement = replacement..v..' %('..mw.text.trim(relay)..'%);'
else
replacement = replacement..mw.text.trim(relay)..' '..v..';'
end
end
else
for i, v in ipairs(niestandardowe[mw.text.trim(current)]) do
replacement = replacement..v..';'
end
end
replacement = string.gsub(replacement, 'x', gender)
replacement = string.sub(replacement, 1, -2)
-- Usuwanie znaków "%" powodujących błędy
replacement = string.gsub(replacement, '%%', '')
end
end
-- Standardowy typ dowolności
if standardowe then
if (prefix == 'Dowolny') or (prefix == 'Jakikolwiek') or (prefix == 'Każdy') then
replacement = 'Czerwony'..current..';Pomarańczowy'..current..';Żółty'..current..';Jasnozielony'..current..';Zielony'..current..';Błękitny'..current..';Jasnoniebieski'..current..';Niebieski'..current..';Fioletowy'..current..';Purpurowy'..current..';Różowy'..current..';Brązowy'..current..';Czarny'..current..';Szary'..current..';Jasnoszary'..current..';Biały'..current
else
if (prefix == 'Dowolna') or (prefix == 'Jakakolwiek') or (prefix == 'Każda') then
replacement = 'Czerwona'..current..';Pomarańczowa'..current..';Żółta'..current..';Jasnozielona'..current..';Zielona'..current..';Błękitna'..current..';Jasnoniebieska'..current..';Niebieska'..current..';Fioletowa'..current..';Purpurowa'..current..';Różowa'..current..';Brązowa'..current..';Czarna'..current..';Szara'..current..';Jasnoszara'..current..';Biała'..current
else replacement = 'Czerwone'..current..';Pomarańczowe'..current..';Żółte'..current..';Jasnozielone'..current..';Zielone'..current..';Błękitne'..current..';Jasnoniebieskie'..current..';Niebieskie'..current..';Fioletowe'..current..';Purpurowe'..current..';Różowe'..current..';Brązowe'..current..';Czarne'..current..';Szare'..current..';Jasnoszare'..current..';Białe'..current
end
end
end
if tylkoBarwione then replacement = string.sub(replacement, 1, string.find(replacement, ';Biał') - 1) end
args[1] = string.sub(args[1], 1, (string.find(args[1], 'Dowoln[yea]') or string.find(args[1], 'Jak[ia]kolwiek') or string.find(args[1], 'Jakiekolwiek') or string.find(args[1], 'Każd[yae]')) - 1)..replacement..string.sub(args[1], string.find(args[1], string.sub(current, 1, (string.find(current,'%(') or 0) - 1)) + string.len(current), -1)
if tylkoBarwione then args[1] = string.sub(args[1], 1, string.find(args[1], '(barwion[yae])') - 2) end
args[1] = mw.text.trim(args[1] or '')
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["mod"] )
local id = frameParts.name
if frameParts.mod then
id = frameParts.mod .. ':' .. id
end
local alias
if modAliases and modAliases[id] then
alias = modAliases[id]
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
--- Tworzenie spriteów
-- Opcje
local sprite
local ids = mw.loadData([[Moduł:InvSprite/IDs]])["ids"]
local modIds = {}
local back_modIds = {}
local animated = mw.ustring.find(args[1], ';')
local pageName = mw.title.getCurrentTitle().text
local imgClass = args["klasa obrazu"]
local numStyle = args["styl numerów"]
local body = mw.html.create('span'):css{['vertical-align'] = args["wyrówn"]}
if animated then
body:addClass('animated')
end
if args["klasa"] then
body:addClass(args["klasa"])
end
body:addClass('invslot')
if args["styl"] then
body:cssText(args["styl"])
end
--[[
if (args["domyślne"] or '') ~= '' then
body:css('background-image', '{{FileUrl|' .. args["domyślne"] .. '.png}}')
end
--]]
--- sprity w tle
if (args["domyślneCSS"] or '') ~= '' then
local mod=args["mod"]
if mod then
local back_modData = back_modIds[mod]
if not back_modData and mw.title.new('Moduł:TłoSprit/' .. mod .. '/ID').exists then
back_modData = mw.loadData('Moduł:TłoSprit/' .. mod .. '/ID')
back_modIds[mod] = back_modData
end
if back_modData then
param = mw.loadData('Moduł:TłoSprit/' .. mod)
local n = args["domyślneCSS"]
local pos = back_modData[n] - 1
local size = param["wielkość"]
local tiles = param["format"] / size
local left = pos % tiles * size
local top = math.floor( pos / tiles ) * size
-- body:css('background-image', '{{FileUrl|' .. mod .. 'CSS.png}}')
body:css('background-size', 'auto')
body:css('background-position', '-' .. left .. 'px -' .. top ..'px')
end
end
end
--- Obsługa klatek
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
end
if frame == '' then
(item or body):tag('br')
else
local category
local parts = p.getParts(frame, args["mod"])
local title = parts.title or mw.text.trim(args["title"] or '')
local mod = parts.mod
local name = parts.name
local num = parts.num
local description = parts.text
local img, idData
if mod then
local modData = modIds[mod]
if not modData and mw.title.new('Moduł:InvSprite/' .. mod .. '/ID').exists then
modData = mw.loadData('Moduł:InvSprite/' .. mod .. '/ID')["IDs"]
modIds[mod] = modData
end
if modData and modData[name] then
idData = modData[name]
else
img = name .. ' (' .. mod .. ')'
end
elseif ids[name] then
idData = ids[name]
else
img = name
end
local link = args["link"] or ''
if link == '' then
if mod then
link = mod .. '/' .. name
else
link = mw.ustring.gsub(name, '^Uszkodzon[yea] ', '')
end
elseif mw.ustring.lower(link) == 'nie' 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) ~= 'nie' 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
}
if img then
--- Obsługa rozszerzeń
local extension = ''
if mw.title.new('Grid '..img..'.gif', 'Plik').exists then
extension = '.gif'
else
extension = '.png'
end
-- & jest ponownie zmieniany, ponieważ mw.html traktuje atrybuty
-- jako zwykły tekst, ale MediaWiki tego nie robi
local escapedTitle = ( plainTitle or '' ):gsub( '&', '&' )
local file = 'Grid '..img..extension
if not mw.title.new(file, 'Plik').exists then
file = 'No image.svg'
end
item:addClass('invslot-item-image')
:wikitext('[[Plik:', file, '|32x32px|link=', link or '', '|', escapedTitle, ']]')
else
if not sprite then
sprite = require([[Moduł:Sprite]]).sprite
end
local image
if mod then
image = (args["tablica Ikonek"] or mod or "Inv") .. 'CSS.png'
end
if link then
item:wikitext('[[', link, '|')
end
local image, spriteCat;
if not mod then
image, spriteCat = sprite{
["danychID"] = idData, ["title"] = plainTitle,
["obraz"] = image, ["ustawienia"] = 'InvSprite'
}
else
image, spriteCat = sprite{
["danychID"] = idData, ["title"] = plainTitle,
["obraz"] = image, ["ustawienia"] = 'InvSprite/' .. 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
if item then
item:addClass('animated-active')
end
end
return tostring( body )
end
function p.expandAlias( frameParts, alias )
-- Jeśli ramka nie ma części, możemy po prostu zwrócić alias bez zmian
--[[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)
----Funkcja pobiera nazwę pozycji w formacie "[tytuł] mod: nazwa [tekst], numer"
----parts.title = tytuł, nazwa przedmiotu po najechaniu myszą
----parts.mod = mod
----parts.name = Nazwa
----parts.text = tekst, dodatkowy tekst po najechaniu kursorem na element
----parts.num = numer
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 '') ---- Uzyskaj nazwę modyfikacji
local vanilla = {v = 1, vanilla = 1, mc = 1, minecraft = 1}
if parts.mod == '' or vanilla[mw.ustring.lower(parts.mod)] then
parts.mod = nil
end
if p.modAliases[parts.mod] then
parts.mod = p.modAliases[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