User:Darkid/Sandbox2/pt-br

From Team Fortress Wiki
< User:Darkid‎ | Sandbox2
Revision as of 03:03, 13 June 2019 by Darkid (talk | contribs)
Jump to: navigation, search

-- TODO: Missing features: -- Stat clocks: https://wiki.teamfortress.com/wiki/Civilian_Grade_Stat_Clock -- Halloween spells: https://www.youtube.com/watch?v=kA7K4jNnMmQ -- War paint prefix -- TODO: Update the golden frying pan (strange professional killstreak)

local p = {}

require('Module:Backpack item/format')

-- Defined here so that it can be referenced inside the next function local frame = nil

--[[ A more natural way to invoke templates in lua. Examples:

 /pt-br -> template('If lang')
Veja também: Foo

-> template('See also', 'Foo')

Foo

-> template('Hatnote', {'Foo', 'Bar'})

 English
 ->
 template('Lang', {
   ['de'] = 'German',
   ['en'] = 'English',
   ['ru'] = 'Russian',
 }

]] function template(title, args)

 if type(args) == 'string' then
   args = {args}
 end
 return frame:expandTemplate{title=title, args=args}

end

-- Returns '(text)', with correct parenthesis characters in Chinese. function paren(text)

 return template('Lang', {
   -- English and default
   ['en']      = '(' .. text .. ')',
   ['zh-hans'] = '(' .. text .. ')',
   ['zh-hant'] = '(' .. text .. ')',
 })

end

-- Colors are from styles in https://wiki.teamfortress.com/wiki/MediaWiki:Common.css local grade_colors = {

 civilian  = 'B0C3D9',
 freelance = '5E98D9',
 mercenary = '4B69FF',
 commando  = '8847FF',
 assassin  = 'D32CE6',
 elite     = 'EB4B4B',

}

local quality_colors = {

 normal         = 'B2B2B2',
 unusual        = '8650AC',
 vintage        = '476291',
 unique         = 'FFD700',
 community      = '70B04A',
 valve          = 'A50F79',
 ['self-made']  = '70B04A',
 customized     = '476291',
 genuine        = '4D7455',
 strange        = 'CF6A32',
 completed      = '8650AC',
 haunted        = '38F3AB',
 collectors     = 'C00000',
 decorated      = 'FAFAFA',

}

-- Potentially add the icon in the corner (paint splotch, unusual, pyroland, etc) function get_corner_icon(args)

 local image
 local image_link
 if args['paint-color'] then
   image = 'Paint Splat ' .. args['paint-color']
   image_link = 'Paint Can'
 elseif args['unusual-effect'] then
   image = 'Viewmode unusual'
   image_link = 'Unusual'
 elseif args['decal-icon'] then
   image = 'Paint Splat Decal'
   image_link = 'Decal Tool'
 elseif args['strange-icon'] then
   image = 'Viewmode strange'
   image_link = 'Strange'
 elseif args['stat-icon'] then
   image = 'Viewmode statclock'
   image_link = 'Decorated'
 elseif args['pyroland-icon'] then
   image = 'Viewmode pyrovision'
   image_link = 'Pyroland'
 else -- Early exit if there's no icon, there's no reason to make an empty div
   return 
 end

local icon_begin = '

' local icon_end = '

'

 return icon_begin .. '25px' .. icon_end

end

-- The main item image (and link) function get_main_image(args)

 local image
 local image_link = args['item-name']
 if args['custom-icon'] then
   image = args['custom-icon']
   image_link = '{Darkid/Sandbox2'
 elseif args['grade'] and args['wear'] then
   image = 'Backpack ' .. args['item-name'] .. ' ' .. args['item-kind'] .. ' ' .. args['wear'] .. '.png'
 elseif args['festivized'] then
   image = 'Backpack Festivized ' .. args['item-name'] .. '.png'
 elseif args['item-name'] then
   image = 'Backpack ' .. args['item-name'] .. '.png'
 else
   image = 'Backpack Unknownweapon.png'
 end
 local wikitext = 'link=' .. image_link   end   return wikitext .. ''

end

-- The color and font for the full name of the item function get_full_item_name_style(args)

 local color
 if args['custom-color'] then
   color = args['custom-color']
 elseif grade_colors[args['grade']] then
   color = '#' .. grade_colors[args['grade']]
 elseif quality_colors[args['quality']] then
   color = '#' .. quality_colors[args['quality']]
 else -- Default
   color = '#' .. quality_colors['unique']
 end
 local style = 'color: ' .. color .. '; font-size:18px; line-height:16px; text-shadow: 2px 1px 1px #24201B; font-family:'
 -- Specific fonts for some languages that aren't supported by the standard TF2 Build font.
 style = style .. template('Lang', {
   ['ar']      = 'مبنيات TF2, bold;',
   -- English and default
   ['en']      = 'TF2 Build, Verdana, Geneva, sans-serif;',
   ['hu']      = 'Verdana, Geneva, sans-serif; font-weight: bold;',
   ['ja']      = 'TF2 Build, Shin Go, Heisei Kaku Gothic W5; font-weight: bold;',
   ['ko']      = 'Pathang, sans-serif, Totum, Kodig, serif; font-weight: bold;',
   ['zh-hans'] = 'SimSum-18030, SimHei, serif; font-weight: bold;',
   ['zh-hant'] = 'JhengHei, Verdana, JhengHei, JhengHei, sans-serif; font-weight: bold;',
 })
 return style

end

-- The full name of the item, including any prefixes and suffixes function get_full_item_name(args)

 -- Early exit if 'custom-name' is specified.
 if args['custom-name'] then
   if args['no-custom-name-quotes'] == 'yes' then
     return args['custom-name']
   else
     return '"' .. args['custom-name'] .. '"'
   end
 end
 -- Step 2: Compute the strings
 local festivized = 
 local filter = 
 local item_name = 
 local killstreak = 
 local quality = 
 if args['festivized'] then
   festivized = template('Decorated name', 'festivized')
 end
 if args['filter'] then
   filter = template('Item name', 'from ' .. args['filter'])
 end
 if args['item-name-local'] then
   item_name = args['item-name-local']
 else
   item_name = template('Item name', args['item-name'])
 end
 -- TODO: killstreak string comes from somewhere, maybe it's directly in the template?
 -- I can probably do better than that.
 if args['killstreak'] then
   killstreak = 'KILLSTREAK'
 end
 if args['quality'] == 'unique' or args['quality'] == 'normal' then
   -- Unique and Normal weapons do not have a quality name
 elseif args['quality'] == 'strange' then
   quality = template('Strange rank name', {['item-name']=args['item-name'], rankson=args['rankson'], kills=args['killcount']})
 elseif args['quality'] ~= nil then
   -- Not one of the above qualities, default to the quality name.
   quality = template('Item name', args['quality'])
 end
 return format_string(template('Lang', item_name_format), {
   festivized=festivized,
   filter=filter,
   item_name=item_name,
   killstreak=killstreak,
   quality=quality,
   prefix=args['prefix'],
   suffix=args['suffix'],
 })

end

-- The full level of the item, including any strange suffixes, wears, grades, etc function get_full_item_level(args)

 if args['no-level'] == 'yes' then
   return 
 end
 -- Step 1: Precompute a bunch of language-aware strings
 local limited = 
 local item_kind = 
 local grade = 
 local wear = 
 local rankson = 
 local strange_rank_name = 
 local item_level = 
 if args['limited'] then
   limited = '' .. template('Common string', 'backpack item limited') .. ' '
 end
 if args['item-kind'] then
   item_kind = args['item-kind'] .. ' '
 end
 if args['grade'] then
   grade = template('Decorated name', args['grade'] .. ' grade') .. ' '
 end
 if args['wear'] then
   wear = paren(template('Decorated name', args['wear'])) .. ' '
 end
 if args['rankson'] then
   strange_rank_name = template('Strange rank name', {['item-name']=args['item-name'], rankson=args['rankson'], kills=args['killcount']}) .. ' '
   rankson = '- ' .. template('Item name', args['rankson']) .. ': ' .. args['killcount'] .. ' '
   for n = 2, 10 do
     if args['rankson' .. n] then
       if args['killcount' .. n] == nil then args['killcount' .. n] = 0 end
       rankson = rankson .. '
' .. paren(template('Item name', args['rankson' .. n]) .. ': ' .. args['killcount' .. n]) end end end
 -- Adapted from WebAPI
 -- Missing languages: de, fi, nl
 -- Self translated: none
 if args['item-level'] then
   item_level = args['item-level']
   if args['item-kind'] then
     item_level = template('Common string', {'backpack item level', args['item-level']}) .. ' '
   end
 end
 -- Step 2: Allow individual languages to specify how to order the strings
 -- Note that there are essentially three types of weapon levels: Strange, Grade/Wear, and default.
 local full_item_level;
 if grade ~=  then
   -- Adapted from WebAPI
   -- Missing translation: all
   -- Self translated: none
   -- TODO

--[[

   full_item_level = template('Lang', {
     ['cs']      =
     ['da']      =
     ['de']      =
     ['en']      = grade .. item_kind .. wear,
     ['es']      =
     ['fi']      =
     ['fr']      =
     ['hu']      =
     ['it']      =
     ['ja']      =
     ['ko']      =
     ['nl']      =
     ['no']      =
     ['pl']      =
     ['pt']      =
     ['pt-br']   =
     ['ro']      =
     ['ru']      =
     ['sv']      =
     ['tr']      =
     ['zh-hans'] =
     ['zh-hant'] =
   })

]]

   full_item_level = grade .. item_kind .. wear
 elseif strange_rank_name ~=  then
   assert(false, template('Lang', item_desc_format_strange) .. item_desc_format_strange);
   full_item_level = format_string(template('Lang', item_desc_format_strange), {
     limited=limited,
     strange_rank_name=strange_rank_name,
     item_kind=item_kind,
     rankson=rankson,
   })
 else
   -- Adapted from WebAPI
   -- Missing translation: all
   -- Self translated: none
   -- TODO

--[[

   full_item_level = template('Lang', {
     ['cs']      =
     ['da']      =
     ['de']      =
     ['en']      = limited .. item_level .. item_kind,
     ['es']      =
     ['fi']      =
     ['fr']      =
     ['hu']      =
     ['it']      =
     ['ja']      =
     ['ko']      =
     ['nl']      =
     ['no']      =
     ['pl']      =
     ['pt']      =
     ['pt-br']   =
     ['ro']      =
     ['ru']      =
     ['sv']      =
     ['tr']      =
     ['zh-hans'] =
     ['zh-hant'] =
   })

]]

   full_item_level = limited .. item_level .. item_kind
 end
 -- Step 3: Add coloring for certain types
 local color = '#756B5E'
 if args['limited'] then
   color = 'yellow'
 elseif grade_colors[args['grade']] then
   color = '#' .. grade_colors[args['grade']]
 end
 return '' .. full_item_level .. ''

end

function p.backpack_item(f)

 frame = f
 -- TODO: Trying this, it may not work.
 local args = f.args
 if #args == 0 then args = f.args end
 -- Setting some defaults for parameters
 if args['width'] == nil then args['width'] = '100%' end
 if args['style'] == nil then args['style'] =  end
 if args['killcount'] == nil then args['killcount'] = 0 end
 if args['item-level'] == nil then args['item-level'] = '1-100' end
 -- Normalize some parameters
 if args['quality'] ~= nil then args['quality'] = args['quality']:lower() end
 if args['grade'] ~= nil then args['grade'] = args['grade']:lower() end
 if args['no-custom-name-quotes'] ~= nil then args['no-custom-name-quotes'] = args['no-custom-name-quotes']:lower() end
 if args['prefix'] ~= nil then args['prefix'] = args['prefix']:lower() end
 if args['suffix'] ~= nil then args['suffix'] = args['suffix']:lower() end
 -- Define the div for the darker, background box with rounded corners

body = '

'
 -- Add the div for the lighter, foreground box which holds the item image
-- TODO:
? This is probably not needed. body = body .. '
'
 body = body .. get_corner_icon(args)
 body = body .. get_main_image(args)
 -- End of foreground box
body = body .. '
'
 -- Add a transparent div for the text.
body = body .. '
'
 -- Add the main item name (and style)
 body = body .. '' .. get_full_item_name(args) .. ''
 -- Add a div for the secondary attributes
body = body .. '
   ['en']      = 'TF2 Secondary, Verdana, Geneva, sans-serif;',
   ['hu']      = 'Verdana, Genva, sans-serif; font-weight: bold;',
   ['ja']      = 'TF2 Secondary, Shin Go, Heisei Kaku Gothic W5; font-weight: bold;',
   ['ko']      = 'Pathang, sans-serif, Totum, Kodig, serif; font-weight: bold;',
   ['zh-hans'] = 'SimSum-18030, SimHei, serif;',
   ['zh-hant'] = 'JhengHei, JhengHei, sans-serif;',
 }) .. 'font-size: 15px">'
 body = body .. get_full_item_level(args)
 -- TODO: Something legacy with strange-secondary and att-strangerank?
 if args['unusual-effect'] then
   body = body .. '
' .. template('Common string', {'backpack item unusual effect', args['unusual-effect']}) .. '' end
 for n = 1, 8 do
   if args['att-' .. n .. '-positive'] then
     body = body .. '
' .. args['att-' .. n .. '-positive'] .. '' elseif args['att-' .. n .. '-negative'] then body = body .. '
' .. args['att-' .. n .. '-negative'] .. '' elseif args['att-' .. n .. '-neutral'] then body = body .. '
' .. args['att-' .. n .. '-neutral'] .. '' end end
 if args['festivized'] then
   body = body .. '
' .. template('Common string', 'backpack item festivized') .. '' end if args['killstreaker'] then body = body .. '
' .. template('Common string', {'backpack item killstreaker', args['killstreaker']}) .. '' end if args['sheen'] then body = body .. '
' .. template('Common string', {'backpack item sheen', args['sheen']}) .. '' end if args['killstreak'] then body = body .. '
' .. template('Common string', 'backpack item killstreaks active') .. '' end
 local item_description
 if args['custom-description'] then
   item_description = '"' .. args['custom-description'] .. '"'
 elseif args['item-description'] then
   item_description = args['item-description']
 end
 if item_description ~= nil then
   -- TODO: Span containing just an nbsp? Why?
   body = body .. '
 ' body = body .. '
' .. item_description .. '' end
 if args['gift-from'] then
   body = body .. '

' .. template('Common string', {'backpack item gift from', args['gift-from']}) .. '' if args['date-received'] then body = body .. '
' .. template('Common string', {'backpack item date received', args['date-received']}) .. '' end end
 if args['item-expiration'] then
   body = body .. '

' .. template('Common string', {'backpack item item expiration', args['item-expiration']}) .. '' end if args['item-uses'] then body = body .. '

' .. template('Common string', {'backpack item item uses', args['item-uses']}) .. '' end if args['item-flags'] then body = body .. '

( ' .. args['item-flags'] .. ' )' end
 -- End of secondary attributes div
 -- End of transparent div
 -- End of darker, background box
body = body .. '

'

 return body

end

return p