Module:HousingTable: Difference between revisions

From Eco - English Wiki
[unchecked revision][unchecked revision]
No edit summary
No edit summary
Line 11: Line 11:
<thead><tr>
<thead><tr>
<th class="headerSort" tabindex="0" role="columnheader button" title="Sort ascending">Item</th>
<th class="headerSort" tabindex="0" role="columnheader button" title="Sort ascending">Item</th>
<th class="headerSort" tabindex="0" role="columnheader button" title="Sort ascending">Room</th>
<th class="headerSort" tabindex="0" role="columnheader button" title="Sort ascending">Type</th>
<th class="headerSort" tabindex="0" role="columnheader button" title="Sort ascending">Type</th>
<th class="headerSort" tabindex="0" role="columnheader button" title="Sort ascending">Value</th>
<th class="headerSort" tabindex="0" role="columnheader button" title="Sort ascending">Value</th>
Line 21: Line 22:
   for itemName, item in pairs(ItemData.items) do
   for itemName, item in pairs(ItemData.items) do
   if item.roomCategory and item.furnitureType and (args.category == nil or args.category == item.roomCategory) and (args.type == nil or args.type == item.furnitureType) then
   if item.roomCategory and item.furnitureType and (args.category == nil or args.category == item.roomCategory) and (args.type == nil or args.type == item.furnitureType) then
   table.insert(items, {item=itemName, type=item.furnitureType, value=item.skillValue, depreciation=item.repeatsDepreciation, dimensions=item.footprint})
   table.insert(items, {item=itemName, room=item.roomCategory, type=item.furnitureType, value=item.skillValue, depreciation=item.repeatsDepreciation, dimensions=item.footprint})
   end
   end
   end
   end
Line 28: Line 29:


   for _, item in pairs(items) do
   for _, item in pairs(items) do
   returnStr = returnStr .. '<tr><td>[[' .. item.item .. ']]</td><td>' .. item.type .. '</td><td>' .. item.value .. '</td><td>' .. item.depreciation .. '</td><td>' .. item.dimensions .. '</td></tr>'
   returnStr = returnStr .. '<tr><td>[[' .. item.item .. ']]</td><td>' .. item.room.. '</td><td>' .. item.type .. '</td><td>' .. item.value .. '</td><td>' .. item.depreciation .. '</td><td>' .. item.dimensions .. '</td></tr>'
   end
   end


Line 36: Line 37:


function compareItems(a,b)
function compareItems(a,b)
   if a.type == b.type then
   if a.room == b.room then
    return a.item < b.item
    if a.type == b.type then
      return a.item < b.item
    else
      return a.type < b.type
    end
   else
   else
     return a.type < b.type
     return a.room < b.room
   end
   end
end
end


return p
return p

Revision as of 02:30, 25 February 2021

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

local p = {}

local Utils = require('Module:Utils')

function p.table(frame)
	local args = Utils.normaliseArgs(frame)

  local ItemData = mw.loadData("Module:ItemData")

  local returnStr = [[<table class="wikitable sortable jquery-tablesorter">
<thead><tr>
<th class="headerSort" tabindex="0" role="columnheader button" title="Sort ascending">Item</th>
<th class="headerSort" tabindex="0" role="columnheader button" title="Sort ascending">Room</th>
<th class="headerSort" tabindex="0" role="columnheader button" title="Sort ascending">Type</th>
<th class="headerSort" tabindex="0" role="columnheader button" title="Sort ascending">Value</th>
<th class="headerSort" tabindex="0" role="columnheader button" title="Sort ascending">Dim. Return %</th>
<th class="headerSort" tabindex="0" role="columnheader button" title="Sort ascending">Dimensions</th>
</tr></thead><tbody>]]

	local items = {}

  for itemName, item in pairs(ItemData.items) do
  	if item.roomCategory and item.furnitureType and (args.category == nil or args.category == item.roomCategory) and (args.type == nil or args.type == item.furnitureType) then
  		table.insert(items, {item=itemName, room=item.roomCategory, type=item.furnitureType, value=item.skillValue, depreciation=item.repeatsDepreciation, dimensions=item.footprint})
  	end
  end

  table.sort(items, compareItems)

  for _, item in pairs(items) do
  	returnStr = returnStr .. '<tr><td>[[' .. item.item .. ']]</td><td>' .. item.room.. '</td><td>' .. item.type .. '</td><td>' .. item.value .. '</td><td>' .. item.depreciation .. '</td><td>' .. item.dimensions .. '</td></tr>'
  end

  return returnStr .. '</tbody></table>'

end

function compareItems(a,b)
  if a.room == b.room then
    if a.type == b.type then
      return a.item < b.item
    else
      return a.type < b.type
    end
  else
    return a.room < b.room
  end
end

return p