Anonymous

Module:Township: Difference between revisions

From Melvor Idle
Update for v1.3
(Fix township building sticky header and add cell borders)
(Update for v1.3)
Line 5: Line 5:
local Shop = require('Module:Shop')
local Shop = require('Module:Shop')
local GameData = require('Module:GameData')
local GameData = require('Module:GameData')
local Constants = require('Module:Constants')
local Modifiers = require('Module:Modifiers')
local Num = require('Module:Number')
local Num = require('Module:Number')


Line 190: Line 190:
-- Modifiers
-- Modifiers
if includeMods and building.modifiers ~= nil then
if includeMods and building.modifiers ~= nil then
table.insert(resultPart, Constants.getModifiersText(building.modifiers))
table.insert(resultPart, Modifiers.getModifiersText(building.modifiers))
end
end


Line 302: Line 302:
table.insert(resultPart, '<br/>Requires ' .. reqs)
table.insert(resultPart, '<br/>Requires ' .. reqs)
end
end
table.insert(resultPart, '\n| ' .. Constants.getModifiersText(season.modifiers))
table.insert(resultPart, '\n| ' .. Modifiers.getModifiersText(season.modifiers))
end
end
table.insert(resultPart, '\n|}')
table.insert(resultPart, '\n|}')
Line 439: Line 439:
local providesText = p._getBuildingBenefitText(building, biomeID)
local providesText = p._getBuildingBenefitText(building, biomeID)
if building.modifiers ~= nil then
if building.modifiers ~= nil then
local modText = Constants.getModifiersText(building.modifiers)
local modText = Modifiers.getModifiersText(building.modifiers)
if providesText == nil then
if providesText == nil then
providesText = modText
providesText = modText
Line 470: Line 470:
if itemDesc == nil then
if itemDesc == nil then
if item.modifiers ~= nil then
if item.modifiers ~= nil then
itemDesc = Constants.getModifiersText(item.modifiers, false, true)
itemDesc = Modifiers.getModifiersText(item.modifiers, false, true)
else
else
itemDesc = ''
itemDesc = ''
Line 533: Line 533:
table.insert(ret, getCheckpointCell(0))
table.insert(ret, getCheckpointCell(0))
for _, worship in ipairs(worships) do
for _, worship in ipairs(worships) do
table.insert(ret, '\n| ' .. Constants.getModifiersText(worship.modifiers))
table.insert(ret, '\n| ' .. Modifiers.getModifiersText(worship.modifiers))
end
end


Line 540: Line 540:
table.insert(ret, getCheckpointCell(checkpoint))
table.insert(ret, getCheckpointCell(checkpoint))
for _, worship in ipairs(worships) do
for _, worship in ipairs(worships) do
table.insert(ret, '\n| ' .. Constants.getModifiersText(worship.checkpoints[i]))
table.insert(ret, '\n| ' .. Modifiers.getModifiersText(worship.checkpoints[i]))
end
end
end
end


-- Total sum
-- Total sum
-- TODO Needs fixing, no function currently for aggregating modifiers
--[==[
table.insert(ret, '\n|-\n!Total')
table.insert(ret, '\n|-\n!Total')
for _, worship in ipairs(worships) do
for _, worship in ipairs(worships) do
Line 563: Line 565:
end
end
end
end
table.insert(ret, '\n|' .. Constants.getModifiersText(modifiers))
table.insert(ret, '\n|' .. Modifiers.getModifiersText(modifiers))
end
end
--]==]
table.insert(ret, '\n|}')
table.insert(ret, '\n|}')


Line 869: Line 872:
local rewards = {}
local rewards = {}
local rewardsVariableQty = {}
local rewardsVariableQty = {}
if task.rewards.gp > 0 and not isDailyTask then
if task.rewards.currency ~= nil then
table.insert(rewards, Icons.GP(task.rewards.gp))
for _, currReward in ipairs(task.rewards.currency) do
end
if isDailyTask then
if task.rewards.slayerCoins > 0 then
table.insert(rewardsVariableQty, Icons._Currency(currReward.id))
if isDailyTask then
else
table.insert(rewardsVariableQty, Icons.SC())
table.insert(rewards, Icons._Currency(currReward.id, currReward.qty))
else
end
table.insert(rewards, Icons.SC(task.rewards.slayerCoins))
end
end
end
end
Line 909: Line 911:
function p.getTaskTable(frame)
function p.getTaskTable(frame)
local category = frame.args ~= nil and frame.args[1] or frame
local category = frame.args ~= nil and frame.args[1] or frame
local categoryData = GameData.getEntityByID(Township.taskCategories, category)
local categoryData = GameData.getEntityByName(Township.taskCategories, category)
local taskData, categoryName, isDailyTask = nil, nil, false
local taskData, categoryName, isDailyTask = nil, nil, false
if category == 'Daily' then
if category == 'Daily' then
Line 938: Line 940:
for _, task in ipairs(taskData) do
for _, task in ipairs(taskData) do
-- Filter out other categories
-- Filter out other categories
if task.category == category then
local categoryID, categoryNS, categoryLocalID = '', '', ''
if categoryData ~= nil then
categoryID = categoryData.id
categoryNS, categoryLocalID = Shared.getLocalID(categoryID)
end
if isDailyTask or task.category == categoryID or task.category == categoryLocalID then
taskcount = taskcount + 1
taskcount = taskcount + 1
local title = categoryName .. ' ' .. taskcount
local title = categoryName .. ' ' .. taskcount
Line 1,018: Line 1,025:
table.insert(ret, '\n!Rewards')
table.insert(ret, '\n!Rewards')
for _, task in ipairs(tasks) do
for _, task in ipairs(tasks) do
local categoryname = GameData.getEntityByID(Township.taskCategories, task.category).name
-- Some categories have a local ID, resolve this before looking up the task category
local taskNS, taskLocalID = Shared.getLocalID(task.id)
local catID = Shared.getNamespacedID(taskNS,  task.category)
local categoryname = GameData.getEntityByID(Township.taskCategories, catID).name
local title = '[[Township/Tasks#'..categoryname..'|'..categoryname..']]'
local title = '[[Township/Tasks#'..categoryname..'|'..categoryname..']]'
table.insert(ret, p._getTaskRow(title, task, false))
table.insert(ret, p._getTaskRow(title, task, false))