Animal Crossing: Pocket Camp Wiki
Advertisement

Documentation for this module may be created at Module:GulliverTable/doc

local util = require('Module:Util')
local p = {}
local cargo = mw.ext.cargo

function p._gulliverFurnitureTable(direction)
  -- Cargo Query
  local themes = getGulliverThemesForQuery(direction)
  local content = ''

  for key,theme in util.sortedPairs( themes ) do
    local tables = 'Furniture'
    local queryFields = "_pageName,Image,Name,Theme,GulliverPoint,MaterialCost,NumBells,CraftTime,Obtain"
    local queryArgs = {
      groupBy = '_pageName',
      limit = '1000',
      where = 'GulliverPoint != "N/A" AND Theme="' .. theme .. '"',
    }
    local furnitureQueryResult = cargo.query(tables, queryFields, queryArgs)

    local tables = 'Clothing'
    local queryFields = "_pageName,Image,Name,Theme,GulliverPoint,MaterialCost,NumBells,CraftTime,Obtain"
    local queryArgs = {
      groupBy = '_pageName',
      limit = '1000',
      where = 'GulliverPoint != "N/A" AND Theme = "' .. theme .. '"',
    }
    local clothingQueryResult = cargo.query(tables, queryFields, queryArgs)

    -- Check if we got results for the query
    if furnitureQueryResult == nil then
        return "(no values)"
    end

    if clothingQueryResult == nil then
        return "(no values)"
    end

    content = content .. '<h2>' .. theme .. '</h2>\n'

    -- Initialize the table
    local tbl = mw.html.create('table')
        :addClass('wikitable default sortable')
        :css('text-align','center')
        :css('width','100%')

    -- Table headers
    tbl:tag('th')
       :wikitext('Icon')       
       :addClass('unsortable')
       :css('width', '75px')
    tbl:tag('th')
       :wikitext('Name')
       :css('width', '15%')
    tbl:tag('th')
       :wikitext('Theme')
       :css('width', '15%')
    tbl:tag('th')
       :wikitext('Gulliver Point')
       :css('width', '15%')
       :attr('data-sort-type', 'number')
    tbl:tag('th')
       :wikitext('Material Cost')
       :css('width', '18%')
    tbl:tag('th')
       :wikitext('Bells')
       :css('width', '9%')
    tbl:tag('th')
       :wikitext('Craft Time')
       :css('width', '10%')
    tbl:tag('th')
       :wikitext('Obtain')
       :css('width', '18%')

    if type( furnitureQueryResult ) == "table" then
      -- Go through all the furniturees in the query result
      for key,furniture in util.sortedPairs( furnitureQueryResult ) do
        tbl = addGulliverTableRow(tbl, furniture)
      end
    end

    if type( clothingQueryResult ) == "table" then
      -- Go through all the clothing in the query result
      for key,clothing in util.sortedPairs( clothingQueryResult ) do
        tbl = addGulliverTableRow(tbl, clothing)
      end
    end

    content = content .. tostring(tbl) .. '\n'
  end

  return tostring(content)
end

-- Returns the query with the proper themes for the given direction
-- @param direction North / South / East / West
-- @return table All the themes for given direction
function getGulliverThemesForQuery(direction)
  if direction == "North" then
    return { [0] = "Natural", [1] = "Hip" }
  elseif direction == "East" then
    return { [0] = "Cute", [1] = "Modern", [2] = "Harmonious" }
  elseif direction == "West" then
    return { [0] = "Sporty", [1] = "Rustic", [2] = "Civic" }
  elseif direction == "South" then
    return { [0] = "Elegant", [1] = "Cool", [2] = "Historical" }
  end

  return {}
end

-- Adds a row to the Gulliver table
-- @param tbl The table the row will be added to
-- @param item Item and its information that will be added to the table
-- @return tbl The table with the row added
function addGulliverTableRow(tbl, item)
  local tr = tbl:tag('tr')

  -- Icon
  tr:tag('td')
    :wikitext( '[[File:' .. item.Image .. '.png|50px|link=]]' )
    
  -- Furniture Name
  tr:tag('td')
    :wikitext( '[[' .. item._pageName .. '|' .. item.Name .. ']]' )
    
  -- Theme
  tr:tag('td')
    :wikitext( '[[File:' .. item.Theme .. ' Banner.png|144px|link=]]<div style="display:none;">' .. item.Theme .. '</div>' )
  
  -- Gulliver Point
  tr:tag('td')
    :wikitext( item.GulliverPoint )
  
  -- Material Cost
  tr:tag('td')
    :wikitext( item.MaterialCost )
  
  -- Bells
  tr:tag('td')
    :wikitext( item.NumBells )
  
  -- Craft Time
  tr:tag('td')
    :wikitext( item.CraftTime )

  -- Obtain
  tr:tag('td')
    :wikitext( item.Obtain )

  return tbl
end
    
function p.gulliverFurnitureTable(frame)
    return p._gulliverFurnitureTable(frame.args[1])
end

return p
Advertisement