🌟 | 現在、 鉄壁ヘッドショットには対応済みです。 鉄壁HSは通常HSと同じダメージになります。LMG及びDMR、チャージライフル、ハンマーポイント弾を除き、すべてのダメージ値が一致していることを確認しています。 |
「モジュール:WeaponInfobox/Duration」の版間の差分
ナビゲーションに移動
検索に移動
(シンプルな表であるかのデータを返すように改善) |
(複数の値を持つ表をlisttableからintableスタイルに変更) |
||
9行目: | 9行目: | ||
local formatter -- lazily initialized | local formatter -- lazily initialized | ||
local function | -- Constants | ||
local leftBorder = { | |||
['border-left-width'] = '1px', | |||
['border-left-style'] = 'solid', | |||
} | |||
local leftBorderWithoutTopRightBorder = { | |||
['border-top'] = '0 none transparent', | |||
['border-right'] = '0 none transparent', | |||
['border-left-width'] = '1px', | |||
['border-left-style'] = 'solid', | |||
} | |||
-- Duration for multiple value | |||
local function createMultipleRow(tbl, name, default, common, rare, epic, opts) | |||
opts = opts or {} | opts = opts or {} | ||
local row = tbl:tag('tr') | local row = tbl:tag('tr') | ||
:tag('th') | if aw.isNumberAndGreaterThanZero(opts.offset) then | ||
for i = 1, opts.offset do | |||
local hasLeftBorder = opts.offsetStyles and opts.offsetStyles[i] and opts.offsetStyles[i].leftBorder | |||
if hasLeftBorder then | |||
row:tag('th') | |||
:css(leftBorderWithoutTopRightBorder) | |||
:wikitext(' ') | |||
else | |||
row:tag('th') | |||
:css('border', '0 none transparent') | |||
:wikitext(' ') | |||
end | |||
end | |||
end | |||
row:tag('th') | |||
:attrIf(aw.isNumber(opts.colspan), { colspan = opts.colspan }) | |||
:cssIf(aw.isNumberAndGreaterThanZero(opts.offset), leftBorder) | |||
:wikitext(name) | |||
row | |||
:tag('td') | :tag('td') | ||
:addClass('cell-type-number') | :addClass('cell-type-number') | ||
:attr('align', ' | :attr('align', 'right') | ||
:wikitext(default) | :wikitext(default) | ||
:done() | :done() | ||
:tag('td') | :tag('td') | ||
:addClass('cell-type-number') | :addClass('cell-type-number') | ||
:attr('align', ' | :attr('align', 'right') | ||
:wikitext(formatter:common(common)) | :wikitext(formatter:common(common)) | ||
:done() | :done() | ||
:tag('td') | :tag('td') | ||
:addClass('cell-type-number') | :addClass('cell-type-number') | ||
:attr('align', ' | :attr('align', 'right') | ||
:wikitext(formatter:rare(rare)) | :wikitext(formatter:rare(rare)) | ||
:done() | :done() | ||
:tag('td') | :tag('td') | ||
:addClass('cell-type-number') | :addClass('cell-type-number') | ||
:attr('align', ' | :attr('align', 'right') | ||
:wikitext(formatter:epic(epic)) | :wikitext(formatter:epic(epic)) | ||
:done() | :done() | ||
return row | return row | ||
end | end | ||
local function renderDurationWithStock(stat, duration, stock, canModdedLoader, tbl) | local function renderDurationWithStock(stat, duration, stock, canModdedLoader, isSniper) | ||
local tbl = mw.html.create('table') | |||
:addClass('intable') | |||
local rootOpts = { colspan = 2 } | |||
local secondOpts = { offset = 1 } | |||
-- Header | |||
local stockName = isSniper and 'スナイパーストック' or '標準ストック' | |||
tbl:tag('tr') | |||
:tag('th') | |||
:attr('colspan', 2) | |||
:wikitext(name) | |||
:done() | |||
:tag('th'):done() | |||
:tag('th'):wikitext(iu.attachment(stockName, 1)):done() | |||
:tag('th'):wikitext(iu.attachment(stockName, 2)):done() | |||
:tag('th'):wikitext(iu.attachment(stockName, 3)) | |||
-- Reload | -- Reload | ||
if aw.isNumber(stat.time.reload.tactical) then | if aw.isNumber(stat.time.reload.tactical) then | ||
createMultipleRow( | |||
tbl, | tbl, | ||
duration.reload.name, | duration.reload.name, | ||
62行目: | 100行目: | ||
string.format(duration.reload.format, stat.time.reload.tactical * stock.reload[2]), | string.format(duration.reload.format, stat.time.reload.tactical * stock.reload[2]), | ||
string.format(duration.reload.format, stat.time.reload.tactical * stock.reload[3]), | string.format(duration.reload.format, stat.time.reload.tactical * stock.reload[3]), | ||
rootOpts) | |||
if canModdedLoader then | if canModdedLoader then | ||
createMultipleRow( | |||
tbl, | tbl, | ||
iu.passive('modded_loader') | iu.passive('modded_loader'), | ||
string.format(duration.reload.format, stat.time.reload.tactical * 0.75), | string.format(duration.reload.format, stat.time.reload.tactical * 0.75), | ||
string.format(duration.reload.format, stat.time.reload.tactical * 0.75 * stock.reload[1]), | string.format(duration.reload.format, stat.time.reload.tactical * 0.75 * stock.reload[1]), | ||
string.format(duration.reload.format, stat.time.reload.tactical * 0.75 * stock.reload[2]), | string.format(duration.reload.format, stat.time.reload.tactical * 0.75 * stock.reload[2]), | ||
string.format(duration.reload.format, stat.time.reload.tactical * 0.75 * stock.reload[3]), | string.format(duration.reload.format, stat.time.reload.tactical * 0.75 * stock.reload[3]), | ||
secondOpts) | |||
end | end | ||
-- Reload (Empty) | -- Reload (Empty) | ||
if aw.isNumber(stat.time.reload.full) and stat.time.reload.tactical ~= stat.time.reload.full then | if aw.isNumber(stat.time.reload.full) and stat.time.reload.tactical ~= stat.time.reload.full then | ||
createMultipleRow( | |||
tbl, | tbl, | ||
duration.reloadempty.name, | duration.reloadempty.name, | ||
83行目: | 121行目: | ||
string.format(duration.reloadempty.format, stat.time.reload.full * stock.reload[2]), | string.format(duration.reloadempty.format, stat.time.reload.full * stock.reload[2]), | ||
string.format(duration.reloadempty.format, stat.time.reload.full * stock.reload[3]), | string.format(duration.reloadempty.format, stat.time.reload.full * stock.reload[3]), | ||
rootOpts) | |||
if canModdedLoader then | if canModdedLoader then | ||
createMultipleRow( | |||
tbl, | tbl, | ||
iu.passive('modded_loader') | iu.passive('modded_loader'), | ||
string.format(duration.reloadempty.format, stat.time.reload.full * 0.75), | string.format(duration.reloadempty.format, stat.time.reload.full * 0.75), | ||
string.format(duration.reloadempty.format, stat.time.reload.full * 0.75 * stock.reload[1]), | string.format(duration.reloadempty.format, stat.time.reload.full * 0.75 * stock.reload[1]), | ||
string.format(duration.reloadempty.format, stat.time.reload.full * 0.75 * stock.reload[2]), | string.format(duration.reloadempty.format, stat.time.reload.full * 0.75 * stock.reload[2]), | ||
string.format(duration.reloadempty.format, stat.time.reload.full * 0.75 * stock.reload[3]), | string.format(duration.reloadempty.format, stat.time.reload.full * 0.75 * stock.reload[3]), | ||
secondOpts) | |||
end | end | ||
end | end | ||
99行目: | 137行目: | ||
-- Zoom In | -- Zoom In | ||
if aw.isNumber(stat.time.zoom_in) then | if aw.isNumber(stat.time.zoom_in) then | ||
createMultipleRow( | |||
tbl, | tbl, | ||
duration.zoomin.name, | duration.zoomin.name, | ||
106行目: | 144行目: | ||
string.format(duration.zoomin.format, stat.time.zoom_in * stock.zoom[2]), | string.format(duration.zoomin.format, stat.time.zoom_in * stock.zoom[2]), | ||
string.format(duration.zoomin.format, stat.time.zoom_in * stock.zoom[3]), | string.format(duration.zoomin.format, stat.time.zoom_in * stock.zoom[3]), | ||
rootOpts) | |||
end | end | ||
-- Zoom Out | -- Zoom Out | ||
if aw.isNumber(stat.time.zoom_out) then | if aw.isNumber(stat.time.zoom_out) then | ||
createMultipleRow( | |||
tbl, | tbl, | ||
duration.zoomout.name, | duration.zoomout.name, | ||
118行目: | 156行目: | ||
string.format(duration.zoomout.format, stat.time.zoom_out * stock.zoom[2]), | string.format(duration.zoomout.format, stat.time.zoom_out * stock.zoom[2]), | ||
string.format(duration.zoomout.format, stat.time.zoom_out * stock.zoom[3]), | string.format(duration.zoomout.format, stat.time.zoom_out * stock.zoom[3]), | ||
rootOpts) | |||
end | end | ||
return tbl | |||
end | end | ||
-- Duration for single value | |||
local function renderRow(tbl, name, num, opts) | local function renderRow(tbl, name, num, opts) | ||
opts = opts or {} | opts = opts or {} | ||
147行目: | 188行目: | ||
end | end | ||
local function renderDurationWithoutStock(stat, duration, stock, canModdedLoader, tbl | local function renderDurationWithoutStock(stat, duration, stock, canModdedLoader, isSpecial) | ||
local tbl = mw.html.create('table') | |||
:addClass('condensedtable') | |||
:addClass('listtable') | |||
-- Reload | -- Reload | ||
if aw.isNumber(stat.time.reload.tactical) then | if aw.isNumber(stat.time.reload.tactical) then | ||
225行目: | 270行目: | ||
{ footer = duration.zoomout.unit }) | { footer = duration.zoomout.unit }) | ||
end | end | ||
return tbl | |||
end | end | ||
231行目: | 278行目: | ||
local duration = cfg[lang].duration | local duration = cfg[lang].duration | ||
local isSniper = stat.category == 'sniper' or stat.category == 'marksman_weapon' | |||
local stock | local stock | ||
if | if isSniper then | ||
stock = attachment.sniper_stock | stock = attachment.sniper_stock | ||
else | else | ||
239行目: | 287行目: | ||
local canModdedLoader = stat.category == 'light_machine_gun' or stat.ammo == 'minigun' | local canModdedLoader = stat.category == 'light_machine_gun' or stat.ammo == 'minigun' | ||
local isSpecial = aw.stringstarts(stat.ammo, 'special_') and not (stat.ammo == 'special_sniper') | local isSpecial = aw.stringstarts(stat.ammo, 'special_') and not (stat.ammo == 'special_sniper') | ||
local isSimple = not stat.attachments.stock or isSpecial | local isSimple = not stat.attachments.stock or isSpecial | ||
local node | |||
if isSimple then | if isSimple then | ||
renderDurationWithoutStock(stat, duration, stock, canModdedLoader | node = renderDurationWithoutStock(stat, duration, stock, canModdedLoader, isSpecial) | ||
else | else | ||
renderDurationWithStock(stat, duration, stock, canModdedLoader, | node = renderDurationWithStock(stat, duration, stock, canModdedLoader, isSniper) | ||
end | end | ||
return | return node, isSimple | ||
end | end | ||
2021年8月6日 (金) 10:58時点における版
このモジュールについての説明文ページを モジュール:WeaponInfobox/Duration/doc に作成できます
require('Module:Utility/mw.html Extensions') local p = {} local cfg = mw.loadData('Module:WeaponInfobox/configuration') local attachment = mw.loadData('Module:Stat/Attachment') local aw = require('Module:Utility/Library') local iu = require('Module:Utility/Image') local formatter -- lazily initialized -- Constants local leftBorder = { ['border-left-width'] = '1px', ['border-left-style'] = 'solid', } local leftBorderWithoutTopRightBorder = { ['border-top'] = '0 none transparent', ['border-right'] = '0 none transparent', ['border-left-width'] = '1px', ['border-left-style'] = 'solid', } -- Duration for multiple value local function createMultipleRow(tbl, name, default, common, rare, epic, opts) opts = opts or {} local row = tbl:tag('tr') if aw.isNumberAndGreaterThanZero(opts.offset) then for i = 1, opts.offset do local hasLeftBorder = opts.offsetStyles and opts.offsetStyles[i] and opts.offsetStyles[i].leftBorder if hasLeftBorder then row:tag('th') :css(leftBorderWithoutTopRightBorder) :wikitext(' ') else row:tag('th') :css('border', '0 none transparent') :wikitext(' ') end end end row:tag('th') :attrIf(aw.isNumber(opts.colspan), { colspan = opts.colspan }) :cssIf(aw.isNumberAndGreaterThanZero(opts.offset), leftBorder) :wikitext(name) row :tag('td') :addClass('cell-type-number') :attr('align', 'right') :wikitext(default) :done() :tag('td') :addClass('cell-type-number') :attr('align', 'right') :wikitext(formatter:common(common)) :done() :tag('td') :addClass('cell-type-number') :attr('align', 'right') :wikitext(formatter:rare(rare)) :done() :tag('td') :addClass('cell-type-number') :attr('align', 'right') :wikitext(formatter:epic(epic)) :done() return row end local function renderDurationWithStock(stat, duration, stock, canModdedLoader, isSniper) local tbl = mw.html.create('table') :addClass('intable') local rootOpts = { colspan = 2 } local secondOpts = { offset = 1 } -- Header local stockName = isSniper and 'スナイパーストック' or '標準ストック' tbl:tag('tr') :tag('th') :attr('colspan', 2) :wikitext(name) :done() :tag('th'):done() :tag('th'):wikitext(iu.attachment(stockName, 1)):done() :tag('th'):wikitext(iu.attachment(stockName, 2)):done() :tag('th'):wikitext(iu.attachment(stockName, 3)) -- Reload if aw.isNumber(stat.time.reload.tactical) then createMultipleRow( tbl, duration.reload.name, string.format(duration.reload.format, stat.time.reload.tactical), string.format(duration.reload.format, stat.time.reload.tactical * stock.reload[1]), string.format(duration.reload.format, stat.time.reload.tactical * stock.reload[2]), string.format(duration.reload.format, stat.time.reload.tactical * stock.reload[3]), rootOpts) if canModdedLoader then createMultipleRow( tbl, iu.passive('modded_loader'), string.format(duration.reload.format, stat.time.reload.tactical * 0.75), string.format(duration.reload.format, stat.time.reload.tactical * 0.75 * stock.reload[1]), string.format(duration.reload.format, stat.time.reload.tactical * 0.75 * stock.reload[2]), string.format(duration.reload.format, stat.time.reload.tactical * 0.75 * stock.reload[3]), secondOpts) end -- Reload (Empty) if aw.isNumber(stat.time.reload.full) and stat.time.reload.tactical ~= stat.time.reload.full then createMultipleRow( tbl, duration.reloadempty.name, string.format(duration.reloadempty.format, stat.time.reload.full), string.format(duration.reloadempty.format, stat.time.reload.full * stock.reload[1]), string.format(duration.reloadempty.format, stat.time.reload.full * stock.reload[2]), string.format(duration.reloadempty.format, stat.time.reload.full * stock.reload[3]), rootOpts) if canModdedLoader then createMultipleRow( tbl, iu.passive('modded_loader'), string.format(duration.reloadempty.format, stat.time.reload.full * 0.75), string.format(duration.reloadempty.format, stat.time.reload.full * 0.75 * stock.reload[1]), string.format(duration.reloadempty.format, stat.time.reload.full * 0.75 * stock.reload[2]), string.format(duration.reloadempty.format, stat.time.reload.full * 0.75 * stock.reload[3]), secondOpts) end end end -- Zoom In if aw.isNumber(stat.time.zoom_in) then createMultipleRow( tbl, duration.zoomin.name, string.format(duration.zoomin.format, stat.time.zoom_in), string.format(duration.zoomin.format, stat.time.zoom_in * stock.zoom[1]), string.format(duration.zoomin.format, stat.time.zoom_in * stock.zoom[2]), string.format(duration.zoomin.format, stat.time.zoom_in * stock.zoom[3]), rootOpts) end -- Zoom Out if aw.isNumber(stat.time.zoom_out) then createMultipleRow( tbl, duration.zoomout.name, string.format(duration.zoomout.format, stat.time.zoom_out), string.format(duration.zoomout.format, stat.time.zoom_out * stock.zoom[1]), string.format(duration.zoomout.format, stat.time.zoom_out * stock.zoom[2]), string.format(duration.zoomout.format, stat.time.zoom_out * stock.zoom[3]), rootOpts) end return tbl end -- Duration for single value local function renderRow(tbl, name, num, opts) opts = opts or {} opts.separator = opts.separator or ' - ' local row = tbl:tag('tr') :addClassIf(opts.class and type(opts.class) == 'string', opts.class) :tag('th') :attrIf(opts.headerAlign and type(opts.headerAlign) == 'string', { align = opts.headerAlign }) :wikitext(name) :done() :tag('td') :addClass('cell-type-number') :attr('align', 'left') :wikitext(num) :done() if opts.footer ~= nil then row:tag('td') :attrIf(opts.footerAlign and type(opts.footerAlign) == 'string', { align = opts.footerAlign }, { align = 'left' }) :attrIf(opts.footerColspan and type(opts.footerColspan) == 'number', { colspan = opts.footerColspan }) :wikitext(opts.footer) end return row end local function renderDurationWithoutStock(stat, duration, stock, canModdedLoader, isSpecial) local tbl = mw.html.create('table') :addClass('condensedtable') :addClass('listtable') -- Reload if aw.isNumber(stat.time.reload.tactical) then local reload if isSpecial then reload = stat.time.reload.tactical * stock.reload[3] else reload = stat.time.reload.tactical end renderRow( tbl, duration.reload.name, string.format(duration.reload.format, reload), { footer = duration.reload.unit }) if canModdedLoader then renderRow( tbl, iu.passive('modded_loader') .. ' ', string.format(duration.reload.format, reload * 0.75), { class = 'no-list-style', headerAlign = 'right', footer = duration.reload.unit }) end -- Reload (Empty) if aw.isNumber(stat.time.reload.full) and stat.time.reload.tactical ~= stat.time.reload.full then local reloadempty if isSpecial then reloadempty = stat.time.reload.full * stock.reload[3] else reloadempty = stat.time.reload.full end renderRow( tbl, duration.reloadempty.name, string.format(duration.reloadempty.format, reloadempty), { footer = duration.reload.unit }) if canModdedLoader then renderRow( tbl, iu.passive('modded_loader') .. ' ', string.format(duration.reloadempty.format, reloadempty * 0.75), { class = 'no-list-style', headerAlign = 'right', footer = duration.reload.unit }) end end end -- Zoom In if aw.isNumber(stat.time.zoom_in) then local zoomin if isSpecial then zoomin = stat.time.zoom_in * stock.zoom[3] else zoomin = stat.time.zoom_in end renderRow( tbl, duration.zoomin.name, string.format(duration.zoomin.format, zoomin), { footer = duration.zoomin.unit }) end -- Zoom Out if aw.isNumber(stat.time.zoom_out) then local zoomout if isSpecial then zoomout = stat.time.zoom_out * stock.zoom[3] else zoomout = stat.time.zoom_out end renderRow( tbl, duration.zoomout.name, string.format(duration.zoomout.format, zoomout), { footer = duration.zoomout.unit }) end return tbl end function p.renderDuration(stat, lang) formatter = require('Module:Utility/Formatter').new(frame) local duration = cfg[lang].duration local isSniper = stat.category == 'sniper' or stat.category == 'marksman_weapon' local stock if isSniper then stock = attachment.sniper_stock else stock = attachment.standard_stock end local canModdedLoader = stat.category == 'light_machine_gun' or stat.ammo == 'minigun' local isSpecial = aw.stringstarts(stat.ammo, 'special_') and not (stat.ammo == 'special_sniper') local isSimple = not stat.attachments.stock or isSpecial local node if isSimple then node = renderDurationWithoutStock(stat, duration, stock, canModdedLoader, isSpecial) else node = renderDurationWithStock(stat, duration, stock, canModdedLoader, isSniper) end return node, isSimple end function p._main(name, lang) lang = lang or 'ja' local stat = mw.loadData('Module:Stat/Weapon')[name] local node, _ = p.renderDuration(stat, lang) return tostring(node) end return p