Module:ItemsTable: Difference between revisions

From Melvor Idle
(tweaked the description to reflect how it works)
No edit summary
 
(15 intermediate revisions by 3 users not shown)
Line 1: Line 1:
-- this module generates [[Template:ItemsTable]] 200 lines at a time.
-- this module generates [[Template:ItemsTable]] 125 lines at a time.
-- run p.getItemsTableAlt() in debug and copy the result to [[Template:ItemsTable]] after an update that adds new items.
-- run p.getItemsTableAlt() in debug and copy the result to [[Template:ItemsTable]] after an update that adds new items.
--[=[
p.getItemsTableAlt(nil, 60)
--]=]


local p = {}
local p = {}


local Shared = require('Module:Shared')
local Shared = require('Module:Shared')
local ItemData = mw.loadData('Module:Items/data')
local GameData = require('Module:GameData')
local Items = require('Module:Items')
local Items = require('Module:Items')
local Icons = require('Module:Icons')
local Icons = require('Module:Icons')
Line 11: Line 14:
local UseTables = require('Module:Items/UseTables')
local UseTables = require('Module:Items/UseTables')


local itemCount = Shared.tableCount(ItemData.Items) - 1
local itemCount = Shared.tableCount(GameData.rawData.items) - 1


function p.getItemsTable(frame)
function p.getItemsTable(frame)
   local itemList = {}
   local itemList = {}
   local i = 0
   for i, item in ipairs(GameData.rawData.items) do
  while i < itemCount do
    local item = Items.getItemByID(i)
     table.insert(itemList, '\r\n|-\r\n|')
     table.insert(itemList, '\r\n|-\r\n|')
     table.insert(itemList, UseTables.getItemUses(item.name))
     table.insert(itemList, UseTables.getItemUses(item.name))
    i = i + 1
   end
   end
   return table.concat(itemList)
   return table.concat(itemList)
Line 26: Line 26:


--Alternate version that has everything still
--Alternate version that has everything still
function p.getItemsTableAlt(startID)
function p.getItemsTableAlt(fromItemID, rows)
   local itemList = {}
   local itemList = {}
   local i = startID
   local rowCount = 0
   local iend = i + 200
  local genRows = fromItemID == nil
   while i < iend do
   local lastItemID = nil
     local item = Items.getItemByID(i)
   for i, item in ipairs(GameData.rawData.items) do
    if item == nil then
     if not genRows then
       break
      genRows = fromItemID == nil or item.id == fromItemID
    elseif genRows then
      rowCount = rowCount + 1
      if rowCount > rows then
        break
      end
      lastItemID = item.id
      local iCat = item.category ~= nil and item.category or ''
      local itemRow = {'\n|-'}
      table.insert(itemRow, '\n|'..Icons.Icon({item.name, type='item', notext=true, size=50}))
      table.insert(itemRow, '||'..Icons.Icon({item.name, type='item', noicon=true})..'||'..item.id..'||'..iCat..'||'..item.type)
      table.insert(itemRow, '|| '..Items._getItemStat(item, 'completionReq'))
      table.insert(itemRow, '||data-sort-value="'..math.floor(item.sellsFor)..'"|'..Icons._Currency('GP', math.floor(item.sellsFor)))
      table.insert(itemRow, '||style="text-align:right;"|'..SourceTables._getItemSources(item))
      table.insert(itemRow, '||style="text-align:right;"|'..UseTables._getItemUses(item, false))
       table.insert(itemList, table.concat(itemRow))
     end
     end
    local itemRow = '\r\n|-'
    itemRow = itemRow..'\r\n|'..Icons.Icon({item.name, type='item', notext=true, size=50})
    itemRow = itemRow..'||'..item.name..'||'..(i)..'||'..item.category..'||'..item.type
    itemRow = itemRow..'||data-sort-value="'..item.sellsFor..'"|'..Icons.GP(item.sellsFor)
    itemRow = itemRow..'||style="text-align:right;"|'..SourceTables._getItemSources(item)
    itemRow = itemRow..'||style="text-align:right;"|'..UseTables._getItemUses(item, false)
    table.insert(itemList, itemRow)
    i = i + 1
   end
   end
   return table.concat(itemList, '')
   mw.log(table.concat(itemList, ''))
  mw.log('\n------------------\nLast item ID: ' .. (lastItemID or 'nil'))
end
end


return p
return p

Latest revision as of 17:58, 22 June 2024

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

-- this module generates [[Template:ItemsTable]] 125 lines at a time.
-- run p.getItemsTableAlt() in debug and copy the result to [[Template:ItemsTable]] after an update that adds new items.
--[=[
	p.getItemsTableAlt(nil, 60)
--]=]

local p = {}

local Shared = require('Module:Shared')
local GameData = require('Module:GameData')
local Items = require('Module:Items')
local Icons = require('Module:Icons')
local SourceTables = require('Module:Items/SourceTables')
local UseTables = require('Module:Items/UseTables')

local itemCount = Shared.tableCount(GameData.rawData.items) - 1

function p.getItemsTable(frame)
  local itemList = {}
  for i, item in ipairs(GameData.rawData.items) do
    table.insert(itemList, '\r\n|-\r\n|')
    table.insert(itemList, UseTables.getItemUses(item.name))
  end
  return table.concat(itemList)
end

--Alternate version that has everything still
function p.getItemsTableAlt(fromItemID, rows)
  local itemList = {}
  local rowCount = 0
  local genRows = fromItemID == nil
  local lastItemID = nil
  for i, item in ipairs(GameData.rawData.items) do
    if not genRows then
      genRows = fromItemID == nil or item.id == fromItemID
    elseif genRows then
      rowCount = rowCount + 1
      if rowCount > rows then
        break
      end
      lastItemID = item.id
      local iCat = item.category ~= nil and item.category or ''
      local itemRow = {'\n|-'}
      table.insert(itemRow, '\n|'..Icons.Icon({item.name, type='item', notext=true, size=50}))
      table.insert(itemRow, '||'..Icons.Icon({item.name, type='item', noicon=true})..'||'..item.id..'||'..iCat..'||'..item.type)
      table.insert(itemRow, '|| '..Items._getItemStat(item, 'completionReq'))
      table.insert(itemRow, '||data-sort-value="'..math.floor(item.sellsFor)..'"|'..Icons._Currency('GP', math.floor(item.sellsFor)))
      table.insert(itemRow, '||style="text-align:right;"|'..SourceTables._getItemSources(item))
      table.insert(itemRow, '||style="text-align:right;"|'..UseTables._getItemUses(item, false))
      table.insert(itemList, table.concat(itemRow))
    end
  end
  mw.log(table.concat(itemList, ''))
  mw.log('\n------------------\nLast item ID: ' .. (lastItemID or 'nil'))
end

return p