Difference between revisions of "Module:3D Viewer/sandbox2"

From Team Fortress Wiki
Jump to: navigation, search
m (Darkid moved page User:Module:3D Viewer/sandbox2 to Module:3D Viewer/sandbox2: If a ~staff could remove the redirect. Sorry, being stupid.)
(Hyphens are not supported for variable names.)
Line 102: Line 102:
 
     local i = 0
 
     local i = 0
 
     while utils.processArg(args['3d-image-' .. i]) ~= '' and colored ~= 1 do
 
     while utils.processArg(args['3d-image-' .. i]) ~= '' and colored ~= 1 do
         local image-postfix = ' 3D.jpg'
+
         local image_postfix = ' 3D.jpg'
 
         if colored == 1 then
 
         if colored == 1 then
 
             i = i - 1
 
             i = i - 1
 
             colored = 0
 
             colored = 0
             image-postfix = ' BLU 3D.jpg'
+
             image_postfix = ' BLU 3D.jpg'
 +
        end
 
         local image_n = utils.processArg(args['3d-image-' .. i])
 
         local image_n = utils.processArg(args['3d-image-' .. i])
 
         local button_n = utils.processArg(args['3d-button-' .. i])
 
         local button_n = utils.processArg(args['3d-button-' .. i])
 
         local button_class = button_classes[button_n]
 
         local button_class = button_classes[button_n]
 
         local viewname_n = utils.processArg(args['3d-viewname-' .. i])
 
         local viewname_n = utils.processArg(args['3d-viewname-' .. i])
         if colored == 1 then
+
         if colored == 1 then -- This block resets the iterator after loading all the details from the previous args.
 
             i = i + 1
 
             i = i + 1
         if colored == 0 then
+
        end
            if button_class == 'colored' then
+
         if colored == 0 and button_class == 'colored' then
                colored = 1
+
            colored = 1
                image-postfix = ' RED 3D.jpg'
+
            image_postfix = ' RED 3D.jpg'
 +
        end
 
          
 
          
 
         if image_n ~= '' then
 
         if image_n ~= '' then

Revision as of 06:24, 6 September 2014

local p = {}

local utils = require('Module:Utils') local HtmlBuilder = require('Module:HtmlBuilder')

function p.viewer(frame)

   local args = utils.get_args(frame)
   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) .. '')
   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 .. ''))
           span_image_map_n = output_view
               .tag('span')
               .addClass('viewer-3d-map-' .. i)
               .wikitext(utils.expandWikitext('File:' .. image n .. ''))
       end
   end
   local viewer_3d_frame = output_view
       .tag('div')
       .addClass('viewer-3d-frame')
   local switch_to_2d = output_view
       .tag('div')
       .attr('id', 'switch-to-2d')
   return tostring(output_view)

end

function p.viewer_new(frame)

   local args = utils.get_args(frame)
   
   -- button classes mapping
   local button_classes = {
       red = 'view-selector-red',
       blu = 'view-selector-blu',
       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 startframe = args['3d-startframe'] or utils.expandWikitext('{{File:' .. utils.processArg(args['3d-image-0']) .. '|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('id', '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']
   elseif args['team-colors'] == 'yes' then
       image_2d = 'RED ' .. mw.title.getCurrentTitle().baseText .. '.png'
   else
       image_2d = mw.title.getCurrentTitle().baseText .. '.png'
   end
   local viewer_2d_frame = output_view
       .tag('div')

.wikitext(utils.expandWikitext('

'))

   -- row button counter for half width buttons
   local current_row_count = 0
   local colored = 0
   local i = 0
   while utils.processArg(args['3d-image-' .. i]) ~=  and colored ~= 1 do
       local image_postfix = ' 3D.jpg'
       if colored == 1 then
           i = i - 1
           colored = 0
           image_postfix = ' BLU 3D.jpg'
       end
       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 colored == 1 then -- This block resets the iterator after loading all the details from the previous args.
           i = i + 1
       end
       if colored == 0 and button_class == 'colored' then
           colored = 1
           image_postfix = ' RED 3D.jpg'
       end
       
       if image_n ~=  then
           span_image_url_n = viewer_container
               .tag('span')
               .addClass('viewer-3d-url-' .. i)
               .wikitext(utils.expandWikitext('File:' .. image n .. image-postfix .. ''))
           span_image_map_n = viewer_container
               .tag('span')
               .addClass('viewer-3d-map-' .. i)
               .wikitext(utils.expandWikitext('File:' .. image n .. image-postfix .. ''))
           -- 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
           button_class = button_class .. ' selector-' .. i
           
           li_button_n = buttons_container
               .tag('li')
               .addClass(button_class)
               .wikitext(utils.expandWikitext('' .. viewname_n .. ''))
       end
       i = i + 1
   end
   return tostring(output_view)

end

return p