Module:OOOInfoBox: Difference between revisions

mNo edit summary
mNo edit summary
 
(8 intermediate revisions by the same user not shown)
Line 44: Line 44:
   if v == nil or v == '' then return nil end
   if v == nil or v == '' then return nil end
   return tostring(v) .. (unit or '')
   return tostring(v) .. (unit or '')
end
local function format_price(v)
  if not v then return nil end
  local n = tonumber(v)
  if not n then return v end
  local s = tostring(math.floor(n))
  s = s:reverse():gsub("(%d%d%d)", "%1 "):reverse():gsub("^ ", "")
  return s .. ".-"
end
end


Line 201: Line 213:


   if caption and caption ~= '' then
   if caption and caption ~= '' then
    box:tag('tr')
 
      :tag('td')
  -- Section title
      :addClass('ooo-infobox__caption')
  add_group_header(box, 'Description')
      :attr('colspan','2')
 
      :wikitext(caption)
  -- Section content
  end
  local tr = box:tag('tr')
  tr:tag('td')
    :attr('colspan','2')
    :css('text-align','left')
    :css('padding','4px 4px')
    :wikitext(caption)
 
end


   -- -------------------------------------------------------------------------
   -- -------------------------------------------------------------------------
Line 212: Line 231:
   -- -------------------------------------------------------------------------
   -- -------------------------------------------------------------------------


   add_group(box,'General',{
   add_group(box,'General Information',{
     {'Art Number', art},
     {'Art Number', art},
     {'Category',  pick(args,data,'category')},
     {'Category',  pick(args,data,'category')},
     {'Subcategory',pick(args,data,'subcategory')},
     {'Subcategory',pick(args,data,'subcategory')},
     {'Price',      pick(args,data,'price')},
     {'Price',      format_price(pick(args,data,'price'))},
   })
   })
-- -------------------------------------------------------------------------
-- Vehicle
-- -------------------------------------------------------------------------
local function format_capacity(v)
  local n = tonumber(v)
  if not n then return v end
  return string.format("%.1f%s", n/1000, U.m3)
end
local function format_fuel_use(v)
  local n = tonumber(v)
  if not n or n < 0 then return nil end
  return tostring(n) .. " L/h"
end
local function format_fuel_capacity(v)
  local n = tonumber(v)
  if not n then return nil end
  return tostring(n) .. " L"
end
local function format_weight(v)
  local n = tonumber(v)
  if not n then return v end
  local s = tostring(math.floor(n))
  s = s:reverse():gsub("(%d%d%d)", "%1 "):reverse():gsub("^ ", "")
  return s .. " kg"
end
add_group(box,'Vehicle Details',{
  {'Unlock Level', pick(args,data,'level')},
  {'Weight', format_weight(pick(args,data,'weight'))},
  {'Capacity', format_capacity(pick(args,data,'capacity'))},
  {'Fuel Tank', format_fuel_capacity(pick(args,data,'fuelCapacity'))},
  {'Fuel Usage', format_fuel_use(pick(args,data,'fuelBaseUse'))},
})


   -- -------------------------------------------------------------------------
   -- -------------------------------------------------------------------------
Line 231: Line 288:
   -- -------------------------------------------------------------------------
   -- -------------------------------------------------------------------------


  if domain ~= 'Vehicles' then
   add_group(box,'Performance',{
   add_group(box,'Performance',{
     {'Throughput (m³/h)', pick(args,data,'throughput_m3h')},
     {'Throughput (m³/h)', pick(args,data,'throughput_m3h')},
     {'Capacity',          pick(args,data,'capacity')},
     {'Capacity',          pick(args,data,'capacity')},
   })
   })
end


   -- -------------------------------------------------------------------------
   -- -------------------------------------------------------------------------
Line 263: Line 322:


   add_group(box,'Dimensions',{
   add_group(box,'Dimensions',{
     {'Overall', join_dims(size_w,size_l,size_h,U.m), 'Width × Length × Height'},
     {'Overall (W × H × L)', join_dims(size_w,size_l,size_h,U.m), 'Width × Height × Length'},
     {'Note',    size_note},
     {'Note',    size_note},
   })
   })