Module:3D viewer advanced

From Inkipedia, the Splatoon wiki
Revision as of 08:21, 7 February 2022 by Shahar (talk | contribs) (removed size parameter)

Usage

Wikitext Output
{{#invoke:3D viewer advanced|viewer_new
  | 3d-image-1 = S2 Weapon Main .96 Gal
}}
https://cdn.wikimg.net/en/splatoonwiki/images/3/34/S2_Weapon_Main_.96_Gal_3D.png20568, 280, 184, 3, 0, 173, 6, 263, 147, 4, 527, 130, 4, 793, 171, 7, 1045, 147, 4, 1302, 133, 6, 1557, 170, 10, 1795, 146, 6, 2038, 133, 9, 2278, 168, 18, 2495, 146, 13, 2718, 135, 16, 2935, 167, 31, 3123, 144, 27, 3317, 136, 30, 3505, 167, 48, 3660, 144, 44, 3821, 138, 47, 3976, 165, 68, 4094, 143, 65, 4215, 138, 66, 4333, 164, 91, 4419, 141, 89, 4507, 136, 91, 4593, 164, 103, 4664, 141, 103, 4735, 135, 103, 4806, 164, 101, 4892, 141, 101, 4980, 136, 101, 5066, 165, 92, 5184, 143, 91, 5307, 138, 92, 5427, 167, 74, 5583, 144, 74, 5744, 138, 76, 5900, 167, 57, 6090, 144, 57, 6284, 136, 60, 6472, 168, 44, 6689, 146, 42, 6911, 135, 44, 7128, 170, 30, 7366, 147, 28, 7609, 133, 30, 7849, 171, 19, 8101, 147, 18, 8358, 133, 18, 8613, 173, 10, 8876, 147, 10, 9140, 130, 9, 9406, 175, 4, 9672, 149, 6, 9941, 129, 3, 10210, 176, 3, 10474, 150, 4, 10740, 127, 0, 11007, 176, 3, 11262, 152, 4, 11520, 126, 1, 11778, 178, 7, 12018, 152, 7, 12263, 126, 6, 12506, 179, 16, 12725, 153, 16, 12947, 126, 15, 13169, 178, 30, 13360, 153, 28, 13554, 127, 30, 13745, 179, 48, 13903, 155, 47, 14064, 130, 50, 14220, 179, 71, 14338, 153, 70, 14459, 130, 73, 14576, 179, 95, 14658, 155, 95, 14738, 132, 97, 14817, 178, 103, 14890, 155, 103, 14963, 132, 103, 15036, 179, 101, 15118, 155, 101, 15200, 132, 101, 15280, 179, 88, 15400, 153, 88, 15521, 130, 88, 15638, 179, 73, 15796, 155, 70, 15958, 129, 71, 16116, 178, 57, 16306, 153, 54, 16502, 127, 56, 16695, 179, 42, 16914, 153, 39, 17137, 126, 42, 17357, 178, 30, 17597, 152, 27, 17842, 126, 30, 18085, 176, 19, 18340, 152, 16, 18598, 126, 19, 18856, 176, 12, 19120, 150, 9, 19386, 126, 10, 19655, 175, 7, 19921, 150, 4, 20190, 129, 6
    {{{2}}}
    {{{2}}}
    {{#invoke:3D viewer advanced|viewer_new
      | 3d-image-1 = S2 Weapon Main Hero Charger Lv.0
      | 3d-image-2 = S2 Weapon Main Hero Charger Lv.1
      | 3d-viewname-1 = Level 1
      | 3d-viewname-2 = Level 2
      | 3d-button-1 = default_half
      | 3d-button-2 = default_half
    }}
    https://cdn.wikimg.net/en/splatoonwiki/images/3/3c/S2_Weapon_Main_Hero_Charger_Lv.0_3D.png19289, 280, 114, 3, 0, 85, 2, 260, 50, 0, 527, 88, 8, 784, 85, 1, 1035, 51, 0, 1292, 90, 9, 1538, 83, 6, 1773, 53, 4, 2012, 91, 13, 2241, 83, 16, 2451, 53, 14, 2666, 91, 23, 2871, 85, 30, 3052, 55, 29, 3237, 92, 37, 3413, 85, 49, 3559, 56, 49, 3707, 93, 56, 3846, 85, 71, 3953, 56, 71, 4061, 94, 77, 4162, 86, 98, 4224, 57, 98, 4286, 93, 99, 4347, 86, 123, 4380, 57, 123, 4413, 94, 123, 4446, 86, 119, 4508, 57, 118, 4570, 93, 118, 4631, 85, 101, 4738, 57, 99, 4846, 94, 101, 4948, 85, 85, 5093, 56, 82, 5241, 93, 83, 5381, 83, 67, 5562, 55, 65, 5747, 93, 67, 5922, 83, 53, 6134, 54, 50, 6349, 91, 51, 6554, 85, 39, 6788, 53, 35, 7028, 91, 37, 7257, 85, 27, 7508, 51, 23, 7764, 90, 24, 8010, 85, 17, 8271, 50, 12, 8538, 88, 13, 8795, 85, 9, 9060, 48, 4, 9331, 88, 6, 9592, 86, 6, 9853, 46, 0, 10120, 87, 2, 10379, 88, 6, 10629, 46, 0, 10886, 88, 2, 11135, 91, 11, 11368, 45, 4, 11607, 88, 7, 11838, 93, 20, 12047, 45, 14, 12262, 90, 17, 12470, 94, 34, 12651, 45, 29, 12837, 90, 32, 13017, 96, 54, 13162, 46, 49, 13312, 90, 51, 13456, 97, 77, 13560, 45, 74, 13668, 91, 76, 13772, 98, 104, 13833, 46, 103, 13895, 91, 104, 13956, 98, 129, 13978, 46, 129, 14000, 91, 129, 14022, 98, 114, 14082, 46, 113, 14144, 91, 114, 14205, 97, 97, 14309, 45, 97, 14417, 91, 98, 14521, 96, 80, 14666, 45, 80, 14816, 90, 83, 14960, 94, 64, 15141, 45, 64, 15327, 90, 69, 15507, 93, 49, 15717, 45, 49, 15934, 90, 54, 16143, 91, 35, 16376, 45, 35, 16616, 88, 40, 16849, 88, 23, 17099, 46, 23, 17355, 88, 29, 17602, 86, 13, 17862, 46, 12, 18129, 87, 19, 18386, 85, 6, 18649, 49, 4, 18920, 88, 12https://cdn.wikimg.net/en/splatoonwiki/images/d/dd/S2_Weapon_Main_Hero_Charger_Lv.1_3D.png19289, 280, 114, 3, 0, 85, 2, 260, 50, 0, 527, 88, 8, 784, 85, 1, 1035, 51, 0, 1292, 90, 9, 1538, 83, 6, 1773, 53, 4, 2012, 91, 13, 2241, 83, 16, 2451, 53, 14, 2666, 91, 23, 2871, 85, 30, 3052, 55, 29, 3237, 92, 37, 3413, 85, 49, 3559, 56, 49, 3707, 93, 56, 3846, 85, 71, 3953, 56, 71, 4061, 94, 77, 4162, 86, 98, 4224, 57, 98, 4286, 93, 99, 4347, 86, 123, 4380, 57, 123, 4413, 94, 123, 4446, 86, 119, 4508, 57, 118, 4570, 93, 118, 4631, 85, 101, 4738, 57, 99, 4846, 94, 101, 4948, 85, 85, 5093, 56, 82, 5241, 93, 83, 5381, 83, 67, 5562, 55, 65, 5747, 93, 67, 5922, 83, 53, 6134, 54, 50, 6349, 91, 51, 6554, 85, 39, 6788, 53, 35, 7028, 91, 37, 7257, 85, 27, 7508, 51, 23, 7764, 90, 24, 8010, 85, 17, 8271, 50, 12, 8538, 88, 13, 8795, 85, 9, 9060, 48, 4, 9331, 88, 6, 9592, 86, 6, 9853, 46, 0, 10120, 87, 2, 10379, 88, 6, 10629, 46, 0, 10886, 88, 2, 11135, 91, 11, 11368, 45, 4, 11607, 88, 7, 11838, 93, 20, 12047, 45, 14, 12262, 90, 17, 12470, 94, 34, 12651, 45, 29, 12837, 90, 32, 13017, 96, 54, 13162, 46, 49, 13312, 90, 51, 13456, 97, 77, 13560, 45, 74, 13668, 91, 76, 13772, 98, 104, 13833, 46, 103, 13895, 91, 104, 13956, 98, 129, 13978, 46, 129, 14000, 91, 129, 14022, 98, 114, 14082, 46, 113, 14144, 91, 114, 14205, 97, 97, 14309, 45, 97, 14417, 91, 98, 14521, 96, 80, 14666, 45, 80, 14816, 90, 83, 14960, 94, 64, 15141, 45, 64, 15327, 90, 69, 15507, 93, 49, 15717, 45, 49, 15934, 90, 54, 16143, 91, 35, 16376, 45, 35, 16616, 88, 40, 16849, 88, 23, 17099, 46, 23, 17355, 88, 29, 17602, 86, 13, 17862, 46, 12, 18129, 87, 19, 18386, 85, 6, 18649, 49, 4, 18920, 88, 12
    {{{2}}}
    {{{2}}}

    Parameters

    3d-image-n
    Filename for the nth 3D image, excluding the ' 3D.png', where n is an integer that starts at 1.
    3d-button-n
    View button class for the nth 3D image, where the class is one of the following:
    default_half: for default coloured buttons that are half width
    default_full or default: for default buttons that are full width
    Note: When using this setting, do NOT specify 3d-image-(n+1), 3d-button-(n+1), or 3d-viewname-(n+1).
    3d-viewname-n
    View name for the nth 3D image, where n is an integer that starts at 1.
    3d-startframe (optional)
    Allows you to override the starting frame for the 3D images, by setting to an integer value between 0 and 15.

    3D images are added to the viewer in the order they are defined.


    -- Module:3D viewer advanced, extracted from TF2Wiki. 
    
    local p = {}
    
    local utils = require('Module:Utils')
    local HtmlBuilder = require('Module:HtmlBuilder')
    local frame = nil
    
    -- Expands the template Common string for a given value. Note that some common string values include an additional parameter, here called opt_arg.
    function common_string(arg, opt_arg)
        return frame:expandTemplate{title='Common string', args={arg, opt_arg}}
    end
    
    -- Returns ' (text)', with correct parenthesis characters in Chinese.
    function paren(text)
        if if_lang == '/zh_hans' or if_lang == '/zh-hant' then
            return ' (' .. text .. ')'
        else
            return ' (' .. text .. ')'
        end
    end
    
    function p.viewer(f)
        local args = utils.get_args(f)
        local startframe = utils.processArg(args['startframe'])
        local image = utils.processArg(args['image'])
        local image_0 = utils.processArg(args['image-0'])
        local fallback = utils.processArg(args['fallback'])
        local startframe_class
        if startframe ~= '' then
            startframe_class = mw.text.trim(startframe)
        else
            startframe_class = utils.expandWikitext('{{File:' .. (image_0 or image) .. '|startframe}}')
        end
        local output_view = HtmlBuilder.create('div')
            .addClass('viewer-3d')
            .addClass('startframe-' .. startframe_class)
            .wikitext(fallback)
    
        for i = 0,10 do
            local image_n = utils.processArg(args['image-' .. i], '')
            if image_n ~= '' then
                span_image_url_n = output_view
                    .tag('span')
                    .addClass('viewer-3d-url-' .. i)
                    .wikitext(utils.expandWikitext('{{File:' .. image_n .. '|url}}'))
    
                span_image_map_n = output_view
                    .tag('span')
                    .addClass('viewer-3d-map-' .. i)
                    .wikitext(utils.expandWikitext('{{File:' .. image_n .. '|map}}'))
            end
        end
    
        local viewer_3d_frame = output_view
            .tag('div')
            .addClass('viewer-3d-frame')
    
        local switch_to_2d = output_view
            .tag('div')
            .attr('class', 'switch-to-2d')
    
        return tostring(output_view)
    end
    
    function p.viewer_new(f)
        frame = f
        local args = utils.get_args(f)
        
        -- button classes mapping
        local button_classes = {
            default_half = 'view-selector-default-',
            default_full = 'view-selector-default-full',
            default = 'view-selector-default-full'
        }
    
        -- create output container
        local output_view = HtmlBuilder.create('div')
            .addClass('viewer-3d-container')
        
        -- create container for viewer
        local startimage = utils.processArg(args['3d-image-1'])
        local startframe = args['3d-startframe'] or utils.expandWikitext('{{File:' .. startimage .. ' 3D.png|startframe}}')
        local viewer_container = output_view
            .tag('div')
            .addClass('viewer-3d')
            .addClass('startframe-' .. startframe)
    
        -- add 3D and 2D selectors
        local viewer_3d_frame = viewer_container
            .tag('div')
            .addClass('viewer-3d-frame')
    
        local switch_to_2d = viewer_container
            .tag('div')
            .attr('class', 'switch-to-2d')
    
        -- create container for model selector buttons
        local buttons_container = output_view
            .tag('ul')
            .addClass('buttons-container-3d')
    
        -- create container for 2D image
        local image_2d
        if args['image'] then
            image_2d = args['image']
        else
            image_2d = mw.title.getCurrentTitle().baseText .. '.png'
        end
        local viewer_2d_frame = output_view
            .tag('div')
            .wikitext(utils.expandWikitext('{{2D viewer|' .. image_2d .. '}}'))
    
        -- row button counter for half width buttons
        local current_row_count = 0
        local i = 1
        while utils.processArg(args['3d-image-' .. i]) ~= '' do
            local image_postfix = ' 3D.png'
            local viewname_postfix = ''
            local image_n = utils.processArg(args['3d-image-' .. i])
            local button_n = utils.processArg(args['3d-button-' .. i])
            local button_class = button_classes[button_n]
            local viewname_n = utils.processArg(args['3d-viewname-' .. i])
            if image_n ~= '' then
                span_image_url_n = viewer_container
                    .tag('span')
                    .addClass('viewer-3d-url-' .. (i-1))
                    .wikitext(utils.expandWikitext('{{File:' .. image_n .. image_postfix .. '|url}}'))
    
                span_image_map_n = viewer_container
                    .tag('span')
                    .addClass('viewer-3d-map-' .. (i-1))
                    .wikitext(utils.expandWikitext('{{File:' .. image_n .. image_postfix .. '|map}}'))
    
                -- if there is only one 3d image then don't attach selector
                if i == 1 and args['3d-image-2'] == nil and args['3d-image-3'] == nil then
                	break
                end
                -- add selector button for this model
                if button_n == 'default_half' then
                    if current_row_count == 0 then
                        button_class = button_class .. 'left'
                        current_row_count = 1
                    else
                        button_class = button_class .. 'right'
                        current_row_count = 0
                    end
                end
                -- selector is 0-indexed
                button_class = button_class .. ' selector-' .. (i-1)
                
                li_button_n = buttons_container
                    .tag('li')
                    .addClass(button_class)
                    .wikitext(utils.expandWikitext('[[:File:' .. image_n .. image_postfix .. '|' .. viewname_n .. viewname_postfix .. ']]'))
            end
    
            i = i + 1
        end
    
        return tostring(output_view)
    end
    
    return p