Moduł:MetroKopUA test: Różnice pomiędzy wersjami
MetroKopUA (dyskusja | edycje) Utworzono nową stronę "local p = {} local formatnum = require( Модуль:Formatnum ) local ukrainian = mw.language.new('uk') local breakingTimeHeader; local function getBreakingTimeHeader( f ) if breakingTimeHeader == nil then breakingTimeHeader = 'Час руйнування (в секундах)' .. f:preprocess( '<ref group="note" name="breakingtimenote">Час не враховує інші фактори впливу (наприклад, «Утома») і вим…" |
(Brak różnic)
|
Wersja z 23:08, 19 lip 2025
W tym module nie ma dokumentacji. Jeśli wiesz jak używać tego modułu, proszę, podaj odpowiednie informacje.
local p = {}
local formatnum = require( [[Модуль:Formatnum]] )
local ukrainian = mw.language.new('uk')
local breakingTimeHeader;
local function getBreakingTimeHeader( f )
if breakingTimeHeader == nil then
breakingTimeHeader = 'Час [[руйнування]] (в секундах)' .. f:preprocess( '<ref group="note" name="breakingtimenote">Час не враховує інші фактори впливу (наприклад, «[[Утома]]») і вимірюється в секундах. Для отримання додаткової інформації див. [[Руйнування#Швидкість|Руйнування § Швидкість]].</ref>' )
end
return breakingTimeHeader
end
local function getBreakingTimeOptionsRows( f, colums, showEfficiency )
local header = mw.html.create('tr')
:css('display', 'none')
:addClass('calculatorgadget-enabled')
:tag('th')
:attr('colspan', colums + 1)
:wikitext('Опції')
:done()
local efficiency = ''
if showEfficiency then
efficiency = mw.html.create('tr')
:css('display', 'none')
:addClass('calculatorgadget-enabled')
:tag('th')
:wikitext(f:expandTemplate{ title = 'Ярлик простого калькулятора', args = {
['ярлик'] = '[[Ефективність]]',
['для'] = 'efficiencyLevel'
}})
:done()
:tag('td')
:attr('colspan', colums)
:tag('div')
:css('display', 'flex')
:css('gap', '3px')
:wikitext(
f:expandTemplate{ title = 'Простий калькулятор', args = {
['стиль'] = 'font-variant-numeric: tabular-nums',
['тип'] = 'plain',
['формула'] = 'efficiencyLevel',
['усталено'] = 0
}},
f:expandTemplate{ title = 'Простий калькулятор', args = {
id = 'efficiencyLevel',
['стиль'] = 'width: 85px',
['тип'] = 'range',
['списокданих'] = '0;1;2;3;4;5',
['мін'] = 0,
['макс'] = 5,
['крок'] = 1,
['усталено'] = 0
}},
f:expandTemplate{ title = 'Простий калькулятор', args = {
id = 'efficiencySpeed' ,
['тип'] = 'hidden',
['формула'] = 'ifzero(efficiencyLevel, 0, 1 +efficiencyLevel *efficiencyLevel)',
['усталено'] = 0
}}
)
:done()
:done()
end
local haste = mw.html.create('tr')
:css('display', 'none')
:addClass('calculatorgadget-enabled')
:tag('th')
:wikitext(f:expandTemplate{ title = 'Простий калькулятор-сховати якщо нуль', args = {
['формула'] = 'hasteJE',
'[[Квапливість]]'
}})
:wikitext(f:expandTemplate{ title = 'Простий калькулятор-сховати якщо нуль', args = {
['формула'] = 'hasteBE',
['початково приховано'] = 1,
'[[Поспіх]]'
}})
:done()
:tag('td')
:css('display', 'none')
:addClass('calculatorgadget-enabled')
:attr('colspan', colums)
:tag('div')
:css('display', 'flex')
:css('gap', '3px')
:wikitext(
f:expandTemplate{ title = 'Простий калькулятор', args = {
['стиль'] = 'font-variant-numeric: tabular-nums',
['тип'] = 'plain',
['формула'] = 'hasteLevel',
['усталено'] = 0
}},
f:expandTemplate{ title = 'Простий калькулятор', args = {
id = 'hasteLevel',
['стиль'] = 'width: 50px',
['тип'] = 'range',
['списокданих'] = '0;1;2',
['мін'] = 0,
['макс'] = 2,
['крок'] = 1,
['усталено'] = 0
}},
f:expandTemplate{ title = 'Простий калькулятор', args = {
id = 'hasteMultiplier',
['тип'] = 'hidden',
['формула'] = '1 +0.2*hasteLevel*ifzero(hasteBE, 1, pow(1.2, hasteLevel))',
['усталено'] = 1
}}
)
:tag('div')
:css('display', 'flex')
:css('gap', 'inherit')
:css('filter', 'grayscale(calc(1 - min(1,var(--calculator-hasteLevel)))) opacity(calc(0.5 + 0.5 * min(1,var(--calculator-hasteLevel))))')
:attr('role', 'radiogroup')
:attr('aria-label', 'Haste Edition')
:attr('id', 'hasteEdition')
:wikitext(
f:expandTemplate{ title = 'Простий калькулятор', args = {
id = 'hasteJE',
['тип'] = 'radio',
['назва'] = 'hasteEdition',
['усталено'] = '1'
}},
f:expandTemplate{ title = 'Ярлик простого калькулятора', args = {
['ярлик'] = 'JE',
['для'] = 'hasteJE'
}},
f:expandTemplate{ title = 'Простий калькулятор', args = {
id = 'hasteBE',
['тип'] = 'radio',
['назва'] = 'hasteEdition'
}},
f:expandTemplate{ title = 'Ярлик простого калькулятора', args = {
['ярлик'] = 'BE',
['для'] = 'hasteBE'
}}
)
:done()
:done()
:done()
return tostring(header) .. tostring(efficiency) .. tostring(haste)
end
p.row = function( f )
local args = require( [[Модуль:ProcessArgs]] ).norm()
local sprite = require( [[Модуль:СпрайтФайл]] )
local getDplVar = function( var )
local val = f:callParserFunction( '#dplvar', 'breaking ' .. var )
if val == '' then
val = false
end
return val
end
local dplVars = {}
local setDplVar = function( var, val )
table.insert( dplVars, 'breaking ' .. var )
table.insert( dplVars, val or '1' )
end
local rows = {}
local tableParts = {}
local categories = {}
local showOptions = false
local horizontal
if args["встовпчик"] or args[1]:match( ';' ) then
horizontal = true
end
local showTool = true
local showShears = true
local showSword = true
local header, sortable, simple
if horizontal or not getDplVar( 'header' ) then
if args["приховатиінструмент"] or horizontal and ( not args[2] or args[2]:lower() == 'Будь-який' or args[2]:lower() == 'Немає' ) then
showTool = false
setDplVar( 'hidetool' )
breakingTimeHeader = 'Час [[Добування|руйнування]] (сек)'
end
if args["приховатиножиці"] or horizontal and not args["ножиці"] then
showShears = false
setDplVar( 'hideshears' )
end
if args["приховатимеч"] or horizontal and not args["меч"] then
showSword = false
setDplVar( 'hidesword' )
end
sortable = not horizontal and args["сортування"]
if sortable then
setDplVar( 'sortable' )
end
simple = args.simple
if simple and not horizontal then
setDplVar( 'simple' )
end
local tableClasses = { 'wikitable' }
if sortable then
table.insert( tableClasses, 'sortable' )
end
table.insert( rows, ' {| class="' .. table.concat( tableClasses, ' ' ) .. '" style="text-align: center; margin: 0;"' )
local sortType = ''
if sortable then
sortType = 'data-sort-type="number"'
end
local rowspan = ''
if not horizontal then
rowspan = 'rowspan="2" '
end
header = {
'! ' .. rowspan .. ' | Блок'
}
if not simple then
table.insert( header, '! ' .. rowspan .. sortType .. ' | [[Добування#Блоки за твердістю|Твердість]]' )
if showTool then
table.insert( header, '! ' .. rowspan .. ' | [[Інструмент]]' )
end
end
local toolColumns = {}
if showTool then
local firsttool = mw.text.trim( simple and 'Інструмент' or args[2] or 'Будь-яке' ):gsub( '^%l', string.upper )
firsttool = mw.text.split( firsttool, ';' )[1]
if firsttool == 'Кайло' or firsttool == 'кайло' then
toolColumns = { "Дерев’яне", "Кам’яне", "Мідне", "Залізне", "Діамантове", "Незеритове", "Золоте" }
elseif firsttool == 'Лопата' or firsttool == 'лопата' or firsttool == 'Сокира' or firsttool == 'сокира' then
toolColumns = { "Дерев’яна", "Кам’яна", "Мідна", "Залізна", "Діамантова", "Незеритова", "Золота" }
else
toolColumns = { "Дерев’яний", "Кам’яний", "Мідний", "Залізний", "Діамантовий", "Незеритовий", "Золотий" }
end
end
table.insert( toolColumns, 1, 'Усталено' )
if not simple then
if showShears then
table.insert( toolColumns, 'Ножиці' )
end
if showSword then
table.insert( toolColumns, 'Меч' )
end
end
if not horizontal then
table.insert( header, '! colspan="' .. #toolColumns .. '" |' .. getBreakingTimeHeader( f ) )
table.insert( header, '|-' )
end
local toolSprites = {
["Дерев’яне"] = { 'Блок', 'дубові-дошки' },
["Дерев’яна"] = { 'Блок', 'дубові-дошки' },
["Дерев’яний"] = { 'Блок', 'дубові-дошки' },
["Кам’яне"] = { 'Блок', 'кругляк' },
["Кам’яна"] = { 'Блок', 'кругляк' },
["Кам’яний"] = { 'Блок', 'кругляк' },
["Мідне"] = { 'Предмет', 'мідний-злиток' },
["Мідна"] = { 'Предмет', 'мідний-злиток' },
["Мідний"] = { 'Предмет', 'мідний-злиток' },
["Залізне"] = { 'Предмет', 'залізний-злиток' },
["Залізна"] = { 'Предмет', 'залізний-злиток' },
["Залізний"] = { 'Предмет', 'залізний-злиток' },
["Діамантове"] = { 'Предмет', 'діамант' },
["Діамантова"] = { 'Предмет', 'діамант' },
["Діамантовий"] = { 'Предмет', 'діамант' },
["Незеритове"] = { 'Предмет', 'незеритовий-злиток' },
["Незеритова"] = { 'Предмет', 'незеритовий-злиток' },
["Незеритовий"] = { 'Предмет', 'незеритовий-злиток' },
["Золоте"] = { 'Предмет', 'золотий-злиток' },
["Золота"] = { 'Предмет', 'золотий-злиток' },
["Золотий"] = { 'Предмет', 'золотий-злиток' },
["Ножиці"] = { 'Предмет', 'ножиці' },
["Меч"] = { 'Предмет', "дерев'яний-меч" }
}
for _, tool in ipairs( toolColumns ) do
if toolSprites[tool] then
local image, spriteCat = sprite.sprite{
name = toolSprites[tool][1],
toolSprites[tool][2],
text = tool
}
table.insert( header, '! style="text-align:left" ' .. sortType .. ' | ' .. image )
table.insert( categories, spriteCat )
else
table.insert( header, '! ' .. sortType .. ' | ' .. tool )
end
end
if not horizontal then
header = table.concat( header, '\n' )
setDplVar( 'header', header )
end
table.insert( tableParts, header )
else
showTool = not getDplVar( 'hidetool' )
showShears = not getDplVar( 'hideshears' )
showSword = not getDplVar( 'hidesword' )
sortable = getDplVar( 'sortable' )
simple = getDplVar( 'simple' )
end
local hardness = require( [[Модуль:Значення блоків]] ).value
local fillCells = function( cellsTable, text, num )
for i = 1, num do
table.insert( cellsTable, text )
end
end
local materialGrade = {
Any = 0,
Wooden = 1, Wood = 1,
Golden = 1,
Stone = 2,
Copper = 2,
Iron = 3,
Diamond = 4,
Netherite = 5,
None = 6,
["Будь-який"] = 0, ["Будь-яка"] = 0, ["Будь-яке"] = 0,
["Дерев'яний"] = 1, ["Дерев'яна"] = 1, ["Дерев'яне"] = 1, ["Дерев’яний"] = 1, ["Дерев’яна"] = 1, ["Дерев’яне"] = 1,
["Золотий"] = 1, ["Золота"] = 1, ["Золоте"] = 1,
["Кам'яний"] = 2, ["Кам'яна"] = 2, ["Кам'яне"] = 2, ["Кам’яний"] = 2, ["Кам’яна"] = 2, ["Кам’яне"] = 2,
["Мідний"] = 2, ["Мідна"] = 2, ["Мідне"] = 2,
["Залізний"] = 3, ["Залізна"] = 3, ["Залізне"] = 3,
["Діамантовий"] = 4, ["Діамантова"] = 4, ["Діамантове"] = 4,
["Незеритовий"] = 5, ["Незеритова"] = 5, ["Незеритове"] = 5,
["Немає"] = 6,
}
local materialSpeed = {
None = 1,
Any = 1,
Wooden = 2, Wood = 2,
Stone = 4,
Copper = 5,
Iron = 6,
Diamond = 8,
Netherite = 9,
Golden = 12,
["Немає"] = 1,
["Будь-який"] = 1, ["Будь-яка"] = 1, ["Будь-яке"] = 1,
["Дерев'яний"] = 2, ["Дерев'яна"] = 2, ["Дерев'яне"] = 2, ["Дерев’яний"] = 2, ["Дерев’яна"] = 2, ["Дерев’яне"] = 2,
["Кам'яний"] = 4, ["Кам'яна"] = 4, ["Кам'яне"] = 4, ["Кам’яний"] = 4, ["Кам’яна"] = 4, ["Кам’яне"] = 4,
["Мідний"] = 5, ["Мідна"] = 5, ["Мідне"] = 5,
["Залізний"] = 6, ["Залізна"] = 6, ["Залізне"] = 6,
["Діамантовий"] = 8, ["Діамантова"] = 8, ["Діамантове"] = 8,
["Незеритовий"] = 9, ["Незеритова"] = 9, ["Незеритове"] = 9,
["Золотий"] = 12, ["Золота"] = 12, ["Золоте"] = 12,
}
local numberMaterials = 6
local insertBlock = function( blockArgs )
local cells = {}
local blocks = mw.text.split( blockArgs[1], '%s*,%s*' )
local hardnessNum = hardness{ blocks[1], ["тип"] = 'твердости' }:gsub(',', '.')
local hardnessVal = tonumber( hardnessNum )
if not hardnessVal then
hardnessVal = '?'
end
local unbreakable
if hardnessVal == -1 or blockArgs.liquid then
unbreakable = true
elseif hardnessVal ~= 0 then
showOptions = true
end
local blockSprites = {}
local links = mw.text.split( blockArgs.link or '', '%s*,%s*' )
local ids = mw.text.split( blockArgs.sprite or '', '%s*,%s*' )
local items = mw.text.split( blockArgs.item or '', '%s*,%s*' )
for i, block in ipairs( blocks ) do
local link
if not links[i] and links[1] ~= '' then
link = links[1]
elseif links[i] ~= '' then
link = links[i]
end
local id
if not ids[i] and ids[1] ~= '' then
id = ids[1]
elseif ids[i] ~= '' then
id = ids[i]
end
local blockText
if args.textTrim then
blockText = block:gsub( args.textTrim .. '$', '' )
else
blockText = block
end
local blockSpriteArgs = {
name = 'Блок',
block,
text = blockText,
link = link,
id = id
}
if items[i] == '1' or not items[i] and items[1] == '1' then
blockSpriteArgs.data = 'Предмет'
end
local image, spriteCat = sprite.link( blockSpriteArgs )
table.insert( blockSprites, image )
table.insert( categories, spriteCat )
end
table.insert( cells,
'!' .. (horizontal and '' or ' style="text-align:left" | ') .. table.concat( blockSprites, '<br>' ) .. ( blockArgs.note or '' )
)
local tool = mw.text.trim( simple and 'інструмент' or blockArgs[2] or 'Будь-яка' or 'Будь-яке' or 'Будь-який' ):gsub( '^%l', string.upper )
local material = mw.text.trim( simple and blockArgs[2] or blockArgs[3] or 'Будь-яка' or 'Будь-яке' or 'Будь-який' ):gsub( '^%l', string.upper )
if tool == 'Немає' then
material = tool
end
if not simple then
local hardnessText = formatnum.formatNum(hardnessVal, 'uk')
if hardnessVal == -1 then
hardnessText = ( sortable and 'data-sort-value="9999" | ' or '' ) .. "-1 (нескінченно)"
end
table.insert( cells, '|' .. hardnessText )
if showTool then
local toolCell = '—'
if tool ~= 'Будь-який' and tool ~= 'Немає' then
local isMaterialSpecified = ( material ~= 'Будь-яка' and material ~= 'Будь-яке' and material ~= 'Будь-який' ) and (material ~= 'Немає')
local toolName = ( isMaterialSpecified and material .. ' ' or '' ) .. tool
local ftoolName = toolName
local toolClass = ''
if not isMaterialSpecified then
if ukrainian:lc(tool) == 'кайло' then
ftoolName = "Потрібне кайло"
toolClass = 'slot-pickaxe-required-sprite-file'
end
if ukrainian:lc(tool) == 'сокира' then
ftoolName = "Потрібна сокира"
toolClass = 'slot-axe-required-sprite-file'
end
if ukrainian:lc(tool) == 'лопата' then
ftoolName = "Потрібна лопата"
toolClass = 'slot-shovel-required-sprite-file'
end
if ukrainian:lc(tool) == 'мотика' then
ftoolName = "Потрібна мотика"
toolClass = 'slot-hoe-required-sprite-file'
end
end
local image, spriteCat = sprite.sprite{
name = isMaterialSpecified and 'Предмет' or 'Слот',
keepcase = not isMaterialSpecified,
ftoolName,
title = toolName,
link = tool,
class = toolClass
}
toolCell = ( sortable and 'data-sort-value="' .. toolName .. '" |' or '' ) .. image
table.insert( categories, spriteCat )
end
table.insert( cells, '|' .. toolCell )
end
end
local choices = {}
local function getChoice( choice, text )
if not choices[choice] then
choices[choice] = f:expandTemplate{ title = 'Table Choice', args = { choice, '' } }
end
return choices[choice] .. text
end
local function processTime( actualHardness, baseSpeed )
-- the number passed in has been multiplied by 100
local num = actualHardness / baseSpeed
if num <= 5 then -- Blocks with a breaking time of <= 1 game tick (0.05 seconds) are not instant mined (no delay after each block broken)
num = "''0.05''" -- Blocks have a minimum breaking time of 1 game tick
else -- And they must be broken in multiples of 1 game tick
num = math.ceil( num / 5 ) / 20
end
return '<span class="calculator-field breakingrow-breakingtime-value" data-calculator-type="plain" data-calculator-formula="'
.. 'max(1,ceil(' .. (actualHardness / 5) .. '/(' .. baseSpeed .. (baseSpeed > 1 and '+efficiencySpeed' or '') .. ')/hasteMultiplier))/20'
.. '">' .. num .. '</span>'
end
if hardnessVal == '?' then
fillCells( cells, '|?', 7 )
else
if unbreakable then
table.insert( cells, '| ' .. ( sortable and 'data-sort-value="9999" ' or '' ) .. getChoice( 'ні', '∞' ) )
if showTool then
fillCells( cells, '|—', 7 )
end
else
local drop = 'так'
if blockArgs['дроп'] == '0' then
drop = 'частково'
elseif blockArgs['дроп'] == '1' then
forceDrop = 'так'
end
local requiredLevel = unbreakable and 999 or materialGrade[material]
local insertMaterialCell = function( material )
local shouldDrop = drop
if materialGrade[material] < requiredLevel then
shouldDrop = 'ні'
end
local breakTime = processTime( hardnessVal * (shouldDrop == 'ні' and 500 or 150), materialSpeed[material])
table.insert( cells, '|' .. getChoice( forceDrop or shouldDrop, formatnum.formatNum(breakTime, 'uk') ) )
end
if not showTool or tool == 'Будь-яке' or tool == 'Ні' then
insertMaterialCell( 'Будь-яке' )
if showTool then
fillCells( cells, '|—', 7 )
end
else
for _, material in ipairs{ 'Any', 'Wooden', 'Stone', 'Copper', 'Iron', 'Diamond', 'Netherite', 'Golden' } do
insertMaterialCell( material )
end
end
end
if not simple and ( showShears or showSword ) then
local tools = {}
if showShears then
table.insert( tools, 'Ножиці' )
end
if showSword then
table.insert( tools, 'Меч' )
end
if hardnessVal == '?' then
fillCells( cells, '|?', #tools )
else
local toolSpeed = {
['Ножиці'] = 1,
['Меч'] = 1.5
}
if blocks[1] == 'Вовна' then
toolSpeed['Ножиці'] = 5
elseif blocks[1] == 'Листя' then
toolSpeed['Ножиці'] = 15
elseif blocks[1] == 'Павутиння' then
toolSpeed['Меч'] = 15
toolSpeed['Ножиці'] = 15
end
for _, tool in ipairs( tools ) do
local toolDrop = blockArgs[mw.ustring.lower( tool )]
if not toolDrop then
table.insert( cells, '|—' )
else
local willDrop = 'так'
if toolDrop == '0' then
willDrop = 'частково'
end
local breakTime = processTime( hardnessVal * 150, toolSpeed[tool] )
table.insert( cells, '|' .. getChoice( willDrop, formatnum.formatNum(breakTime, 'uk') ) )
end
end
end
end
end
if not horizontal then
cells = table.concat( cells, '\n' )
end
table.insert( tableParts, cells )
end
if horizontal then
local blocksArgs = {}
for _, arg in ipairs{ 1, 'note', 'sprite', 'link', 'item', 'дроп', 2, 3, 'ножиці', 'меч' } do
if args[arg] then
local col = 0
for colVal in mw.text.gsplit( args[arg], '%s*;%s*' ) do
col = col + 1
if colVal ~= '' then
if not blocksArgs[col] then
blocksArgs[col] = {}
end
blocksArgs[col][arg] = colVal
end
end
end
end
for _, block in ipairs( blocksArgs ) do
insertBlock( block )
end
local columns = #tableParts
for row = 1, #tableParts[1] do
local cells = {}
for col = 1, columns do
table.insert( cells, tableParts[col][row] )
end
table.insert( rows, table.concat( cells, '\n' ) )
end
-- Insert breaking time header after block row when simple, or after tool or hardness row when not
table.insert( rows, simple and 3 or showTool and 5 or 4, '! colspan="' .. columns + 1 .. '" |' .. getBreakingTimeHeader( f ) )
if showOptions and not args.hideoptions and not args['сховатиопції'] then
table.insert( rows, getBreakingTimeOptionsRows( f, columns, showTool ) )
end
else
insertBlock( args )
for _, row in ipairs( tableParts ) do
table.insert( rows, row )
end
table.insert( rows, '' )
end
local note = ''
if args.foot or horizontal then
note = f:preprocess( '<references group="note"/>' )
if args.foot == '2' then
table.insert( rows, header or getDplVar( 'header' ) )
end
table.insert( rows, '|}' )
if not horizontal then
f:callParserFunction( '#dplvar:set',
'breaking header', '',
'breaking hidetool', '',
'breaking hideshears', '',
'breaking hidesword', '',
'breaking simple', '',
'breaking sortable', ''
)
end
elseif #dplVars > 0 then
f:callParserFunction( '#dplvar:set', dplVars )
end
local result = table.concat( rows, '\n|-\n' )
if horizontal then
local styles = require( [[Модуль:Завантажувач TS]] ).call( 'Шаблон:Таблиця руйнування/styles.css' ) .. '\n'
return styles ..
'<div style="--calculator-hasteLevel: 0;" class="calculator-container breakingrow-container">' ..
'<div>\n' .. result .. '\n</div>' ..
'<div>' ..
"'''Легенда'''" ..
'\n*' .. f:expandTemplate{ title = 'Легенда', args = {'', ['клас'] = 'tc-no', 'нічого не випадає'}} ..
'\n*' .. f:expandTemplate{ title = 'Легенда', args = {'', ['клас'] = 'tc-partial', 'випадає щось крім самого блока'}} ..
'\n*' .. f:expandTemplate{ title = 'Легенда', args = {'', ['клас'] = 'tc-yes', 'випадає сам блок'}} ..
"\n* ''курсивний'' можна [[Миттєвий видобуток|видобути миттєво]]" ..
'\n' ..
'</div>' ..
'</div>' ..
note .. table.concat( categories )
end
return result .. note .. table.concat( categories )
end
return p