Module:HousingTable: Difference between revisions

From Eco - English Wiki
[unchecked revision][checked revision]
m (Avaren moved page Module:TaggedItemTable to Module:HousingTable without leaving a redirect)
No edit summary
 
(15 intermediate revisions by 2 users not shown)
Line 2: Line 2:


local Utils = require('Module:Utils')
local Utils = require('Module:Utils')
local ItemUtils = require('Module:UtilsItemTables')
local L = require('Module:Localization')
local HEADER = [[<table class="wikitable sortable jquery-tablesorter">
<tr>
<th class="headerSort" tabindex="0" role="columnheader button" title="Sort ascending">%s</th>
<th class="headerSort" tabindex="0" role="columnheader button" title="Sort ascending">%s</th>
<th class="headerSort" tabindex="0" role="columnheader button" title="Sort ascending">%s</th>
<th class="headerSort" tabindex="0" role="columnheader button" title="Sort ascending">%s</th>
<th class="headerSort" tabindex="0" role="columnheader button" title="Sort ascending">%s</th>
<th class="headerSort" tabindex="0" role="columnheader button" title="Sort ascending">%s</th>
</tr>]]
local TIER_HEADER = [[<table class="wikitable sortable jquery-tablesorter">
<tr>
<th class="headerSort" tabindex="0" role="columnheader button" title="Sort ascending">%s</th>
<th class="headerSort" tabindex="0" role="columnheader button" title="Sort ascending">%s</th>
</tr>]]


function p.table(frame)
function p.table(frame)
local args = Utils.normaliseArgs(frame)
    local args = Utils.normaliseArgs(frame)
 
    local ItemData = mw.loadData("Module:ItemData")
 
    local returnStr = string.format(HEADER, L.t('Item'), L.t('Room'), L.t('Type'), L.t('Value'), L.t('Dim. Return %'), L.t('Dimensions (X,Y,Z)'))
 
    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 * 100 .. '%</td><td>' .. ItemUtils.formatFootprintDimensions(item.dimensions) .. '</td></tr>'
    end
 
    return returnStr .. '</table>'
 
end
 
function p.blockTiers(frame)
    local args = Utils.normaliseArgs(frame)
 
    local ItemData = mw.loadData("Module:ItemData")
 
    local returnStr = string.format(TIER_HEADER, L.t('Block'), L.t('Tier'))
 
    local items = {}


if args.category == nil and args.type == nil then
    for itemName, item in pairs(ItemData.items) do
return 'category or type are required arguments'
        if item.group == 'Blocks' and item.materialTier ~= nil then
end
            table.insert(items, { item = itemName, tier = item.materialTier })
        end
    end


  local ItemData = mw.loadData("Module:ItemData")
    table.sort(items, compareTiers)


  local returnStr = [[<table class="wikitable sortable jquery-tablesorter">
    for _, item in pairs(items) do
<thead><tr>
        returnStr = returnStr .. '<tr><td>[[' .. item.item .. ']]</td><td>' .. item.tier .. '</td></tr>'
<th class="headerSort" tabindex="0" role="columnheader button" title="Sort ascending">Item</th>
    end
<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>]]


  for itemName, item in pairs(ItemData.items) do
    return returnStr .. '</table>'
  if (args.category == nil or args.category == item.roomCategory) and (args.type == nil or args.type == item.furnitureType) then
end
  mw.log(itemName)
returnStr = returnStr .. '<tr><td>' .. itemName .. '</td><td>' .. item.furnitureType .. '</td><td>' .. item.skillValue .. '</td><td>' .. item.repeatsDepreciation .. '</td><td>' .. item.footprint .. '</td></tr>'
  end
  end


  return returnStr .. '</tbody><tfoot></tfoot></table>'
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


function compareTiers(a, b)
    if a.tier == b.tier then
        return a.item < b.item
    else
        return a.tier < b.tier
    end
end
end


return p
return p

Latest revision as of 22:27, 30 December 2023

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

local p = {}

local Utils = require('Module:Utils')
local ItemUtils = require('Module:UtilsItemTables')
local L = require('Module:Localization')

local HEADER = [[<table class="wikitable sortable jquery-tablesorter">
<tr>
<th class="headerSort" tabindex="0" role="columnheader button" title="Sort ascending">%s</th>
<th class="headerSort" tabindex="0" role="columnheader button" title="Sort ascending">%s</th>
<th class="headerSort" tabindex="0" role="columnheader button" title="Sort ascending">%s</th>
<th class="headerSort" tabindex="0" role="columnheader button" title="Sort ascending">%s</th>
<th class="headerSort" tabindex="0" role="columnheader button" title="Sort ascending">%s</th>
<th class="headerSort" tabindex="0" role="columnheader button" title="Sort ascending">%s</th>
</tr>]]

local TIER_HEADER = [[<table class="wikitable sortable jquery-tablesorter">
<tr>
<th class="headerSort" tabindex="0" role="columnheader button" title="Sort ascending">%s</th>
<th class="headerSort" tabindex="0" role="columnheader button" title="Sort ascending">%s</th>
</tr>]]

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

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

    local returnStr = string.format(HEADER, L.t('Item'), L.t('Room'), L.t('Type'), L.t('Value'), L.t('Dim. Return %'), L.t('Dimensions (X,Y,Z)'))

    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 * 100 .. '%</td><td>' .. ItemUtils.formatFootprintDimensions(item.dimensions) .. '</td></tr>'
    end

    return returnStr .. '</table>'

end

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

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

    local returnStr = string.format(TIER_HEADER, L.t('Block'), L.t('Tier'))

    local items = {}

    for itemName, item in pairs(ItemData.items) do
        if item.group == 'Blocks' and item.materialTier ~= nil then
            table.insert(items, { item = itemName, tier = item.materialTier })
        end
    end

    table.sort(items, compareTiers)

    for _, item in pairs(items) do
        returnStr = returnStr .. '<tr><td>[[' .. item.item .. ']]</td><td>' .. item.tier .. '</td></tr>'
    end

    return returnStr .. '</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

function compareTiers(a, b)
    if a.tier == b.tier then
        return a.item < b.item
    else
        return a.tier < b.tier
    end
end

return p